Skip to content

Commit

Permalink
Revert "feat(IEX-910): Add method to fetch a drop image object (#90)" (
Browse files Browse the repository at this point in the history
  • Loading branch information
reobin authored Mar 7, 2024
1 parent ba6f9ec commit 8d78b56
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 97 deletions.
5 changes: 1 addition & 4 deletions examples/drops/backend/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { DropsClient } from '@poap-xyz/drops';
import { PoapCompass, PoapDropApi } from '@poap-xyz/providers';
import { create_drop } from './methods/create_drop';
import { fetch_drop_image } from './methods/fetch_drop_image';
import { fetch_multiple_drops } from './methods/fetch_multiple_drops';
import { fetch_single_drop } from './methods/fetch_single_drop';
import { create_drop } from './methods/create_drop';
import { getRequiredEnvVar } from './methods/get_required_env_var';

import dotenv from 'dotenv';
Expand All @@ -26,8 +25,6 @@ async function main(): Promise<void> {
await fetch_multiple_drops(client);
// One Drop by id
await fetch_single_drop(client);
// A Drop Image
await fetch_drop_image(client);
// Create Drop
await create_drop(client);
}
Expand Down
11 changes: 0 additions & 11 deletions examples/drops/backend/src/methods/fetch_drop_image.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/drops/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@poap-xyz/drops",
"version": "0.1.4",
"version": "0.1.5",
"description": "Drops module for the poap.js library",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.mjs",
Expand Down
67 changes: 25 additions & 42 deletions packages/drops/src/DropsClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,9 @@ import {
PaginatedDropsResponse,
PAGINATED_DROPS_QUERY,
DropImageResponse,
DropImageQueryResponse,
DROP_IMAGE_QUERY,
DropResponse,
} from './queries';
import {
CreateDropsInput,
FetchDropsInput,
UpdateDropsInput,
DropImage,
DropImageGatewayType,
} from './types';
import { CreateDropsInput, FetchDropsInput, UpdateDropsInput } from './types';
import {
PaginatedResult,
nextCursor,
Expand All @@ -27,6 +20,7 @@ import {
createFilter,
createInFilter,
} from '@poap-xyz/utils';
import { DropImage } from './types/dropImage';

/**
* Represents a client for working with POAP drops.
Expand All @@ -46,21 +40,6 @@ export class DropsClient {
private dropApiProvider: DropApiProvider,
) {}

/**
* Fetches the drop image object containing the original as well as the
* cropped image URLs for the specified drop id.
*
* @param id - The drop id.
* @returns The drop image object.
*/
async fetchDropImage(id: number): Promise<DropImage | undefined> {
const { data } = await this.compassProvider.request<DropImageQueryResponse>(
DROP_IMAGE_QUERY,
{ id },
);
return this.mapDropImage(data.drops[0]);
}

/**
* Fetches drops based on the specified input.
*
Expand Down Expand Up @@ -100,7 +79,7 @@ export class DropsClient {
);

const drops = data.drops.map((drop) => {
const dropImage = this.mapDropImage(drop);
const { imageUrl, originalImageUrl } = this.computeDropImages(drop);

return new Drop({
id: Number(drop.id),
Expand All @@ -113,6 +92,8 @@ export class DropsClient {
platform: drop.platform,
locationType: drop.location_type,
dropUrl: drop.drop_url,
imageUrl,
originalImageUrl,
animationUrl: drop.animation_url,
year: Number(drop.year),
startDate: new Date(drop.start_date),
Expand All @@ -130,7 +111,6 @@ export class DropsClient {
: 0,
expiryDate: new Date(drop.expiry_date),
endDate: new Date(drop.end_date),
...dropImage,
});
});

Expand All @@ -149,7 +129,7 @@ export class DropsClient {
* @returns {Promise<Drop>} The newly created drop.
*/
async create(input: CreateDropsInput): Promise<Drop> {
const response = await this.dropApiProvider.createDrop({
const repsonse = await this.dropApiProvider.createDrop({
name: input.name,
description: input.description,
city: input.city,
Expand All @@ -168,7 +148,7 @@ export class DropsClient {
requested_codes: input.requestedCodes,
private_event: input.privateEvent,
});
return this.formatDrop(response);
return this.formatDrop(repsonse);
}

/**
Expand Down Expand Up @@ -225,22 +205,25 @@ export class DropsClient {
});
}

/**
* Maps the response drop_image object into a DropImage object.
*
* @param drop - The response drop with drop_image object.
* @returns The mapped DropImage object.
*/
private mapDropImage(drop: DropImageResponse): DropImage {
const images = drop.drop_image?.gateways?.reduce(
(acc, gateway) => ({ ...acc, [gateway.type]: gateway.url }),
private computeDropImages(drop: DropResponse): {
imageUrl: string;
originalImageUrl: string;
} {
const dropImage = this.mapDropImage(drop.drop_image);
return {
imageUrl: dropImage?.crop || drop.image_url,
originalImageUrl: dropImage?.original || drop.image_url,
};
}

private mapDropImage(response?: DropImageResponse): DropImage | undefined {
if (!response) return response;

const images = response.gateways.reduce(
(acc, gateway) => ({ ...acc, [gateway.type.toLowerCase()]: gateway.url }),
{},
);

return {
originalImageUrl:
images?.[DropImageGatewayType.ORIGINAL] || drop.image_url,
imageUrl: images?.[DropImageGatewayType.CROP] || drop.image_url,
};
return { ...images };
}
}
33 changes: 0 additions & 33 deletions packages/drops/src/queries/DropImage.ts

This file was deleted.

13 changes: 11 additions & 2 deletions packages/drops/src/queries/PaginatedDrop.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DropImageGatewaysResponse } from './DropImage';
import { DropImageGatewayType } from '../types/dropImage';

export const PAGINATED_DROPS_QUERY = `
query PaginatedDrops(
Expand Down Expand Up @@ -48,6 +48,15 @@ export const PAGINATED_DROPS_QUERY = `
}
`;

export interface DropImageGatewayResponse {
type: DropImageGatewayType;
url: string;
}

export interface DropImageResponse {
gateways: Array<DropImageGatewayResponse>;
}

export interface DropResponse {
id: number;
fancy_id: string;
Expand Down Expand Up @@ -79,7 +88,7 @@ export interface DropResponse {
email_claims_stats: {
total: number;
};
drop_image?: DropImageGatewaysResponse;
drop_image?: DropImageResponse;
}

export interface PaginatedDropsResponse {
Expand Down
1 change: 0 additions & 1 deletion packages/drops/src/queries/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from './PaginatedDrop';
export * from './DropImage';
4 changes: 2 additions & 2 deletions packages/drops/src/types/dropImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ export enum DropImageGatewayType {
}

export interface DropImage {
imageUrl: string;
originalImageUrl: string;
original?: string;
crop?: string;
}
1 change: 0 additions & 1 deletion packages/drops/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from './input';
export * from './dropImage';

0 comments on commit 8d78b56

Please sign in to comment.