Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32561062
D11676.1767310535.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
D11676.1767310535.diff
View Options
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
Details
Attached
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)
Attached To
Mode
D11676: [lib] introduce fetchFollowedFarcasterChannels to neynar client class
Attached
Detach File
Event Timeline
Log In to Comment