Skip to content

Commit

Permalink
Merge pull request #5 from Ovenn-lab/feature/additional-endpoints-sup…
Browse files Browse the repository at this point in the history
…port

Feature/additional endpoints support
  • Loading branch information
vgumonis authored Nov 8, 2022
2 parents 029734c + a2d968f commit 3d8392f
Show file tree
Hide file tree
Showing 34 changed files with 8,738 additions and 25 deletions.
120 changes: 120 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ Please note, that for Sandbox you must generate separate API credentials on http

Usage of CoinGate package looks like:

Importing:

```ts
import { Client } from '@coingate/coingate-sdk';
```

Or

```ts
const { Client } = require('@coingate/coingate-sdk');
```

In order, to use live mode, provide only api token.

```ts
const client = new Client('YOUR_API_TOKEN');
```
Expand Down Expand Up @@ -272,6 +286,112 @@ client.refunds
.catch((error) => console.log(error));
```

### Ledger

#### Get Account

Retrieving specific account.

```ts
(async () => {
try {
const account = await client.ledger.getAccount('10801');
} catch {
// Oops... Something went wrong...
console.error(error);
}
})();
```

Or

```ts
client.ledger
.getAccount('10801')
.then((account) => console.log(account))
.catch((error) => console.log(error));
```

#### Get Accounts

Retrieving all accounts.

```ts
const searchParams = { page: 2, per_page: 29 };

(async () => {
try {
// search params is optional, and default is { page: 1, per_page: 100 }
const accounts = await client.ledger.getAccounts(searchParams);
} catch {
// Oops... Something went wrong...
console.error(error);
}
})();
```

Or

```ts
client.ledger
.getAccounts()
.then((accounts) => console.log(accounts))
.catch((error) => console.log(error));
```

### Withdrawals

#### Get Withdrawal

Retrieving specific withdrawal.

```ts
(async () => {
try {
const withdrawals = await client.withdrawals.getWithdrawal(0029);
} catch {
// Oops... Something went wrong...
console.error(error);
}
})();
```

Or

```ts
client.withdrawals
.getWithdrawal(0029)
.then((withdrawals) => console.log(withdrawal))
.catch((error) => console.log(error));
```

#### Get Withdrawals

Retrieving all withdrawals.

```ts
const searchParams = { page: 2, per_page: 29 };

