Skip to content

Commit

Permalink
adds project_id to orders and estimates (#3)
Browse files Browse the repository at this point in the history
* update readme
* regenerated code
* bump version to 1.1.0
  • Loading branch information
thdaraujo authored Aug 20, 2020
1 parent 91ad231 commit 630708b
Show file tree
Hide file tree
Showing 43 changed files with 1,022 additions and 773 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# OpenAPI Code gen artifacts
.openapi-generator
.openapi-generator-ignore
/node_modules
yarn.lock
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
dist
dist
3 changes: 2 additions & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"singleQuote": true,
"trailingComma": "none"
"trailingComma": "none",
"semi": false
}
44 changes: 44 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Changelog

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).

## [Unreleased]

## [1.1.0] - 2020-08-19

### Added

- `project_id` optional field to `order` creation
- `metadata` optional field to `order` creation
- `project_id` optional field to `estimate` creation
- changelog file

## [1.0.0] - 2020-07-31

### Added

- This is the first official release of Patch's Node library.

## [1.0.0-rc.2] - 2020-07-30

### Added

- Pre-commit styling with Prettier

### Changed

- Corrects readme usage instructions
- Upgrades old version of superagent

### Removed

- Removes @babel/cli as a dependency

## [1.0.0-rc.1] - 2020-07-29

### Added

- Patch's first pre-release of our core javascript client library.
82 changes: 60 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ After installing the package, you'll have to configure it with your API key whic

```javascript
// ES6+
import Patch from '@patch-technology/patch';
const patch = Patch('key_test_1234');
import Patch from '@patch-technology/patch'
const patch = Patch('key_test_1234')

// ES5
var patch = require('@patch-technology/patch').default('key_test_1234');
var patch = require('@patch-technology/patch').default('key_test_1234')
```

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

// You can also specify a project-id field (optional) to be used instead of the preferred one
const projectId = 'pro_test_1234' // Pass in the project's ID
patch.orders.createOrder({ mass_g: mass, project_id: projectId })

// Orders also accept a metadata field (optional)
const metadata = { user: 'john doe' }
patch.orders.createOrder({ mass_g: mass, metadata: metadata })

// Retrieve an order
orderId = 'ord_test_1234' // Pass in the order's id
const orderId = 'ord_test_1234' // Pass in the order's id
patch.orders.retrieveOrder(orderId)

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

```javascript
// Create an estimate
const mass = 1000000; // Pass in the mass in grams (i.e. 1 metric tonne)
patch.estimates.createMassEstimate({ mass_g: mass });
const mass = 1000000 // Pass in the mass in grams (i.e. 1 metric tonne)
patch.estimates.createMassEstimate({ mass_g: mass })

// You can also specify a project-id field (optional) to be used instead of the preferred one
const projectId = 'pro_test_1234' // Pass in the project's ID
patch.estimates.createMassEstimate({ mass_g: mass, project_id: projectId })

// Retrieve an estimate
const estimateId = 'est_test_1234';
patch.estimates.retrieveEstimate(estimate_id);
const estimateId = 'est_test_1234'
patch.estimates.retrieveEstimate(estimate_id)

// Retrieve a list of estimates
const page = 1; // Pass in which page of estimates you'd like
patch.estimates.retrieveEstimates({ page });
const page = 1 // Pass in which page of estimates you'd like
patch.estimates.retrieveEstimates({ page })
```

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

```javascript
// Retrieve a project
const projectId = 'pro_test_1234'; // Pass in the project's ID
patch.projects.retrieveProject(projectId);
const projectId = 'pro_test_1234' // Pass in the project's ID
patch.projects.retrieveProject(projectId)

// Retrieve a list of projects
const page = 1; // Pass in which page of projects you'd like
patch.projects.retrieveProjects({ page });
const page = 1 // Pass in which page of projects you'd like
patch.projects.retrieveProjects({ page })
```

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

```javascript
// Create a preference
const projectId = 'pro_test_1234'; // Pass in the project_id for your preference
patch.preferences.createPreference((project_id: projectId));
const projectId = 'pro_test_1234' // Pass in the project_id for your preference
patch.preferences.createPreference({ project_id: projectId })

// Retrieve a preference
const preferenceId = 'pre_test_1234'; // Pass in the preferences's id
patch.preferences.retrievePreference(preferenceId);
const preferenceId = 'pre_test_1234' // Pass in the preferences's id
patch.preferences.retrievePreference(preferenceId)

// Delete a preference
const preferenceId = 'pre_test_1234'; // Pass in the preferences's id
patch.preferences.deletePreference(preferenceId);
const preferenceId = 'pre_test_1234' // Pass in the preferences's id
patch.preferences.deletePreference(preferenceId)

// Retrieve a list of preferences
const page = 1; // Pass in which page of preferences you'd like
patch.preferences.retrievePreferences({ page });
const page = 1 // Pass in which page of preferences you'd like
patch.preferences.retrievePreferences({ page })
```

## Development

Install node modules

```
$ npm install
```

Set required environment variables:

```
$ export SANDBOX_API_KEY=<SANDBOX API KEY>
```

