Skip to content

Commit

Permalink
Feature/add fetchUserFollowingFeed and fetchActiveUsersInSingleChannel
Browse files Browse the repository at this point in the history
Feature/add fetchUserFollowingFeed and fetchActiveUsersInSingleChannel
  • Loading branch information
Shreyaschorge authored Jan 11, 2024
2 parents 0dc1a4f + b4e7abb commit 3b91048
Show file tree
Hide file tree
Showing 6 changed files with 434 additions and 2 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.5.0",
"version": "1.6.0",
"description": "SDK to interact with Neynar APIs (https://docs.neynar.com/)",
"main": "./build/index.js",
"types": "./build/index.d.ts",
Expand Down
87 changes: 87 additions & 0 deletions src/neynar-api/neynar-api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,45 @@ export class NeynarAPIClient {
return await this.clients.v2.fetchFeedByChannelIds(channelIds, options);
}

/**
* Retrieve feed based on who a user is following
*
* @param {number} fid - fid of user whose feed you want to create
* @param {Object} [options] - Optional parameters for customizing the feed.
* @param {boolean} [options.withRecasts] - Include recasts in the response, true by default
* @param {boolean} [options.withReplies] - Include replies in the response, false by default
* @param {number} [options.limit] - Number of results to retrieve (default 25, max 100).
* @param {string} [options.cursor] - Pagination cursor for the next set of results,
* omit this parameter for the initial request.
*
* @returns {Promise<FeedResponse>} A promise that resolves to a `FeedResponse` object,
* containing the requested feed data.
*
* @example
* // Example: Retrieve a user's feed based on who they are following
* client.fetchUserFollowingFeed(3, {
* withRecasts: true,
* withReplies: false,
* limit: 30,
* // cursor: "nextPageCursor" // Omit this parameter for the initial request.
* }).then(response => {
* console.log('User Feed:', response); // Outputs the user's feed
* });
*
* For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/feed-following).
*/
public async fetchUserFollowingFeed(
fid: number,
options?: {
withRecasts?: boolean;
withReplies?: boolean;
limit?: number;
cursor?: string;
}
): Promise<FeedResponse> {
return await this.clients.v2.fetchUserFollowingFeed(fid, options);
}

// ------------ Reaction ------------

/**
Expand Down Expand Up @@ -1401,6 +1440,54 @@ export class NeynarAPIClient {
return await this.clients.v2.lookupChannel(id);
}

/**
* Retrieves a list of users who are active in a given channel, ordered by ascending FIDs
*
* @param {string} id - Channel ID for the channel being queried
* @param {boolean} hasRootCastAuthors - Include users who posted the root cast in the channel
* @param {Object} [options] - Optional parameters for the request
* @param {boolean} [options.hasCastLikers] - Include users who liked a cast in the channel
* @param {boolean} [options.hasCastRecasters] - Include users who recasted a cast in the channel
* @param {boolean} [options.hasReplyAuthors] - Include users who replied to a cast in the channel
* @param {number} [options.limit] - Number of results to retrieve (default 25, max 100).
* @param {string} [options.cursor] - Pagination cursor for the next set of results,
* omit this parameter for the initial request.
*
* @returns {Promise<BulkUsersResponse>} A promise that resolves to a `BulkUsersResponse` object,
* containing the users active in the specified channel.
*
* @example
* // Example: Retrieve active users in a channel
* client.fetchActiveUsersInSingleChannel('neynar', true, {
* hasCastLikers: true,
* hasCastRecasters: true,
* hasReplyAuthors: true,
* limit: 10
* // cursor: "nextPageCursor" // Omit this parameter for the initial request.
* }).then(response => {
* console.log('Active Users:', response);
* });
*
* For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/channel-users).
*/
public async fetchActiveUsersInSingleChannel(
id: string,
hasRootCastAuthors: boolean,
options?: {
hasCastLikers?: boolean;
hasCastRecasters?: boolean;
hasReplyAuthors?: boolean;
limit?: number;
cursor?: string;
}
): Promise<BulkUsersResponse> {
return await this.clients.v2.fetchActiveUsersInSingleChannel(
id,
hasRootCastAuthors,
options
);
}

