Skip to content

Commit

Permalink
Add fetchChannelNotificationsForUser method
Browse files Browse the repository at this point in the history
Add fetchChannelNotificationsForUser method
  • Loading branch information
Shreyaschorge authored Dec 5, 2023
2 parents 358ddb4 + cfbd89c commit 62b706d
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 9 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": "1.1.1",
"version": "1.2.0",
"description": "SDK to interact with Neynar APIs (https://docs.neynar.com/)",
"main": "./build/index.js",
"types": "./build/index.d.ts",
Expand Down
39 changes: 39 additions & 0 deletions src/neynar-api/neynar-api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1298,6 +1298,45 @@ export class NeynarAPIClient {
return await this.clients.v2.fetchAllNotifications(fid, options);
}

/**
* Retrieves a list of notifications for a user within specific channels. This method is useful for
* obtaining notifications related to user interactions within designated channels, identified by
* their parent URLs.
*
* @param {number} fid - The FID of the user whose channel notifications are being fetched.
* @param {Array<string>} parentUrls - An array of channel parent URLs.
* @param {Object} [options] - Optional parameters for the request.
* @param {number} [options.limit] - Number of results to retrieve (default 25, max 50).
* @param {string} [options.cursor] - Pagination cursor for the next set of results,
* omit this parameter for the initial request.
*
* @returns {Promise<NotificationsResponse>} A promise that resolves to a `NotificationsResponse` object,
* containing the channel-specific notifications for the user.
*
* @example
* // Example: Retrieve channel notifications for a user limit to 30 results
* client.fetchChannelNotificationsForUser(3, ['chain://eip155:1/erc721:0xd4498134211baad5846ce70ce04e7c4da78931cc', 'chain://eip155:7777777/erc721:0x5556efe18d87f132054fbd4ba9afc13ebb1b0594'],
* {
* limit: 30,
* // cursor: "nextPageCursor" // Omit this parameter for the initial request
* }).then(response => {
* console.log('Channel Notifications:', response);
* });
*
* For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/notifications).
*/
public async fetchChannelNotificationsForUser(
fid: number,
parentUrls: string[],
options?: { cursor?: string; limit?: number }
): Promise<NotificationsResponse> {
return await this.clients.v2.fetchChannelNotificationsForUser(
fid,
parentUrls,
options
);
}

// ------------ Follows ------------

/**
Expand Down
43 changes: 43 additions & 0 deletions src/neynar-api/v2/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,49 @@ export class NeynarV2APIClient {
return response.data;
}

/**
* Retrieves a list of notifications for a user within specific channels. This method is useful for
* obtaining notifications related to user interactions within designated channels, identified by
* their parent URLs.
*
* @param {number} fid - The FID of the user whose channel notifications are being fetched.
* @param {Array<string>} parentUrls - An array of channel parent URLs.
* @param {Object} [options] - Optional parameters for the request.
* @param {number} [options.limit] - Number of results to retrieve (default 25, max 50).
* @param {string} [options.cursor] - Pagination cursor for the next set of results,
* omit this parameter for the initial request.
*
* @returns {Promise<NotificationsResponse>} A promise that resolves to a `NotificationsResponse` object,
* containing the channel-specific notifications for the user.
*
* @example
* // Example: Retrieve channel notifications for a user limit to 30 results
* client.fetchChannelNotificationsForUser(3, ['chain://eip155:1/erc721:0xd4498134211baad5846ce70ce04e7c4da78931cc', 'chain://eip155:7777777/erc721:0x5556efe18d87f132054fbd4ba9afc13ebb1b0594'],
* {
* limit: 30,
* // cursor: "nextPageCursor" // Omit this parameter for the initial request.
* }).then(response => {
* console.log('Channel Notifications:', response);
* });
*
* For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/notifications).
*/
public async fetchChannelNotificationsForUser(
fid: number,
parentUrls: string[],
options?: { cursor?: string; limit?: number }
): Promise<NotificationsResponse> {
const _parentUrls = parentUrls.join(",");
const response = await this.apis.notifications.notificationsChannel(
this.apiKey,
fid,
_parentUrls,
options?.limit,
options?.cursor
);
return response.data;
}

// ------------ Follows ------------

