aboutsummaryrefslogtreecommitdiffstats
path: root/packages/connect/src/http_client.ts
diff options
context:
space:
mode:
authorBrandon Millman <brandon.millman@gmail.com>2017-11-28 06:34:34 +0800
committerBrandon Millman <brandon.millman@gmail.com>2017-11-28 06:34:34 +0800
commit426a412ba1a0e3cd955d11bbe6d7426a61e5dd63 (patch)
tree5d3e9f2749411ba91fa567f96ce81d1206d273be /packages/connect/src/http_client.ts
parent4a17f5e82074b01e74ae6982e82419a037eebdb4 (diff)
downloaddexon-sol-tools-426a412ba1a0e3cd955d11bbe6d7426a61e5dd63.tar
dexon-sol-tools-426a412ba1a0e3cd955d11bbe6d7426a61e5dd63.tar.gz
dexon-sol-tools-426a412ba1a0e3cd955d11bbe6d7426a61e5dd63.tar.bz2
dexon-sol-tools-426a412ba1a0e3cd955d11bbe6d7426a61e5dd63.tar.lz
dexon-sol-tools-426a412ba1a0e3cd955d11bbe6d7426a61e5dd63.tar.xz
dexon-sol-tools-426a412ba1a0e3cd955d11bbe6d7426a61e5dd63.tar.zst
dexon-sol-tools-426a412ba1a0e3cd955d11bbe6d7426a61e5dd63.zip
Move all connect types into types.ts
Diffstat (limited to 'packages/connect/src/http_client.ts')
-rw-r--r--packages/connect/src/http_client.ts27
1 files changed, 10 insertions, 17 deletions
diff --git a/packages/connect/src/http_client.ts b/packages/connect/src/http_client.ts
index 85dc83c61..18855693f 100644
--- a/packages/connect/src/http_client.ts
+++ b/packages/connect/src/http_client.ts
@@ -9,6 +9,8 @@ import {
Client,
FeesRequest,
FeesResponse,
+ HttpRequestOptions,
+ HttpRequestType,
OrderbookRequest,
OrderbookResponse,
OrdersRequest,
@@ -23,16 +25,6 @@ BigNumber.config({
EXPONENTIAL_AT: 1000,
});
-interface RequestOptions {
- params?: object;
- payload?: object;
-}
-
-enum RequestType {
- Get = 'GET',
- Post = 'POST',
-}
-
/**
* This class includes all the functionality related to interacting with a set of HTTP endpoints
* that implement the standard relayer API v0
@@ -61,7 +53,7 @@ export class HttpClient implements Client {
const requestOpts = {
params: request,
};
- const tokenPairs = await this._requestAsync('/token_pairs', RequestType.Get, requestOpts);
+ const tokenPairs = await this._requestAsync('/token_pairs', HttpRequestType.Get, requestOpts);
assert.doesConformToSchema(
'tokenPairs', tokenPairs, schemas.relayerApiTokenPairsResponseSchema);
_.each(tokenPairs, (tokenPair: object) => {
@@ -86,7 +78,7 @@ export class HttpClient implements Client {
const requestOpts = {
params: request,
};
- const orders = await this._requestAsync(`/orders`, RequestType.Get, requestOpts);
+ const orders = await this._requestAsync(`/orders`, HttpRequestType.Get, requestOpts);
assert.doesConformToSchema('orders', orders, schemas.signedOrdersSchema);
_.each(orders, (order: object) => typeConverters.convertOrderStringFieldsToBigNumber(order));
return orders;
@@ -98,7 +90,7 @@ export class HttpClient implements Client {
*/
public async getOrderAsync(orderHash: string): Promise<SignedOrder> {
assert.doesConformToSchema('orderHash', orderHash, schemas.orderHashSchema);
- const order = await this._requestAsync(`/order/${orderHash}`, RequestType.Get);
+ const order = await this._requestAsync(`/order/${orderHash}`, HttpRequestType.Get);
assert.doesConformToSchema('order', order, schemas.signedOrderSchema);
typeConverters.convertOrderStringFieldsToBigNumber(order);
return order;
@@ -113,7 +105,7 @@ export class HttpClient implements Client {
const requestOpts = {
params: request,
};
- const orderBook = await this._requestAsync('/orderbook', RequestType.Get, requestOpts);
+ const orderBook = await this._requestAsync('/orderbook', HttpRequestType.Get, requestOpts);
assert.doesConformToSchema('orderBook', orderBook, schemas.relayerApiOrderBookResponseSchema);
typeConverters.convertOrderbookStringFieldsToBigNumber(orderBook);
return orderBook;
@@ -134,7 +126,7 @@ export class HttpClient implements Client {
const requestOpts = {
payload: request,
};
- const fees = await this._requestAsync('/fees', RequestType.Post, requestOpts);
+ const fees = await this._requestAsync('/fees', HttpRequestType.Post, requestOpts);
assert.doesConformToSchema('fees', fees, schemas.relayerApiFeesResponseSchema);
typeConverters.convertStringsFieldsToBigNumbers(fees, ['makerFee', 'takerFee']);
return fees;
@@ -148,9 +140,10 @@ export class HttpClient implements Client {
const requestOpts = {
payload: signedOrder,
};
- await this._requestAsync('/order', RequestType.Post, requestOpts);
+ await this._requestAsync('/order', HttpRequestType.Post, requestOpts);
}
- private async _requestAsync(path: string, requestType: RequestType, requestOptions?: RequestOptions): Promise<any> {
+ private async _requestAsync(path: string, requestType: HttpRequestType,
+ requestOptions?: HttpRequestOptions): Promise<any> {
const params = _.get(requestOptions, 'params');
const payload = _.get(requestOptions, 'payload');
let query = '';