/**
* Retrieves a list of all channels, including their details. This method is particularly useful for
* obtaining a comprehensive overview of all available channels on the platform.
Expand Down
101 changes: 101 additions & 0 deletions src/neynar-api/v2/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,53 @@ export class NeynarV2APIClient {
return response.data;
}

/**
* Retrieve feed based on who a user is following
*
* @param {number} fid - fid of user whose feed you want to create
* @param {Object} [options] - Optional parameters for customizing the feed.
* @param {boolean} [options.withRecasts] - Include recasts in the response, true by default
* @param {boolean} [options.withReplies] - Include replies in the response, false by default
* @param {number} [options.limit] - Number of results to retrieve (default 25, max 100).
* @param {string} [options.cursor] - Pagination cursor for the next set of results,
* omit this parameter for the initial request.
*
* @returns {Promise<FeedResponse>} A promise that resolves to a `FeedResponse` object,
* containing the requested feed data.
*
* @example
* // Example: Retrieve a user's feed based on who they are following
* client.fetchUserFollowingFeed(3, {
* withRecasts: true,
* withReplies: false,
* limit: 30,
* // cursor: "nextPageCursor" // Omit this parameter for the initial request.
* }).then(response => {
* console.log('User Feed:', response); // Outputs the user's feed
* });
*
* For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/feed-following).
*/
public async fetchUserFollowingFeed(
fid: number,
options?: {
withRecasts?: boolean;
withReplies?: boolean;
limit?: number;
cursor?: string;
}
): Promise<FeedResponse> {
const response = await this.apis.feed.feedFollowing(
this.apiKey,
fid,
options?.withRecasts,
options?.withReplies,
options?.limit,
options?.cursor
);
return response.data;
}

// ------------ Reaction ------------

/**
Expand Down Expand Up @@ -1008,6 +1055,60 @@ export class NeynarV2APIClient {
return response.data;
}

/**
* Retrieves a list of users who are active in a given channel, ordered by ascending FIDs
*
* @param {string} id - Channel ID for the channel being queried
* @param {boolean} hasRootCastAuthors - Include users who posted the root cast in the channel
* @param {Object} [options] - Optional parameters for the request
* @param {boolean} [options.hasCastLikers] - Include users who liked a cast in the channel
* @param {boolean} [options.hasCastRecasters] - Include users who recasted a cast in the channel
* @param {boolean} [options.hasReplyAuthors] - Include users who replied to a cast in the channel
* @param {number} [options.limit] - Number of results to retrieve (default 25, max 100).
* @param {string} [options.cursor] - Pagination cursor for the next set of results,
* omit this parameter for the initial request.
*
* @returns {Promise<BulkUsersResponse>} A promise that resolves to a `BulkUsersResponse` object,
* containing the users active in the specified channel.
*
* @example
* // Example: Retrieve active users in a channel
* client.fetchActiveUsersInSingleChannel('neynar', true, {
* hasCastLikers: true,
* hasCastRecasters: true,
* hasReplyAuthors: true,
* limit: 10
* // cursor: "nextPageCursor" // Omit this parameter for the initial request.
* }).then(response => {
* console.log('Active Users:', response);
* });
*
* For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/channel-users).
*/
public async fetchActiveUsersInSingleChannel(
id: string,
hasRootCastAuthors: boolean,
options?: {
hasCastLikers?: boolean;
hasCastRecasters?: boolean;
hasReplyAuthors?: boolean;
cursor?: string;
limit?: number;
}
): Promise<BulkUsersResponse> {
const response = await this.apis.channel.channelUsers(
this.apiKey,
id,
hasRootCastAuthors,
options?.hasCastLikers,
options?.hasCastRecasters,
options?.hasReplyAuthors,
options?.cursor,
options?.limit
);
return response.data;
}

