Skip to content

Commit

Permalink
Merge pull request #215 from prezly/feature/dev-10111-sdk-add-pricing…
Browse files Browse the repository at this point in the history
…-table-endpoints-and

[DEV-10111] Implement `PricingTables` API SDK
  • Loading branch information
mohammadxali authored Feb 22, 2023
2 parents 4548714 + dfd2002 commit 1a689b7
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
NewsroomDomains,
NewsroomGalleries,
NewsroomHub,
PricingTables,
SenderAddresses,
Signup,
Stories,
Expand Down Expand Up @@ -55,6 +56,7 @@ export interface Client {
newsroomDomains: NewsroomDomains.Client;
newsroomGalleries: NewsroomGalleries.Client;
newsroomHub: NewsroomHub.Client;
pricingTables: PricingTables.Client;
senderAddresses: SenderAddresses.Client;
signup: Signup.Client;
stories: Stories.Client;
Expand Down Expand Up @@ -96,6 +98,7 @@ export function createClient({
newsroomDomains: new NewsroomDomains.Client(apiClient),
newsroomGalleries: new NewsroomGalleries.Client(apiClient),
newsroomHub: new NewsroomHub.Client(apiClient),
pricingTables: new PricingTables.Client(apiClient),
senderAddresses: new SenderAddresses.Client(apiClient),
signup: new Signup.Client(apiClient),
stories: new Stories.Client(apiClient),
Expand Down
18 changes: 18 additions & 0 deletions src/endpoints/PricingTables/Client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { DeferredJobsApiClient } from '../../api';
import { routing } from '../../routing';

import type { PricingTable } from './types';

export class Client {
private readonly apiClient: DeferredJobsApiClient;

constructor(apiClient: DeferredJobsApiClient) {
this.apiClient = apiClient;
}

public async get(tableId: 'standard'): Promise<PricingTable> {
const url = routing.pricingTablesUrl.replace(':table_id', String(tableId));
const { table } = await this.apiClient.get<{ table: PricingTable }>(url);
return table;
}
}
2 changes: 2 additions & 0 deletions src/endpoints/PricingTables/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './Client';
export * from './types';
38 changes: 38 additions & 0 deletions src/endpoints/PricingTables/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
export interface PricingTable {
options: Option[];
}

export interface Option {
id: string;
display_name: string;
description: string | null;
overview_features_list: PlanFeatureRef[];
limits: Limit[];
prices: Price[];
add_ons: AddOn[];
}

export interface PlanFeatureRef {
name: string;
details?: string;
}

export interface Limit {
id: string;
display_name: string;
value: null | number;
per: null | string;
}

export interface Price {
billing_cycle: string;
currency: string;
amount: number;
unit: string | null;
}

export interface AddOn {
id: string;
display_name: string;
prices: Price[];
}
1 change: 1 addition & 0 deletions src/endpoints/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export * as Newsrooms from './Newsrooms';
export * as NewsroomSubscriptions from './NewsroomSubscriptions';
export * as NewsroomThemes from './NewsroomThemes';
export * as NewsroomWebhooks from './NewsroomWebhooks';
export * as PricingTables from './PricingTables';
export * as SenderAddresses from './SenderAddresses';
export * as Signup from './Signup';
export * as Snippets from './Snippets';
Expand Down
1 change: 1 addition & 0 deletions src/routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const routing = {
newsroomGalleriesUrl: '/v2/newsrooms/:newsroom_id/galleries',
newsroomHubUrl: '/v2/newsrooms/:newsroom_id/hub',
notificationSubscriptionsUrl: '/v2/notification-subscriptions',
pricingTablesUrl: '/v2/pricing-tables/:table_id',
senderAddressesUrl: '/v2/sender-addresses',
signup: '/v2/signup',
storiesUrl: '/v2/stories',
Expand Down

0 comments on commit 1a689b7

Please sign in to comment.