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