From c3c930685080b78d393a120e65f21c738e9d04a5 Mon Sep 17 00:00:00 2001 From: Shreyaschorge Date: Fri, 27 Oct 2023 21:08:59 +0530 Subject: [PATCH 1/3] Refactor user-api generated code --- .../neynar-v1-api/openapi/apis/user-api.ts | 1242 +++++++++++------ 1 file changed, 792 insertions(+), 450 deletions(-) diff --git a/src/neynar-api/neynar-v1-api/openapi/apis/user-api.ts b/src/neynar-api/neynar-v1-api/openapi/apis/user-api.ts index 50583f5a..f793c6f7 100644 --- a/src/neynar-api/neynar-v1-api/openapi/apis/user-api.ts +++ b/src/neynar-api/neynar-v1-api/openapi/apis/user-api.ts @@ -1,524 +1,866 @@ /* tslint:disable */ /* eslint-disable */ /** - * Farcaster API V1 + * v1 Farcaster * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) * * The version of the OpenAPI document: 1.0 - * + * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). * https://openapi-generator.tech * Do not edit the class manually. */ - -import type { Configuration } from '../configuration'; -import type { AxiosPromise, AxiosInstance, AxiosRequestConfig } from 'axios'; -import globalAxios from 'axios'; +import type { Configuration } from "../configuration"; +import type { AxiosPromise, AxiosInstance, AxiosRequestConfig } from "axios"; +import globalAxios from "axios"; // Some imports not used depending on template conditions // @ts-ignore -import { DUMMY_BASE_URL, assertParamExists, setApiKeyToObject, setBasicAuthToObject, setBearerAuthToObject, setOAuthToObject, setSearchParams, serializeDataIfNeeded, toPathString, createRequestFunction } from '../common'; +import { + DUMMY_BASE_URL, + assertParamExists, + setApiKeyToObject, + setBasicAuthToObject, + setBearerAuthToObject, + setOAuthToObject, + setSearchParams, + serializeDataIfNeeded, + toPathString, + createRequestFunction, +} from "../common"; // @ts-ignore -import { BASE_PATH, COLLECTION_FORMATS, RequestArgs, BaseAPI, RequiredError } from '../base'; +import { + BASE_PATH, + COLLECTION_FORMATS, + RequestArgs, + BaseAPI, + RequiredError, +} from "../base"; // @ts-ignore -import { CustodyAddressResponse } from '../models'; +import { CustodyAddressResponse } from "../models"; // @ts-ignore -import { ErrorRes } from '../models'; +import { ErrorRes } from "../models"; // @ts-ignore -import { RecentUsersResponse } from '../models'; +import { RecentUsersResponse } from "../models"; // @ts-ignore -import { User200Response } from '../models'; +import { User200Response } from "../models"; // @ts-ignore -import { UserCastLikeResponse } from '../models'; +import { UserCastLikeResponse } from "../models"; /** * UserApi - axios parameter creator * @export */ -export const UserApiAxiosParamCreator = function (configuration?: Configuration) { - return { - /** - * Returns the custody address for a given FID - * @summary Get the custody address for a given FID - * @param {string} apiKey API key required for authentication. - * @param {number} fid fid of a user - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - custodyAddress: async (apiKey: string, fid: number, options: AxiosRequestConfig = {}): Promise => { - // verify required parameter 'apiKey' is not null or undefined - assertParamExists('custodyAddress', 'apiKey', apiKey) - // verify required parameter 'fid' is not null or undefined - assertParamExists('custodyAddress', 'fid', fid) - const localVarPath = `/farcaster/custody-address`; - // use dummy base URL string because the URL constructor only accepts absolute URLs. - const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); - let baseOptions; - if (configuration) { - baseOptions = configuration.baseOptions; - } - - const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options}; - const localVarHeaderParameter = {} as any; - const localVarQueryParameter = {} as any; - - if (fid !== undefined) { - localVarQueryParameter['fid'] = fid; - } - - if (apiKey != null) { - localVarHeaderParameter['api_key'] = String(apiKey); - } - - - - setSearchParams(localVarUrlObj, localVarQueryParameter); - let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; - localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; - - return { - url: toPathString(localVarUrlObj), - options: localVarRequestOptions, - }; - }, - /** - * Get a list of casts from the protocol in reverse chronological order based on timestamp - * @summary Get Recent Users - * @param {string} apiKey API key required for authentication. - * @param {number} [viewerFid] fid of the user viewing this information, needed for contextual information. - * @param {string} [cursor] Pagination cursor. - * @param {number} [limit] Number of results to retrieve (default 100, max 1000) - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - recentUsers: async (apiKey: string, viewerFid?: number, cursor?: string, limit?: number, options: AxiosRequestConfig = {}): Promise => { - // verify required parameter 'apiKey' is not null or undefined - assertParamExists('recentUsers', 'apiKey', apiKey) - const localVarPath = `/farcaster/recent-users`; - // use dummy base URL string because the URL constructor only accepts absolute URLs. - const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); - let baseOptions; - if (configuration) { - baseOptions = configuration.baseOptions; - } - - const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options}; - const localVarHeaderParameter = {} as any; - const localVarQueryParameter = {} as any; - - if (viewerFid !== undefined) { - localVarQueryParameter['viewerFid'] = viewerFid; - } - - if (cursor !== undefined) { - localVarQueryParameter['cursor'] = cursor; - } - - if (limit !== undefined) { - localVarQueryParameter['limit'] = limit; - } - - if (apiKey != null) { - localVarHeaderParameter['api_key'] = String(apiKey); - } - - - - setSearchParams(localVarUrlObj, localVarQueryParameter); - let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; - localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; - - return { - url: toPathString(localVarUrlObj), - options: localVarRequestOptions, - }; - }, - /** - * Returns metadata about a specific user - * @summary Get User Information by FID - * @param {string} apiKey API key required for authentication. - * @param {number} fid fid of a user - * @param {number} [viewerFid] fid of the user viewing this information, needed for contextual information. - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - user: async (apiKey: string, fid: number, viewerFid?: number, options: AxiosRequestConfig = {}): Promise => { - // verify required parameter 'apiKey' is not null or undefined - assertParamExists('user', 'apiKey', apiKey) - // verify required parameter 'fid' is not null or undefined - assertParamExists('user', 'fid', fid) - const localVarPath = `/farcaster/user`; - // use dummy base URL string because the URL constructor only accepts absolute URLs. - const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); - let baseOptions; - if (configuration) { - baseOptions = configuration.baseOptions; - } - - const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options}; - const localVarHeaderParameter = {} as any; - const localVarQueryParameter = {} as any; - - if (fid !== undefined) { - localVarQueryParameter['fid'] = fid; - } - - if (viewerFid !== undefined) { - localVarQueryParameter['viewerFid'] = viewerFid; - } - - if (apiKey != null) { - localVarHeaderParameter['api_key'] = String(apiKey); - } - - - - setSearchParams(localVarUrlObj, localVarQueryParameter); - let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; - localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; - - return { - url: toPathString(localVarUrlObj), - options: localVarRequestOptions, - }; - }, - /** - * Returns metadata about a specific user - * @summary Get User Information by username - * @param {string} apiKey API key required for authentication. - * @param {string} username Username of the user - * @param {number} [viewerFid] fid of the user viewing this information, needed for contextual information. - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - userByUsername: async (apiKey: string, username: string, viewerFid?: number, options: AxiosRequestConfig = {}): Promise => { - // verify required parameter 'apiKey' is not null or undefined - assertParamExists('userByUsername', 'apiKey', apiKey) - // verify required parameter 'username' is not null or undefined - assertParamExists('userByUsername', 'username', username) - const localVarPath = `/farcaster/user-by-username`; - // use dummy base URL string because the URL constructor only accepts absolute URLs. - const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); - let baseOptions; - if (configuration) { - baseOptions = configuration.baseOptions; - } - - const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options}; - const localVarHeaderParameter = {} as any; - const localVarQueryParameter = {} as any; - - if (username !== undefined) { - localVarQueryParameter['username'] = username; - } - - if (viewerFid !== undefined) { - localVarQueryParameter['viewerFid'] = viewerFid; - } - - if (apiKey != null) { - localVarHeaderParameter['api_key'] = String(apiKey); - } - - - - setSearchParams(localVarUrlObj, localVarQueryParameter); - let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; - localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; - - return { - url: toPathString(localVarUrlObj), - options: localVarRequestOptions, - }; - }, - /** - * Fetch all the liked cast of a User - * @summary Get User Cast Likes - * @param {string} apiKey API key required for authentication. - * @param {number} fid FID of the user - * @param {number} [viewerFid] fid of the user viewing this information, needed for contextual information. - * @param {number} [limit] Number of results to retrieve (default 25, max 150) - * @param {string} [cursor] Pagination cursor - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - userCastLikes: async (apiKey: string, fid: number, viewerFid?: number, limit?: number, cursor?: string, options: AxiosRequestConfig = {}): Promise => { - // verify required parameter 'apiKey' is not null or undefined - assertParamExists('userCastLikes', 'apiKey', apiKey) - // verify required parameter 'fid' is not null or undefined - assertParamExists('userCastLikes', 'fid', fid) - const localVarPath = `/farcaster/user-cast-likes`; - // use dummy base URL string because the URL constructor only accepts absolute URLs. - const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); - let baseOptions; - if (configuration) { - baseOptions = configuration.baseOptions; - } - - const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options}; - const localVarHeaderParameter = {} as any; - const localVarQueryParameter = {} as any; - - if (fid !== undefined) { - localVarQueryParameter['fid'] = fid; - } - - if (viewerFid !== undefined) { - localVarQueryParameter['viewerFid'] = viewerFid; - } - - if (limit !== undefined) { - localVarQueryParameter['limit'] = limit; - } - - if (cursor !== undefined) { - localVarQueryParameter['cursor'] = cursor; - } - - if (apiKey != null) { - localVarHeaderParameter['api_key'] = String(apiKey); - } - - - - setSearchParams(localVarUrlObj, localVarQueryParameter); - let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; - localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; - - return { - url: toPathString(localVarUrlObj), - options: localVarRequestOptions, - }; - }, - } +export const UserApiAxiosParamCreator = function ( + configuration?: Configuration +) { + return { + /** + * Returns the custody address for a given FID + * @summary Get the custody address for a given FID + * @param {number} fid fid of a user + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + custodyAddress: async ( + fid: number, + options: AxiosRequestConfig = {} + ): Promise => { + // verify required parameter 'fid' is not null or undefined + assertParamExists("custodyAddress", "fid", fid); + const localVarPath = `/farcaster/custody-address`; + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { + method: "GET", + ...baseOptions, + ...options, + }; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + // authentication ApiKeyAuth required + await setApiKeyToObject( + localVarHeaderParameter, + "api_key", + configuration + ); + + if (fid !== undefined) { + localVarQueryParameter["fid"] = fid; + } + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = + baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = { + ...localVarHeaderParameter, + ...headersFromBaseOptions, + ...options.headers, + }; + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + /** + * Get a list of casts from the protocol in reverse chronological order based on timestamp + * @summary Get Recent Users + * @param {number} [viewerFid] fid of the user viewing this information, needed for contextual information. + * @param {string} [cursor] Pagination cursor. + * @param {number} [limit] Number of results to retrieve (default 100, max 1000) + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + recentUsers: async ( + viewerFid?: number, + cursor?: string, + limit?: number, + options: AxiosRequestConfig = {} + ): Promise => { + const localVarPath = `/farcaster/recent-users`; + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { + method: "GET", + ...baseOptions, + ...options, + }; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + // authentication ApiKeyAuth required + await setApiKeyToObject( + localVarHeaderParameter, + "api_key", + configuration + ); + + if (viewerFid !== undefined) { + localVarQueryParameter["viewerFid"] = viewerFid; + } + + if (cursor !== undefined) { + localVarQueryParameter["cursor"] = cursor; + } + + if (limit !== undefined) { + localVarQueryParameter["limit"] = limit; + } + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = + baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = { + ...localVarHeaderParameter, + ...headersFromBaseOptions, + ...options.headers, + }; + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + /** + * Returns metadata about a specific user + * @summary Get User Information by FID + * @param {number} fid fid of a user + * @param {number} [viewerFid] fid of the user viewing this information, needed for contextual information. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + user: async ( + fid: number, + viewerFid?: number, + options: AxiosRequestConfig = {} + ): Promise => { + // verify required parameter 'fid' is not null or undefined + assertParamExists("user", "fid", fid); + const localVarPath = `/farcaster/user`; + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { + method: "GET", + ...baseOptions, + ...options, + }; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + // authentication ApiKeyAuth required + await setApiKeyToObject( + localVarHeaderParameter, + "api_key", + configuration + ); + + if (fid !== undefined) { + localVarQueryParameter["fid"] = fid; + } + + if (viewerFid !== undefined) { + localVarQueryParameter["viewerFid"] = viewerFid; + } + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = + baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = { + ...localVarHeaderParameter, + ...headersFromBaseOptions, + ...options.headers, + }; + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + /** + * Returns metadata about a specific user + * @summary Get User Information by username + * @param {string} username Username of the user + * @param {number} [viewerFid] fid of the user viewing this information, needed for contextual information. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + userByUsername: async ( + username: string, + viewerFid?: number, + options: AxiosRequestConfig = {} + ): Promise => { + // verify required parameter 'username' is not null or undefined + assertParamExists("userByUsername", "username", username); + const localVarPath = `/farcaster/user-by-username`; + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { + method: "GET", + ...baseOptions, + ...options, + }; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + // authentication ApiKeyAuth required + await setApiKeyToObject( + localVarHeaderParameter, + "api_key", + configuration + ); + + if (username !== undefined) { + localVarQueryParameter["username"] = username; + } + + if (viewerFid !== undefined) { + localVarQueryParameter["viewerFid"] = viewerFid; + } + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = + baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = { + ...localVarHeaderParameter, + ...headersFromBaseOptions, + ...options.headers, + }; + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + /** + * Fetch all the liked cast of a User + * @summary Get User Cast Likes + * @param {number} fid FID of the user + * @param {number} [viewerFid] fid of the user viewing this information, needed for contextual information. + * @param {number} [limit] Number of results to retrieve (default 25, max 150) + * @param {string} [cursor] Pagination cursor + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + userCastLikes: async ( + fid: number, + viewerFid?: number, + limit?: number, + cursor?: string, + options: AxiosRequestConfig = {} + ): Promise => { + // verify required parameter 'fid' is not null or undefined + assertParamExists("userCastLikes", "fid", fid); + const localVarPath = `/farcaster/user-cast-likes`; + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { + method: "GET", + ...baseOptions, + ...options, + }; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + // authentication ApiKeyAuth required + await setApiKeyToObject( + localVarHeaderParameter, + "api_key", + configuration + ); + + if (fid !== undefined) { + localVarQueryParameter["fid"] = fid; + } + + if (viewerFid !== undefined) { + localVarQueryParameter["viewerFid"] = viewerFid; + } + + if (limit !== undefined) { + localVarQueryParameter["limit"] = limit; + } + + if (cursor !== undefined) { + localVarQueryParameter["cursor"] = cursor; + } + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = + baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = { + ...localVarHeaderParameter, + ...headersFromBaseOptions, + ...options.headers, + }; + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + }; }; /** * UserApi - functional programming interface * @export */ -export const UserApiFp = function(configuration?: Configuration) { - const localVarAxiosParamCreator = UserApiAxiosParamCreator(configuration) - return { - /** - * Returns the custody address for a given FID - * @summary Get the custody address for a given FID - * @param {string} apiKey API key required for authentication. - * @param {number} fid fid of a user - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - async custodyAddress(apiKey: string, fid: number, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { - const localVarAxiosArgs = await localVarAxiosParamCreator.custodyAddress(apiKey, fid, options); - return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); - }, - /** - * Get a list of casts from the protocol in reverse chronological order based on timestamp - * @summary Get Recent Users - * @param {string} apiKey API key required for authentication. - * @param {number} [viewerFid] fid of the user viewing this information, needed for contextual information. - * @param {string} [cursor] Pagination cursor. - * @param {number} [limit] Number of results to retrieve (default 100, max 1000) - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - async recentUsers(apiKey: string, viewerFid?: number, cursor?: string, limit?: number, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { - const localVarAxiosArgs = await localVarAxiosParamCreator.recentUsers(apiKey, viewerFid, cursor, limit, options); - return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); - }, - /** - * Returns metadata about a specific user - * @summary Get User Information by FID - * @param {string} apiKey API key required for authentication. - * @param {number} fid fid of a user - * @param {number} [viewerFid] fid of the user viewing this information, needed for contextual information. - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - async user(apiKey: string, fid: number, viewerFid?: number, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { - const localVarAxiosArgs = await localVarAxiosParamCreator.user(apiKey, fid, viewerFid, options); - return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); - }, - /** - * Returns metadata about a specific user - * @summary Get User Information by username - * @param {string} apiKey API key required for authentication. - * @param {string} username Username of the user - * @param {number} [viewerFid] fid of the user viewing this information, needed for contextual information. - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - async userByUsername(apiKey: string, username: string, viewerFid?: number, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { - const localVarAxiosArgs = await localVarAxiosParamCreator.userByUsername(apiKey, username, viewerFid, options); - return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); - }, - /** - * Fetch all the liked cast of a User - * @summary Get User Cast Likes - * @param {string} apiKey API key required for authentication. - * @param {number} fid FID of the user - * @param {number} [viewerFid] fid of the user viewing this information, needed for contextual information. - * @param {number} [limit] Number of results to retrieve (default 25, max 150) - * @param {string} [cursor] Pagination cursor - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - async userCastLikes(apiKey: string, fid: number, viewerFid?: number, limit?: number, cursor?: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { - const localVarAxiosArgs = await localVarAxiosParamCreator.userCastLikes(apiKey, fid, viewerFid, limit, cursor, options); - return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); - }, - } -}; - -/** - * UserApi - factory interface - * @export - */ -export const UserApiFactory = function (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) { - const localVarFp = UserApiFp(configuration) - return { - /** - * Returns the custody address for a given FID - * @summary Get the custody address for a given FID - * @param {string} apiKey API key required for authentication. - * @param {number} fid fid of a user - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - custodyAddress(apiKey: string, fid: number, options?: any): AxiosPromise { - return localVarFp.custodyAddress(apiKey, fid, options).then((request) => request(axios, basePath)); - }, - /** - * Get a list of casts from the protocol in reverse chronological order based on timestamp - * @summary Get Recent Users - * @param {string} apiKey API key required for authentication. - * @param {number} [viewerFid] fid of the user viewing this information, needed for contextual information. - * @param {string} [cursor] Pagination cursor. - * @param {number} [limit] Number of results to retrieve (default 100, max 1000) - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - recentUsers(apiKey: string, viewerFid?: number, cursor?: string, limit?: number, options?: any): AxiosPromise { - return localVarFp.recentUsers(apiKey, viewerFid, cursor, limit, options).then((request) => request(axios, basePath)); - }, - /** - * Returns metadata about a specific user - * @summary Get User Information by FID - * @param {string} apiKey API key required for authentication. - * @param {number} fid fid of a user - * @param {number} [viewerFid] fid of the user viewing this information, needed for contextual information. - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - user(apiKey: string, fid: number, viewerFid?: number, options?: any): AxiosPromise { - return localVarFp.user(apiKey, fid, viewerFid, options).then((request) => request(axios, basePath)); - }, - /** - * Returns metadata about a specific user - * @summary Get User Information by username - * @param {string} apiKey API key required for authentication. - * @param {string} username Username of the user - * @param {number} [viewerFid] fid of the user viewing this information, needed for contextual information. - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - userByUsername(apiKey: string, username: string, viewerFid?: number, options?: any): AxiosPromise { - return localVarFp.userByUsername(apiKey, username, viewerFid, options).then((request) => request(axios, basePath)); - }, - /** - * Fetch all the liked cast of a User - * @summary Get User Cast Likes - * @param {string} apiKey API key required for authentication. - * @param {number} fid FID of the user - * @param {number} [viewerFid] fid of the user viewing this information, needed for contextual information. - * @param {number} [limit] Number of results to retrieve (default 25, max 150) - * @param {string} [cursor] Pagination cursor - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - userCastLikes(apiKey: string, fid: number, viewerFid?: number, limit?: number, cursor?: string, options?: any): AxiosPromise { - return localVarFp.userCastLikes(apiKey, fid, viewerFid, limit, cursor, options).then((request) => request(axios, basePath)); - }, - }; -}; - -/** - * UserApi - object-oriented interface - * @export - * @class UserApi - * @extends {BaseAPI} - */ -export class UserApi extends BaseAPI { +export const UserApiFp = function (configuration?: Configuration) { + const localVarAxiosParamCreator = UserApiAxiosParamCreator(configuration); + return { /** * Returns the custody address for a given FID * @summary Get the custody address for a given FID - * @param {string} apiKey API key required for authentication. * @param {number} fid fid of a user * @param {*} [options] Override http request option. * @throws {RequiredError} - * @memberof UserApi */ - public custodyAddress(apiKey: string, fid: number, options?: AxiosRequestConfig) { - return UserApiFp(this.configuration).custodyAddress(apiKey, fid, options).then((request) => request(this.axios, this.basePath)); - } - + async custodyAddress( + fid: number, + options?: AxiosRequestConfig + ): Promise< + ( + axios?: AxiosInstance, + basePath?: string + ) => AxiosPromise + > { + const localVarAxiosArgs = await localVarAxiosParamCreator.custodyAddress( + fid, + options + ); + return createRequestFunction( + localVarAxiosArgs, + globalAxios, + BASE_PATH, + configuration + ); + }, /** * Get a list of casts from the protocol in reverse chronological order based on timestamp * @summary Get Recent Users - * @param {string} apiKey API key required for authentication. * @param {number} [viewerFid] fid of the user viewing this information, needed for contextual information. * @param {string} [cursor] Pagination cursor. * @param {number} [limit] Number of results to retrieve (default 100, max 1000) * @param {*} [options] Override http request option. * @throws {RequiredError} - * @memberof UserApi */ - public recentUsers(apiKey: string, viewerFid?: number, cursor?: string, limit?: number, options?: AxiosRequestConfig) { - return UserApiFp(this.configuration).recentUsers(apiKey, viewerFid, cursor, limit, options).then((request) => request(this.axios, this.basePath)); - } - + async recentUsers( + viewerFid?: number, + cursor?: string, + limit?: number, + options?: AxiosRequestConfig + ): Promise< + ( + axios?: AxiosInstance, + basePath?: string + ) => AxiosPromise + > { + const localVarAxiosArgs = await localVarAxiosParamCreator.recentUsers( + viewerFid, + cursor, + limit, + options + ); + return createRequestFunction( + localVarAxiosArgs, + globalAxios, + BASE_PATH, + configuration + ); + }, /** * Returns metadata about a specific user * @summary Get User Information by FID - * @param {string} apiKey API key required for authentication. * @param {number} fid fid of a user * @param {number} [viewerFid] fid of the user viewing this information, needed for contextual information. * @param {*} [options] Override http request option. * @throws {RequiredError} - * @memberof UserApi */ - public user(apiKey: string, fid: number, viewerFid?: number, options?: AxiosRequestConfig) { - return UserApiFp(this.configuration).user(apiKey, fid, viewerFid, options).then((request) => request(this.axios, this.basePath)); - } - + async user( + fid: number, + viewerFid?: number, + options?: AxiosRequestConfig + ): Promise< + ( + axios?: AxiosInstance, + basePath?: string + ) => AxiosPromise + > { + const localVarAxiosArgs = await localVarAxiosParamCreator.user( + fid, + viewerFid, + options + ); + return createRequestFunction( + localVarAxiosArgs, + globalAxios, + BASE_PATH, + configuration + ); + }, /** * Returns metadata about a specific user * @summary Get User Information by username - * @param {string} apiKey API key required for authentication. * @param {string} username Username of the user * @param {number} [viewerFid] fid of the user viewing this information, needed for contextual information. * @param {*} [options] Override http request option. * @throws {RequiredError} - * @memberof UserApi */ - public userByUsername(apiKey: string, username: string, viewerFid?: number, options?: AxiosRequestConfig) { - return UserApiFp(this.configuration).userByUsername(apiKey, username, viewerFid, options).then((request) => request(this.axios, this.basePath)); - } - + async userByUsername( + username: string, + viewerFid?: number, + options?: AxiosRequestConfig + ): Promise< + ( + axios?: AxiosInstance, + basePath?: string + ) => AxiosPromise + > { + const localVarAxiosArgs = await localVarAxiosParamCreator.userByUsername( + username, + viewerFid, + options + ); + return createRequestFunction( + localVarAxiosArgs, + globalAxios, + BASE_PATH, + configuration + ); + }, /** * Fetch all the liked cast of a User * @summary Get User Cast Likes - * @param {string} apiKey API key required for authentication. * @param {number} fid FID of the user * @param {number} [viewerFid] fid of the user viewing this information, needed for contextual information. * @param {number} [limit] Number of results to retrieve (default 25, max 150) * @param {string} [cursor] Pagination cursor * @param {*} [options] Override http request option. * @throws {RequiredError} - * @memberof UserApi */ - public userCastLikes(apiKey: string, fid: number, viewerFid?: number, limit?: number, cursor?: string, options?: AxiosRequestConfig) { - return UserApiFp(this.configuration).userCastLikes(apiKey, fid, viewerFid, limit, cursor, options).then((request) => request(this.axios, this.basePath)); - } + async userCastLikes( + fid: number, + viewerFid?: number, + limit?: number, + cursor?: string, + options?: AxiosRequestConfig + ): Promise< + ( + axios?: AxiosInstance, + basePath?: string + ) => AxiosPromise + > { + const localVarAxiosArgs = await localVarAxiosParamCreator.userCastLikes( + fid, + viewerFid, + limit, + cursor, + options + ); + return createRequestFunction( + localVarAxiosArgs, + globalAxios, + BASE_PATH, + configuration + ); + }, + }; +}; + +/** + * UserApi - factory interface + * @export + */ +export const UserApiFactory = function ( + configuration?: Configuration, + basePath?: string, + axios?: AxiosInstance +) { + const localVarFp = UserApiFp(configuration); + return { + /** + * Returns the custody address for a given FID + * @summary Get the custody address for a given FID + * @param {UserApiCustodyAddressRequest} requestParameters Request parameters. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + custodyAddress( + requestParameters: UserApiCustodyAddressRequest, + options?: AxiosRequestConfig + ): AxiosPromise { + return localVarFp + .custodyAddress(requestParameters.fid, options) + .then((request) => request(axios, basePath)); + }, + /** + * Get a list of casts from the protocol in reverse chronological order based on timestamp + * @summary Get Recent Users + * @param {UserApiRecentUsersRequest} requestParameters Request parameters. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + recentUsers( + requestParameters: UserApiRecentUsersRequest = {}, + options?: AxiosRequestConfig + ): AxiosPromise { + return localVarFp + .recentUsers( + requestParameters.viewerFid, + requestParameters.cursor, + requestParameters.limit, + options + ) + .then((request) => request(axios, basePath)); + }, + /** + * Returns metadata about a specific user + * @summary Get User Information by FID + * @param {UserApiUserRequest} requestParameters Request parameters. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + user( + requestParameters: UserApiUserRequest, + options?: AxiosRequestConfig + ): AxiosPromise { + return localVarFp + .user(requestParameters.fid, requestParameters.viewerFid, options) + .then((request) => request(axios, basePath)); + }, + /** + * Returns metadata about a specific user + * @summary Get User Information by username + * @param {UserApiUserByUsernameRequest} requestParameters Request parameters. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + userByUsername( + requestParameters: UserApiUserByUsernameRequest, + options?: AxiosRequestConfig + ): AxiosPromise { + return localVarFp + .userByUsername( + requestParameters.username, + requestParameters.viewerFid, + options + ) + .then((request) => request(axios, basePath)); + }, + /** + * Fetch all the liked cast of a User + * @summary Get User Cast Likes + * @param {UserApiUserCastLikesRequest} requestParameters Request parameters. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + userCastLikes( + requestParameters: UserApiUserCastLikesRequest, + options?: AxiosRequestConfig + ): AxiosPromise { + return localVarFp + .userCastLikes( + requestParameters.fid, + requestParameters.viewerFid, + requestParameters.limit, + requestParameters.cursor, + options + ) + .then((request) => request(axios, basePath)); + }, + }; +}; + +/** + * Request parameters for custodyAddress operation in UserApi. + * @export + * @interface UserApiCustodyAddressRequest + */ +export interface UserApiCustodyAddressRequest { + /** + * fid of a user + * @type {number} + * @memberof UserApiCustodyAddress + */ + readonly fid: number; } +/** + * Request parameters for recentUsers operation in UserApi. + * @export + * @interface UserApiRecentUsersRequest + */ +export interface UserApiRecentUsersRequest { + /** + * fid of the user viewing this information, needed for contextual information. + * @type {number} + * @memberof UserApiRecentUsers + */ + readonly viewerFid?: number; + + /** + * Pagination cursor. + * @type {string} + * @memberof UserApiRecentUsers + */ + readonly cursor?: string; + + /** + * Number of results to retrieve (default 100, max 1000) + * @type {number} + * @memberof UserApiRecentUsers + */ + readonly limit?: number; +} + +/** + * Request parameters for user operation in UserApi. + * @export + * @interface UserApiUserRequest + */ +export interface UserApiUserRequest { + /** + * fid of a user + * @type {number} + * @memberof UserApiUser + */ + readonly fid: number; + + /** + * fid of the user viewing this information, needed for contextual information. + * @type {number} + * @memberof UserApiUser + */ + readonly viewerFid?: number; +} + +/** + * Request parameters for userByUsername operation in UserApi. + * @export + * @interface UserApiUserByUsernameRequest + */ +export interface UserApiUserByUsernameRequest { + /** + * Username of the user + * @type {string} + * @memberof UserApiUserByUsername + */ + readonly username: string; + + /** + * fid of the user viewing this information, needed for contextual information. + * @type {number} + * @memberof UserApiUserByUsername + */ + readonly viewerFid?: number; +} + +/** + * Request parameters for userCastLikes operation in UserApi. + * @export + * @interface UserApiUserCastLikesRequest + */ +export interface UserApiUserCastLikesRequest { + /** + * FID of the user + * @type {number} + * @memberof UserApiUserCastLikes + */ + readonly fid: number; + + /** + * fid of the user viewing this information, needed for contextual information. + * @type {number} + * @memberof UserApiUserCastLikes + */ + readonly viewerFid?: number; + + /** + * Number of results to retrieve (default 25, max 150) + * @type {number} + * @memberof UserApiUserCastLikes + */ + readonly limit?: number; + + /** + * Pagination cursor + * @type {string} + * @memberof UserApiUserCastLikes + */ + readonly cursor?: string; +} + +/** + * UserApi - object-oriented interface + * @export + * @class UserApi + * @extends {BaseAPI} + */ +export class UserApi extends BaseAPI { + /** + * Returns the custody address for a given FID + * @summary Get the custody address for a given FID + * @param {UserApiCustodyAddressRequest} requestParameters Request parameters. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof UserApi + */ + public custodyAddress( + requestParameters: UserApiCustodyAddressRequest, + options?: AxiosRequestConfig + ) { + return UserApiFp(this.configuration) + .custodyAddress(requestParameters.fid, options) + .then((request) => request(this.axios, this.basePath)); + } + + /** + * Get a list of casts from the protocol in reverse chronological order based on timestamp + * @summary Get Recent Users + * @param {UserApiRecentUsersRequest} requestParameters Request parameters. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof UserApi + */ + public recentUsers( + requestParameters: UserApiRecentUsersRequest = {}, + options?: AxiosRequestConfig + ) { + return UserApiFp(this.configuration) + .recentUsers( + requestParameters.viewerFid, + requestParameters.cursor, + requestParameters.limit, + options + ) + .then((request) => request(this.axios, this.basePath)); + } + + /** + * Returns metadata about a specific user + * @summary Get User Information by FID + * @param {UserApiUserRequest} requestParameters Request parameters. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof UserApi + */ + public user( + requestParameters: UserApiUserRequest, + options?: AxiosRequestConfig + ) { + return UserApiFp(this.configuration) + .user(requestParameters.fid, requestParameters.viewerFid, options) + .then((request) => request(this.axios, this.basePath)); + } + + /** + * Returns metadata about a specific user + * @summary Get User Information by username + * @param {UserApiUserByUsernameRequest} requestParameters Request parameters. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof UserApi + */ + public userByUsername( + requestParameters: UserApiUserByUsernameRequest, + options?: AxiosRequestConfig + ) { + return UserApiFp(this.configuration) + .userByUsername( + requestParameters.username, + requestParameters.viewerFid, + options + ) + .then((request) => request(this.axios, this.basePath)); + } + + /** + * Fetch all the liked cast of a User + * @summary Get User Cast Likes + * @param {UserApiUserCastLikesRequest} requestParameters Request parameters. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof UserApi + */ + public userCastLikes( + requestParameters: UserApiUserCastLikesRequest, + options?: AxiosRequestConfig + ) { + return UserApiFp(this.configuration) + .userCastLikes( + requestParameters.fid, + requestParameters.viewerFid, + requestParameters.limit, + requestParameters.cursor, + options + ) + .then((request) => request(this.axios, this.basePath)); + } +} From 7308a8edac5037f8332c354e6a37a24856521d0f Mon Sep 17 00:00:00 2001 From: Shreyaschorge Date: Fri, 27 Oct 2023 21:33:28 +0530 Subject: [PATCH 2/3] Add User methods in neynar v1 client --- .../neynar-v1-api/neynar-api-v1-client.ts | 112 +++++++++++++++++- 1 file changed, 111 insertions(+), 1 deletion(-) diff --git a/src/neynar-api/neynar-v1-api/neynar-api-v1-client.ts b/src/neynar-api/neynar-v1-api/neynar-api-v1-client.ts index 80ad9f50..7435c07a 100644 --- a/src/neynar-api/neynar-v1-api/neynar-api-v1-client.ts +++ b/src/neynar-api/neynar-v1-api/neynar-api-v1-client.ts @@ -25,6 +25,7 @@ export class NeynarV1APIClient { private readonly logger: Logger; public readonly apis: { + user: UserApi; cast: CastApi; follows: FollowsApi; }; @@ -69,6 +70,7 @@ export class NeynarV1APIClient { apiKey: apiKey, }); this.apis = { + user: new UserApi(config, undefined, axiosInstance), cast: new CastApi(config, undefined, axiosInstance), follows: new FollowsApi(config, undefined, axiosInstance), }; @@ -89,6 +91,114 @@ export class NeynarV1APIClient { ); } + // ------------ User ------------ + + /** + * A list of users in reverse chronological order based on sign up. + * See [Neynar documentation](https://docs.neynar.com/reference/recent-users-v1) + * + */ + public async *fetchRecentUsers(options?: { + viewerFid?: number; + pageSize?: number; + }): AsyncGenerator { + let cursor: string | undefined; + + while (true) { + // fetch one page of casts (with refreshed auth if necessary) + const response = await this.apis.user.recentUsers({ + viewerFid: options?.viewerFid, + cursor: cursor, + limit: options?.pageSize, + }); + + yield* response.data.result.users; + // prep for next page + if (response.data.result.next.cursor === null) { + break; + } + cursor = response.data.result.next.cursor; + } + } + + /** + * Fetch all likes by a given user. + * See [Neynar documentation](https://docs.neynar.com/reference/user-cast-likes-v1) + * + */ + public async *fetchUserCastLikes( + fid: number, + options?: { viewerFid?: number; pageSize?: number } + ): AsyncGenerator { + let cursor: string | undefined; + + while (true) { + // fetch one page of likes + const response = await this.apis.user.userCastLikes({ + fid: fid, + viewerFid: options?.viewerFid, + limit: options?.pageSize, + cursor: cursor, + }); + + yield* response.data.result.likes; + + // prep for next page + if (response.data.result.next.cursor === null) { + break; + } + cursor = response.data.result.next.cursor; + } + } + + /** + * Gets the specified user via their FID (if found). + * See [Neynar documentation](https://docs.neynar.com/reference/user-v1) + * + */ + public async lookupUserByFid( + fid: number, + viewerFid?: number + ): Promise { + try { + const response = await this.apis.user.user({ fid, viewerFid }); + return response.data.result.user; + } catch (error) { + if (NeynarV1APIClient.isApiErrorResponse(error)) { + if (error.response.status === 404) return null; + } + throw error; + } + } + + /** + * Gets the specified user via their username (if found). + * See [Neynar documentation](https://docs.neynar.com/reference/user-by-username-v1) + * + */ + public async lookupUserByUsername( + username: string, + viewerFid?: number + ): Promise { + const response = await this.apis.user.userByUsername({ + username, + viewerFid, + }); + // result.user is undefined if not found + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition + return response.data.result.user ?? null; + } + + /** + * Gets the custody address for the specified user via their username (if found). + * See [Neynar documentation](https://docs.neynar.com/reference/custody-address-v1) + * + */ + public async fetchCustodyAddressForUser(fid: number): Promise { + const response = await this.apis.user.custodyAddress({ fid }); + return response.data.result.custodyAddress; + } + // ------------ Cast ------------ /** @@ -96,7 +206,7 @@ export class NeynarV1APIClient { * See [Neynar documentation](https://docs.neynar.com/reference/cast-v1) * */ - public async fetchCast( + public async lookUpCastByHash( hash: string, options?: { viewerFid?: number } ): Promise { From d3126b730999731845ea80c1e9cdfb23d7c47f20 Mon Sep 17 00:00:00 2001 From: Shreyaschorge Date: Fri, 27 Oct 2023 21:37:22 +0530 Subject: [PATCH 3/3] Patch update: v0.0.6 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ea9821bf..521bdd9a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@neynar/nodejs-sdk", - "version": "0.0.5", + "version": "0.0.6", "description": "SDK to interact with Neynar APIs (https://docs.neynar.com/)", "main": "./build/index.js", "types": "./build/index.d.ts",