/**
Expand Down
22 changes: 15 additions & 7 deletions src/neynar-api/v2/openapi-farcaster/apis/cast-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,11 @@ export const CastApiAxiosParamCreator = function (configuration?: Configuration)
* @summary Gets information about an array of casts
* @param {string} apiKey API key required for authentication.
* @param {string} casts Hashes of the cast to be retrived (Comma separated)
* @param {'trending' | 'likes' | 'recasts' | 'replies' | 'recent'} [sortType] Optional parameter to sort the casts based on different criteria
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
casts: async (apiKey: string, casts: string, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
casts: async (apiKey: string, casts: string, sortType?: 'trending' | 'likes' | 'recasts' | 'replies' | 'recent', options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
// verify required parameter 'apiKey' is not null or undefined
assertParamExists('casts', 'apiKey', apiKey)
// verify required parameter 'casts' is not null or undefined
Expand All @@ -123,6 +124,10 @@ export const CastApiAxiosParamCreator = function (configuration?: Configuration)
localVarQueryParameter['casts'] = casts;
}

if (sortType !== undefined) {
localVarQueryParameter['sort_type'] = sortType;
}

if (apiKey != null) {
localVarHeaderParameter['api_key'] = String(apiKey);
}
Expand Down Expand Up @@ -252,11 +257,12 @@ export const CastApiFp = function(configuration?: Configuration) {
* @summary Gets information about an array of casts
* @param {string} apiKey API key required for authentication.
* @param {string} casts Hashes of the cast to be retrived (Comma separated)
* @param {'trending' | 'likes' | 'recasts' | 'replies' | 'recent'} [sortType] Optional parameter to sort the casts based on different criteria
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async casts(apiKey: string, casts: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<CastsResponse>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.casts(apiKey, casts, options);
async casts(apiKey: string, casts: string, sortType?: 'trending' | 'likes' | 'recasts' | 'replies' | 'recent', options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<CastsResponse>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.casts(apiKey, casts, sortType, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
/**
Expand Down Expand Up @@ -310,11 +316,12 @@ export const CastApiFactory = function (configuration?: Configuration, basePath?
* @summary Gets information about an array of casts
* @param {string} apiKey API key required for authentication.
* @param {string} casts Hashes of the cast to be retrived (Comma separated)
* @param {'trending' | 'likes' | 'recasts' | 'replies' | 'recent'} [sortType] Optional parameter to sort the casts based on different criteria
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
casts(apiKey: string, casts: string, options?: any): AxiosPromise<CastsResponse> {
return localVarFp.casts(apiKey, casts, options).then((request) => request(axios, basePath));
casts(apiKey: string, casts: string, sortType?: 'trending' | 'likes' | 'recasts' | 'replies' | 'recent', options?: any): AxiosPromise<CastsResponse> {
return localVarFp.casts(apiKey, casts, sortType, options).then((request) => request(axios, basePath));
},
/**
* Delete an existing cast. \\ (In order to delete a cast `signer_uuid` must be approved)
Expand Down Expand Up @@ -367,12 +374,13 @@ export class CastApi extends BaseAPI {
* @summary Gets information about an array of casts
* @param {string} apiKey API key required for authentication.
* @param {string} casts Hashes of the cast to be retrived (Comma separated)
* @param {'trending' | 'likes' | 'recasts' | 'replies' | 'recent'} [sortType] Optional parameter to sort the casts based on different criteria
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof CastApi
*/
public casts(apiKey: string, casts: string, options?: AxiosRequestConfig) {
return CastApiFp(this.configuration).casts(apiKey, casts, options).then((request) => request(this.axios, this.basePath));
public casts(apiKey: string, casts: string, sortType?: 'trending' | 'likes' | 'recasts' | 'replies' | 'recent', options?: AxiosRequestConfig) {
return CastApiFp(this.configuration).casts(apiKey, casts, sortType, options).then((request) => request(this.axios, this.basePath));
}

/**
Expand Down
106 changes: 106 additions & 0 deletions src/neynar-api/v2/openapi-farcaster/apis/notifications-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,67 @@ export const NotificationsApiAxiosParamCreator = function (configuration?: Confi



setSearchParams(localVarUrlObj, localVarQueryParameter);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};

return {
url: toPathString(localVarUrlObj),
options: localVarRequestOptions,
};
},
/**
* Returns a list of notifications for a user in a specific channel
* @summary Retrieve notifications for a user for a given channel
* @param {string} apiKey API key required for authentication.
* @param {number} fid
* @param {string} parentUrls Comma separated channel parent_urls (find mappings here - https://github.com/neynarxyz/farcaster-channels/blob/main/warpcast.json)
* @param {number} [limit] Number of results to retrieve (default 25, max 50)
* @param {string} [cursor] Pagination cursor.
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
notificationsChannel: async (apiKey: string, fid: number, parentUrls: string, limit?: number, cursor?: string, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
// verify required parameter 'apiKey' is not null or undefined
assertParamExists('notificationsChannel', 'apiKey', apiKey)
// verify required parameter 'fid' is not null or undefined
assertParamExists('notificationsChannel', 'fid', fid)
// verify required parameter 'parentUrls' is not null or undefined
assertParamExists('notificationsChannel', 'parentUrls', parentUrls)
const localVarPath = `/farcaster/notifications/channel`;
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
let baseOptions;
if (configuration) {
baseOptions = configuration.baseOptions;
}

const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;

if (fid !== undefined) {
localVarQueryParameter['fid'] = fid;
}

if (parentUrls !== undefined) {
localVarQueryParameter['parent_urls'] = parentUrls;
}

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

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

if (apiKey != null) {
localVarHeaderParameter['api_key'] = String(apiKey);
}



setSearchParams(localVarUrlObj, localVarQueryParameter);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
Expand Down Expand Up @@ -109,6 +170,21 @@ export const NotificationsApiFp = function(configuration?: Configuration) {
const localVarAxiosArgs = await localVarAxiosParamCreator.notifications(apiKey, fid, limit, cursor, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
/**
* Returns a list of notifications for a user in a specific channel
* @summary Retrieve notifications for a user for a given channel
* @param {string} apiKey API key required for authentication.
* @param {number} fid
* @param {string} parentUrls Comma separated channel parent_urls (find mappings here - https://github.com/neynarxyz/farcaster-channels/blob/main/warpcast.json)
* @param {number} [limit] Number of results to retrieve (default 25, max 50)
* @param {string} [cursor] Pagination cursor.
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async notificationsChannel(apiKey: string, fid: number, parentUrls: string, limit?: number, cursor?: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<NotificationsResponse>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.notificationsChannel(apiKey, fid, parentUrls, limit, cursor, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
}
};

Expand All @@ -132,6 +208,20 @@ export const NotificationsApiFactory = function (configuration?: Configuration,
notifications(apiKey: string, fid: number, limit?: number, cursor?: string, options?: any): AxiosPromise<NotificationsResponse> {
return localVarFp.notifications(apiKey, fid, limit, cursor, options).then((request) => request(axios, basePath));
},
/**
* Returns a list of notifications for a user in a specific channel
* @summary Retrieve notifications for a user for a given channel
* @param {string} apiKey API key required for authentication.
* @param {number} fid
* @param {string} parentUrls Comma separated channel parent_urls (find mappings here - https://github.com/neynarxyz/farcaster-channels/blob/main/warpcast.json)
* @param {number} [limit] Number of results to retrieve (default 25, max 50)
* @param {string} [cursor] Pagination cursor.
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
notificationsChannel(apiKey: string, fid: number, parentUrls: string, limit?: number, cursor?: string, options?: any): AxiosPromise<NotificationsResponse> {
return localVarFp.notificationsChannel(apiKey, fid, parentUrls, limit, cursor, options).then((request) => request(axios, basePath));
},
};
};

Expand All @@ -156,4 +246,20 @@ export class NotificationsApi extends BaseAPI {
public notifications(apiKey: string, fid: number, limit?: number, cursor?: string, options?: AxiosRequestConfig) {
return NotificationsApiFp(this.configuration).notifications(apiKey, fid, limit, cursor, options).then((request) => request(this.axios, this.basePath));
}

/**
* Returns a list of notifications for a user in a specific channel
* @summary Retrieve notifications for a user for a given channel
* @param {string} apiKey API key required for authentication.
* @param {number} fid
* @param {string} parentUrls Comma separated channel parent_urls (find mappings here - https://github.com/neynarxyz/farcaster-channels/blob/main/warpcast.json)
* @param {number} [limit] Number of results to retrieve (default 25, max 50)
* @param {string} [cursor] Pagination cursor.
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof NotificationsApi
*/
public notificationsChannel(apiKey: string, fid: number, parentUrls: string, limit?: number, cursor?: string, options?: AxiosRequestConfig) {
return NotificationsApiFp(this.configuration).notificationsChannel(apiKey, fid, parentUrls, limit, cursor, options).then((request) => request(this.axios, this.basePath));
}
}
2 changes: 1 addition & 1 deletion src/oas
Submodule oas updated 1 files
+59 −0 src/v2/spec.yaml
Empty file removed test-sdk.ts
Empty file.

0 comments on commit 62b706d

Please sign in to comment.