From b0ab8a3efd9ddd69f2041ca84c965719888270df Mon Sep 17 00:00:00 2001 From: Paul Cothenet Date: Thu, 15 Jul 2021 23:45:11 +0200 Subject: [PATCH 1/4] Add ETH estimates --- mocha.opts | 1 + package-lock.json | 2 +- package.json | 2 +- src/api/EstimatesApi.js | 48 +++++++++++++++++++ src/model/CreateEthereumEstimateRequest.js | 55 ++++++++++++++++++++++ test/integration/estimates.test.js | 14 ++++++ 6 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 mocha.opts create mode 100644 src/model/CreateEthereumEstimateRequest.js diff --git a/mocha.opts b/mocha.opts new file mode 100644 index 0000000..9070118 --- /dev/null +++ b/mocha.opts @@ -0,0 +1 @@ +--timeout 10000 diff --git a/package-lock.json b/package-lock.json index 2e0db26..06867d5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@patch-technology/patch", - "version": "1.7.0", + "version": "1.7.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 03b53c8..5b8b367 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@patch-technology/patch", - "version": "1.7.0", + "version": "1.7.1", "description": "JavaScript wrapper for the Patch API", "license": "MIT", "repository": { diff --git a/src/api/EstimatesApi.js b/src/api/EstimatesApi.js index c7173a7..943f0f3 100644 --- a/src/api/EstimatesApi.js +++ b/src/api/EstimatesApi.js @@ -7,6 +7,7 @@ import ApiClient from '../ApiClient'; import CreateBitcoinEstimateRequest from '../model/CreateBitcoinEstimateRequest'; +import CreateEthereumEstimateRequest from '../model/CreateEthereumEstimateRequest'; import CreateFlightEstimateRequest from '../model/CreateFlightEstimateRequest'; import CreateMassEstimateRequest from '../model/CreateMassEstimateRequest'; import CreateShippingEstimateRequest from '../model/CreateShippingEstimateRequest'; @@ -21,6 +22,9 @@ export default class EstimatesApi { this.createBitcoinEstimate = this.createBitcoinEstimate.bind(this); this.createBitcoinEstimateWithHttpInfo = this.createBitcoinEstimateWithHttpInfo.bind(this); + this.createEthereumEstimate = this.createEthereumEstimate.bind(this); + this.createEthereumEstimateWithHttpInfo = + this.createEthereumEstimateWithHttpInfo.bind(this); this.createFlightEstimate = this.createFlightEstimate.bind(this); this.createFlightEstimateWithHttpInfo = this.createFlightEstimateWithHttpInfo.bind(this); @@ -83,6 +87,50 @@ export default class EstimatesApi { return this.createBitcoinEstimateWithHttpInfo(createBitcoinEstimateRequest); } + createEthereumEstimateWithHttpInfo(createEthereumEstimateRequest) { + let postBody = createEthereumEstimateRequest; + + // verify the required parameter 'createEthereumEstimateRequest' is set + if ( + createEthereumEstimateRequest === undefined || + createEthereumEstimateRequest === null + ) { + throw new Error( + "Missing the required parameter 'createEthereumEstimateRequest' when calling createEthereumEstimate" + ); + } + + let pathParams = {}; + let queryParams = {}; + let headerParams = {}; + let formParams = {}; + + let authNames = ['bearer_auth']; + let contentTypes = ['application/json']; + let accepts = ['application/json']; + let returnType = EstimateResponse; + + return this.apiClient.callApi( + '/v1/estimates/crypto/eth', + 'POST', + pathParams, + queryParams, + headerParams, + formParams, + postBody, + authNames, + contentTypes, + accepts, + returnType + ); + } + + createEthereumEstimate(createEthereumEstimateRequest) { + return this.createEthereumEstimateWithHttpInfo( + createEthereumEstimateRequest + ); + } + createFlightEstimateWithHttpInfo(createFlightEstimateRequest) { let postBody = createFlightEstimateRequest; diff --git a/src/model/CreateEthereumEstimateRequest.js b/src/model/CreateEthereumEstimateRequest.js new file mode 100644 index 0000000..7bc2738 --- /dev/null +++ b/src/model/CreateEthereumEstimateRequest.js @@ -0,0 +1,55 @@ +/** + * Patch API V1 + * The core API used to integrate with Patch's service + * + * Contact: developers@usepatch.com + */ + +import ApiClient from '../ApiClient'; + +class CreateEthereumEstimateRequest { + constructor() { + CreateEthereumEstimateRequest.initialize(this); + } + + static initialize(obj) {} + + static constructFromObject(data, obj) { + if (data) { + obj = obj || new CreateEthereumEstimateRequest(); + + if (data.hasOwnProperty('timestamp')) { + obj['timestamp'] = ApiClient.convertToType(data['timestamp'], 'String'); + } + + if (data.hasOwnProperty('gas_used')) { + obj['gas_used'] = ApiClient.convertToType(data['gas_used'], 'Number'); + } + + if (data.hasOwnProperty('project_id')) { + obj['project_id'] = ApiClient.convertToType( + data['project_id'], + 'String' + ); + } + + if (data.hasOwnProperty('create_order')) { + obj['create_order'] = ApiClient.convertToType( + data['create_order'], + 'Boolean' + ); + } + } + return obj; + } +} + +CreateEthereumEstimateRequest.prototype['timestamp'] = undefined; + +CreateEthereumEstimateRequest.prototype['gas_used'] = undefined; + +CreateEthereumEstimateRequest.prototype['project_id'] = undefined; + +CreateEthereumEstimateRequest.prototype['create_order'] = undefined; + +export default CreateEthereumEstimateRequest; diff --git a/test/integration/estimates.test.js b/test/integration/estimates.test.js index fbaf11c..028762b 100644 --- a/test/integration/estimates.test.js +++ b/test/integration/estimates.test.js @@ -79,4 +79,18 @@ describe('Estimates Integration', function () { expect(estimate.production).to.be.eq(false); expect(estimate.order).to.be.eq(null); }); + + it('supports creating ethereum estimates with a gas value', async function () { + const createEstimateResponse = await patch.estimates.createEthereumEstimate( + { + gas_used: 1000 + } + ); + + const estimate = createEstimateResponse.data; + + expect(estimate.type).to.be.eq('ethereum'); + expect(estimate.mass_g).to.be.above(0); + expect(estimate.production).to.be.eq(false); + }); }); From 45d0ea91fe6b96787bbcde5726ee21eabfbfa2a0 Mon Sep 17 00:00:00 2001 From: Paul Cothenet Date: Thu, 15 Jul 2021 23:46:10 +0200 Subject: [PATCH 2/4] Remove mocha.opts --- mocha.opts | 1 - 1 file changed, 1 deletion(-) delete mode 100644 mocha.opts diff --git a/mocha.opts b/mocha.opts deleted file mode 100644 index 9070118..0000000 --- a/mocha.opts +++ /dev/null @@ -1 +0,0 @@ ---timeout 10000 From ef79d0295cbfe1b82610f808183a812472f8bff7 Mon Sep 17 00:00:00 2001 From: Paul Cothenet Date: Mon, 19 Jul 2021 22:27:03 +0200 Subject: [PATCH 3/4] Bump version --- CHANGELOG.md | 6 ++++++ package-lock.json | 2 +- package.json | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b2fe5b6..a115cb6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.8.0] - 2021-07-20 + +### Added + +- Add support for Ethereum estimates + ## [1.7.0] - 2021-07-14 ### Changed diff --git a/package-lock.json b/package-lock.json index 06867d5..decad7f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@patch-technology/patch", - "version": "1.7.1", + "version": "1.8.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 5b8b367..5c36908 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@patch-technology/patch", - "version": "1.7.1", + "version": "1.8.0", "description": "JavaScript wrapper for the Patch API", "license": "MIT", "repository": { From 8ce6e6d7bedf8bf98b4b986f3dadbcb2ba8946d4 Mon Sep 17 00:00:00 2001 From: Paul Cothenet Date: Mon, 19 Jul 2021 22:42:06 +0200 Subject: [PATCH 4/4] Add tests --- test/integration/estimates.test.js | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/test/integration/estimates.test.js b/test/integration/estimates.test.js index 028762b..32efe4f 100644 --- a/test/integration/estimates.test.js +++ b/test/integration/estimates.test.js @@ -67,19 +67,39 @@ describe('Estimates Integration', function () { expect(estimate.order).to.be.eq(null); }); - it('supports creating bitcoin estimates without an order', async function () { - const createEstimateResponse = await patch.estimates.createBitcoinEstimate({ - create_order: false + it('supports creating bitcoin estimates without parameters', async function () { + const { data: estimate } = await patch.estimates.createBitcoinEstimate({ + create_order: false // TODO: this should work without this }); - const estimate = createEstimateResponse.data; - expect(estimate.type).to.be.eq('bitcoin'); expect(estimate.mass_g).to.be.above(0); expect(estimate.production).to.be.eq(false); expect(estimate.order).to.be.eq(null); }); + it('supports creating bitcoin estimates with a timestamp', async function () { + const { data: estimate1 } = await patch.estimates.createBitcoinEstimate({ + timestamp: '2021-06-01T20:31:18.403Z' + }); + const { data: estimate2 } = await patch.estimates.createBitcoinEstimate({ + timestamp: '2021-07-01T20:31:18.403Z' + }); + + expect(estimate1.mass_g).to.be.above(estimate2.mass_g); // BTC emitted less in July than in June + }); + + it('supports creating bitcoin estimates with a transaction value', async function () { + const { data: estimate1 } = await patch.estimates.createBitcoinEstimate({ + transaction_value_btc_sats: 2000 + }); + const { data: estimate2 } = await patch.estimates.createBitcoinEstimate({ + transaction_value_btc_sats: 1000 + }); + + expect(estimate1.mass_g).to.be.above(estimate2.mass_g); + }); + it('supports creating ethereum estimates with a gas value', async function () { const createEstimateResponse = await patch.estimates.createEthereumEstimate( {