Skip to content

Commit

Permalink
Add methods for channel apis
Browse files Browse the repository at this point in the history
Add methods for channel apis
  • Loading branch information
Shreyaschorge authored Dec 20, 2023
2 parents 207f7d9 + becbf63 commit e79c2ce
Show file tree
Hide file tree
Showing 12 changed files with 600 additions and 4 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.3.2",
"version": "1.4.0",
"description": "SDK to interact with Neynar APIs (https://docs.neynar.com/)",
"main": "./build/index.js",
"types": "./build/index.d.ts",
Expand Down
68 changes: 67 additions & 1 deletion src/neynar-api/neynar-api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import {
StorageAllocationsResponse,
StorageUsageResponse,
SignerStatusEnum,
ChannelResponse,
ChannelListResponse,
} from "./v2/openapi-farcaster";

import {
Expand Down Expand Up @@ -1060,6 +1062,7 @@ export class NeynarAPIClient {
* @param {Object} [options] - Optional parameters for the cast.
* @param {Array<EmbeddedCast>} [options.embeds] - An array of embeds to be included in the cast.
* @param {string} [options.replyTo] - The URL or hash of the parent cast if this is a reply.
* @param {string} [options.channelId] - Channel ID of the channel where the cast is to be posted. e.g. neynar, farcaster, warpcast.
*
* @returns {Promise<PostCastResponseCast>} A promise that resolves to a `PostCastResponseCast` object,
* representing the published cast.
Expand All @@ -1081,7 +1084,7 @@ export class NeynarAPIClient {
public async publishCast(
signerUuid: string,
text: string,
options?: { embeds?: EmbeddedCast[]; replyTo?: string }
options?: { embeds?: EmbeddedCast[]; replyTo?: string; channelId?: string }
): Promise<PostCastResponseCast> {
return await this.clients.v2.publishCast(signerUuid, text, options);
}
Expand Down Expand Up @@ -1339,6 +1342,69 @@ export class NeynarAPIClient {
);
}

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

/**
* Retrieves details of a specific channel based on its ID. This method is essential for
* obtaining comprehensive information about a channel, including its attributes and metadata.
*
* @param {string} id - The ID of the channel being queried.
*
* @returns {Promise<ChannelResponse>} A promise that resolves to a `ChannelResponse` object,
* containing detailed information about the specified channel.
*
* @example
* // Example: Retrieve details of a channel by its ID
* client.lookupChannel('neynar').then(response => {
* console.log('Channel Details:', response);
* });
*
* For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/channel-details).
*/
public async lookupChannel(id: string): Promise<ChannelResponse> {
return await this.clients.v2.lookupChannel(id);
}

/**
* 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.
*
* @returns {Promise<ChannelListResponse>} A promise that resolves to an `ChannelListResponse` object,
* containing a list of all channels along with their respective details.
*
* @example
* // Example: Retrieve a list of all channels
* client.fetchAllChannels().then(response => {
* console.log('All Channels:', response);
* });
*
* For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/list-all-channels).
*/
public async fetchAllChannels(): Promise<ChannelListResponse> {
return await this.clients.v2.fetchAllChannels();
}

/**
* Searches for channels based on their ID or name. This method is useful for locating specific
* channels on the platform using search queries.
*
* @param {string} q - The query string used for searching channels, which can be a channel ID or name.
*
* @returns {Promise<ChannelListResponse>} A promise that resolves to a `ChannelListResponse` object,
* containing a list of channels that match the search criteria.
*
* @example
* // Example: Search for channels using a query string
* client.searchChannels('ux').then(response => {
* console.log('Search Results:', response);
* });
*
* For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/search-channels).
*/
public async searchChannels(q: string): Promise<ChannelListResponse> {
return await this.clients.v2.searchChannels(q);
}

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

/**
Expand Down
75 changes: 74 additions & 1 deletion src/neynar-api/v2/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ import {
StorageApi,
StorageAllocationsResponse,
StorageUsageResponse,
ChannelApi,
ChannelResponse,
ChannelListResponse,
} from "./openapi-farcaster";
import axios, { AxiosError, AxiosInstance } from "axios";
import { silentLogger, Logger } from "../common/logger";
Expand All @@ -52,6 +55,7 @@ export class NeynarV2APIClient {
reaction: ReactionApi;
feed: FeedApi;
notifications: NotificationsApi;
channel: ChannelApi;
follows: FollowsApi;
storage: StorageApi;
nft: NFTApi;
Expand Down Expand Up @@ -111,6 +115,7 @@ export class NeynarV2APIClient {
reaction: new ReactionApi(config, undefined, axiosInstance),
feed: new FeedApi(config, undefined, axiosInstance),
notifications: new NotificationsApi(config, undefined, axiosInstance),
channel: new ChannelApi(config, undefined, axiosInstance),
follows: new FollowsApi(config, undefined, axiosInstance),
storage: new StorageApi(config, undefined, axiosInstance),
nft: new NFTApi(config, undefined, axiosInstance),
Expand Down Expand Up @@ -581,6 +586,7 @@ export class NeynarV2APIClient {
* @param {Object} [options] - Optional parameters for the cast.
* @param {Array<EmbeddedCast>} [options.embeds] - An array of embeds to be included in the cast.
* @param {string} [options.replyTo] - The URL or hash of the parent cast if this is a reply.
* @param {string} [options.channelId] - Channel ID of the channel where the cast is to be posted. e.g. neynar, farcaster, warpcast.
*
* @returns {Promise<PostCastResponseCast>} A promise that resolves to a `PostCastResponseCast` object,
* representing the published cast.
Expand All @@ -602,13 +608,14 @@ export class NeynarV2APIClient {
public async publishCast(
signerUuid: string,
text: string,
options?: { embeds?: EmbeddedCast[]; replyTo?: string }
options?: { embeds?: EmbeddedCast[]; replyTo?: string; channelId?: string }
): Promise<PostCastResponseCast> {
const postCastReqBody = {
signer_uuid: signerUuid,
text: text,
embeds: options?.embeds,
parent: options?.replyTo,
channel_id: options?.channelId,
};
const response = await this.apis.cast.postCast(
this.apiKey,
Expand Down Expand Up @@ -928,6 +935,72 @@ export class NeynarV2APIClient {
return response.data;
}

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

/**
* Retrieves details of a specific channel based on its ID. This method is essential for
* obtaining comprehensive information about a channel, including its attributes and metadata.
*
* @param {string} id - The ID of the channel being queried.
*
* @returns {Promise<ChannelResponse>} A promise that resolves to a `ChannelResponse` object,
* containing detailed information about the specified channel.
*
* @example
* // Example: Retrieve details of a channel by its ID
* client.lookupChannel('neynar').then(response => {
* console.log('Channel Details:', response);
* });
*
* For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/channel-details).
*/
public async lookupChannel(id: string): Promise<ChannelResponse> {
const response = await this.apis.channel.channelDetails(this.apiKey, id);
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.
*
* @returns {Promise<ChannelListResponse>} A promise that resolves to an `ChannelListResponse` object,
* containing a list of all channels along with their respective details.
*
* @example
* // Example: Retrieve a list of all channels
* client.fetchAllChannels().then(response => {
* console.log('All Channels:', response);
* });
*
* For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/list-all-channels).
*/
public async fetchAllChannels(): Promise<ChannelListResponse> {
const response = await this.apis.channel.listAllChannels(this.apiKey);
return response.data;
}

/**
* Searches for channels based on their ID or name. This method is useful for locating specific
* channels on the platform using search queries.
*
* @param {string} q - The query string used for searching channels, which can be a channel ID or name.
*
* @returns {Promise<ChannelListResponse>} A promise that resolves to a `ChannelListResponse` object,
* containing a list of channels that match the search criteria.
*
* @example
* // Example: Search for channels using a query string
* client.searchChannels('ux').then(response => {
* console.log('Search Results:', response);
* });
*
* For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/search-channels).
*/
public async searchChannels(q: string): Promise<ChannelListResponse> {
const response = await this.apis.channel.searchChannels(this.apiKey, q);
return response.data;
}

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

/**
Expand Down
4 changes: 4 additions & 0 deletions src/neynar-api/v2/openapi-farcaster/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
.openapi-generator-ignore
api.ts
apis/cast-api.ts
apis/channel-api.ts
apis/feed-api.ts
apis/follows-api.ts
apis/notifications-api.ts
Expand Down Expand Up @@ -32,6 +33,9 @@ models/cast-with-interactions.ts
models/cast.ts
models/casts-response-result.ts
models/casts-response.ts
models/channel-list-response.ts
models/channel-response.ts
models/channel.ts
models/dehydrated-follower.ts
models/delete-cast-req-body.ts
models/embed-cast-id.ts
Expand Down
1 change: 1 addition & 0 deletions src/neynar-api/v2/openapi-farcaster/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@


export * from './apis/cast-api';
export * from './apis/channel-api';
export * from './apis/feed-api';
export * from './apis/follows-api';
export * from './apis/notifications-api';
Expand Down
Loading

0 comments on commit e79c2ce

Please sign in to comment.