(async () => {
try {
// search params is optional, and default is { page: 1, per_page: 100 }
const withdrawals = await client.withdrawals.getWithdrawals(searchParams);
} catch {
// Oops... Something went wrong...
console.error(error);
}
})();
```

Or

```ts
client.withdrawals
.getWithdrawals()
.then((withdrawals) => console.log(withdrawals))
.catch((error) => console.log(error));
```

### Public API

#### Get Exchange Rate
Expand Down
10 changes: 9 additions & 1 deletion build/Client.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OrderService, PublicService, RefundsService, AbstractService } from './Modules';
import { OrderService, PublicService, RefundsService, AbstractService, WithdrawalsService, LedgerService } from './Modules';
import { AppInfo, EnvironmentEnum } from './types';
/**
* Class representing a Client
Expand Down Expand Up @@ -27,6 +27,14 @@ export declare class Client extends AbstractService {
* @public order service
*/
order: OrderService;
/**
* @public ledger service
*/
ledger: LedgerService;
/**
* @public withdrawals service
*/
withdrawals: WithdrawalsService;
/**
* @public refunds service
*/
Expand Down
10 changes: 9 additions & 1 deletion build/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ class Client extends _Modules_1.AbstractService {
this.validateConfig();
const { apiBase } = this.config;
this.prepareModules(apiBase);
this.services = [this.public, this.order, this.refunds];
this.services = [
this.public,
this.order,
this.refunds,
this.ledger,
this.withdrawals
];
this.setApiKey(this.config.apiKey);
}
/**
Expand All @@ -48,6 +54,8 @@ class Client extends _Modules_1.AbstractService {
this.public = new _Modules_1.PublicService(apiBase);
this.refunds = new _Modules_1.RefundsService(apiBase);
this.order = new _Modules_1.OrderService(apiBase);
this.ledger = new _Modules_1.LedgerService(apiBase);
this.withdrawals = new _Modules_1.WithdrawalsService(apiBase);
}
/**
* Config validator
Expand Down
10 changes: 10 additions & 0 deletions build/Modules/AbstractService/Abstract.service.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { PaginationParams } from '../../Modules/types';
import { BuildPathInput } from './types';
/**
* Class representing Abstract service
*/
export declare class AbstractService {
protected defaultPaginationParams: {
page: number;
per_page: number;
};
/**
* Builds path with provided params
* @param {BuildPathInput} param
Expand All @@ -14,4 +19,9 @@ export declare class AbstractService {
* @param {string|null} apiKey
*/
protected validateApiKey(apiKey: string | null): void;
/**
* Checks if params exists, if no then sets default params and formats it
* @param {PaginationParams} params
*/
protected formatPaginationParams(params?: PaginationParams): URLSearchParams;
}
14 changes: 14 additions & 0 deletions build/Modules/AbstractService/Abstract.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const _Exception_1 = require("../../Exception");
* Class representing Abstract service
*/
class AbstractService {
constructor() {
this.defaultPaginationParams = { page: 1, per_page: 100 };
}
/**
* Builds path with provided params
* @param {BuildPathInput} param
Expand Down Expand Up @@ -37,5 +40,16 @@ class AbstractService {
}
}
}
/**
* Checks if params exists, if no then sets default params and formats it
* @param {PaginationParams} params
*/
formatPaginationParams(params) {
const searchParams = params || this.defaultPaginationParams;
const formattedParams = new URLSearchParams();
formattedParams.append('page', searchParams.page.toString());
formattedParams.append('per_page', searchParams.per_page.toString());
return formattedParams;
}
}
exports.AbstractService = AbstractService;
3 changes: 2 additions & 1 deletion build/Modules/AbstractService/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { GetAccountParamsType } from '../../Modules/Ledger/types';
import { PaymentParamType } from '../../Modules/Order/types';
import { GetCurrenciesData, GetExchangeRateData, SeparatorType } from '../../Modules/Public/types';
import { RefundParamsType } from '../../Modules/Refunds/types';
export declare type BuildPathInput = {
path: string;
params?: GetExchangeRateData | GetCurrenciesData | PaymentParamType | SeparatorType | RefundParamsType;
params?: GetExchangeRateData | GetCurrenciesData | PaymentParamType | SeparatorType | RefundParamsType | GetAccountParamsType;
};
2 changes: 1 addition & 1 deletion build/Modules/Client/CoinGate.client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export declare class CoinGateClient extends AbstractService {
* @param {GetRequestType} params
* @returns {Promise}
*/
protected get({ path, params, apiKey }: GetRequestType): Promise<any>;
protected get({ path, params, apiKey, searchParams }: GetRequestType): Promise<any>;
/**
* Set request timeout
* @param {number} timeout
Expand Down
7 changes: 4 additions & 3 deletions build/Modules/Client/CoinGate.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class CoinGateClient extends Abstract_service_1.AbstractService {
/**
* @description coingate-sdk version
*/
this.VERSION = '1.0.0';
this.VERSION = '1.1.2';
/**
* @description default request timeout is 30 seconds
*/
Expand Down Expand Up @@ -80,13 +80,14 @@ class CoinGateClient extends Abstract_service_1.AbstractService {
* @param {GetRequestType} params
* @returns {Promise}
*/
get({ path, params, apiKey }) {
get({ path, params, apiKey, searchParams }) {
return __awaiter(this, void 0, void 0, function* () {
try {
const { data } = yield this.client.get(this.baseUrl + path, {
params,
headers: this.getDefaultHeaders(apiKey),
timeout: this.timeout
timeout: this.timeout,
data: searchParams
});
return data;
}
Expand Down
1 change: 1 addition & 0 deletions build/Modules/Client/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export declare type GetRequestType = {
path: string;
params?: object;
apiKey?: string;
searchParams?: URLSearchParams;
};
export declare type HeadersType = {
'Content-Type'?: string;
Expand Down
20 changes: 20 additions & 0 deletions build/Modules/Ledger/Ledger.service.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { CoinGateClient } from '../../Modules/Client/CoinGate.client';
import { PaginationParams } from '../../Modules/types';
/**
* Class representing a Ledger Service
* @extends CoinGateClient
*/
export declare class LedgerService extends CoinGateClient {
/**
* Retrieving a specific ledger account.
* @param {string} id
* @returns Account
*/
getAccount(id: string): Promise<any>;
/**
* Retrieving all ledger accounts.
* @param {PaginationParams} params page number and number of accounts per page
* @returns Accounts
*/
listAccounts(params?: PaginationParams): Promise<any>;
}
32 changes: 32 additions & 0 deletions build/Modules/Ledger/Ledger.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LedgerService = void 0;
const CoinGate_client_1 = require("../../Modules/Client/CoinGate.client");
/**
* Class representing a Ledger Service
* @extends CoinGateClient
*/
class LedgerService extends CoinGate_client_1.CoinGateClient {
/**
* Retrieving a specific ledger account.
* @param {string} id
* @returns Account
*/
getAccount(id) {
const path = this.buildPath({
path: '/v2/ledger/accounts/:id',
params: { id }
});
return this.get({ path });
}
/**
* Retrieving all ledger accounts.
* @param {PaginationParams} params page number and number of accounts per page
* @returns Accounts
*/
listAccounts(params) {
const searchParams = this.formatPaginationParams(params);
return this.get({ path: '/v2/ledger/accounts', searchParams });
}
}
exports.LedgerService = LedgerService;
3 changes: 3 additions & 0 deletions build/Modules/Ledger/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export declare type GetAccountParamsType = {
id: string;
};
2 changes: 2 additions & 0 deletions build/Modules/Ledger/types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
20 changes: 20 additions & 0 deletions build/Modules/Withdrawals/Withdrawals.service.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { CoinGateClient } from '../../Modules/Client/CoinGate.client';
import { PaginationParams } from '../../Modules/types';
/**
* Class representing a Withdrawals Service
* @extends CoinGateClient
*/
export declare class WithdrawalsService extends CoinGateClient {
/**
* Retrieving a specific withdrawal.
* @param {number} id
* @returns Withdrawal
*/
getWithdrawal(id: number): Promise<any>;
/**
* Retrieving all withdrawals
* @param {PaginationParams} params page number and number of withdrawals per page
* @returns Withdrawals
*/
getWithdrawals(params?: PaginationParams): Promise<any>;
}
32 changes: 32 additions & 0 deletions build/Modules/Withdrawals/Withdrawals.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WithdrawalsService = void 0;
const CoinGate_client_1 = require("../../Modules/Client/CoinGate.client");
/**
* Class representing a Withdrawals Service
* @extends CoinGateClient
*/
class WithdrawalsService extends CoinGate_client_1.CoinGateClient {
/**
* Retrieving a specific withdrawal.
* @param {number} id
* @returns Withdrawal
*/
getWithdrawal(id) {
const path = this.buildPath({
path: '/v2/withdrawals/:id',
params: { id }
});
return this.get({ path });
}
/**
* Retrieving all withdrawals
* @param {PaginationParams} params page number and number of withdrawals per page
* @returns Withdrawals
*/
getWithdrawals(params) {
const searchParams = this.formatPaginationParams(params);
return this.get({ path: '/v2/withdrawals', searchParams });
}
}
exports.WithdrawalsService = WithdrawalsService;
Loading

0 comments on commit 3d8392f

Please sign in to comment.