Skip to content

Commit

Permalink
PLT-1397 changed how to create poapTokenApi
Browse files Browse the repository at this point in the history
  • Loading branch information
rlajous committed Sep 13, 2023
1 parent f257988 commit d27144e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
10 changes: 5 additions & 5 deletions examples/poaps/backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ async function main(): Promise<void> {
// Use your library here
const client = new PoapsClient(
new PoapCompass(getRequiredEnvVar('API_KEY')),
new PoapTokenApi(
getRequiredEnvVar('API_KEY'),
getRequiredEnvVar('POAP_TOKEN_BASE_URL'),
new AuthenticationProviderHttp(
new PoapTokenApi({
apiKey: getRequiredEnvVar('API_KEY'),
baseUrl: getRequiredEnvVar('POAP_TOKEN_BASE_URL'),
authenticationProvider: new AuthenticationProviderHttp(
getRequiredEnvVar('CLIENT_ID'),
getRequiredEnvVar('CLIENT_SECRET'),
getRequiredEnvVar('OAUTH_SERVER_DOMAIN'),
),
),
}),
);
// Multiple Poaps
await measurePerformance(
Expand Down
23 changes: 18 additions & 5 deletions packages/providers/src/core/PoapTokenApi/PoapTokenApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,24 @@ const instance = axios.create({
const DEFAULT_DROP_BASE_URL = 'https://api.poap.tech';

export class PoapTokenApi implements TokensApiProvider {
private apiKey: string;
private baseUrl: string;
private authenticationProvider?: AuthenticationProvider;
/**
* Creates a new instance of the `PoapDropApi` class.
*
* @constructor
* @param {string} apiKey - The API key to use for requests.
*/
constructor(
private apiKey: string,
private baseUrl: string = DEFAULT_DROP_BASE_URL,
private authenticationProvider?: AuthenticationProvider,
) {}
constructor({
apiKey,
baseUrl = DEFAULT_DROP_BASE_URL,
authenticationProvider,
}: PoapTokenApiOptions) {
this.apiKey = apiKey;
this.baseUrl = baseUrl;
this.authenticationProvider = authenticationProvider;
}

async getClaimCode(code: string): Promise<GetClaimCodeResponse> {
return await this.secureFetch<GetClaimCodeResponse>(
Expand Down Expand Up @@ -94,3 +101,9 @@ export class PoapTokenApi implements TokensApiProvider {
return `Bearer ${await this.authenticationProvider.getJWT(this.baseUrl)}`;
}
}

export interface PoapTokenApiOptions {
apiKey: string;
baseUrl?: string;
authenticationProvider?: AuthenticationProvider;
}
2 changes: 1 addition & 1 deletion packages/providers/src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ export { PoapMomentsApi } from './PoapMomentsApi/PoapMomentsApi';
export { PoapDropApi } from './PoapDropApi/PoapDropApi';
export { PoapCompass } from './PoapCompass/PoapCompass';
export { AuthenticationProviderHttp } from './AuthenticationProviderHttp/AuthenticationProviderHttp';
export { PoapTokenApi } from './PoapTokenApi/PoapTokenApi';
export { PoapTokenApi, PoapTokenApiOptions } from './PoapTokenApi/PoapTokenApi';
export { InvalidMediaError } from './PoapMomentsApi/errors/InvalidMediaError';

0 comments on commit d27144e

Please sign in to comment.