Skip to content

Commit

Permalink
1.21.0 (#65)
Browse files Browse the repository at this point in the history
* 1.21.0 - api completeness changes

* Additional order tests

* changelog

* update readme
  • Loading branch information
rmody3 authored May 4, 2022
1 parent 86bb62b commit 04165df
Show file tree
Hide file tree
Showing 13 changed files with 360 additions and 14 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ 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.21.0] - 2022-05-03

### Added

- Adds optional `total_price` and `currency` field to `order` creation
- Adds optional `amount` and `unit` field to `order` creation
- Adds inventory to `project` responses
- Adds inventory to `order` responses

### Changed

- Deprecates `mass_g` and `total_price_cents_usd` fields for create `order` requests
- Deprecates `average_price_per_tonne_cents_usd` and `remaining_mass_g` from `project` responses
- Deprecates `price_cents_usd`, `patch_fee_cents_usd`, and `mass_g` from `order` responses

## [1.20.0] - 2022-04-18

### Added
Expand Down
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,17 @@ fulfill the order for you.

```javascript
// Create an order - you can create an order
// providing either mass_g or total_price_cents_usd, but not both
// providing either amount (and unit) or total_price (and currency), but not both

// Create order with mass
const mass = 1000000; // Pass in the mass in grams (i.e. 1 metric tonne)
patch.orders.createOrder({ mass_g: mass });
// Create order with amount
const amount = 1_000_000; // Pass in the amount in unit specified
const unit = 'g';
patch.orders.createOrder({ amount: amount, unit: unit });

// Create an order with a maximum total price
const totalPriceCentsUSD = 500; // Pass in the total price in cents (i.e. 5 dollars)
patch.orders.createOrder({ total_price_cents_usd: totalPriceCentsUSD });
// Create an order with total price
const totalPrice = 500; // Pass in the total price in smallest currency unit (ie cents for USD).
const currency = 'USD';
patch.orders.createOrder({ total_price: totalPrice, currency: currency });

// Retrieve an order
orderId = 'ord_test_1234'; // Pass in the order's id
Expand Down
4 changes: 2 additions & 2 deletions 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.20.0",
"version": "1.21.0",
"description": "Node.js wrapper for the Patch API",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion src/ApiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ApiClient {
};

this.defaultHeaders = {
'User-Agent': 'patch-node/1.20.0'
'User-Agent': 'patch-node/1.21.0'
};

/**
Expand Down
27 changes: 27 additions & 0 deletions src/model/CreateOrderRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,25 @@ class CreateOrderRequest {
'Number'
);
}

if (data.hasOwnProperty('total_price')) {
obj['total_price'] = ApiClient.convertToType(
data['total_price'],
'Number'
);
}

if (data.hasOwnProperty('currency')) {
obj['currency'] = ApiClient.convertToType(data['currency'], 'String');
}

if (data.hasOwnProperty('amount')) {
obj['amount'] = ApiClient.convertToType(data['amount'], 'Number');
}

if (data.hasOwnProperty('unit')) {
obj['unit'] = ApiClient.convertToType(data['unit'], 'String');
}
}
return obj;
}
Expand All @@ -67,4 +86,12 @@ CreateOrderRequest.prototype['state'] = undefined;

CreateOrderRequest.prototype['vintage_year'] = undefined;

CreateOrderRequest.prototype['total_price'] = undefined;

CreateOrderRequest.prototype['currency'] = undefined;

CreateOrderRequest.prototype['amount'] = undefined;

CreateOrderRequest.prototype['unit'] = undefined;

export default CreateOrderRequest;
74 changes: 74 additions & 0 deletions src/model/Inventory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* Patch API V1
* The core API used to integrate with Patch's service
*
* Contact: engineering@usepatch.com
*/

import ApiClient from '../ApiClient';

class Inventory {
constructor(vintageYear, amountAvailable, price, currency, unit) {
Inventory.initialize(
this,
vintageYear,
amountAvailable,
price,
currency,
unit
);
}

static initialize(obj, vintageYear, amountAvailable, price, currency, unit) {
obj['vintage_year'] = vintageYear;
obj['amount_available'] = amountAvailable;
obj['price'] = price;
obj['currency'] = currency;
obj['unit'] = unit;
}

static constructFromObject(data, obj) {
if (data) {
obj = obj || new Inventory();

if (data.hasOwnProperty('vintage_year')) {
obj['vintage_year'] = ApiClient.convertToType(
data['vintage_year'],
'Number'
);
}

if (data.hasOwnProperty('amount_available')) {
obj['amount_available'] = ApiClient.convertToType(
data['amount_available'],
'Number'
);
}

if (data.hasOwnProperty('price')) {
obj['price'] = ApiClient.convertToType(data['price'], 'Number');
}

if (data.hasOwnProperty('currency')) {
obj['currency'] = ApiClient.convertToType(data['currency'], 'String');
}

if (data.hasOwnProperty('unit')) {
obj['unit'] = ApiClient.convertToType(data['unit'], 'String');
}
}
return obj;
}
}

Inventory.prototype['vintage_year'] = undefined;

Inventory.prototype['amount_available'] = undefined;

Inventory.prototype['price'] = undefined;

Inventory.prototype['currency'] = undefined;

Inventory.prototype['unit'] = undefined;

export default Inventory;
59 changes: 59 additions & 0 deletions src/model/Order.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@

import ApiClient from '../ApiClient';
import Allocation from './Allocation';
import OrderInventory from './OrderInventory';

class Order {
constructor(
id,
massG,
production,
state,
amount,
unit,
price,
patchFee,
currency,
allocationState,
priceCentsUsd,
patchFeeCentsUsd,
Expand All @@ -25,6 +31,11 @@ class Order {
massG,
production,
state,
amount,
unit,
price,
patchFee,
currency,
allocationState,
priceCentsUsd,
patchFeeCentsUsd,
Expand All @@ -38,6 +49,11 @@ class Order {
massG,
production,
state,
amount,
unit,
price,
patchFee,
currency,
allocationState,
priceCentsUsd,
patchFeeCentsUsd,
Expand All @@ -47,6 +63,11 @@ class Order {
obj['mass_g'] = massG;
obj['production'] = production;
obj['state'] = state;
obj['amount'] = amount;
obj['unit'] = unit;
obj['price'] = price;
obj['patch_fee'] = patchFee;
obj['currency'] = currency;
obj['allocation_state'] = allocationState;
obj['price_cents_usd'] = priceCentsUsd;
obj['patch_fee_cents_usd'] = patchFeeCentsUsd;
Expand Down Expand Up @@ -80,6 +101,26 @@ class Order {
obj['state'] = ApiClient.convertToType(data['state'], 'String');
}

if (data.hasOwnProperty('amount')) {
obj['amount'] = ApiClient.convertToType(data['amount'], 'Number');
}

if (data.hasOwnProperty('unit')) {
obj['unit'] = ApiClient.convertToType(data['unit'], 'String');
}

if (data.hasOwnProperty('price')) {
obj['price'] = ApiClient.convertToType(data['price'], 'Number');
}

if (data.hasOwnProperty('patch_fee')) {
obj['patch_fee'] = ApiClient.convertToType(data['patch_fee'], 'Number');
}

if (data.hasOwnProperty('currency')) {
obj['currency'] = ApiClient.convertToType(data['currency'], 'String');
}

if (data.hasOwnProperty('allocation_state')) {
obj['allocation_state'] = ApiClient.convertToType(
data['allocation_state'],
Expand Down Expand Up @@ -117,6 +158,12 @@ class Order {
if (data.hasOwnProperty('metadata')) {
obj['metadata'] = ApiClient.convertToType(data['metadata'], Object);
}

if (data.hasOwnProperty('inventory')) {
obj['inventory'] = ApiClient.convertToType(data['inventory'], [
OrderInventory
]);
}
}
return obj;
}
Expand All @@ -132,6 +179,16 @@ Order.prototype['production'] = undefined;

Order.prototype['state'] = undefined;

Order.prototype['amount'] = undefined;

Order.prototype['unit'] = undefined;

Order.prototype['price'] = undefined;

Order.prototype['patch_fee'] = undefined;

Order.prototype['currency'] = undefined;

Order.prototype['allocation_state'] = undefined;

Order.prototype['price_cents_usd'] = undefined;
Expand All @@ -144,4 +201,6 @@ Order.prototype['registry_url'] = undefined;

Order.prototype['metadata'] = undefined;

Order.prototype['inventory'] = undefined;

export default Order;
83 changes: 83 additions & 0 deletions src/model/OrderInventory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/**
* Patch API V1
* The core API used to integrate with Patch's service
*
* Contact: engineering@usepatch.com
*/

import ApiClient from '../ApiClient';
import OrderInventoryProject from './OrderInventoryProject';

class OrderInventory {
constructor(project, vintageYear, amount, unit, price, currency) {
OrderInventory.initialize(
this,
project,
vintageYear,
amount,
unit,
price,
currency
);
}

static initialize(obj, project, vintageYear, amount, unit, price, currency) {
obj['project'] = project;
obj['vintage_year'] = vintageYear;
obj['amount'] = amount;
obj['unit'] = unit;
obj['price'] = price;
obj['currency'] = currency;
}

static constructFromObject(data, obj) {
if (data) {
obj = obj || new OrderInventory();

if (data.hasOwnProperty('project')) {
obj['project'] = ApiClient.convertToType(
data['project'],
OrderInventoryProject
);
}

if (data.hasOwnProperty('vintage_year')) {
obj['vintage_year'] = ApiClient.convertToType(
data['vintage_year'],
'Number'
);
}

if (data.hasOwnProperty('amount')) {
obj['amount'] = ApiClient.convertToType(data['amount'], 'Number');
}

if (data.hasOwnProperty('unit')) {
obj['unit'] = ApiClient.convertToType(data['unit'], 'String');
}

if (data.hasOwnProperty('price')) {
obj['price'] = ApiClient.convertToType(data['price'], 'Number');
}

if (data.hasOwnProperty('currency')) {
obj['currency'] = ApiClient.convertToType(data['currency'], 'String');
}
}
return obj;
}
}

OrderInventory.prototype['project'] = undefined;

OrderInventory.prototype['vintage_year'] = undefined;

OrderInventory.prototype['amount'] = undefined;

OrderInventory.prototype['unit'] = undefined;

OrderInventory.prototype['price'] = undefined;

OrderInventory.prototype['currency'] = undefined;

export default OrderInventory;
Loading

0 comments on commit 04165df

Please sign in to comment.