Skip to content

Commit ada08a6

Browse files
committed
Add specs
1 parent bd620ac commit ada08a6

17 files changed

+1100
-204
lines changed

Diff for: .babelrc

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
{
22
"presets": [
3-
"@babel/preset-env"
3+
[
4+
"@babel/preset-env",
5+
{
6+
"targets": {
7+
"node": "10"
8+
}
9+
}
10+
]
411
],
512
"plugins": [
613
"@babel/plugin-syntax-dynamic-import",

Diff for: .gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
# OpenAPI Code gen artifacts
2-
.openapi-generator/**
2+
.openapi-generator
3+
.openapi-generator-ignore

Diff for: README.md

+131-78
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,170 @@
1-
# Patch Node 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/AU8543D)
1+
# patch_api_v1
42

5-
The official Node package for the [Patch API](https://www.usepatch.com)
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:
66

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

1011
## Installation
1112

12-
Add the gem to your `package.json` with `npm`:
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+
1321
```shell
14-
npm install patch-node --save
22+
npm install patch_api_v1 --save
1523
```
1624

17-
Or `yarn`:
25+
Finally, you need to build the module:
26+
1827
```shell
19-
yarn add patch-node
28+
npm run build
2029
```
2130

22-
## Usage
31+
##### Local development
2332

24-
### Configuration
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:
2534

26-
After installing the gem, you'll have to configure it with your API key which is available from the API key page in the Patch dashboard:
27-
```javascript
28-
patch = require('patch-node')('key_test_123')
35+
```shell
36+
npm install
2937
```
3038

31-
### Orders
32-
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.
39+
Next, [link](https://docs.npmjs.com/cli/link) it globally in npm with the following, also from `JAVASCRIPT_CLIENT_DIR`:
3340

34-
[API Reference](https://docs.usepatch.com/docs/patch/openapi/v1/swagger.yaml/paths/~1v1~1orders/get)
35-
36-
#### Examples
37-
```ruby
38-
# Create an order
39-
mass = 1_000_000 # Pass in the mass in grams (i.e. 1 metric tonne)
40-
Patch::Order.create_order(mass_g: mass)
41+
```shell
42+
npm link
43+
```
4144

42-
# Retrieve an order
43-
order_id = 'ord_test_1234' # Pass in the order's id
44-
Patch::Order.retrieve_order(order_id)
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:
4546

46-
# Place an order
47-
order_id = 'ord_test_1234' # Pass in the order's id
48-
Patch::Order.place_order(order_id)
47+
```shell
48+
npm link /path/to/<JAVASCRIPT_CLIENT_DIR>
49+
```
4950

50-
# Cancel an order
51-
order_id = 'ord_test_1234' # Pass in the order's id
52-
Patch::Order.cancel_order(order_id)
51+
Finally, you need to build the module:
5352

54-
# Retrieve a list of orders
55-
page = 1 # Pass in which page of orders you'd like
56-
Patch::Order.retrieve_orders(page: page)
53+
```shell
54+
npm run build
5755
```
5856

59-
### Estimates
60-
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.
57+
#### git
6158

62-
[API Reference](https://docs.usepatch.com/docs/patch/openapi/v1/swagger.yaml/paths/~1v1~1estimates/get)
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:
6361

64-
#### Examples
65-
```ruby
66-
# Create an estimate
67-
mass = 1_000_000 # Pass in the mass in grams (i.e. 1 metric tonne)
68-
Patch::Estimate.create_mass_estimate(mass_g: mass)
62+
```shell
63+
npm install GIT_USER_ID/GIT_REPO_ID --save
64+
```
6965

70-
# Retrieve an estimate
71-
estimate_id = 'est_test_1234'
72-
Patch::Estimate.retrieve_estimate(estimate_id)
66+
### For browser
7367

74-
# Retrieve a list of estimates
75-
page = 1 # Pass in which page of estimates you'd like
76-
Patch::Estimate.retrieve_estimates(page: page)
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):
71+
72+
```shell
73+
browserify main.js > bundle.js
7774
```
7875

79-
### Projects
80-
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.
76+
Then include *bundle.js* in the HTML pages.
8177

82-
[API Reference](https://docs.usepatch.com/docs/patch/openapi/v1/swagger.yaml/paths/~1v1~1projects/get)
78+
### Webpack Configuration
8379

84-
#### Examples
85-
```ruby
86-
# Retrieve a project
87-
project_id = 'pro_test_1234' # Pass in the project's ID
88-
Patch::Project.retrieve_project(project_id)
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:
8983

90-
# Retrieve a list of projects
91-
page = 1 # Pass in which page of projects you'd like
92-
Patch::Project.retrieve_projects(page: page)
84+
```javascript
85+
module: {
86+
rules: [
87+
{
88+
parser: {
89+
amd: false
90+
}
91+
}
92+
]
93+
}
9394
```
9495

95-
### Preferences
96-
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).
96+
## Getting Started
97+
98+
Please follow the [installation](#installation) instruction and execute the following JS code:
9799

98-
[API Reference](https://docs.usepatch.com/docs/patch/openapi/v1/swagger.yaml/paths/~1v1~1preferences/post)
100+
```javascript
101+
var Patch = require('patch_api_v1');
99102

100-
#### Examples
101-
```ruby
102-
# Create a preference
103-
project_id = 'pro_test_1234' # Pass in the project_id for your preference
104-
Patch::Preference.create_preference(project_id: project_id)
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"
105107

106-
# Retrieve a preference
107-
preference_id = 'pre_test_1234' # Pass in the preferences's id
108-
Patch::Preference.retrieve_preference(preference_id)
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+
});
109115

110-
# Delete a preference
111-
preference_id = 'pre_test_1234' # Pass in the preferences's id
112-
Patch::Preference.delete_preference(preference_id)
113116

114-
# Retrieve a list of preferences
115-
page = 1 # Pass in which page of preferences you'd like
116-
Patch::Preference.retrieve_preferences(page: page)
117117
```
118+
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
164+
165+
166+
167+
### bearer_auth
168+
169+
- **Type**: Bearer authentication
170+

Diff for: dist/api/EstimatesApi.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,18 @@ var EstimatesApi = /*#__PURE__*/function () {
2828
_classCallCheck(this, EstimatesApi);
2929

3030
this.apiClient = apiClient || _ApiClient["default"].instance;
31+
this.createMassEstimate = this.createMassEstimate.bind(this);
32+
this.createMassEstimateWithHttpInfo = this.createMassEstimateWithHttpInfo.bind(this);
33+
this.retrieveEstimate = this.retrieveEstimate.bind(this);
34+
this.retrieveEstimateWithHttpInfo = this.retrieveEstimateWithHttpInfo.bind(this);
35+
this.retrieveEstimates = this.retrieveEstimates.bind(this);
36+
this.retrieveEstimatesWithHttpInfo = this.retrieveEstimatesWithHttpInfo.bind(this);
3137
}
3238

3339
_createClass(EstimatesApi, [{
3440
key: "createMassEstimateWithHttpInfo",
3541
value: function createMassEstimateWithHttpInfo(createMassEstimateRequest) {
36-
var postBody = opts['']; // verify the required parameter 'createMassEstimateRequest' is set
42+
var postBody = createMassEstimateRequest; // verify the required parameter 'createMassEstimateRequest' is set
3743

3844
if (createMassEstimateRequest === undefined || createMassEstimateRequest === null) {
3945
throw new Error("Missing the required parameter 'createMassEstimateRequest' when calling createMassEstimate");

Diff for: dist/api/OrdersApi.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ var OrdersApi = /*#__PURE__*/function () {
2828
_classCallCheck(this, OrdersApi);
2929

3030
this.apiClient = apiClient || _ApiClient["default"].instance;
31+
this.cancelOrder = this.cancelOrder.bind(this);
32+
this.cancelOrderWithHttpInfo = this.cancelOrderWithHttpInfo.bind(this);
33+
this.createOrder = this.createOrder.bind(this);
34+
this.createOrderWithHttpInfo = this.createOrderWithHttpInfo.bind(this);
35+
this.placeOrder = this.placeOrder.bind(this);
36+
this.placeOrderWithHttpInfo = this.placeOrderWithHttpInfo.bind(this);
37+
this.retrieveOrder = this.retrieveOrder.bind(this);
38+
this.retrieveOrderWithHttpInfo = this.retrieveOrderWithHttpInfo.bind(this);
39+
this.retrieveOrders = this.retrieveOrders.bind(this);
40+
this.retrieveOrdersWithHttpInfo = this.retrieveOrdersWithHttpInfo.bind(this);
3141
}
3242

3343
_createClass(OrdersApi, [{
@@ -61,7 +71,7 @@ var OrdersApi = /*#__PURE__*/function () {
6171
}, {
6272
key: "createOrderWithHttpInfo",
6373
value: function createOrderWithHttpInfo(createOrderRequest) {
64-
var postBody = opts['']; // verify the required parameter 'createOrderRequest' is set
74+
var postBody = createOrderRequest; // verify the required parameter 'createOrderRequest' is set
6575

6676
if (createOrderRequest === undefined || createOrderRequest === null) {
6777
throw new Error("Missing the required parameter 'createOrderRequest' when calling createOrder");

Diff for: dist/api/PreferencesApi.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,20 @@ var PreferencesApi = /*#__PURE__*/function () {
2828
_classCallCheck(this, PreferencesApi);
2929

3030
this.apiClient = apiClient || _ApiClient["default"].instance;
31+
this.createPreference = this.createPreference.bind(this);
32+
this.createPreferenceWithHttpInfo = this.createPreferenceWithHttpInfo.bind(this);
33+
this.deletePreference = this.deletePreference.bind(this);
34+
this.deletePreferenceWithHttpInfo = this.deletePreferenceWithHttpInfo.bind(this);
35+
this.retrievePreference = this.retrievePreference.bind(this);
36+
this.retrievePreferenceWithHttpInfo = this.retrievePreferenceWithHttpInfo.bind(this);
37+
this.retrievePreferences = this.retrievePreferences.bind(this);
38+
this.retrievePreferencesWithHttpInfo = this.retrievePreferencesWithHttpInfo.bind(this);
3139
}
3240

3341
_createClass(PreferencesApi, [{
3442
key: "createPreferenceWithHttpInfo",
3543
value: function createPreferenceWithHttpInfo(createPreferenceRequest) {
36-
var postBody = opts['']; // verify the required parameter 'createPreferenceRequest' is set
44+
var postBody = createPreferenceRequest; // verify the required parameter 'createPreferenceRequest' is set
3745

3846
if (createPreferenceRequest === undefined || createPreferenceRequest === null) {
3947
throw new Error("Missing the required parameter 'createPreferenceRequest' when calling createPreference");

Diff for: dist/api/ProjectsApi.js

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ var ProjectsApi = /*#__PURE__*/function () {
2626
_classCallCheck(this, ProjectsApi);
2727

2828
this.apiClient = apiClient || _ApiClient["default"].instance;
29+
this.retrieveProject = this.retrieveProject.bind(this);
30+
this.retrieveProjectWithHttpInfo = this.retrieveProjectWithHttpInfo.bind(this);
31+
this.retrieveProjects = this.retrieveProjects.bind(this);
32+
this.retrieveProjectsWithHttpInfo = this.retrieveProjectsWithHttpInfo.bind(this);
2933
}
3034

3135
_createClass(ProjectsApi, [{

0 commit comments

Comments
 (0)