Skip to content

Commit

Permalink
Merge pull request #1 from patch-technology/bs/1.0.0-rc.2
Browse files Browse the repository at this point in the history
1.0.0-rc.2
  • Loading branch information
bspellacy authored Jul 30, 2020
2 parents 52a0d5d + 88aa716 commit 2028dc6
Show file tree
Hide file tree
Showing 57 changed files with 4,145 additions and 3,415 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
4 changes: 4 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"trailingComma": "none"
}
62 changes: 38 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,55 @@
# Patch Javascript SDK

![Test](https://github.com/patch-technology/patch-node/workflows/Test/badge.svg)
[![Discord](https://img.shields.io/discord/733029448558837792)](https://discord.gg/M23NnGR)

The official Javascript package for the [Patch API](https://www.usepatch.com)

## Documentation

For a complete API reference, check out [Patch's API Reference.](https://docs.usepatch.com/docs/patch/openapi/v1/swagger.yaml)

## Installation

### NPM

```shell
npm install patch-node --save
npm install @patch-technology/patch --save
```

### Yarn

```shell
yarn add patch-node
yarn add @patch-technology/patch
```

### Requirements
* Node 10 +

- Node 10 +

## Usage

### Configuration

After installing the package, you'll have to configure it with your API key which is available from the API key page in the Patch dashboard:

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

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

### Orders

In Patch, orders represent a purchase of carbon offsets or negative emissions by mass. Place orders directly if you know the amount of carbon dioxide you would like to sequester. If you do not know how much to purchase, use an estimate.

[API Reference](https://docs.usepatch.com/docs/patch/openapi/v1/swagger.yaml/paths/~1v1~1orders/get)

#### Examples

```javascript
// Create an order
const mass = 1000000 // Pass in the mass in grams (i.e. 1 metric tonne)
Expand All @@ -65,61 +73,67 @@ patch.orders.retrieveOrders({ page })
```

### Estimates

Estimates allow API users to get a quote for the cost of compensating a certain amount of CO2. When creating an estimate, an order in the `draft` state will also be created, reserving the allocation of a project for 5 minutes. If you don't place your draft order within those 5 minutes, the order will automatically be cancelled.

[API Reference](https://docs.usepatch.com/docs/patch/openapi/v1/swagger.yaml/paths/~1v1~1estimates/get)

#### Examples

```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 });

// 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

Projects are the ways Patch takes CO2 out of the air. They can represent reforestation, enhanced weathering, direct air carbon capture, etc. When you place an order via Patch, it is allocated to a project.

[API Reference](https://docs.usepatch.com/docs/patch/openapi/v1/swagger.yaml/paths/~1v1~1projects/get)

#### Examples

```javascript
// Retrieve a project
const project_id = 'pro_test_1234' // Pass in the project's ID
patch.projects.retrieveProject(project_id)
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.retrieve_projects({ page })
const page = 1; // Pass in which page of projects you'd like
patch.projects.retrieveProjects({ page });
```

### Preferences

Preferences are how you route your orders in Patch. If you don't have a preference, Patch will allocate your order to the least expensive option. If you do have a preference, all of your orders will be sent to that project. You can set your preferences via API, or through the [Patch Dashboard](https://dashboard.usepatch.com/projects).

[API Reference](https://docs.usepatch.com/docs/patch/openapi/v1/swagger.yaml/paths/~1v1~1preferences/post)

#### Examples

```javascript
// Create a preference
const projectId = 'pro_test_1234' // Pass in the project_id for your preference
patch.preferences.create_preference(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.retrieve_preference(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.delete_preference(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.retrieve_preferences({ page })
const page = 1; // Pass in which page of preferences you'd like
patch.preferences.retrievePreferences({ page });
```
Loading

0 comments on commit 2028dc6

Please sign in to comment.