Skip to content

Commit

Permalink
feat: search users by location (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
valerierose authored Oct 30, 2024
1 parent 408cfef commit e473b78
Show file tree
Hide file tree
Showing 6 changed files with 185 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@neynar/nodejs-sdk",
"version": "1.67.4",
"version": "1.68.0",
"description": "SDK to interact with Neynar APIs (https://docs.neynar.com/)",
"main": "./build/index.js",
"types": "./build/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/neynar-api/common/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const version = "1.67.4";
export const version = "1.68.0";
33 changes: 33 additions & 0 deletions src/neynar-api/neynar-api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1525,6 +1525,39 @@ export class NeynarAPIClient {
return await this.clients.v2.lookupUserByUsernameV2(username, options);
}

/**
* Retrieves users by their location, specified by latitude and longitude coordinates.
*
* @param {number} latitude - The latitude coordinate of the location.
* @param {number} longitude - The longitude coordinate of the location.
* @param {Object} [options] - Optional parameters to tailor the request.
* @param {number} [options.viewerFid] - The FID of the user viewing this information, used for providing contextual data specific to the viewer.
* @param {number} [options.limit] - The number of users to fetch per request. Defaults to 25 with a maximum of 100.
* @param {string} [options.cursor] - Pagination cursor for fetching specific subsets of results.
*
* @returns {Promise<UsersResponse>} A promise that resolves to a `UsersResponse` object,
* containing information about the users at the specified location.
*
* @example
* // Example: Fetch users by location with viewer fid
* client.fetchUsersByLocation(37.7749, -122.4194, {viewerFid: 3}).then(response => {
* console.log('Users by Location:', response);
* });
*
* For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/user-by-location).
*/
public async fetchUsersByLocation(
latitude: number,
longitude: number,
options?: {
viewerFid?: number;
limit?: number;
cursor?: string;
}
): Promise<UsersResponse> {
return await this.clients.v2.fetchUsersByLocation(latitude, longitude, options);
}

// ------------ Cast ------------

/**
Expand Down
40 changes: 40 additions & 0 deletions src/neynar-api/v2/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,46 @@ export class NeynarV2APIClient {
return response.data;
}

/**
* Retrieves users by their location, specified by latitude and longitude coordinates.
*
* @param {number} latitude - The latitude coordinate of the location.
* @param {number} longitude - The longitude coordinate of the location.
* @param {Object} [options] - Optional parameters to tailor the request.
* @param {number} [options.viewerFid] - The FID of the user viewing this information, used for providing contextual data specific to the viewer.
* @param {number} [options.limit] - The number of users to fetch per request. Defaults to 25 with a maximum of 100.
* @param {string} [options.cursor] - Pagination cursor for fetching specific subsets of results.
*
* @returns {Promise<UsersResponse>} A promise that resolves to a `UsersResponse` object,
* containing information about the users at the specified location.
*
* @example
* // Example: Fetch users by location with viewer fid
* client.fetchUsersByLocation(37.7749, -122.4194, {viewerFid: 3}).then(response => {
* console.log('Users by Location:', response);
* });
*
* For more information, refer to the [Neynar documentation](https://docs.neynar.com/reference/user-by-location).
*/
public async fetchUsersByLocation(
latitude: number,
longitude: number,
options?: {
viewerFid?: number;
limit?: number;
cursor?: string;
}
): Promise<UsersResponse> {
const response = await this.apis.user.fetchUsersByLocation(
latitude,
longitude,
options?.viewerFid,
options?.limit,
options?.cursor
);
return response.data;
}

// ------------ Cast ------------

/**
Expand Down
109 changes: 109 additions & 0 deletions src/neynar-api/v2/openapi-farcaster/apis/user-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,68 @@ export const UserApiAxiosParamCreator = function (configuration?: Configuration)
options: localVarRequestOptions,
};
},
/**
* Fetches a list of users given a location
* @summary By location
* @param {number} latitude Latitude of the location
* @param {number} longitude Longitude of the location
* @param {number} [viewerFid] FID of the user viewing the feed. Providing this will return a list of users that respects this user\&#39;s mutes and blocks and includes &#x60;viewer_context&#x60;.
* @param {number} [limit] Number of results to fetch
* @param {string} [cursor] Pagination cursor
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
fetchUsersByLocation: async (latitude: number, longitude: number, viewerFid?: number, limit?: number, cursor?: string, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
// verify required parameter 'latitude' is not null or undefined
assertParamExists('fetchUsersByLocation', 'latitude', latitude)
// verify required parameter 'longitude' is not null or undefined
assertParamExists('fetchUsersByLocation', 'longitude', longitude)
const localVarPath = `/farcaster/user/by_location`;
// 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, "x-api-key", configuration)

if (latitude !== undefined) {
localVarQueryParameter['latitude'] = latitude;
}

if (longitude !== undefined) {
localVarQueryParameter['longitude'] = longitude;
}

if (viewerFid !== undefined) {
localVarQueryParameter['viewer_fid'] = 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,
};
},
/**
* Follow a user \\ (In order to follow a user `signer_uuid` must be approved)
* @summary Follow user
Expand Down Expand Up @@ -739,6 +801,23 @@ export const UserApiFp = function(configuration?: Configuration) {
const localVarOperationServerBasePath = operationServerMap['UserApi.farcasterUserVerificationPost']?.[localVarOperationServerIndex]?.url;
return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
},
/**
* Fetches a list of users given a location
* @summary By location
* @param {number} latitude Latitude of the location
* @param {number} longitude Longitude of the location
* @param {number} [viewerFid] FID of the user viewing the feed. Providing this will return a list of users that respects this user\&#39;s mutes and blocks and includes &#x60;viewer_context&#x60;.
* @param {number} [limit] Number of results to fetch
* @param {string} [cursor] Pagination cursor
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async fetchUsersByLocation(latitude: number, longitude: number, viewerFid?: number, limit?: number, cursor?: string, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<UsersResponse>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.fetchUsersByLocation(latitude, longitude, viewerFid, limit, cursor, options);
const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
const localVarOperationServerBasePath = operationServerMap['UserApi.fetchUsersByLocation']?.[localVarOperationServerIndex]?.url;
return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
},
/**
* Follow a user \\ (In order to follow a user `signer_uuid` must be approved)
* @summary Follow user
Expand Down Expand Up @@ -944,6 +1023,20 @@ export const UserApiFactory = function (configuration?: Configuration, basePath?
farcasterUserVerificationPost(addVerificationReqBody: AddVerificationReqBody, options?: RawAxiosRequestConfig): AxiosPromise<OperationResponse> {
return localVarFp.farcasterUserVerificationPost(addVerificationReqBody, options).then((request) => request(axios, basePath));
},
/**
* Fetches a list of users given a location
* @summary By location
* @param {number} latitude Latitude of the location
* @param {number} longitude Longitude of the location
* @param {number} [viewerFid] FID of the user viewing the feed. Providing this will return a list of users that respects this user\&#39;s mutes and blocks and includes &#x60;viewer_context&#x60;.
* @param {number} [limit] Number of results to fetch
* @param {string} [cursor] Pagination cursor
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
fetchUsersByLocation(latitude: number, longitude: number, viewerFid?: number, limit?: number, cursor?: string, options?: RawAxiosRequestConfig): AxiosPromise<UsersResponse> {
return localVarFp.fetchUsersByLocation(latitude, longitude, viewerFid, limit, cursor, options).then((request) => request(axios, basePath));
},
/**
* Follow a user \\ (In order to follow a user `signer_uuid` must be approved)
* @summary Follow user
Expand Down Expand Up @@ -1119,6 +1212,22 @@ export class UserApi extends BaseAPI {
return UserApiFp(this.configuration).farcasterUserVerificationPost(addVerificationReqBody, options).then((request) => request(this.axios, this.basePath));
}

/**
* Fetches a list of users given a location
* @summary By location
* @param {number} latitude Latitude of the location
* @param {number} longitude Longitude of the location
* @param {number} [viewerFid] FID of the user viewing the feed. Providing this will return a list of users that respects this user\&#39;s mutes and blocks and includes &#x60;viewer_context&#x60;.
* @param {number} [limit] Number of results to fetch
* @param {string} [cursor] Pagination cursor
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof UserApi
*/
public fetchUsersByLocation(latitude: number, longitude: number, viewerFid?: number, limit?: number, cursor?: string, options?: RawAxiosRequestConfig) {
return UserApiFp(this.configuration).fetchUsersByLocation(latitude, longitude, viewerFid, limit, cursor, options).then((request) => request(this.axios, this.basePath));
}

/**
* Follow a user \\ (In order to follow a user `signer_uuid` must be approved)
* @summary Follow user
Expand Down
2 changes: 1 addition & 1 deletion src/oas
Submodule oas updated 1 files
+59 −0 src/v2/spec.yaml

0 comments on commit e473b78

Please sign in to comment.