Skip to content

Commit ada5bd8

Browse files
committed
update readme
1 parent 0c88696 commit ada5bd8

File tree

1 file changed

+83
-128
lines changed

1 file changed

+83
-128
lines changed

README.md

Lines changed: 83 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -1,170 +1,125 @@
1-
# patch_api_v1
1+
# Patch Javascript SDK
2+
![Test](https://github.com/patch-technology/patch-node/workflows/Test/badge.svg)
3+
[![Discord](https://img.shields.io/discord/733029448558837792)](https://discord.gg/M23NnGR)
24

3-
Patch - JavaScript client for patch_api_v1
4-
The core API used to integrate with Patch's service
5-
This SDK is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project:
5+
The official Javascript package for the [Patch API](https://www.usepatch.com)
66

7-
- API version: v1
8-
- Package version: v1
9-
- Build package: org.openapitools.codegen.languages.JavascriptClientCodegen
7+
## Documentation
8+
For a complete API reference, check out [Patch's API Reference.](https://docs.usepatch.com/docs/patch/openapi/v1/swagger.yaml)
109

1110
## Installation
1211

13-
### For [Node.js](https://nodejs.org/)
14-
15-
#### npm
16-
17-
To publish the library as a [npm](https://www.npmjs.com/), please follow the procedure in ["Publishing npm packages"](https://docs.npmjs.com/getting-started/publishing-npm-packages).
18-
19-
Then install it via:
20-
12+
### NPM
2113
```shell
22-
npm install patch_api_v1 --save
14+
npm install patch-node --save
2315
```
2416

25-
Finally, you need to build the module:
26-
17+
### Yarn
2718
```shell
28-
npm run build
19+
yarn add patch-node
2920
```
3021

31-
##### Local development
22+
### Requirements
23+
* Node 10 +
3224

33-
To use the library locally without publishing to a remote npm registry, first install the dependencies by changing into the directory containing `package.json` (and this README). Let's call this `JAVASCRIPT_CLIENT_DIR`. Then run:
25+
## Usage
3426

35-
```shell
36-
npm install
37-
```
27+
### Configuration
3828

39-
Next, [link](https://docs.npmjs.com/cli/link) it globally in npm with the following, also from `JAVASCRIPT_CLIENT_DIR`:
29+
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:
30+
```javascript
31+
// ES6+
32+
import Patch from 'patch-node'
33+
const patch = Patch('key_test_1234')
4034

41-
```shell
42-
npm link
35+
// ES5
36+
var patch = require('patch-node')('key_test_1234')
4337
```
4438

45-
To use the link you just defined in your project, switch to the directory you want to use your patch_api_v1 from, and run:
39+
### Orders
40+
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.
4641

47-
```shell
48-
npm link /path/to/<JAVASCRIPT_CLIENT_DIR>
49-
```
42+
[API Reference](https://docs.usepatch.com/docs/patch/openapi/v1/swagger.yaml/paths/~1v1~1orders/get)
5043

51-
Finally, you need to build the module:
44+
#### Examples
45+
```javascript
46+
// Create an order
47+
const mass = 1000000 // Pass in the mass in grams (i.e. 1 metric tonne)
48+
patch.orders.createOrder({ mass_g: mass })
5249

53-
```shell
54-
npm run build
55-
```
50+
# Retrieve an order
51+
orderId = 'ord_test_1234' // Pass in the order's id
52+
patch.orders.retrieveOrder(orderId)
5653

57-
#### git
54+
// Place an order
55+
const orderId = 'ord_test_1234' // Pass in the order's id
56+
patch.orders.placeOrder(orderId)
5857

59-
If the library is hosted at a git repository, e.g.https://github.com/GIT_USER_ID/GIT_REPO_ID
60-
then install it via:
58+
// Cancel an order
59+
const orderId = 'ord_test_1234' // Pass in the order's id
60+
patch.orders.cancelOrder(orderId)
6161

62-
```shell
63-
npm install GIT_USER_ID/GIT_REPO_ID --save
62+
// Retrieve a list of orders
63+
const page = 1 // Pass in which page of orders you'd like
64+
patch.orders.retrieveOrders({ page })
6465
```
6566

66-
### For browser
67+
### Estimates
68+
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.
6769

68-
The library also works in the browser environment via npm and [browserify](http://browserify.org/). After following
69-
the above steps with Node.js and installing browserify with `npm install -g browserify`,
70-
perform the following (assuming *main.js* is your entry file):
70+
[API Reference](https://docs.usepatch.com/docs/patch/openapi/v1/swagger.yaml/paths/~1v1~1estimates/get)
7171

72-
```shell
73-
browserify main.js > bundle.js
74-
```
75-
76-
Then include *bundle.js* in the HTML pages.
77-
78-
### Webpack Configuration
72+
#### Examples
73+
```javascript
74+
// Create an estimate
75+
const mass = 1000000 // Pass in the mass in grams (i.e. 1 metric tonne)
76+
patch.estimates.createMassEstimate({ mass_g: mass })
7977

80-
Using Webpack you may encounter the following error: "Module not found: Error:
81-
Cannot resolve module", most certainly you should disable AMD loader. Add/merge
82-
the following section to your webpack config:
78+
// Retrieve an estimate
79+
const estimateId = 'est_test_1234'
80+
patch.estimates.retrieveEstimate(estimate_id)
8381

84-
```javascript
85-
module: {
86-
rules: [
87-
{
88-
parser: {
89-
amd: false
90-
}
91-
}
92-
]
93-
}
82+
// Retrieve a list of estimates
83+
const page = 1 // Pass in which page of estimates you'd like
84+
patch.estimates.retrieveEstimates({ page })
9485
```
9586

96-
## Getting Started
87+
### Projects
88+
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.
9789

98-
Please follow the [installation](#installation) instruction and execute the following JS code:
90+
[API Reference](https://docs.usepatch.com/docs/patch/openapi/v1/swagger.yaml/paths/~1v1~1projects/get)
9991

92+
#### Examples
10093
```javascript
101-
var Patch = require('patch_api_v1');
102-
103-
var defaultClient = Patch.ApiClient.instance;
104-
// Configure Bearer access token for authorization: bearer_auth
105-
var bearer_auth = defaultClient.authentications['bearer_auth'];
106-
bearer_auth.accessToken = "YOUR ACCESS TOKEN"
107-
108-
var api = new Patch.EstimatesApi()
109-
var createMassEstimateRequest = new Patch.CreateMassEstimateRequest(); // {CreateMassEstimateRequest}
110-
api.createMassEstimate(createMassEstimateRequest).then(function(data) {
111-
console.log('API called successfully. Returned data: ' + data);
112-
}, function(error) {
113-
console.error(error);
114-
});
115-
94+
// Retrieve a project
95+
const project_id = 'pro_test_1234' // Pass in the project's ID
96+
patch.projects.retrieveProject(project_id)
11697

98+
// Retrieve a list of projects
99+
const page = 1 // Pass in which page of projects you'd like
100+
patch.projects.retrieve_projects({ page })
117101
```
118102

119-
## Documentation for API Endpoints
120-
121-
All URIs are relative to *https://api.usepatch.com*
122-
123-
Class | Method | HTTP request | Description
124-
------------ | ------------- | ------------- | -------------
125-
*Patch.EstimatesApi* | [**createMassEstimate**](docs/EstimatesApi.md#createMassEstimate) | **POST** /v1/estimates/mass | Create an estimate based on mass of CO2
126-
*Patch.EstimatesApi* | [**retrieveEstimate**](docs/EstimatesApi.md#retrieveEstimate) | **GET** /v1/estimates/{id} | Retrieves an estimate
127-
*Patch.EstimatesApi* | [**retrieveEstimates**](docs/EstimatesApi.md#retrieveEstimates) | **GET** /v1/estimates | Retrieves a list of estimates
128-
*Patch.OrdersApi* | [**cancelOrder**](docs/OrdersApi.md#cancelOrder) | **PATCH** /v1/orders/{id}/cancel | Cancel an order
129-
*Patch.OrdersApi* | [**createOrder**](docs/OrdersApi.md#createOrder) | **POST** /v1/orders | Creates an order
130-
*Patch.OrdersApi* | [**placeOrder**](docs/OrdersApi.md#placeOrder) | **PATCH** /v1/orders/{id}/place | Place an order
131-
*Patch.OrdersApi* | [**retrieveOrder**](docs/OrdersApi.md#retrieveOrder) | **GET** /v1/orders/{id} | Retrieves an order
132-
*Patch.OrdersApi* | [**retrieveOrders**](docs/OrdersApi.md#retrieveOrders) | **GET** /v1/orders | Retrieves a list of orders
133-
*Patch.PreferencesApi* | [**createPreference**](docs/PreferencesApi.md#createPreference) | **POST** /v1/preferences | creates a project preference
134-
*Patch.PreferencesApi* | [**deletePreference**](docs/PreferencesApi.md#deletePreference) | **DELETE** /v1/preferences/{id} | Deletes an organization&#39;s preference for a project
135-
*Patch.PreferencesApi* | [**retrievePreference**](docs/PreferencesApi.md#retrievePreference) | **GET** /v1/preferences/{id} | Retrieve the preference
136-
*Patch.PreferencesApi* | [**retrievePreferences**](docs/PreferencesApi.md#retrievePreferences) | **GET** /v1/preferences | Retrieves a list of preferences
137-
*Patch.ProjectsApi* | [**retrieveProject**](docs/ProjectsApi.md#retrieveProject) | **GET** /v1/projects/{id} | Retrieves a project
138-
*Patch.ProjectsApi* | [**retrieveProjects**](docs/ProjectsApi.md#retrieveProjects) | **GET** /v1/projects | Retrieves a list of projects
139-
140-
141-
## Documentation for Models
142-
143-
- [Patch.Allocation](docs/Allocation.md)
144-
- [Patch.CreateMassEstimateRequest](docs/CreateMassEstimateRequest.md)
145-
- [Patch.CreateOrderRequest](docs/CreateOrderRequest.md)
146-
- [Patch.CreatePreferenceRequest](docs/CreatePreferenceRequest.md)
147-
- [Patch.ErrorResponse](docs/ErrorResponse.md)
148-
- [Patch.Estimate](docs/Estimate.md)
149-
- [Patch.EstimateListResponse](docs/EstimateListResponse.md)
150-
- [Patch.EstimateResponse](docs/EstimateResponse.md)
151-
- [Patch.MetaIndexObject](docs/MetaIndexObject.md)
152-
- [Patch.Order](docs/Order.md)
153-
- [Patch.OrderListResponse](docs/OrderListResponse.md)
154-
- [Patch.OrderResponse](docs/OrderResponse.md)
155-
- [Patch.Preference](docs/Preference.md)
156-
- [Patch.PreferenceListResponse](docs/PreferenceListResponse.md)
157-
- [Patch.PreferenceResponse](docs/PreferenceResponse.md)
158-
- [Patch.Project](docs/Project.md)
159-
- [Patch.ProjectListResponse](docs/ProjectListResponse.md)
160-
- [Patch.ProjectResponse](docs/ProjectResponse.md)
161-
162-
163-
## Documentation for Authorization
103+
### Preferences
104+
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).
164105

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

108+
#### Examples
109+
```javascript
110+
// Create a preference
111+
const projectId = 'pro_test_1234' // Pass in the project_id for your preference
112+
patch.preferences.create_preference(project_id: projectId)
166113

167-
### bearer_auth
114+
// Retrieve a preference
115+
const preferenceId = 'pre_test_1234' // Pass in the preferences's id
116+
patch.preferences.retrieve_preference(preferenceId)
168117

169-
- **Type**: Bearer authentication
118+
// Delete a preference
119+
const preferenceId = 'pre_test_1234' // Pass in the preferences's id
120+
patch.preferences.delete_preference(preferenceId)
170121

122+
// Retrieve a list of preferences
123+
const page = 1 // Pass in which page of preferences you'd like
124+
patch.preferences.retrieve_preferences({ page })
125+
```

0 commit comments

Comments
 (0)