Skip to content

Commit

Permalink
Add ReactionAPI related methods and Combine fetchCastByHash and fetch…
Browse files Browse the repository at this point in the history
…CastByUrl

Add ReactionAPI related methods and Combine fetchCastByHash and fetchCastByUrl
  • Loading branch information
Shreyaschorge authored Oct 31, 2023
2 parents 0f2e2c2 + 47d799b commit f1768d9
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 90 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": "0.5.1",
"version": "0.5.2",
"description": "SDK to interact with Neynar APIs (https://docs.neynar.com/)",
"main": "./build/index.js",
"types": "./build/index.d.ts",
Expand Down
90 changes: 64 additions & 26 deletions src/neynar-api/neynar-v2-api/neynar-api-v2-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class NeynarV2APIClient {

public readonly apis: {
cast: CastApi;
reaction: ReactionApi;
};

/**
Expand Down Expand Up @@ -75,6 +76,7 @@ export class NeynarV2APIClient {
});
this.apis = {
cast: new CastApi(config, undefined, axiosInstance),
reaction: new ReactionApi(config, undefined, axiosInstance),
};
}

Expand All @@ -93,39 +95,21 @@ export class NeynarV2APIClient {
);
}

/**
* Gets information about an individual cast by cast hash.
* See [Neynar documentation](https://docs.neynar.com/reference/cast)
*
*/
public async fetchCastByHash(castHash: string): Promise<Cast | null> {
try {
const response = await this.apis.cast.cast({
type: CastParamType.Hash,
identifier: castHash,
});
return response.data.cast;
} catch (error) {
if (NeynarV2APIClient.isApiErrorResponse(error)) {
const status = error.response.status;
if (status === 404) {
return null;
}
}
throw error;
}
}
// ------------ Cast ------------

/**
* Gets information about an individual cast by cast hash.
* Gets information about an individual cast.
* See [Neynar documentation](https://docs.neynar.com/reference/cast)
*
*/
public async fetchCastByUrl(castUrl: string): Promise<Cast | null> {
public async fetchCast(
castHashOrUrl: string,
type: CastParamType
): Promise<Cast | null> {
try {
const response = await this.apis.cast.cast({
type: CastParamType.Url,
identifier: castUrl,
type,
identifier: castHashOrUrl,
});
return response.data.cast;
} catch (error) {
Expand Down Expand Up @@ -209,4 +193,58 @@ export class NeynarV2APIClient {
});
return response.data;
}

// ------------ Rection ------------

/**
* React to a cast.
* See [Neynar documentation](https://docs.neynar.com/reference/post-reaction)
*
*/
public async reactToCast(
signerUuid: string,
reaction: ReactionType,
castOrCastHash: Cast | string
): Promise<OperationResponse> {
let castHash: string;
if (typeof castOrCastHash === "string") {
castHash = castOrCastHash;
} else {
castHash = castOrCastHash.hash;
}
const body: ReactionReqBody = {
signer_uuid: signerUuid,
reaction_type: reaction,
target: castHash,
};
const response = await this.apis.reaction.postReaction({
reactionReqBody: body,
});
return response.data;
}

/**
* Remove a reaction to a cast. See [Neynar documentation](https://docs.neynar.com/reference/delete-reaction)
*/
public async removeReactionToCast(
signerUuid: string,
reaction: ReactionType,
castOrCastHash: Cast | string
): Promise<OperationResponse> {
let castHash: string;
if (typeof castOrCastHash === "string") {
castHash = castOrCastHash;
} else {
castHash = castOrCastHash.hash;
}
const body: ReactionReqBody = {
signer_uuid: signerUuid,
reaction_type: reaction,
target: castHash,
};
const response = await this.apis.reaction.deleteReaction({
reactionReqBody: body,
});
return response.data;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Farcaster API V2
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 1.0
* The version of the OpenAPI document: 2.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
98 changes: 55 additions & 43 deletions src/neynar-api/neynar-v2-api/openapi-farcaster/apis/reaction-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Farcaster API V2
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 2.0
* The version of the OpenAPI document: 1.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down Expand Up @@ -54,18 +54,14 @@ export const ReactionApiAxiosParamCreator = function (
/**
* Delete a reaction (like or recast) to a given cast \\ (In order to delete a reaction `signer_uuid` must be approved)
* @summary Delete a reaction
* @param {string} apiKey API key required for authentication.
* @param {ReactionReqBody} reactionReqBody
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
deleteReaction: async (
apiKey: string,
reactionReqBody: ReactionReqBody,
options: AxiosRequestConfig = {}
): Promise<RequestArgs> => {
// verify required parameter 'apiKey' is not null or undefined
assertParamExists("deleteReaction", "apiKey", apiKey);
// verify required parameter 'reactionReqBody' is not null or undefined
assertParamExists("deleteReaction", "reactionReqBody", reactionReqBody);
const localVarPath = `/farcaster/reaction`;
Expand All @@ -84,9 +80,12 @@ export const ReactionApiAxiosParamCreator = function (
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;

if (apiKey != null) {
localVarHeaderParameter["api_key"] = String(apiKey);
}
// authentication ApiKeyAuth required
await setApiKeyToObject(
localVarHeaderParameter,
"api_key",
configuration
);

localVarHeaderParameter["Content-Type"] = "application/json";

Expand All @@ -112,18 +111,14 @@ export const ReactionApiAxiosParamCreator = function (
/**
* Post a reaction (like or recast) to a given cast \\ (In order to post a reaction `signer_uuid` must be approved)
* @summary Posts a reaction
* @param {string} apiKey API key required for authentication.
* @param {ReactionReqBody} reactionReqBody
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
postReaction: async (
apiKey: string,
reactionReqBody: ReactionReqBody,
options: AxiosRequestConfig = {}
): Promise<RequestArgs> => {
// verify required parameter 'apiKey' is not null or undefined
assertParamExists("postReaction", "apiKey", apiKey);
// verify required parameter 'reactionReqBody' is not null or undefined
assertParamExists("postReaction", "reactionReqBody", reactionReqBody);
const localVarPath = `/farcaster/reaction`;
Expand All @@ -142,9 +137,12 @@ export const ReactionApiAxiosParamCreator = function (
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;

if (apiKey != null) {
localVarHeaderParameter["api_key"] = String(apiKey);
}
// authentication ApiKeyAuth required
await setApiKeyToObject(
localVarHeaderParameter,
"api_key",
configuration
);

localVarHeaderParameter["Content-Type"] = "application/json";

Expand Down Expand Up @@ -180,13 +178,11 @@ export const ReactionApiFp = function (configuration?: Configuration) {
/**
* Delete a reaction (like or recast) to a given cast \\ (In order to delete a reaction `signer_uuid` must be approved)
* @summary Delete a reaction
* @param {string} apiKey API key required for authentication.
* @param {ReactionReqBody} reactionReqBody
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async deleteReaction(
apiKey: string,
reactionReqBody: ReactionReqBody,
options?: AxiosRequestConfig
): Promise<
Expand All @@ -196,7 +192,6 @@ export const ReactionApiFp = function (configuration?: Configuration) {
) => AxiosPromise<OperationResponse>
> {
const localVarAxiosArgs = await localVarAxiosParamCreator.deleteReaction(
apiKey,
reactionReqBody,
options
);
Expand All @@ -210,13 +205,11 @@ export const ReactionApiFp = function (configuration?: Configuration) {
/**
* Post a reaction (like or recast) to a given cast \\ (In order to post a reaction `signer_uuid` must be approved)
* @summary Posts a reaction
* @param {string} apiKey API key required for authentication.
* @param {ReactionReqBody} reactionReqBody
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async postReaction(
apiKey: string,
reactionReqBody: ReactionReqBody,
options?: AxiosRequestConfig
): Promise<
Expand All @@ -226,7 +219,6 @@ export const ReactionApiFp = function (configuration?: Configuration) {
) => AxiosPromise<OperationResponse>
> {
const localVarAxiosArgs = await localVarAxiosParamCreator.postReaction(
apiKey,
reactionReqBody,
options
);
Expand Down Expand Up @@ -254,40 +246,64 @@ export const ReactionApiFactory = function (
/**
* Delete a reaction (like or recast) to a given cast \\ (In order to delete a reaction `signer_uuid` must be approved)
* @summary Delete a reaction
* @param {string} apiKey API key required for authentication.
* @param {ReactionReqBody} reactionReqBody
* @param {ReactionApiDeleteReactionRequest} requestParameters Request parameters.
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
deleteReaction(
apiKey: string,
reactionReqBody: ReactionReqBody,
options?: any
requestParameters: ReactionApiDeleteReactionRequest,
options?: AxiosRequestConfig
): AxiosPromise<OperationResponse> {
return localVarFp
.deleteReaction(apiKey, reactionReqBody, options)
.deleteReaction(requestParameters.reactionReqBody, options)
.then((request) => request(axios, basePath));
},
/**
* Post a reaction (like or recast) to a given cast \\ (In order to post a reaction `signer_uuid` must be approved)
* @summary Posts a reaction
* @param {string} apiKey API key required for authentication.
* @param {ReactionReqBody} reactionReqBody
* @param {ReactionApiPostReactionRequest} requestParameters Request parameters.
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
postReaction(
apiKey: string,
reactionReqBody: ReactionReqBody,
options?: any
requestParameters: ReactionApiPostReactionRequest,
options?: AxiosRequestConfig
): AxiosPromise<OperationResponse> {
return localVarFp
.postReaction(apiKey, reactionReqBody, options)
.postReaction(requestParameters.reactionReqBody, options)
.then((request) => request(axios, basePath));
},
};
};

/**
* Request parameters for deleteReaction operation in ReactionApi.
* @export
* @interface ReactionApiDeleteReactionRequest
*/
export interface ReactionApiDeleteReactionRequest {
/**
*
* @type {ReactionReqBody}
* @memberof ReactionApiDeleteReaction
*/
readonly reactionReqBody: ReactionReqBody;
}

/**
* Request parameters for postReaction operation in ReactionApi.
* @export
* @interface ReactionApiPostReactionRequest
*/
export interface ReactionApiPostReactionRequest {
/**
*
* @type {ReactionReqBody}
* @memberof ReactionApiPostReaction
*/
readonly reactionReqBody: ReactionReqBody;
}

/**
* ReactionApi - object-oriented interface
* @export
Expand All @@ -298,38 +314,34 @@ export class ReactionApi extends BaseAPI {
/**
* Delete a reaction (like or recast) to a given cast \\ (In order to delete a reaction `signer_uuid` must be approved)
* @summary Delete a reaction
* @param {string} apiKey API key required for authentication.
* @param {ReactionReqBody} reactionReqBody
* @param {ReactionApiDeleteReactionRequest} requestParameters Request parameters.
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof ReactionApi
*/
public deleteReaction(
apiKey: string,
reactionReqBody: ReactionReqBody,
requestParameters: ReactionApiDeleteReactionRequest,
options?: AxiosRequestConfig
) {
return ReactionApiFp(this.configuration)
.deleteReaction(apiKey, reactionReqBody, options)
.deleteReaction(requestParameters.reactionReqBody, options)
.then((request) => request(this.axios, this.basePath));
}

/**
* Post a reaction (like or recast) to a given cast \\ (In order to post a reaction `signer_uuid` must be approved)
* @summary Posts a reaction
* @param {string} apiKey API key required for authentication.
* @param {ReactionReqBody} reactionReqBody
* @param {ReactionApiPostReactionRequest} requestParameters Request parameters.
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof ReactionApi
*/
public postReaction(
apiKey: string,
reactionReqBody: ReactionReqBody,
requestParameters: ReactionApiPostReactionRequest,
options?: AxiosRequestConfig
) {
return ReactionApiFp(this.configuration)
.postReaction(apiKey, reactionReqBody, options)
.postReaction(requestParameters.reactionReqBody, options)
.then((request) => request(this.axios, this.basePath));
}
}
Loading

0 comments on commit f1768d9

Please sign in to comment.