Skip to content

Commit 630708b

Browse files
authored
adds project_id to orders and estimates (#3)
* update readme * regenerated code * bump version to 1.1.0
1 parent 91ad231 commit 630708b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1022
-773
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
# OpenAPI Code gen artifacts
22
.openapi-generator
33
.openapi-generator-ignore
4+
/node_modules
5+
yarn.lock

.prettierignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
dist
1+
dist

.prettierrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"singleQuote": true,
3-
"trailingComma": "none"
3+
"trailingComma": "none",
4+
"semi": false
45
}

CHANGELOG.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
## [1.1.0] - 2020-08-19
11+
12+
### Added
13+
14+
- `project_id` optional field to `order` creation
15+
- `metadata` optional field to `order` creation
16+
- `project_id` optional field to `estimate` creation
17+
- changelog file
18+
19+
## [1.0.0] - 2020-07-31
20+
21+
### Added
22+
23+
- This is the first official release of Patch's Node library.
24+
25+
## [1.0.0-rc.2] - 2020-07-30
26+
27+
### Added
28+
29+
- Pre-commit styling with Prettier
30+
31+
### Changed
32+
33+
- Corrects readme usage instructions
34+
- Upgrades old version of superagent
35+
36+
### Removed
37+
38+
- Removes @babel/cli as a dependency
39+
40+
## [1.0.0-rc.1] - 2020-07-29
41+
42+
### Added
43+
44+
- Patch's first pre-release of our core javascript client library.

README.md

Lines changed: 60 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ After installing the package, you'll have to configure it with your API key whic
3636

3737
```javascript
3838
// ES6+
39-
import Patch from '@patch-technology/patch';
40-
const patch = Patch('key_test_1234');
39+
import Patch from '@patch-technology/patch'
40+
const patch = Patch('key_test_1234')
4141

4242
// ES5
43-
var patch = require('@patch-technology/patch').default('key_test_1234');
43+
var patch = require('@patch-technology/patch').default('key_test_1234')
4444
```
4545

4646
### Orders
@@ -56,8 +56,16 @@ In Patch, orders represent a purchase of carbon offsets or negative emissions by
5656
const mass = 1000000 // Pass in the mass in grams (i.e. 1 metric tonne)
5757
patch.orders.createOrder({ mass_g: mass })
5858

59+
// You can also specify a project-id field (optional) to be used instead of the preferred one
60+
const projectId = 'pro_test_1234' // Pass in the project's ID
61+
patch.orders.createOrder({ mass_g: mass, project_id: projectId })
62+
63+
// Orders also accept a metadata field (optional)
64+
const metadata = { user: 'john doe' }
65+
patch.orders.createOrder({ mass_g: mass, metadata: metadata })
66+
5967
// Retrieve an order
60-
orderId = 'ord_test_1234' // Pass in the order's id
68+
const orderId = 'ord_test_1234' // Pass in the order's id
6169
patch.orders.retrieveOrder(orderId)
6270

6371
// Place an order
@@ -83,16 +91,20 @@ Estimates allow API users to get a quote for the cost of compensating a certain
8391

8492
```javascript
8593
// Create an estimate
86-
const mass = 1000000; // Pass in the mass in grams (i.e. 1 metric tonne)
87-
patch.estimates.createMassEstimate({ mass_g: mass });
94+
const mass = 1000000 // Pass in the mass in grams (i.e. 1 metric tonne)
95+
patch.estimates.createMassEstimate({ mass_g: mass })
96+
97+
// You can also specify a project-id field (optional) to be used instead of the preferred one
98+
const projectId = 'pro_test_1234' // Pass in the project's ID
99+
patch.estimates.createMassEstimate({ mass_g: mass, project_id: projectId })
88100

89101
// Retrieve an estimate
90-
const estimateId = 'est_test_1234';
91-
patch.estimates.retrieveEstimate(estimate_id);
102+
const estimateId = 'est_test_1234'
103+
patch.estimates.retrieveEstimate(estimate_id)
92104

93105
// Retrieve a list of estimates
94-
const page = 1; // Pass in which page of estimates you'd like
95-
patch.estimates.retrieveEstimates({ page });
106+
const page = 1 // Pass in which page of estimates you'd like
107+
patch.estimates.retrieveEstimates({ page })
96108
```
97109

