Skip to content

Commit

Permalink
Update Followers and Following methods to incorporate pagination in t…
Browse files Browse the repository at this point in the history
…hem.

Update Followers and Following methods to incorporate pagination in them.
  • Loading branch information
Shreyaschorge authored Oct 30, 2023
2 parents c7e02fe + 3ff59e9 commit 9c9b888
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@neynar/nodejs-sdk",
"version": "0.3.1",
"version": "0.3.2",
"description": "SDK to interact with Neynar APIs (https://docs.neynar.com/)",
"main": "./build/index.js",
"types": "./build/index.d.ts",
Expand Down
54 changes: 44 additions & 10 deletions src/neynar-api/neynar-v1-api/neynar-api-v1-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,26 +342,60 @@ export class NeynarV1APIClient {
* See [Neynar documentation](https://docs.neynar.com/reference/followers-v1)
*
*/
public async fetchUserFollowers(
public async *fetchUserFollowers(
fid: number,
viewerFid?: number
): Promise<User[]> {
const response = await this.apis.follows.followers({ fid, viewerFid });
options?: { viewerFid?: number; pageSize?: number }
): AsyncGenerator<User, void, undefined> {
let cursor: string | undefined;

while (true) {
const response = await this.apis.follows.followers({
fid,
viewerFid: options?.viewerFid,
cursor: cursor,
limit: options?.pageSize,
});

return response.data.result.users;
// yield current page of users
yield* response.data.result.users;

// prep for next page
if (response.data.result.next.cursor === null) {
break;
}

cursor = response.data.result.next.cursor;
}
}

/**
* Get all users the specified user is following.
* See [Neynar documentation](https://docs.neynar.com/reference/following-v1)
*
*/
public async fetchUserFollowing(
public async *fetchUserFollowing(
fid: number,
viewerFid?: number
): Promise<User[]> {
const response = await this.apis.follows.following({ fid, viewerFid });
options?: { viewerFid?: number; pageSize?: number }
): AsyncGenerator<User, void, undefined> {
let cursor: string | undefined;

while (true) {
const response = await this.apis.follows.following({
fid,
viewerFid: options?.viewerFid,
cursor: cursor,
limit: options?.pageSize,
});

return response.data.result.users;
// yield current page of users
yield* response.data.result.users;

// prep for next page
if (response.data.result.next.cursor === null) {
break;
}

cursor = response.data.result.next.cursor;
}
}
}
96 changes: 92 additions & 4 deletions src/neynar-api/neynar-v1-api/openapi/apis/follows-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,16 @@ export const FollowsApiAxiosParamCreator = function (
* @summary Gets all followers for a given FID
* @param {number} fid FID of the user
* @param {number} [viewerFid] fid of the user viewing this information, needed for contextual information.
* @param {string} [cursor] Pagination cursor.
* @param {number} [limit] Number of results to retrieve (default 25, max 150)
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
followers: async (
fid: number,
viewerFid?: number,
cursor?: string,
limit?: number,
options: AxiosRequestConfig = {}
): Promise<RequestArgs> => {
// verify required parameter 'fid' is not null or undefined
Expand Down Expand Up @@ -95,6 +99,14 @@ export const FollowsApiAxiosParamCreator = function (
localVarQueryParameter["viewerFid"] = viewerFid;
}

if (cursor !== undefined) {
localVarQueryParameter["cursor"] = cursor;
}

if (limit !== undefined) {
localVarQueryParameter["limit"] = limit;
}

setSearchParams(localVarUrlObj, localVarQueryParameter);
let headersFromBaseOptions =
baseOptions && baseOptions.headers ? baseOptions.headers : {};
Expand All @@ -114,12 +126,16 @@ export const FollowsApiAxiosParamCreator = function (
* @summary Gets all following users of a FID
* @param {number} fid FID of the user
* @param {number} [viewerFid] fid of the user viewing this information, needed for contextual information.
* @param {string} [cursor] Pagination cursor.
* @param {number} [limit] Number of results to retrieve (default 25, max 150)
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
following: async (
fid: number,
viewerFid?: number,
cursor?: string,
limit?: number,
options: AxiosRequestConfig = {}
): Promise<RequestArgs> => {
// verify required parameter 'fid' is not null or undefined
Expand Down Expand Up @@ -155,6 +171,14 @@ export const FollowsApiAxiosParamCreator = function (
localVarQueryParameter["viewerFid"] = viewerFid;
}

if (cursor !== undefined) {
localVarQueryParameter["cursor"] = cursor;
}

if (limit !== undefined) {
localVarQueryParameter["limit"] = limit;
}

setSearchParams(localVarUrlObj, localVarQueryParameter);
let headersFromBaseOptions =
baseOptions && baseOptions.headers ? baseOptions.headers : {};
Expand Down Expand Up @@ -184,19 +208,25 @@ export const FollowsApiFp = function (configuration?: Configuration) {
* @summary Gets all followers for a given FID
* @param {number} fid FID of the user
* @param {number} [viewerFid] fid of the user viewing this information, needed for contextual information.
* @param {string} [cursor] Pagination cursor.
* @param {number} [limit] Number of results to retrieve (default 25, max 150)
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async followers(
fid: number,
viewerFid?: number,
cursor?: string,
limit?: number,
options?: AxiosRequestConfig
): Promise<
(axios?: AxiosInstance, basePath?: string) => AxiosPromise<FollowResponse>
> {
const localVarAxiosArgs = await localVarAxiosParamCreator.followers(
fid,
viewerFid,
cursor,
limit,
options
);
return createRequestFunction(
Expand All @@ -211,19 +241,25 @@ export const FollowsApiFp = function (configuration?: Configuration) {
* @summary Gets all following users of a FID
* @param {number} fid FID of the user
* @param {number} [viewerFid] fid of the user viewing this information, needed for contextual information.
* @param {string} [cursor] Pagination cursor.
* @param {number} [limit] Number of results to retrieve (default 25, max 150)
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async following(
fid: number,
viewerFid?: number,
cursor?: string,
limit?: number,
options?: AxiosRequestConfig
): Promise<
(axios?: AxiosInstance, basePath?: string) => AxiosPromise<FollowResponse>
> {
const localVarAxiosArgs = await localVarAxiosParamCreator.following(
fid,
viewerFid,
cursor,
limit,
options
);
return createRequestFunction(
Expand Down Expand Up @@ -259,7 +295,13 @@ export const FollowsApiFactory = function (
options?: AxiosRequestConfig
): AxiosPromise<FollowResponse> {
return localVarFp
.followers(requestParameters.fid, requestParameters.viewerFid, options)
.followers(
requestParameters.fid,
requestParameters.viewerFid,
requestParameters.cursor,
requestParameters.limit,
options
)
.then((request) => request(axios, basePath));
},
/**
Expand All @@ -274,7 +316,13 @@ export const FollowsApiFactory = function (
options?: AxiosRequestConfig
): AxiosPromise<FollowResponse> {
return localVarFp
.following(requestParameters.fid, requestParameters.viewerFid, options)
.following(
requestParameters.fid,
requestParameters.viewerFid,
requestParameters.cursor,
requestParameters.limit,
options
)
.then((request) => request(axios, basePath));
},
};
Expand All @@ -299,6 +347,20 @@ export interface FollowsApiFollowersRequest {
* @memberof FollowsApiFollowers
*/
readonly viewerFid?: number;

/**
* Pagination cursor.
* @type {string}
* @memberof FollowsApiFollowers
*/
readonly cursor?: string;

/**
* Number of results to retrieve (default 25, max 100)
* @type {number}
* @memberof FollowsApiFollowers
*/
readonly limit?: number;
}

/**
Expand All @@ -320,6 +382,20 @@ export interface FollowsApiFollowingRequest {
* @memberof FollowsApiFollowing
*/
readonly viewerFid?: number;

/**
* Pagination cursor.
* @type {string}
* @memberof FollowsApiFollowing
*/
readonly cursor?: string;

/**
* Number of results to retrieve (default 25, max 100)
* @type {number}
* @memberof FollowsApiFollowing
*/
readonly limit?: number;
}

/**
Expand All @@ -342,7 +418,13 @@ export class FollowsApi extends BaseAPI {
options?: AxiosRequestConfig
) {
return FollowsApiFp(this.configuration)
.followers(requestParameters.fid, requestParameters.viewerFid, options)
.followers(
requestParameters.fid,
requestParameters.viewerFid,
requestParameters.cursor,
requestParameters.limit,
options
)
.then((request) => request(this.axios, this.basePath));
}

Expand All @@ -359,7 +441,13 @@ export class FollowsApi extends BaseAPI {
options?: AxiosRequestConfig
) {
return FollowsApiFp(this.configuration)
.following(requestParameters.fid, requestParameters.viewerFid, options)
.following(
requestParameters.fid,
requestParameters.viewerFid,
requestParameters.cursor,
requestParameters.limit,
options
)
.then((request) => request(this.axios, this.basePath));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
// May contain unused imports in some cases
// @ts-ignore
import { FollowResponseUser } from './follow-response-user';
// May contain unused imports in some cases
// @ts-ignore
import { NextCursor } from './next-cursor';

/**
*
Expand All @@ -29,5 +32,11 @@ export interface FollowResponseResult {
* @memberof FollowResponseResult
*/
'users': Array<FollowResponseUser>;
/**
*
* @type {NextCursor}
* @memberof FollowResponseResult
*/
'next': NextCursor;
}

6 changes: 5 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,9 @@
"skipLibCheck": true /* Skip type checking all .d.ts files. */
},
"include": ["src/**/*"],
"exclude": ["src/oas/*"]
"exclude": [
"src/oas/*",
"src/neynar-api/neynar-v1-api/openapi-tmp/*",
"src/neynar-api/neynar-v2-api/openapi-tmp/*"
]
}

0 comments on commit 9c9b888

Please sign in to comment.