|
1 |
| -# Patch Node SDK |
2 |
| - |
3 |
| -[](https://discord.gg/AU8543D) |
| 1 | +# patch_api_v1 |
4 | 2 |
|
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: |
6 | 6 |
|
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 |
9 | 10 |
|
10 | 11 | ## Installation
|
11 | 12 |
|
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 | + |
13 | 21 | ```shell
|
14 |
| -npm install patch-node --save |
| 22 | +npm install patch_api_v1 --save |
15 | 23 | ```
|
16 | 24 |
|
17 |
| -Or `yarn`: |
| 25 | +Finally, you need to build the module: |
| 26 | + |
18 | 27 | ```shell
|
19 |
| -yarn add patch-node |
| 28 | +npm run build |
20 | 29 | ```
|
21 | 30 |
|
22 |
| -## Usage |
| 31 | +##### Local development |
23 | 32 |
|
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: |
25 | 34 |
|
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 |
29 | 37 | ```
|
30 | 38 |
|
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`: |
33 | 40 |
|
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 | +``` |
41 | 44 |
|
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: |
45 | 46 |
|
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 | +``` |
49 | 50 |
|
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: |
53 | 52 |
|
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 |
57 | 55 | ```
|
58 | 56 |
|
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 |
61 | 58 |
|
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: |
63 | 61 |
|
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 | +``` |
69 | 65 |
|
70 |
| -# Retrieve an estimate |
71 |
| -estimate_id = 'est_test_1234' |
72 |
| -Patch::Estimate.retrieve_estimate(estimate_id) |
| 66 | +### For browser |
73 | 67 |
|
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 |
77 | 74 | ```
|
78 | 75 |
|
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. |
81 | 77 |
|
82 |
| -[API Reference](https://docs.usepatch.com/docs/patch/openapi/v1/swagger.yaml/paths/~1v1~1projects/get) |
| 78 | +### Webpack Configuration |
83 | 79 |
|
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: |
89 | 83 |
|
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 | +} |
93 | 94 | ```
|
94 | 95 |
|
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: |
97 | 99 |
|
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'); |
99 | 102 |
|
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" |
105 | 107 |
|
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 | +}); |
109 | 115 |
|
110 |
| -# Delete a preference |
111 |
| -preference_id = 'pre_test_1234' # Pass in the preferences's id |
112 |
| -Patch::Preference.delete_preference(preference_id) |
113 | 116 |
|
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) |
117 | 117 | ```
|
| 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'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 | + |
0 commit comments