Skip to content

Commit

Permalink
Feature/add fetchTrendingChannels and fetchNotificationsByParentUrlFo…
Browse files Browse the repository at this point in the history
…rUser

Feature/add fetchTrendingChannels and fetchNotificationsByParentUrlForUser
  • Loading branch information
Shreyaschorge authored Jan 19, 2024
2 parents bed9b89 + d3e68a1 commit 55b7fb1
Show file tree
Hide file tree
Showing 8 changed files with 357 additions and 21 deletions.
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,12 @@
"@openapitools/openapi-generator-cli": "^2.7.0",
"axios": "^1.6.2",
"viem": "^1.19.9"
}
},
"keywords": [
"ethereum",
"optimism",
"farcaster",
"neynar",
"nodejs"
]
}
6 changes: 6 additions & 0 deletions src/neynar-api/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,9 @@ export const SIGNED_KEY_REQUEST_TYPE_FOR_ADD_FOR = [
{ name: "nonce", type: "uint256" },
{ name: "deadline", type: "uint256" },
];

export enum TimeWindow {
ONE_DAY = "1d",
SEVEN_DAYS = "7d",
THIRTY_DAYS = "30d",
}
9 changes: 8 additions & 1 deletion src/neynar-api/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
export * from "./neynar-api-client";
export * from "./utils";
export { FeedType, FilterType, ReactionsType, CastParamType, ReactionType } from "./v2";
export {
FeedType,
FilterType,
ReactionsType,
CastParamType,
ReactionType,
} from "./v2";
export { TimeWindow } from "./common/constants";
64 changes: 63 additions & 1 deletion src/neynar-api/neynar-api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import {
SIGNED_KEY_REQUEST_TYPE_FOR_ADD_FOR,
SIGNED_KEY_REQUEST_VALIDATOR,
SIGNED_KEY_REQUEST_VALIDATOR_EIP_712_DOMAIN,
TimeWindow,
} from "./common/constants";
import { isApiErrorResponse } from "./utils";

