From 8fa45bf9cce6b50897aa6efbbddd26bade117fea Mon Sep 17 00:00:00 2001 From: Shreyaschorge Date: Mon, 30 Oct 2023 19:48:35 +0530 Subject: [PATCH 1/2] Update methods for Follower and Following APIs for pagination --- .../neynar-v1-api/neynar-api-v1-client.ts | 54 +++++++++-- .../neynar-v1-api/openapi/apis/follows-api.ts | 96 ++++++++++++++++++- .../openapi/models/follow-response-result.ts | 9 ++ tsconfig.json | 6 +- 4 files changed, 150 insertions(+), 15 deletions(-) diff --git a/src/neynar-api/neynar-v1-api/neynar-api-v1-client.ts b/src/neynar-api/neynar-v1-api/neynar-api-v1-client.ts index 882f0d5c..e7ef526e 100644 --- a/src/neynar-api/neynar-v1-api/neynar-api-v1-client.ts +++ b/src/neynar-api/neynar-v1-api/neynar-api-v1-client.ts @@ -342,13 +342,30 @@ export class NeynarV1APIClient { * See [Neynar documentation](https://docs.neynar.com/reference/followers-v1) * */ - public async fetchUserFollowers( + public async *fetchUserFollowers( fid: number, - viewerFid?: number - ): Promise { - const response = await this.apis.follows.followers({ fid, viewerFid }); + options?: { viewerFid?: number; pageSize?: number } + ): AsyncGenerator { + 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; + } } /** @@ -356,12 +373,29 @@ export class NeynarV1APIClient { * See [Neynar documentation](https://docs.neynar.com/reference/following-v1) * */ - public async fetchUserFollowing( + public async *fetchUserFollowing( fid: number, - viewerFid?: number - ): Promise { - const response = await this.apis.follows.following({ fid, viewerFid }); + options?: { viewerFid?: number; pageSize?: number } + ): AsyncGenerator { + 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; + } } } diff --git a/src/neynar-api/neynar-v1-api/openapi/apis/follows-api.ts b/src/neynar-api/neynar-v1-api/openapi/apis/follows-api.ts index 0658621a..e41ec390 100644 --- a/src/neynar-api/neynar-v1-api/openapi/apis/follows-api.ts +++ b/src/neynar-api/neynar-v1-api/openapi/apis/follows-api.ts @@ -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 => { // verify required parameter 'fid' is not null or undefined @@ -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 : {}; @@ -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 => { // verify required parameter 'fid' is not null or undefined @@ -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 : {}; @@ -184,12 +208,16 @@ 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 @@ -197,6 +225,8 @@ export const FollowsApiFp = function (configuration?: Configuration) { const localVarAxiosArgs = await localVarAxiosParamCreator.followers( fid, viewerFid, + cursor, + limit, options ); return createRequestFunction( @@ -211,12 +241,16 @@ 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 @@ -224,6 +258,8 @@ export const FollowsApiFp = function (configuration?: Configuration) { const localVarAxiosArgs = await localVarAxiosParamCreator.following( fid, viewerFid, + cursor, + limit, options ); return createRequestFunction( @@ -259,7 +295,13 @@ export const FollowsApiFactory = function ( options?: AxiosRequestConfig ): AxiosPromise { return localVarFp - .followers(requestParameters.fid, requestParameters.viewerFid, options) + .followers( + requestParameters.fid, + requestParameters.viewerFid, + requestParameters.cursor, + requestParameters.limit, + options + ) .then((request) => request(axios, basePath)); }, /** @@ -274,7 +316,13 @@ export const FollowsApiFactory = function ( options?: AxiosRequestConfig ): AxiosPromise { return localVarFp - .following(requestParameters.fid, requestParameters.viewerFid, options) + .following( + requestParameters.fid, + requestParameters.viewerFid, + requestParameters.cursor, + requestParameters.limit, + options + ) .then((request) => request(axios, basePath)); }, }; @@ -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; } /** @@ -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; } /** @@ -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)); } @@ -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)); } } diff --git a/src/neynar-api/neynar-v1-api/openapi/models/follow-response-result.ts b/src/neynar-api/neynar-v1-api/openapi/models/follow-response-result.ts index ac5a1d08..d77bbd89 100644 --- a/src/neynar-api/neynar-v1-api/openapi/models/follow-response-result.ts +++ b/src/neynar-api/neynar-v1-api/openapi/models/follow-response-result.ts @@ -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'; /** * @@ -29,5 +32,11 @@ export interface FollowResponseResult { * @memberof FollowResponseResult */ 'users': Array; + /** + * + * @type {NextCursor} + * @memberof FollowResponseResult + */ + 'next': NextCursor; } diff --git a/tsconfig.json b/tsconfig.json index a586501c..1c46bdbe 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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/*" + ] } From 3ff59e9c0ca37c0007787d514c218332482a6a3c Mon Sep 17 00:00:00 2001 From: Shreyaschorge Date: Mon, 30 Oct 2023 19:50:02 +0530 Subject: [PATCH 2/2] Patch update: v0.3.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4e42273c..6816fd8d 100644 --- a/package.json +++ b/package.json @@ -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",