98110
### Projects
@@ -105,12 +117,12 @@ Projects are the ways Patch takes CO2 out of the air. They can represent refores
105117

106118
```javascript
107119
// Retrieve a project
108-
const projectId = 'pro_test_1234'; // Pass in the project's ID
109-
patch.projects.retrieveProject(projectId);
120+
const projectId = 'pro_test_1234' // Pass in the project's ID
121+
patch.projects.retrieveProject(projectId)
110122

111123
// Retrieve a list of projects
112-
const page = 1; // Pass in which page of projects you'd like
113-
patch.projects.retrieveProjects({ page });
124+
const page = 1 // Pass in which page of projects you'd like
125+
patch.projects.retrieveProjects({ page })
114126
```
115127

116128
### Preferences
@@ -123,18 +135,44 @@ Preferences are how you route your orders in Patch. If you don't have a preferen
123135

124136
```javascript
125137
// Create a preference
126-
const projectId = 'pro_test_1234'; // Pass in the project_id for your preference
127-
patch.preferences.createPreference((project_id: projectId));
138+
const projectId = 'pro_test_1234' // Pass in the project_id for your preference
139+
patch.preferences.createPreference({ project_id: projectId })
128140

129141
// Retrieve a preference
130-
const preferenceId = 'pre_test_1234'; // Pass in the preferences's id
131-
patch.preferences.retrievePreference(preferenceId);
142+
const preferenceId = 'pre_test_1234' // Pass in the preferences's id
143+
patch.preferences.retrievePreference(preferenceId)
132144

133145
// Delete a preference
134-
const preferenceId = 'pre_test_1234'; // Pass in the preferences's id
135-
patch.preferences.deletePreference(preferenceId);
146+
const preferenceId = 'pre_test_1234' // Pass in the preferences's id
147+
patch.preferences.deletePreference(preferenceId)
136148

137149
// Retrieve a list of preferences
138-
const page = 1; // Pass in which page of preferences you'd like
139-
patch.preferences.retrievePreferences({ page });
150+
const page = 1 // Pass in which page of preferences you'd like
151+
patch.preferences.retrievePreferences({ page })
152+
```
153+
154+
## Development
155+
156+
Install node modules
157+
158+
```
159+
$ npm install
160+
```
161+
162+
Set required environment variables:
163+
164+
```
165+
$ export SANDBOX_API_KEY=<SANDBOX API KEY>
166+
```
167+
168+
Build:
169+
170+
```
171+
$ npm run build
172+
```
173+
174+
Run tests:
175+
176+
```
177+
$ npm test
140178
```