Expand Down Expand Up @@ -1403,7 +1404,7 @@ export class NeynarAPIClient {
* console.log('Channel Notifications:', response);
* });
*
* For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/notifications).
* For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/notifications-channel).
*/
public async fetchChannelNotificationsForUser(
fid: number,
Expand Down Expand Up @@ -1528,6 +1529,67 @@ export class NeynarAPIClient {
return await this.clients.v2.searchChannels(q);
}

/**
* Retrieves a list of trending channels based on activity within a specified time window.
* This method is useful for identifying channels that are currently popular or receiving significant engagement.
*
* @param {'1d' | '7d' | '30d'} [timeWindow] - The time window for trending analysis. Options are '1d' (one day),
* '7d' (seven days), or '30d' (thirty days).
*
* @returns {Promise<ChannelListResponse>} A promise that resolves to a `ChannelListResponse` object,
* containing a list of trending channels based on the specified time window.
*
* @example
* // Example: Retrieve trending channels over the past week
* import { TimeWindow } from '@neynar/nodejs-sdk'
*
* client.fetchTrendingChannels(TimeWindow.SEVEN_DAYS).then(response => {
* console.log('Trending Channels:', response);
* });
*
* For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/trending-channels).
*/
public async fetchTrendingChannels(
timeWindow?: TimeWindow
): Promise<ChannelListResponse> {
return await this.clients.v2.fetchTrendingChannels(timeWindow);
}

/**
* Retrieves a list of notifications for a user based on specific parent URLs. This method is
* particularly useful for fetching notifications related to user interactions within designated
* channels or content categories.
*
* @param {number} fid - The FID of the user for whom notifications are being fetched.
* @param {Array<string>} parentUrls - An array of parent URLs to specify the channels.
* @param {Object} [options] - Optional parameters for customizing the response.
* @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 notifications for the specified user and parent URLs.
*
* @example
* // Example: Retrieve notifications for a user based on specific parent URLs
* client.fetchNotificationsByParentUrlForUser(3, ['chain://eip155:1/erc721:0xd4498134211baad5846ce70ce04e7c4da78931cc', 'chain://eip155:1/erc721:0xfd8427165df67df6d7fd689ae67c8ebf56d9ca61'], { limit: 30 }).then(response => {
* console.log('User Notifications:', response);
* });
*
* For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/notifications-parent-url).
*/
public async fetchNotificationsByParentUrlForUser(
fid: number,
parentUrls: string[],
options?: { cursor?: string; limit?: number }
) {
return await this.clients.v2.fetchNotificationsByParentUrlForUser(
fid,
parentUrls,
options
);
}

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

/**
Expand Down
72 changes: 71 additions & 1 deletion src/neynar-api/v2/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import axios, { AxiosError, AxiosInstance } from "axios";
import { silentLogger, Logger } from "../common/logger";
import type { SetRequired } from "type-fest";
import { NFTApi, RelevantMints } from "./openapi-recommendation";
import { TimeWindow } from "../common/constants";

const BASE_PATH = "https://api.neynar.com/v2";

Expand Down Expand Up @@ -1013,7 +1014,7 @@ export class NeynarV2APIClient {
* console.log('Channel Notifications:', response);
* });
*
* For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/notifications).
* For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/notifications-channel).
*/
public async fetchChannelNotificationsForUser(
fid: number,
Expand All @@ -1031,6 +1032,45 @@ export class NeynarV2APIClient {
return response.data;
}

/**
* Retrieves a list of notifications for a user based on specific parent URLs. This method is
* particularly useful for fetching notifications related to user interactions within designated
* channels or content categories.
*
* @param {number} fid - The FID of the user for whom notifications are being fetched.
* @param {Array<string>} parentUrls - An array of parent URLs to specify the channels.
* @param {Object} [options] - Optional parameters for customizing the response.
* @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 notifications for the specified user and parent URLs.
*
* @example
* // Example: Retrieve notifications for a user based on specific parent URLs
* client.fetchNotificationsByParentUrlForUser(3, ['chain://eip155:1/erc721:0xd4498134211baad5846ce70ce04e7c4da78931cc', 'chain://eip155:1/erc721:0xfd8427165df67df6d7fd689ae67c8ebf56d9ca61'], { limit: 30 }).then(response => {
* console.log('User Notifications:', response);
* });
*
* For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/notifications-parent-url).
*/
public async fetchNotificationsByParentUrlForUser(
fid: number,
parentUrls: string[],
options?: { cursor?: string; limit?: number }
) {
const _parentUrls = parentUrls.join(",");
const response = await this.apis.notifications.notificationsParentUrl(
this.apiKey,
fid,
_parentUrls,
options?.limit,
options?.cursor
);
return response.data;
}

// ------------ Channel ------------

/**
Expand Down Expand Up @@ -1151,6 +1191,36 @@ export class NeynarV2APIClient {
return response.data;
}

/**
* Retrieves a list of trending channels based on activity within a specified time window.
* This method is useful for identifying channels that are currently popular or receiving significant engagement.
*
* @param {'1d' | '7d' | '30d'} [timeWindow] - The time window for trending analysis. Options are '1d' (one day),
* '7d' (seven days), or '30d' (thirty days).
*
* @returns {Promise<ChannelListResponse>} A promise that resolves to a `ChannelListResponse` object,
* containing a list of trending channels based on the specified time window.
*
* @example
* // Example: Retrieve trending channels over the past week
* import { TimeWindow } from '@neynar/nodejs-sdk'
*
* client.fetchTrendingChannels(TimeWindow.SEVEN_DAYS).then(response => {
* console.log('Trending Channels:', response);
* });
*
* For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/trending-channels).
*/
public async fetchTrendingChannels(
timeWindow?: TimeWindow
): Promise<ChannelListResponse> {
const response = await this.apis.channel.trendingChannels(
this.apiKey,
timeWindow
);
return response.data;
}

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

/**
Expand Down
78 changes: 78 additions & 0 deletions src/neynar-api/v2/openapi-farcaster/apis/channel-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,48 @@ export const ChannelApiAxiosParamCreator = function (configuration?: Configurati



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 trending channels based on activity
* @summary Retrieve trending channels based on activity
* @param {string} apiKey API key required for authentication.
* @param {'1d' | '7d' | '30d'} [timeWindow]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
trendingChannels: async (apiKey: string, timeWindow?: '1d' | '7d' | '30d', options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
// verify required parameter 'apiKey' is not null or undefined
assertParamExists('trendingChannels', 'apiKey', apiKey)
const localVarPath = `/farcaster/channel/trending`;
// 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 (timeWindow !== undefined) {
localVarQueryParameter['time_window'] = timeWindow;
}

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 @@ -299,6 +341,18 @@ export const ChannelApiFp = function(configuration?: Configuration) {
const localVarAxiosArgs = await localVarAxiosParamCreator.searchChannels(apiKey, q, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
/**
* Returns a list of trending channels based on activity
* @summary Retrieve trending channels based on activity
* @param {string} apiKey API key required for authentication.
* @param {'1d' | '7d' | '30d'} [timeWindow]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async trendingChannels(apiKey: string, timeWindow?: '1d' | '7d' | '30d', options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<ChannelListResponse>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.trendingChannels(apiKey, timeWindow, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
}
};

Expand Down Expand Up @@ -358,6 +412,17 @@ export const ChannelApiFactory = function (configuration?: Configuration, basePa
searchChannels(apiKey: string, q: string, options?: any): AxiosPromise<ChannelListResponse> {
return localVarFp.searchChannels(apiKey, q, options).then((request) => request(axios, basePath));
},
/**
* Returns a list of trending channels based on activity
* @summary Retrieve trending channels based on activity
* @param {string} apiKey API key required for authentication.
* @param {'1d' | '7d' | '30d'} [timeWindow]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
trendingChannels(apiKey: string, timeWindow?: '1d' | '7d' | '30d', options?: any): AxiosPromise<ChannelListResponse> {
return localVarFp.trendingChannels(apiKey, timeWindow, options).then((request) => request(axios, basePath));
},
};
};

Expand Down Expand Up @@ -424,4 +489,17 @@ export class ChannelApi extends BaseAPI {
public searchChannels(apiKey: string, q: string, options?: AxiosRequestConfig) {
return ChannelApiFp(this.configuration).searchChannels(apiKey, q, options).then((request) => request(this.axios, this.basePath));
}

/**
* Returns a list of trending channels based on activity
* @summary Retrieve trending channels based on activity
* @param {string} apiKey API key required for authentication.
* @param {'1d' | '7d' | '30d'} [timeWindow]
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof ChannelApi
*/
public trendingChannels(apiKey: string, timeWindow?: '1d' | '7d' | '30d', options?: AxiosRequestConfig) {
return ChannelApiFp(this.configuration).trendingChannels(apiKey, timeWindow, options).then((request) => request(this.axios, this.basePath));
}
}
Loading

0 comments on commit 55b7fb1

Please sign in to comment.