/**
* Retrieves a list of all channels, including their details. This method is particularly useful for
* obtaining a comprehensive overview of all available channels on the platform.
Expand Down
132 changes: 132 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 @@ -22,6 +22,8 @@ import { DUMMY_BASE_URL, assertParamExists, setApiKeyToObject, setBasicAuthToObj
// @ts-ignore
import { BASE_PATH, COLLECTION_FORMATS, RequestArgs, BaseAPI, RequiredError } from '../base';
// @ts-ignore
import { BulkUsersResponse } from '../models';
// @ts-ignore
import { ChannelListResponse } from '../models';
// @ts-ignore
import { ChannelResponse } from '../models';
Expand Down Expand Up @@ -68,6 +70,82 @@ 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 users who are active in a given channel, ordered by ascending FIDs
* @summary Retrieve users who are active in a channel
* @param {string} apiKey API key required for authentication.
* @param {string} id Channel ID for the channel being queried
* @param {boolean} hasRootCastAuthors Include users who posted the root cast in the channel
* @param {boolean} [hasCastLikers] Include users who liked a cast in the channel
* @param {boolean} [hasCastRecasters] Include users who recasted a cast in the channel
* @param {boolean} [hasReplyAuthors] Include users who replied to a cast in the channel
* @param {string} [cursor] Pagination cursor.
* @param {number} [limit] Number of results to retrieve (default 25, max 100)
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
channelUsers: async (apiKey: string, id: string, hasRootCastAuthors: boolean, hasCastLikers?: boolean, hasCastRecasters?: boolean, hasReplyAuthors?: boolean, cursor?: string, limit?: number, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
// verify required parameter 'apiKey' is not null or undefined
assertParamExists('channelUsers', 'apiKey', apiKey)
// verify required parameter 'id' is not null or undefined
assertParamExists('channelUsers', 'id', id)
// verify required parameter 'hasRootCastAuthors' is not null or undefined
assertParamExists('channelUsers', 'hasRootCastAuthors', hasRootCastAuthors)
const localVarPath = `/farcaster/channel/users`;
// 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 (id !== undefined) {
localVarQueryParameter['id'] = id;
}

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

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

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

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

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

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

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 @@ -180,6 +258,24 @@ export const ChannelApiFp = function(configuration?: Configuration) {
const localVarAxiosArgs = await localVarAxiosParamCreator.channelDetails(apiKey, id, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
/**
* Returns a list of users who are active in a given channel, ordered by ascending FIDs
* @summary Retrieve users who are active in a channel
* @param {string} apiKey API key required for authentication.
* @param {string} id Channel ID for the channel being queried
* @param {boolean} hasRootCastAuthors Include users who posted the root cast in the channel
* @param {boolean} [hasCastLikers] Include users who liked a cast in the channel
* @param {boolean} [hasCastRecasters] Include users who recasted a cast in the channel
* @param {boolean} [hasReplyAuthors] Include users who replied to a cast in the channel
* @param {string} [cursor] Pagination cursor.
* @param {number} [limit] Number of results to retrieve (default 25, max 100)
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async channelUsers(apiKey: string, id: string, hasRootCastAuthors: boolean, hasCastLikers?: boolean, hasCastRecasters?: boolean, hasReplyAuthors?: boolean, cursor?: string, limit?: number, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<BulkUsersResponse>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.channelUsers(apiKey, id, hasRootCastAuthors, hasCastLikers, hasCastRecasters, hasReplyAuthors, cursor, limit, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
/**
* Returns a list of all channels with their details
* @summary Retrieve all channels with their details
Expand Down Expand Up @@ -224,6 +320,23 @@ export const ChannelApiFactory = function (configuration?: Configuration, basePa
channelDetails(apiKey: string, id: string, options?: any): AxiosPromise<ChannelResponse> {
return localVarFp.channelDetails(apiKey, id, options).then((request) => request(axios, basePath));
},
/**
* Returns a list of users who are active in a given channel, ordered by ascending FIDs
* @summary Retrieve users who are active in a channel
* @param {string} apiKey API key required for authentication.
* @param {string} id Channel ID for the channel being queried
* @param {boolean} hasRootCastAuthors Include users who posted the root cast in the channel
* @param {boolean} [hasCastLikers] Include users who liked a cast in the channel
* @param {boolean} [hasCastRecasters] Include users who recasted a cast in the channel
* @param {boolean} [hasReplyAuthors] Include users who replied to a cast in the channel
* @param {string} [cursor] Pagination cursor.
* @param {number} [limit] Number of results to retrieve (default 25, max 100)
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
channelUsers(apiKey: string, id: string, hasRootCastAuthors: boolean, hasCastLikers?: boolean, hasCastRecasters?: boolean, hasReplyAuthors?: boolean, cursor?: string, limit?: number, options?: any): AxiosPromise<BulkUsersResponse> {
return localVarFp.channelUsers(apiKey, id, hasRootCastAuthors, hasCastLikers, hasCastRecasters, hasReplyAuthors, cursor, limit, options).then((request) => request(axios, basePath));
},
/**
* Returns a list of all channels with their details
* @summary Retrieve all channels with their details
Expand Down Expand Up @@ -268,6 +381,25 @@ export class ChannelApi extends BaseAPI {
return ChannelApiFp(this.configuration).channelDetails(apiKey, id, options).then((request) => request(this.axios, this.basePath));
}

/**
* Returns a list of users who are active in a given channel, ordered by ascending FIDs
* @summary Retrieve users who are active in a channel
* @param {string} apiKey API key required for authentication.
* @param {string} id Channel ID for the channel being queried
* @param {boolean} hasRootCastAuthors Include users who posted the root cast in the channel
* @param {boolean} [hasCastLikers] Include users who liked a cast in the channel
* @param {boolean} [hasCastRecasters] Include users who recasted a cast in the channel
* @param {boolean} [hasReplyAuthors] Include users who replied to a cast in the channel
* @param {string} [cursor] Pagination cursor.
* @param {number} [limit] Number of results to retrieve (default 25, max 100)
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof ChannelApi
*/
public channelUsers(apiKey: string, id: string, hasRootCastAuthors: boolean, hasCastLikers?: boolean, hasCastRecasters?: boolean, hasReplyAuthors?: boolean, cursor?: string, limit?: number, options?: AxiosRequestConfig) {
return ChannelApiFp(this.configuration).channelUsers(apiKey, id, hasRootCastAuthors, hasCastLikers, hasCastRecasters, hasReplyAuthors, cursor, limit, options).then((request) => request(this.axios, this.basePath));
}

/**
* Returns a list of all channels with their details
* @summary Retrieve all channels with their details
Expand Down
Loading

0 comments on commit 3b91048

Please sign in to comment.