dist/ApiClient.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ class ApiClient {
427427

428428
hostSettings() {
429429
return [{
430-
url: 'https://api.usepatch.com',
430+
url: 'https://{defaultHost}',
431431
description: 'No description provided',
432432
variables: {
433433
defaultHost: {

dist/model/Allocation.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,15 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
1616
* Contact: [email protected]
1717
*/
1818
class Allocation {
19-
constructor() {
20-
Allocation.initialize(this);
19+
constructor(id, production, massG) {
20+
Allocation.initialize(this, id, production, massG);
2121
}
2222

23-
static initialize(obj) {}
23+
static initialize(obj, id, production, massG) {
24+
obj['id'] = id;
25+
obj['production'] = production;
26+
obj['mass_g'] = massG;
27+
}
2428

2529
static constructFromObject(data, obj) {
2630
if (data) {

dist/model/CreateMassEstimateRequest.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ class CreateMassEstimateRequest {
3131
if (data.hasOwnProperty('mass_g')) {
3232
obj['mass_g'] = _ApiClient.default.convertToType(data['mass_g'], 'Number');
3333
}
34+
35+
if (data.hasOwnProperty('project_id')) {
36+
obj['project_id'] = _ApiClient.default.convertToType(data['project_id'], 'String');
37+
}
3438
}
3539

3640
return obj;
@@ -39,5 +43,6 @@ class CreateMassEstimateRequest {
3943
}
4044

4145
CreateMassEstimateRequest.prototype['mass_g'] = undefined;
46+
CreateMassEstimateRequest.prototype['project_id'] = undefined;
4247
var _default = CreateMassEstimateRequest;
4348
exports.default = _default;

dist/model/CreateOrderRequest.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ class CreateOrderRequest {
3131
if (data.hasOwnProperty('mass_g')) {
3232
obj['mass_g'] = _ApiClient.default.convertToType(data['mass_g'], 'Number');
3333
}
34+
35+
if (data.hasOwnProperty('project_id')) {
36+
obj['project_id'] = _ApiClient.default.convertToType(data['project_id'], 'String');
37+
}
38+
39+
if (data.hasOwnProperty('metadata')) {
40+
obj['metadata'] = _ApiClient.default.convertToType(data['metadata'], Object);
41+
}
3442
}
3543

3644
return obj;
@@ -39,5 +47,7 @@ class CreateOrderRequest {
3947
}
4048

4149
CreateOrderRequest.prototype['mass_g'] = undefined;
50+
CreateOrderRequest.prototype['project_id'] = undefined;
51+
CreateOrderRequest.prototype['metadata'] = undefined;
4252
var _default = CreateOrderRequest;
4353
exports.default = _default;

dist/model/Estimate.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,15 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
1818
* Contact: [email protected]
1919
*/
2020
class Estimate {
21-
constructor() {
22-
Estimate.initialize(this);
21+
constructor(id, production, type) {
22+
Estimate.initialize(this, id, production, type);
2323
}
2424

25-
static initialize(obj) {}
25+
static initialize(obj, id, production, type) {
26+
obj['id'] = id;
27+
obj['production'] = production;
28+
obj['type'] = type;
29+
}
2630

2731
static constructFromObject(data, obj) {
2832
if (data) {

dist/model/Order.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,20 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
1818
* Contact: [email protected]
1919
*/
2020
class Order {
21-
constructor() {
22-
Order.initialize(this);
21+
constructor(id, massG, production, state, allocationState, priceCentsUsd, allocations, metadata) {
22+
Order.initialize(this, id, massG, production, state, allocationState, priceCentsUsd, allocations, metadata);
2323
}
2424

25-
static initialize(obj) {}
25+
static initialize(obj, id, massG, production, state, allocationState, priceCentsUsd, allocations, metadata) {
26+
obj['id'] = id;
27+
obj['mass_g'] = massG;
28+
obj['production'] = production;
29+
obj['state'] = state;
30+
obj['allocation_state'] = allocationState;
31+
obj['price_cents_usd'] = priceCentsUsd;
32+
obj['allocations'] = allocations;
33+
obj['metadata'] = metadata;
34+
}
2635

2736
static constructFromObject(data, obj) {
2837
if (data) {
@@ -55,6 +64,10 @@ class Order {
5564
if (data.hasOwnProperty('allocations')) {
5665
obj['allocations'] = _ApiClient.default.convertToType(data['allocations'], [_Allocation.default]);
5766
}
67+
68+
if (data.hasOwnProperty('metadata')) {
69+
obj['metadata'] = _ApiClient.default.convertToType(data['metadata'], Object);
70+
}
5871
}
5972

6073
return obj;
@@ -69,5 +82,6 @@ Order.prototype['state'] = undefined;
6982
Order.prototype['allocation_state'] = undefined;
7083
Order.prototype['price_cents_usd'] = undefined;
7184
Order.prototype['allocations'] = undefined;
85+
Order.prototype['metadata'] = undefined;
7286
var _default = Order;
7387
exports.default = _default;

dist/model/Preference.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,15 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
1818
* Contact: [email protected]
1919
*/
2020
class Preference {
21-
constructor() {
22-
Preference.initialize(this);
21+
constructor(id, allocationPercentage, project) {
22+
Preference.initialize(this, id, allocationPercentage, project);
2323
}
2424

25-
static initialize(obj) {}
25+
static initialize(obj, id, allocationPercentage, project) {
26+
obj['id'] = id;
27+
obj['allocation_percentage'] = allocationPercentage;
28+
obj['project'] = project;
29+
}
2630

2731
static constructFromObject(data, obj) {
2832
if (data) {

0 commit comments

Comments
 (0)