Skip to content

Commit

Permalink
Add fetchTrendingFeed and remove with replies
Browse files Browse the repository at this point in the history
Add fetchTrendingFeed and remove with replies
  • Loading branch information
Shreyaschorge authored Mar 19, 2024
2 parents e371197 + 3a6d0ab commit db18b9b
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 45 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.12.0",
"version": "1.13.0",
"description": "SDK to interact with Neynar APIs (https://docs.neynar.com/)",
"main": "./build/index.js",
"types": "./build/index.d.ts",
Expand Down
7 changes: 7 additions & 0 deletions src/neynar-api/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ export enum TimeWindow {
THIRTY_DAYS = "30d",
}

export enum TrendingFeedTimeWindow {
ONE_HOUR = "1h",
SIX_HOUR = "6h",
TWELVE_HOUR = "12h",
TWENTY_FOUR_HOUR = "24h",
}

export enum BulkCastsSortType {
TRENDING = "trending",
LIKES = "likes",
Expand Down
36 changes: 31 additions & 5 deletions src/neynar-api/neynar-api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ import {
SIGNED_KEY_REQUEST_VALIDATOR,
SIGNED_KEY_REQUEST_VALIDATOR_EIP_712_DOMAIN,
TimeWindow,
TrendingFeedTimeWindow,
} from "./common/constants";
import { isApiErrorResponse } from "./utils";

Expand Down Expand Up @@ -1388,7 +1389,6 @@ export class NeynarAPIClient {
* @param {string} [options.channelId] Used when filter_type=channel_id can be used to fetch all casts under a channel. Requires feed_type and filter_type
* @param {string} [options.embedUrl] - Used when filter_type=embed_url can be used to fetch all casts with an embed url that contains embed_url. Requires feed_type and filter_type
* @param {boolean} [options.withRecasts] - Whether to 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, with a default of 25 and a maximum of 100.
* @param {string} [options.cursor] - Pagination cursor for fetching specific subsets of results.
*
Expand All @@ -1415,7 +1415,6 @@ export class NeynarAPIClient {
limit?: number;
cursor?: string;
withRecasts?: boolean;
withReplies?: boolean;
}
): Promise<FeedResponse> {
return await this.clients.v2.fetchFeed(feedType, options);
Expand Down Expand Up @@ -1461,7 +1460,6 @@ export class NeynarAPIClient {
* @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.
Expand All @@ -1473,7 +1471,6 @@ export class NeynarAPIClient {
* // 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 => {
Expand All @@ -1486,7 +1483,6 @@ export class NeynarAPIClient {
fid: number,
options?: {
withRecasts?: boolean;
withReplies?: boolean;
limit?: number;
cursor?: string;
}
Expand Down Expand Up @@ -1574,6 +1570,36 @@ export class NeynarAPIClient {
return await this.clients.v2.fetchFramesOnlyFeed(options);
}

/**
* Retrieves a feed of the most popular cast.
*
* @param {Object} [options] - Optional parameters for customizing the response.
* @param {number} [options.limit] - Number of results to retrieve (default 10, max 10).
* @param {string} [options.cursor] - Pagination cursor for the next set of results,
* omit this parameter for the initial request.
* @param {TrendingFeedTimeWindow} [options.timeWindow] - Time window for the trending feed.
*
* @returns {Promise<FeedResponse>} A promise that resolves to a `FeedResponse` object,
* containing the most popular casts on the platform.
*
* @example
* // Example: Retrieve a feed of the most popular casts
* import { TrendingFeedTimeWindow } from "@neynar/nodejs-sdk";
*
* client.fetchTrendingFeed({ limit: 10, timeWindow: TrendingFeedTimeWindow.SIX_HOUR }).then(response => {
* console.log('Popular Feed:', response);
* });
*
* For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/feed-trending).
*/
public async fetchTrendingFeed(options?: {
limit?: number;
cursor?: string;
timeWindow?: TrendingFeedTimeWindow;
}) {
return await this.clients.v2.fetchTrendingFeed(options);
}

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

/**
Expand Down
49 changes: 41 additions & 8 deletions src/neynar-api/v2/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ 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 { BulkCastsSortType, TimeWindow } from "../common/constants";
import {
BulkCastsSortType,
TimeWindow,
TrendingFeedTimeWindow,
} from "../common/constants";

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

Expand Down Expand Up @@ -979,7 +983,6 @@ export class NeynarV2APIClient {
* @param {string} [options.channelId] Used when filter_type=channel_id can be used to fetch all casts under a channel. Requires feed_type and filter_type
* @param {string} [options.embedUrl] - Used when filter_type=embed_url can be used to fetch all casts with an embed url that contains embed_url. Requires feed_type and filter_type
* @param {boolean} [options.withRecasts] - Whether to 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, with a default of 25 and a maximum of 100.
* @param {string} [options.cursor] - Pagination cursor for fetching specific subsets of results.
*
Expand All @@ -1006,7 +1009,6 @@ export class NeynarV2APIClient {
limit?: number;
cursor?: string;
withRecasts?: boolean;
withReplies?: boolean;
}
): Promise<FeedResponse> {
const _fids = options?.fids?.join(",");
Expand All @@ -1021,7 +1023,6 @@ export class NeynarV2APIClient {
options?.channelId,
options?.embedUrl,
options?.withRecasts,
options?.withReplies,
options?.limit,
options?.cursor
);
Expand Down Expand Up @@ -1077,7 +1078,6 @@ export class NeynarV2APIClient {
* @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.
Expand All @@ -1089,7 +1089,6 @@ export class NeynarV2APIClient {
* // 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 => {
Expand All @@ -1102,7 +1101,6 @@ export class NeynarV2APIClient {
fid: number,
options?: {
withRecasts?: boolean;
withReplies?: boolean;
limit?: number;
cursor?: string;
}
Expand All @@ -1111,7 +1109,6 @@ export class NeynarV2APIClient {
this.apiKey,
fid,
options?.withRecasts,
options?.withReplies,
options?.limit,
options?.cursor
);
Expand Down Expand Up @@ -1213,6 +1210,42 @@ export class NeynarV2APIClient {
return response.data;
}

/**
* Retrieves a feed of the most popular cast.
*
* @param {Object} [options] - Optional parameters for customizing the response.
* @param {number} [options.limit] - Number of results to retrieve (default 10, max 10).
* @param {string} [options.cursor] - Pagination cursor for the next set of results,
* omit this parameter for the initial request.
* @param {TrendingFeedTimeWindow} [options.timeWindow] - Time window for the trending feed.
*
* @returns {Promise<FeedResponse>} A promise that resolves to a `FeedResponse` object,
* containing the most popular casts on the platform.
*
* @example
* // Example: Retrieve a feed of the most popular casts
* import { TrendingFeedTimeWindow } from "@neynar/nodejs-sdk";
*
* client.fetchTrendingFeed({ limit: 10, timeWindow: TrendingFeedTimeWindow.SIX_HOUR }).then(response => {
* console.log('Popular Feed:', response);
* });
*
* For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/feed-trending).
*/
public async fetchTrendingFeed(options?: {
limit?: number;
cursor?: string;
timeWindow?: TrendingFeedTimeWindow;
}) {
const response = await this.apis.feed.feedTrending(
this.apiKey,
options?.limit,
options?.cursor,
options?.timeWindow
);
return response.data;
}

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

/**
Expand Down
Loading

0 comments on commit db18b9b

Please sign in to comment.