Page MenuHomePhorge

D11676.1767310535.diff
No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None

D11676.1767310535.diff

diff --git a/lib/utils/neynar-client.js b/lib/utils/neynar-client.js
--- a/lib/utils/neynar-client.js
+++ b/lib/utils/neynar-client.js
@@ -19,9 +19,23 @@
},
};
+type FarcasterChannel = {
+ +id: string,
+ +name: string,
+ ...
+};
+
+type FetchFollowedFarcasterChannelsResponse = {
+ +channels: $ReadOnlyArray<FarcasterChannel>,
+ +next: {
+ +cursor: ?string,
+ },
+};
+
const neynarBaseURL = 'https://api.neynar.com/';
const neynarURLs = {
'1': `${neynarBaseURL}v1/farcaster/`,
+ '2': `${neynarBaseURL}v2/farcaster/`,
};
function getNeynarURL(
apiVersion: string,
@@ -37,6 +51,7 @@
}
const fetchFollowerLimit = 150;
+const fetchFollowedChannelsLimit = 100;
class NeynarClient {
apiKey: string;
@@ -86,6 +101,50 @@
return fids;
}
+
+ async fetchFollowedFarcasterChannels(
+ fid: string,
+ ): Promise<$ReadOnlyArray<FarcasterChannel>> {
+ const farcasterChannels = [];
+ let paginationCursor = null;
+
+ do {
+ const params: { [string]: string } = {
+ fid,
+ limit: fetchFollowedChannelsLimit.toString(),
+ ...(paginationCursor ? { cursor: paginationCursor } : null),
+ };
+
+ const url = getNeynarURL('2', 'user/channels', params);
+
+ try {
+ const response = await fetch(url, {
+ method: 'GET',
+ headers: {
+ Accept: 'application/json',
+ api_key: this.apiKey,
+ },
+ });
+
+ const json: FetchFollowedFarcasterChannelsResponse =
+ await response.json();
+
+ const { channels, next } = json;
+
+ channels.forEach(channel => {
+ farcasterChannels.push(channel);
+ });
+
+ paginationCursor = next.cursor;
+ } catch (error) {
+ throw new Error(
+ `Failed to fetch followed Farcaster channels: ${error}`,
+ );
+ }
+ } while (paginationCursor);
+
+ return farcasterChannels;
+ }
}
export { NeynarClient };

File Metadata

Mime Type
text/plain
Expires
Thu, Jan 1, 11:35 PM (2 h, 12 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5877777
Default Alt Text
D11676.1767310535.diff (1 KB)

Event Timeline