Page MenuHomePhabricator

D11676.id39204.diff
No OneTemporary

D11676.id39204.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
@@ -21,9 +21,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,
@@ -39,6 +53,7 @@
}
const fetchFollowerLimit = 150;
+const fetchFollowedChannelsLimit = 100;
class NeynarClient {
apiKey: string;
@@ -89,6 +104,49 @@
return fids;
}
+
+ async fetchFollowedFarcasterChannels(
+ fid: string,
+ ): Promise<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) {
+ console.log('Failed to fetch followed Farcaster channels:', error);
+ throw new Error(getMessageForException(error) ?? 'unknown');
+ }
+ } while (paginationCursor);
+
+ return farcasterChannels;
+ }
}
export { NeynarClient };

File Metadata

Mime Type
text/plain
Expires
Tue, Nov 26, 6:39 AM (20 h, 38 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2583320
Default Alt Text
D11676.id39204.diff (1 KB)

Event Timeline