Skip to content

Add ETH estimates #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@patch-technology/patch",
"version": "1.7.0",
"version": "1.8.0",
"description": "JavaScript wrapper for the Patch API",
"license": "MIT",
"repository": {
Expand Down
48 changes: 48 additions & 0 deletions src/api/EstimatesApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
Expand Down Expand Up @@ -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;

Expand Down
55 changes: 55 additions & 0 deletions src/model/CreateEthereumEstimateRequest.js
Original file line number Diff line number Diff line change
@@ -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;
44 changes: 39 additions & 5 deletions test/integration/estimates.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,50 @@ 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(
{
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);
});
Copy link
Contributor

@kleinjm kleinjm Jul 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be tests for project_id,timestamp, and create_order params as well?

});