Skip to content

Commit

Permalink
Remove default query parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
fragosti committed Aug 17, 2018
1 parent 48ec78d commit f2d1d95
Show file tree
Hide file tree
Showing 8 changed files with 2,880 additions and 37 deletions.
21 changes: 7 additions & 14 deletions packages/connect/src/http_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,6 @@ import {
import { relayerResponseJsonParsers } from './utils/relayer_response_json_parsers';

const TRAILING_SLASHES_REGEX = /\/+$/;
const DEFAULT_PAGED_REQUEST_OPTS: PagedRequestOpts = {
page: 1,
perPage: 100,
};
const DEFAULT_REQUEST_OPTS: RequestOpts = {
networkId: 1,
};

/**
* This class includes all the functionality related to interacting with a set of HTTP endpoints
Expand Down Expand Up @@ -73,7 +66,7 @@ export class HttpClient implements Client {
assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.requestOptsSchema);
}
const httpRequestOpts = {
params: _.defaults({}, requestOpts, DEFAULT_REQUEST_OPTS, DEFAULT_PAGED_REQUEST_OPTS),
params: requestOpts,
};
const responseJson = await this._requestAsync('/asset_pairs', HttpRequestType.Get, httpRequestOpts);
const assetDataPairs = relayerResponseJsonParsers.parseAssetDataPairsJson(responseJson);
Expand All @@ -91,7 +84,7 @@ export class HttpClient implements Client {
assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.requestOptsSchema);
}
const httpRequestOpts = {
params: _.defaults({}, requestOpts, DEFAULT_REQUEST_OPTS, DEFAULT_PAGED_REQUEST_OPTS),
params: requestOpts,
};
const responseJson = await this._requestAsync(`/orders`, HttpRequestType.Get, httpRequestOpts);
const orders = relayerResponseJsonParsers.parseOrdersJson(responseJson);
Expand All @@ -108,7 +101,7 @@ export class HttpClient implements Client {
}
assert.doesConformToSchema('orderHash', orderHash, schemas.orderHashSchema);
const httpRequestOpts = {
params: _.defaults({}, requestOpts, DEFAULT_REQUEST_OPTS),
params: requestOpts,
};
const responseJson = await this._requestAsync(`/order/${orderHash}`, HttpRequestType.Get, httpRequestOpts);
const order = relayerResponseJsonParsers.parseAPIOrderJson(responseJson);
Expand All @@ -130,7 +123,7 @@ export class HttpClient implements Client {
assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.requestOptsSchema);
}
const httpRequestOpts = {
params: _.defaults({}, request, requestOpts, DEFAULT_REQUEST_OPTS, DEFAULT_PAGED_REQUEST_OPTS),
params: _.defaults({}, request, requestOpts),
};
const responseJson = await this._requestAsync('/orderbook', HttpRequestType.Get, httpRequestOpts);
const orderbook = relayerResponseJsonParsers.parseOrderbookResponseJson(responseJson);
Expand All @@ -147,7 +140,7 @@ export class HttpClient implements Client {
}
assert.doesConformToSchema('request', request, clientSchemas.orderConfigRequestSchema);
const httpRequestOpts = {
params: _.defaults({}, requestOpts, DEFAULT_REQUEST_OPTS),
params: requestOpts,
payload: request,
};
const responseJson = await this._requestAsync('/order_config', HttpRequestType.Post, httpRequestOpts);
Expand All @@ -163,7 +156,7 @@ export class HttpClient implements Client {
assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.requestOptsSchema);
}
const httpRequestOpts = {
params: _.defaults({}, requestOpts, DEFAULT_REQUEST_OPTS, DEFAULT_PAGED_REQUEST_OPTS),
params: requestOpts,
};
const feeRecipients = await this._requestAsync('/fee_recipients', HttpRequestType.Get, httpRequestOpts);
assert.doesConformToSchema('feeRecipients', feeRecipients, schemas.relayerApiFeeRecipientsResponseSchema);
Expand All @@ -176,7 +169,7 @@ export class HttpClient implements Client {
public async submitOrderAsync(signedOrder: SignedOrder, requestOpts?: RequestOpts): Promise<void> {
assert.doesConformToSchema('signedOrder', signedOrder, schemas.signedOrderSchema);
const httpRequestOpts = {
params: _.defaults({}, requestOpts, DEFAULT_REQUEST_OPTS),
params: requestOpts,
payload: signedOrder,
};
await this._requestAsync('/order', HttpRequestType.Post, httpRequestOpts);
Expand Down
7 changes: 7 additions & 0 deletions packages/connect/src/schemas/request_opts_schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const requestOptsSchema = {
id: '/RequestOpts',
type: 'object',
properties: {
networkId: { type: 'number' },
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"page": 1,
"perPage": 10,
"records": [
"0x6eC92694ea172ebC430C30fa31De87620967A082",
"0x6ec92694ea172ebc430c30fa31de87620967a082",
"0x9e56625509c2f60af937f23b7b532600390e8c8b",
"0xa2b31dacf30a9c50ca473337c01d8a201ae33e32"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const feeRecipientsResponse: FeeRecipientsResponse = {
page: 1,
perPage: 10,
records: [
'0x6eC92694ea172ebC430C30fa31De87620967A082',
'0x6ec92694ea172ebc430c30fa31de87620967a082',
'0x9e56625509c2f60af937f23b7b532600390e8c8b',
'0xa2b31dacf30a9c50ca473337c01d8a201ae33e32',
],
Expand Down
31 changes: 18 additions & 13 deletions packages/connect/test/http_client_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ describe('HttpClient', () => {
describe('#getAssetPairsAsync', () => {
const url = `${relayUrl}/asset_pairs`;
it('gets assetData pairs with default options when none are provided', async () => {
const urlWithQuery = `${url}?page=1&perPage=100`;
fetchMock.get(urlWithQuery, assetDataPairsResponseJSON);
fetchMock.get(url, assetDataPairsResponseJSON);
const assetDataPairs = await relayerClient.getAssetPairsAsync();
expect(assetDataPairs).to.be.deep.equal(assetDataPairsResponse);
});
Expand All @@ -54,8 +53,9 @@ describe('HttpClient', () => {
assetDataA: assetData,
page: 3,
perPage: 50,
networkdId: 42,
};
const urlWithQuery = `${url}?assetDataA=${assetData}&page=3&perPage=50`;
const urlWithQuery = `${url}?assetDataA=${assetData}&networkdId=42&page=3&perPage=50`;
fetchMock.get(urlWithQuery, assetDataPairsResponseJSON);
const assetDataPairs = await relayerClient.getAssetPairsAsync(assetPairsRequestOpts);
expect(assetDataPairs).to.be.deep.equal(assetDataPairsResponse);
Expand All @@ -68,8 +68,7 @@ describe('HttpClient', () => {
describe('#getOrdersAsync', () => {
const url = `${relayUrl}/orders`;
it('gets orders with default options when none are provided', async () => {
const urlWithQuery = `${url}?page=1&perPage=100`;
fetchMock.get(urlWithQuery, ordersResponseJSON);
fetchMock.get(url, ordersResponseJSON);
const orders = await relayerClient.getOrdersAsync();
expect(orders).to.be.deep.equal(ordersResponse);
});
Expand All @@ -79,8 +78,9 @@ describe('HttpClient', () => {
assetDataAddress,
page: 3,
perPage: 50,
networkdId: 42,
};
const urlWithQuery = `${url}?assetDataAddress=${assetDataAddress}&page=3&perPage=50`;
const urlWithQuery = `${url}?assetDataAddress=${assetDataAddress}&networkdId=42&page=3&perPage=50`;
fetchMock.get(urlWithQuery, ordersResponseJSON);
const orders = await relayerClient.getOrdersAsync(ordersRequest);
expect(orders).to.be.deep.equal(ordersResponse);
Expand Down Expand Up @@ -112,19 +112,20 @@ describe('HttpClient', () => {
it('gets orderbook with default page options when none are provided', async () => {
const urlWithQuery = `${url}?baseAssetData=${
request.baseAssetData
}&page=1&perPage=100&quoteAssetData=${request.quoteAssetData}`;
}&quoteAssetData=${request.quoteAssetData}`;
fetchMock.get(urlWithQuery, orderbookJSON);
const orderbook = await relayerClient.getOrderbookAsync(request);
expect(orderbook).to.be.deep.equal(orderbookResponse);
});
it('gets orderbook with specified page options', async () => {
const urlWithQuery = `${url}?baseAssetData=${
request.baseAssetData
}&page=3&perPage=50&quoteAssetData=${request.quoteAssetData}`;
}&networkId=42&page=3&perPage=50&quoteAssetData=${request.quoteAssetData}`;
fetchMock.get(urlWithQuery, orderbookJSON);
const pagedRequestOptions = {
page: 3,
perPage: 50,
networkId: 42,
};
const orderbook = await relayerClient.getOrderbookAsync(request, pagedRequestOptions);
expect(orderbook).to.be.deep.equal(orderbookResponse);
Expand All @@ -146,7 +147,7 @@ describe('HttpClient', () => {
exchangeAddress: '0x12459c951127e0c374ff9105dda097662a027093',
};
const url = `${relayUrl}/order_config`;
it('gets fees', async () => {
it('gets order config', async () => {
fetchMock.post(url, orderConfigResponseJSON);
const fees = await relayerClient.getOrderConfigAsync(request);
expect(fees).to.be.deep.equal(orderConfigResponse);
Expand All @@ -168,17 +169,18 @@ describe('HttpClient', () => {
});
describe('#getFeeRecipientsAsync', () => {
const url = `${relayUrl}/fee_recipients`;
it('gets orderbook with default page options when none are provided', async () => {
it('gets fee recipients with default page options when none are provided', async () => {
fetchMock.get(url, feeRecipientsResponseJSON);
const feeRecipients = await relayerClient.getFeeRecipientsAsync();
expect(feeRecipients).to.be.deep.equal(feeRecipientsResponse);
});
it('gets orderbook with specified page options', async () => {
const urlWithQuery = `${url}?&page=3&perPage=50`;
fetchMock.get(url, feeRecipientsResponseJSON);
it('gets fee reciipient with specified page options', async () => {
const urlWithQuery = `${url}?networkId=42&page=3&perPage=50`;
fetchMock.get(urlWithQuery, feeRecipientsResponseJSON);
const pagedRequestOptions = {
page: 3,
perPage: 50,
networkId: 42,
};
const feeRecipients = await relayerClient.getFeeRecipientsAsync(pagedRequestOptions);
expect(feeRecipients).to.be.deep.equal(feeRecipientsResponse);
Expand All @@ -189,3 +191,6 @@ describe('HttpClient', () => {
});
});
});

// https://example.com/fee_recipients?networkId=42&page=3&perPage=50
// https://example.com/fee_recipients?networkId=42&page=3&perPage=50
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ export const relayerApiFeeRecipientsResponseSchema = {
{ $ref: '/paginatedCollectionSchema' },
{
properties: {
records: { $ref: '/relayerApiFeeRecipientsSchema' },
records: {
id: '/relayerApiFeeRecipientsSchema',
type: 'array',
items: { $ref: '/addressSchema' },
},
},
required: ['records'],
},
],
};

export const relayerApiFeeRecipientsSchema = {
id: '/relayerApiFeeRecipientsSchema',
type: 'array',
items: { $ref: '/addressSchema' },
};
};
Loading

0 comments on commit f2d1d95

Please sign in to comment.