Build:

```
$ npm run build
```

Run tests:

```
$ npm test
```
2 changes: 1 addition & 1 deletion dist/ApiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ class ApiClient {

hostSettings() {
return [{
url: 'https://api.usepatch.com',
url: 'https://{defaultHost}',
description: 'No description provided',
variables: {
defaultHost: {
Expand Down
10 changes: 7 additions & 3 deletions dist/model/Allocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
* Contact: [email protected]
*/
class Allocation {
constructor() {
Allocation.initialize(this);
constructor(id, production, massG) {
Allocation.initialize(this, id, production, massG);
}

static initialize(obj) {}
static initialize(obj, id, production, massG) {
obj['id'] = id;
obj['production'] = production;
obj['mass_g'] = massG;
}

static constructFromObject(data, obj) {
if (data) {
Expand Down
5 changes: 5 additions & 0 deletions dist/model/CreateMassEstimateRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ class CreateMassEstimateRequest {
if (data.hasOwnProperty('mass_g')) {
obj['mass_g'] = _ApiClient.default.convertToType(data['mass_g'], 'Number');
}

if (data.hasOwnProperty('project_id')) {
obj['project_id'] = _ApiClient.default.convertToType(data['project_id'], 'String');
}
}

return obj;
Expand All @@ -39,5 +43,6 @@ class CreateMassEstimateRequest {
}

CreateMassEstimateRequest.prototype['mass_g'] = undefined;
CreateMassEstimateRequest.prototype['project_id'] = undefined;
var _default = CreateMassEstimateRequest;
exports.default = _default;
10 changes: 10 additions & 0 deletions dist/model/CreateOrderRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ class CreateOrderRequest {
if (data.hasOwnProperty('mass_g')) {
obj['mass_g'] = _ApiClient.default.convertToType(data['mass_g'], 'Number');
}

if (data.hasOwnProperty('project_id')) {
obj['project_id'] = _ApiClient.default.convertToType(data['project_id'], 'String');
}

if (data.hasOwnProperty('metadata')) {
obj['metadata'] = _ApiClient.default.convertToType(data['metadata'], Object);
}
}

return obj;
Expand All @@ -39,5 +47,7 @@ class CreateOrderRequest {
}

CreateOrderRequest.prototype['mass_g'] = undefined;
CreateOrderRequest.prototype['project_id'] = undefined;
CreateOrderRequest.prototype['metadata'] = undefined;
var _default = CreateOrderRequest;
exports.default = _default;
10 changes: 7 additions & 3 deletions dist/model/Estimate.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
* Contact: [email protected]
*/
class Estimate {
constructor() {
Estimate.initialize(this);
constructor(id, production, type) {
Estimate.initialize(this, id, production, type);
}

static initialize(obj) {}
static initialize(obj, id, production, type) {
obj['id'] = id;
obj['production'] = production;
obj['type'] = type;
}

static constructFromObject(data, obj) {
if (data) {
Expand Down
20 changes: 17 additions & 3 deletions dist/model/Order.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,20 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
* Contact: [email protected]
*/
class Order {
constructor() {
Order.initialize(this);
constructor(id, massG, production, state, allocationState, priceCentsUsd, allocations, metadata) {
Order.initialize(this, id, massG, production, state, allocationState, priceCentsUsd, allocations, metadata);
}

static initialize(obj) {}
static initialize(obj, id, massG, production, state, allocationState, priceCentsUsd, allocations, metadata) {
obj['id'] = id;
obj['mass_g'] = massG;
obj['production'] = production;
obj['state'] = state;
obj['allocation_state'] = allocationState;
obj['price_cents_usd'] = priceCentsUsd;
obj['allocations'] = allocations;
obj['metadata'] = metadata;
}

static constructFromObject(data, obj) {
if (data) {
Expand Down Expand Up @@ -55,6 +64,10 @@ class Order {
if (data.hasOwnProperty('allocations')) {
obj['allocations'] = _ApiClient.default.convertToType(data['allocations'], [_Allocation.default]);
}

if (data.hasOwnProperty('metadata')) {
obj['metadata'] = _ApiClient.default.convertToType(data['metadata'], Object);
}
}

return obj;
Expand All @@ -69,5 +82,6 @@ Order.prototype['state'] = undefined;
Order.prototype['allocation_state'] = undefined;
Order.prototype['price_cents_usd'] = undefined;
Order.prototype['allocations'] = undefined;
Order.prototype['metadata'] = undefined;
var _default = Order;
exports.default = _default;
10 changes: 7 additions & 3 deletions dist/model/Preference.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
* Contact: [email protected]
*/
class Preference {
constructor() {
Preference.initialize(this);
constructor(id, allocationPercentage, project) {
Preference.initialize(this, id, allocationPercentage, project);
}

static initialize(obj) {}
static initialize(obj, id, allocationPercentage, project) {
obj['id'] = id;
obj['allocation_percentage'] = allocationPercentage;
obj['project'] = project;
}

static constructFromObject(data, obj) {
if (data) {
Expand Down
Loading

0 comments on commit 630708b

Please sign in to comment.