From 5c40c466f6e9f690afa86f23dd5ba240691dceb8 Mon Sep 17 00:00:00 2001 From: fragosti Date: Tue, 14 Aug 2018 14:59:53 -0700 Subject: Update json-schemas, update HTTPClient types --- packages/connect/src/http_client.ts | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) (limited to 'packages/connect/src/http_client.ts') diff --git a/packages/connect/src/http_client.ts b/packages/connect/src/http_client.ts index b2e15775e..20a2f9cc0 100644 --- a/packages/connect/src/http_client.ts +++ b/packages/connect/src/http_client.ts @@ -7,17 +7,19 @@ import * as queryString from 'query-string'; import { schemas as clientSchemas } from './schemas/schemas'; import { + APIOrder, + AssetPairsItem, AssetPairsRequestOpts, Client, - OrderConfigRequest, - OrderConfigResponse, HttpRequestOptions, HttpRequestType, OrderbookRequest, OrderbookResponse, + OrderConfigRequest, + OrderConfigResponse, OrdersRequestOpts, PagedRequestOpts, - TokenPairsItem, + PaginatedCollection, } from './types'; import { relayerResponseJsonParsers } from './utils/relayer_response_json_parsers'; @@ -26,12 +28,6 @@ const DEFAULT_PAGED_REQUEST_OPTS: PagedRequestOpts = { page: 1, perPage: 100, }; -/** - * This mapping defines how an option property name gets converted into an HTTP request query field - */ -const OPTS_TO_QUERY_FIELD_MAP = { - perPage: 'per_page', -}; /** * This class includes all the functionality related to interacting with a set of HTTP endpoints @@ -47,12 +43,8 @@ export class HttpClient implements Client { if (_.isUndefined(params) || _.isEmpty(params)) { return ''; } - // format params into a form the api expects - const formattedParams = _.mapKeys(params, (_value: any, key: string) => { - return _.get(OPTS_TO_QUERY_FIELD_MAP, key, key); - }); // stringify the formatted object - const stringifiedParams = queryString.stringify(formattedParams); + const stringifiedParams = queryString.stringify(params); return `?${stringifiedParams}`; } /** @@ -67,9 +59,9 @@ export class HttpClient implements Client { /** * Retrieve assetData pair info from the API * @param requestOpts Options specifying assetData information to retrieve and page information, defaults to { page: 1, perPage: 100 } - * @return The resulting TokenPairsItems that match the request + * @return The resulting AssetPairsItems that match the request */ - public async getAssetPairsAsync(requestOpts?: AssetPairsRequestOpts & PagedRequestOpts): Promise { + public async getAssetPairsAsync(requestOpts?: AssetPairsRequestOpts & PagedRequestOpts): Promise> { if (!_.isUndefined(requestOpts)) { assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.AssetPairsRequestOptsSchema); assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.pagedRequestOptsSchema); @@ -78,7 +70,7 @@ export class HttpClient implements Client { params: _.defaults({}, requestOpts, DEFAULT_PAGED_REQUEST_OPTS), }; const responseJson = await this._requestAsync('/assetData_pairs', HttpRequestType.Get, httpRequestOpts); - const assetDataPairs = relayerResponseJsonParsers.parseTokenPairsJson(responseJson); + const assetDataPairs = relayerResponseJsonParsers.parseAssetDataPairsJson(responseJson); return assetDataPairs; } /** @@ -86,7 +78,7 @@ export class HttpClient implements Client { * @param requestOpts Options specifying orders to retrieve and page information, defaults to { page: 1, perPage: 100 } * @return The resulting SignedOrders that match the request */ - public async getOrdersAsync(requestOpts?: OrdersRequestOpts & PagedRequestOpts): Promise { + public async getOrdersAsync(requestOpts?: OrdersRequestOpts & PagedRequestOpts): Promise> { if (!_.isUndefined(requestOpts)) { assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.ordersRequestOptsSchema); assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.pagedRequestOptsSchema); @@ -103,7 +95,7 @@ export class HttpClient implements Client { * @param orderHash An orderHash generated from the desired order * @return The SignedOrder that matches the supplied orderHash */ - public async getOrderAsync(orderHash: string): Promise { + public async getOrderAsync(orderHash: string): Promise { assert.doesConformToSchema('orderHash', orderHash, schemas.orderHashSchema); const responseJson = await this._requestAsync(`/order/${orderHash}`, HttpRequestType.Get); const order = relayerResponseJsonParsers.parseOrderJson(responseJson); @@ -144,6 +136,12 @@ export class HttpClient implements Client { const fees = relayerResponseJsonParsers.parseOrderConfigResponseJson(responseJson); return fees; } + + public async getFeeRecipientsAsync(): Promise> { + // TODO + return; + } + /** * Submit a signed order to the API * @param signedOrder A SignedOrder instance to submit -- cgit v1.2.3