Skip to content

Commit

Permalink
Add support for optional API secrets
Browse files Browse the repository at this point in the history
  • Loading branch information
coreh committed Jul 12, 2018
1 parent 3b16b1b commit e5da55b
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/buyer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export interface Buyer extends Resource {

export class BuyerEndpoint extends Endpoint<Buyer> {
constructor(marketplace: MarketplaceEndpoint, id: string) {
super(marketplace.base + `/buyers/${id}`, marketplace.apiKey);
super(marketplace.base + `/buyers/${id}`, marketplace.apiKey, marketplace.apiSecret);
}

async get() {
Expand Down
4 changes: 2 additions & 2 deletions lib/endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ enum StatusClass {
}

export abstract class Endpoint<T extends Resource = AnyResource> {
constructor(readonly base: string, readonly apiKey: string) { }
constructor(readonly base: string, readonly apiKey: string, readonly apiSecret: string) { }

private static statusClass(statusCode: number): StatusClass {
return Math.floor(statusCode / 100);
Expand All @@ -31,7 +31,7 @@ export abstract class Endpoint<T extends Resource = AnyResource> {

public async request<U extends Resource = T>(method: string, route: string = '', payload?: object): Promise<U | undefined> {
const headers = new Headers({
Authorization: `Basic ${btoa(`${this.apiKey}:${this.apiKey}`)}`,
Authorization: `Basic ${btoa(`${this.apiKey}:${this.apiSecret}`)}`,
});

let uri;
Expand Down
2 changes: 1 addition & 1 deletion lib/marketplace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export interface Marketplace extends Resource {

export class MarketplaceEndpoint extends Endpoint<Marketplace> {
constructor(zoop: Zoop, id: string) {
super(zoop.base + `/marketplaces/${id}`, zoop.apiKey);
super(zoop.base + `/marketplaces/${id}`, zoop.apiKey, zoop.apiSecret);
}

buyer(id: string): BuyerEndpoint {
Expand Down
2 changes: 1 addition & 1 deletion lib/seller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface Seller extends Resource {

export class SellerEndpoint extends Endpoint<Seller> {
constructor(marketplace: MarketplaceEndpoint, id: string) {
super(marketplace.base + `/sellers/${id}`, marketplace.apiKey);
super(marketplace.base + `/sellers/${id}`, marketplace.apiKey, marketplace.apiSecret);
}

async get() {
Expand Down
2 changes: 1 addition & 1 deletion lib/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export type Token = BankAccountToken | CardToken;

export class TokenEndpoint extends Endpoint<Token> {
constructor(marketplace: MarketplaceEndpoint, id: string) {
super(marketplace.base + `/tokens/${id}`, marketplace.apiKey);
super(marketplace.base + `/tokens/${id}`, marketplace.apiKey, marketplace.apiSecret);
}

async get() {
Expand Down
2 changes: 1 addition & 1 deletion lib/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export interface Transaction extends Resource {

export class TransactionEndpoint extends Endpoint<Transaction> {
constructor(marketplace: MarketplaceEndpoint, id: string) {
super(marketplace.base + `/transactions/${id}`, marketplace.apiKey);
super(marketplace.base + `/transactions/${id}`, marketplace.apiKey, marketplace.apiSecret);
}

async get() {
Expand Down
4 changes: 2 additions & 2 deletions lib/zoop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { AnyResource, Resource } from './resource';
const API_BASE = 'https://api.zoop.ws/v1';

export class Zoop extends Endpoint {
constructor(readonly apiKey: string) {
super(API_BASE, apiKey);
constructor(readonly apiKey: string, readonly apiSecret: string = apiKey) {
super(API_BASE, apiKey, apiSecret);
}

marketplace(id: string) {
Expand Down

0 comments on commit e5da55b

Please sign in to comment.