Skip to content

Commit 04165df

Browse files
author
Rahul Mody
authored
1.21.0 (#65)
* 1.21.0 - api completeness changes * Additional order tests * changelog * update readme
1 parent 86bb62b commit 04165df

13 files changed

+360
-14
lines changed

Diff for: CHANGELOG.md

+15
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.21.0] - 2022-05-03
9+
10+
### Added
11+
12+
- Adds optional `total_price` and `currency` field to `order` creation
13+
- Adds optional `amount` and `unit` field to `order` creation
14+
- Adds inventory to `project` responses
15+
- Adds inventory to `order` responses
16+
17+
### Changed
18+
19+
- Deprecates `mass_g` and `total_price_cents_usd` fields for create `order` requests
20+
- Deprecates `average_price_per_tonne_cents_usd` and `remaining_mass_g` from `project` responses
21+
- Deprecates `price_cents_usd`, `patch_fee_cents_usd`, and `mass_g` from `order` responses
22+
823
## [1.20.0] - 2022-04-18
924

1025
### Added

Diff for: README.md

+9-7
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,17 @@ fulfill the order for you.
6565

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

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

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

7880
// Retrieve an order
7981
orderId = 'ord_test_1234'; // Pass in the order's id

Diff for: package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@patch-technology/patch",
3-
"version": "1.20.0",
3+
"version": "1.21.0",
44
"description": "Node.js wrapper for the Patch API",
55
"license": "MIT",
66
"repository": {

Diff for: src/ApiClient.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class ApiClient {
1616
};
1717

1818
this.defaultHeaders = {
19-
'User-Agent': 'patch-node/1.20.0'
19+
'User-Agent': 'patch-node/1.21.0'
2020
};
2121

2222
/**

Diff for: src/model/CreateOrderRequest.js

+27
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,25 @@ class CreateOrderRequest {
5050
'Number'
5151
);
5252
}
53+
54+
if (data.hasOwnProperty('total_price')) {
55+
obj['total_price'] = ApiClient.convertToType(
56+
data['total_price'],
57+
'Number'
58+
);
59+
}
60+
61+
if (data.hasOwnProperty('currency')) {
62+
obj['currency'] = ApiClient.convertToType(data['currency'], 'String');
63+
}
64+
65+
if (data.hasOwnProperty('amount')) {
66+
obj['amount'] = ApiClient.convertToType(data['amount'], 'Number');
67+
}
68+
69+
if (data.hasOwnProperty('unit')) {
70+
obj['unit'] = ApiClient.convertToType(data['unit'], 'String');
71+
}
5372
}
5473
return obj;
5574
}
@@ -67,4 +86,12 @@ CreateOrderRequest.prototype['state'] = undefined;
6786

6887
CreateOrderRequest.prototype['vintage_year'] = undefined;
6988

89+
CreateOrderRequest.prototype['total_price'] = undefined;
90+
91+
CreateOrderRequest.prototype['currency'] = undefined;
92+
93+
CreateOrderRequest.prototype['amount'] = undefined;
94+
95+
CreateOrderRequest.prototype['unit'] = undefined;
96+
7097
export default CreateOrderRequest;

Diff for: src/model/Inventory.js

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/**
2+
* Patch API V1
3+
* The core API used to integrate with Patch's service
4+
*
5+
* Contact: [email protected]
6+
*/
7+
8+
import ApiClient from '../ApiClient';
9+
10+
class Inventory {
11+
constructor(vintageYear, amountAvailable, price, currency, unit) {
12+
Inventory.initialize(
13+
this,
14+
vintageYear,
15+
amountAvailable,
16+
price,
17+
currency,
18+
unit
19+
);
20+
}
21+
22+
static initialize(obj, vintageYear, amountAvailable, price, currency, unit) {
23+
obj['vintage_year'] = vintageYear;
24+
obj['amount_available'] = amountAvailable;
25+
obj['price'] = price;
26+
obj['currency'] = currency;
27+
obj['unit'] = unit;
28+
}
29+
30+
static constructFromObject(data, obj) {
31+
if (data) {
32+
obj = obj || new Inventory();
33+
34+
if (data.hasOwnProperty('vintage_year')) {
35+
obj['vintage_year'] = ApiClient.convertToType(
36+
data['vintage_year'],
37+
'Number'
38+
);
39+
}
40+
41+
if (data.hasOwnProperty('amount_available')) {
42+
obj['amount_available'] = ApiClient.convertToType(
43+
data['amount_available'],
44+
'Number'
45+
);
46+
}
47+
48+
if (data.hasOwnProperty('price')) {
49+
obj['price'] = ApiClient.convertToType(data['price'], 'Number');
50+
}
51+
52+
if (data.hasOwnProperty('currency')) {
53+
obj['currency'] = ApiClient.convertToType(data['currency'], 'String');
54+
}
55+
56+
if (data.hasOwnProperty('unit')) {
57+
obj['unit'] = ApiClient.convertToType(data['unit'], 'String');
58+
}
59+
}
60+
return obj;
61+
}
62+
}
63+
64+
Inventory.prototype['vintage_year'] = undefined;
65+
66+
Inventory.prototype['amount_available'] = undefined;
67+
68+
Inventory.prototype['price'] = undefined;
69+
70+
Inventory.prototype['currency'] = undefined;
71+
72+
Inventory.prototype['unit'] = undefined;
73+
74+
export default Inventory;

Diff for: src/model/Order.js

+59
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,19 @@
77

88
import ApiClient from '../ApiClient';
99
import Allocation from './Allocation';
10+
import OrderInventory from './OrderInventory';
1011

1112
class Order {
1213
constructor(
1314
id,
1415
massG,
1516
production,
1617
state,
18+
amount,
19+
unit,
20+
price,
21+
patchFee,
22+
currency,
1723
allocationState,
1824
priceCentsUsd,
1925
patchFeeCentsUsd,
@@ -25,6 +31,11 @@ class Order {
2531
massG,
2632
production,
2733
state,
34+
amount,
35+
unit,
36+
price,
37+
patchFee,
38+
currency,
2839
allocationState,
2940
priceCentsUsd,
3041
patchFeeCentsUsd,
@@ -38,6 +49,11 @@ class Order {
3849
massG,
3950
production,
4051
state,
52+
amount,
53+
unit,
54+
price,
55+
patchFee,
56+
currency,
4157
allocationState,
4258
priceCentsUsd,
4359
patchFeeCentsUsd,
@@ -47,6 +63,11 @@ class Order {
4763
obj['mass_g'] = massG;
4864
obj['production'] = production;
4965
obj['state'] = state;
66+
obj['amount'] = amount;
67+
obj['unit'] = unit;
68+
obj['price'] = price;
69+
obj['patch_fee'] = patchFee;
70+
obj['currency'] = currency;
5071
obj['allocation_state'] = allocationState;
5172
obj['price_cents_usd'] = priceCentsUsd;
5273
obj['patch_fee_cents_usd'] = patchFeeCentsUsd;
@@ -80,6 +101,26 @@ class Order {
80101
obj['state'] = ApiClient.convertToType(data['state'], 'String');
81102
}
82103

104+
if (data.hasOwnProperty('amount')) {
105+
obj['amount'] = ApiClient.convertToType(data['amount'], 'Number');
106+
}
107+
108+
if (data.hasOwnProperty('unit')) {
109+
obj['unit'] = ApiClient.convertToType(data['unit'], 'String');
110+
}
111+
112+
if (data.hasOwnProperty('price')) {
113+
obj['price'] = ApiClient.convertToType(data['price'], 'Number');
114+
}
115+
116+
if (data.hasOwnProperty('patch_fee')) {
117+
obj['patch_fee'] = ApiClient.convertToType(data['patch_fee'], 'Number');
118+
}
119+
120+
if (data.hasOwnProperty('currency')) {
121+
obj['currency'] = ApiClient.convertToType(data['currency'], 'String');
122+
}
123+
83124
if (data.hasOwnProperty('allocation_state')) {
84125
obj['allocation_state'] = ApiClient.convertToType(
85126
data['allocation_state'],
@@ -117,6 +158,12 @@ class Order {
117158
if (data.hasOwnProperty('metadata')) {
118159
obj['metadata'] = ApiClient.convertToType(data['metadata'], Object);
119160
}
161+
162+
if (data.hasOwnProperty('inventory')) {
163+
obj['inventory'] = ApiClient.convertToType(data['inventory'], [
164+
OrderInventory
165+
]);
166+
}
120167
}
121168
return obj;
122169
}
@@ -132,6 +179,16 @@ Order.prototype['production'] = undefined;
132179

133180
Order.prototype['state'] = undefined;
134181

182+
Order.prototype['amount'] = undefined;
183+
184+
Order.prototype['unit'] = undefined;
185+
186+
Order.prototype['price'] = undefined;
187+
188+
Order.prototype['patch_fee'] = undefined;
189+
190+
Order.prototype['currency'] = undefined;
191+
135192
Order.prototype['allocation_state'] = undefined;
136193

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

145202
Order.prototype['metadata'] = undefined;
146203

204+
Order.prototype['inventory'] = undefined;
205+
147206
export default Order;

Diff for: src/model/OrderInventory.js

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/**
2+
* Patch API V1
3+
* The core API used to integrate with Patch's service
4+
*
5+
* Contact: [email protected]
6+
*/
7+
8+
import ApiClient from '../ApiClient';
9+
import OrderInventoryProject from './OrderInventoryProject';
10+
11+
class OrderInventory {
12+
constructor(project, vintageYear, amount, unit, price, currency) {
13+
OrderInventory.initialize(
14+
this,
15+
project,
16+
vintageYear,
17+
amount,
18+
unit,
19+
price,
20+
currency
21+
);
22+
}
23+
24+
static initialize(obj, project, vintageYear, amount, unit, price, currency) {
25+
obj['project'] = project;
26+
obj['vintage_year'] = vintageYear;
27+
obj['amount'] = amount;
28+
obj['unit'] = unit;
29+
obj['price'] = price;
30+
obj['currency'] = currency;
31+
}
32+
33+
static constructFromObject(data, obj) {
34+
if (data) {
35+
obj = obj || new OrderInventory();
36+
37+
if (data.hasOwnProperty('project')) {
38+
obj['project'] = ApiClient.convertToType(
39+
data['project'],
40+
OrderInventoryProject
41+
);
42+
}
43+
44+
if (data.hasOwnProperty('vintage_year')) {
45+
obj['vintage_year'] = ApiClient.convertToType(
46+
data['vintage_year'],
47+
'Number'
48+
);
49+
}
50+
51+
if (data.hasOwnProperty('amount')) {
52+
obj['amount'] = ApiClient.convertToType(data['amount'], 'Number');
53+
}
54+
55+
if (data.hasOwnProperty('unit')) {
56+
obj['unit'] = ApiClient.convertToType(data['unit'], 'String');
57+
}
58+
59+
if (data.hasOwnProperty('price')) {
60+
obj['price'] = ApiClient.convertToType(data['price'], 'Number');
61+
}
62+
63+
if (data.hasOwnProperty('currency')) {
64+
obj['currency'] = ApiClient.convertToType(data['currency'], 'String');
65+
}
66+
}
67+
return obj;
68+
}
69+
}
70+
71+
OrderInventory.prototype['project'] = undefined;
72+
73+
OrderInventory.prototype['vintage_year'] = undefined;
74+
75+
OrderInventory.prototype['amount'] = undefined;
76+
77+
OrderInventory.prototype['unit'] = undefined;
78+
79+
OrderInventory.prototype['price'] = undefined;
80+
81+
OrderInventory.prototype['currency'] = undefined;
82+
83+
export default OrderInventory;

0 commit comments

Comments
 (0)