@@ -63,41 +63,45 @@ fulfill the order for you.
63
63
64
64
#### Examples
65
65
``` python
66
+ import patch_api
67
+ from patch_api.api.orders_api import OrdersApi as Orders
68
+
69
+ api_client = patch_api.ApiClient(api_key = os.environ.get(' SANDBOX_API_KEY' ))
70
+ orders_api = Orders(api_client = api_client)
71
+
66
72
# Create an order - you can create an order
67
73
# providing either mass_g or total_price_cents_usd, but not both
68
74
69
- from patch_api.api.orders_api import OrdersApi as Orders
70
-
71
75
# Create order with mass
72
- Orders .create_order(opts = {' mass_g' : 1_000_000 }) # Pass in the mass in grams (i.e. 1 metric tonne)
76
+ orders_api .create_order(opts = {' mass_g' : 1_000_000 }) # Pass in the mass in grams (i.e. 1 metric tonne)
73
77
74
78
# Create an order with maximum total price
75
79
total_price_cents_usd = 5_00 # Pass in the total price in cents (i.e. 5 dollars)
76
- Orders .create_order(opts = {' total_price_cents_usd' : total_price_cents_usd})
80
+ orders_api .create_order(opts = {' total_price_cents_usd' : total_price_cents_usd})
77
81
78
82
# # You can also specify a project-id field (optional) to be used instead of the preferred one
79
83
project_id = ' pro_test_1234' # Pass in the project's ID
80
- Orders .create_order(opts = {' project_id' : project_id, ' mass_g' : mass_g})
84
+ orders_api .create_order(opts = {' project_id' : project_id, ' mass_g' : mass_g})
81
85
82
86
# # Orders also accept a metadata field (optional)
83
87
metadata = {user: " john doe" }
84
- Orders .create_order(opts = {' metadata' : metadata, ' mass_g' : mass_g})
88
+ orders_api .create_order(opts = {' metadata' : metadata, ' mass_g' : mass_g})
85
89
86
90
# Retrieve an order
87
91
order_id = ' ord_test_1234' # Pass in the order's id
88
- Orders .retrieve_order(id = order_id)
92
+ orders_api .retrieve_order(id = order_id)
89
93
90
94
# Place an order
91
95
order_id = ' ord_test_1234' # Pass in the order's id
92
- Orders .place_order(id = order_id)
96
+ orders_api .place_order(id = order_id)
93
97
94
98
# Cancel an order
95
99
order_id = ' ord_test_1234' # Pass in the order's id
96
- Orders .cancel_order(id = order_id)
100
+ orders_api .cancel_order(id = order_id)
97
101
98
102
# Retrieve a list of orders
99
103
page = 1 # Pass in which page of orders you'd like
100
- Orders .retrieve_orders(page = page)
104
+ orders_api .retrieve_orders(page = page)
101
105
```
102
106
103
107
### Estimates
@@ -107,23 +111,28 @@ Estimates allow API users to get a quote for the cost of compensating a certain
107
111
108
112
#### Examples
109
113
``` python
110
- # Create an estimate
114
+ import patch_api
111
115
from patch_api.api.estimates_api import EstimatesApi as Estimates
112
116
117
+ api_client = patch_api.ApiClient(api_key = os.environ.get(' SANDBOX_API_KEY' ))
118
+ estimates_api = Estimates(api_client = api_client)
119
+
120
+ # Create an estimate
121
+
113
122
mass_g = 1_000_000 # Pass in the mass in grams (i.e. 1 metric tonne)
114
- Estimates .create_estimate(opts = {' mass_g' : mass_g})
123
+ estimates_api .create_estimate(opts = {' mass_g' : mass_g})
115
124
116
125
# # You can also specify a project-id field (optional) to be used instead of the preferred one
117
126
project_id = ' pro_test_1234' # Pass in the project's ID
118
- Estimates .create_estimate(opts = {' mass_g' : mass_g, ' project_id' : project_id})
127
+ estimates_api .create_estimate(opts = {' mass_g' : mass_g, ' project_id' : project_id})
119
128
120
129
# Retrieve an estimate
121
130
estimate_id = ' est_test_1234'
122
- Estimates .retrieve_estimate(id = estimate_id)
131
+ estimates_api .retrieve_estimate(id = estimate_id)
123
132
124
133
# Retrieve a list of estimates
125
134
page = 1 # Pass in which page of estimates you'd like
126
- Estimates .retrieve_estimates(page = page)
135
+ estimates_api .retrieve_estimates(page = page)
127
136
```
128
137
129
138
### Projects
@@ -133,15 +142,19 @@ Projects are the ways Patch takes CO2 out of the air. They can represent refores
133
142
134
143
#### Examples
135
144
``` python
145
+ import patch_api
136
146
from patch_api.api.projects_api import ProjectsApi as Projects
137
147
148
+ api_client = patch_api.ApiClient(api_key = os.environ.get(' SANDBOX_API_KEY' ))
149
+ projects_api = Projects(api_client = api_client)
150
+
138
151
# Retrieve a project
139
152
project_id = ' pro_test_1234' # Pass in the project's ID
140
- Projects .retrieve_project(id = project_id)
153
+ projects_api .retrieve_project(id = project_id)
141
154
142
155
# Retrieve a list of projects
143
156
page = 1 # Pass in which page of projects you'd like
144
- Projects .retrieve_projects(page = page)
157
+ projects_api .retrieve_projects(page = page)
145
158
```
146
159
147
160
### Preferences
@@ -151,48 +164,82 @@ Preferences are how you route your orders in Patch. If you don't have a preferen
151
164
152
165
#### Examples
153
166
``` python
154
- # Create a preference
167
+ import patch_api
155
168
from patch_api.api.preferences_api import PreferencesApi as Preferences
156
169
170
+ api_client = patch_api.ApiClient(api_key = os.environ.get(' SANDBOX_API_KEY' ))
171
+ preferences_api = Preferences(api_client = api_client)
172
+
173
+ # Create a preference
174
+
157
175
project_id = ' pro_test_1234' # Pass in the project_id for your preference
158
- Preferences .create_preference(opts = {' project_id' : project_id})
176
+ preferences_api .create_preference(opts = {' project_id' : project_id})
159
177
160
178
# Retrieve a preference
161
179
preference_id = ' pre_test_1234' # Pass in the preferences's id
162
- Preferences .retrieve_preference(preference_id = preference_id)
180
+ preferences_api .retrieve_preference(preference_id = preference_id)
163
181
164
182
# Delete a preference
165
183
preference_id = ' pre_test_1234' # Pass in the preferences's id
166
- Preferences .delete_preference(preference_id = preference_id)
184
+ preferences_api .delete_preference(preference_id = preference_id)
167
185
168
186
# Retrieve a list of preferences
169
187
page = 1 # Pass in which page of preferences you'd like
170
- Preferences .retrieve_preferences(page = page)
188
+ preferences_api .retrieve_preferences(page = page)
171
189
```
172
190
173
191
## Development
174
192
193
+ ### Running tests
194
+
195
+ Set up the required environment variable:
196
+ ```
197
+ $ export SANDBOX_API_KEY=<SANDBOX API KEY>
198
+ ```
199
+
200
+ Run tests:
201
+ ```
202
+ $ make test
203
+ ```
204
+
205
+ To run an individual test:
206
+ ```
207
+ $ python -m unittest
208
+ ```
209
+
210
+ ### Testing the built package locally
211
+
175
212
To build the library locally, run:
176
213
```
177
214
$ make build
178
215
```
179
216
180
- To test the library locally, create a python file in a sibling directory and add the following:
181
- ``` python
182
- import sys
183
- sys.path.append(" ../patch-python" )
184
-
185
- import patch_api
217
+ In another directory, create a file called ` patch.py ` and install the local package in this directory:
186
218
187
- # ..... your Patch API code goes here
219
+ ```
220
+ $ touch patch.py
221
+ $ pip install ../patch-python
188
222
```
189
223
190
- Set up required environment variables :
224
+ Set up the required environment variable :
191
225
```
192
226
$ export SANDBOX_API_KEY=<SANDBOX API KEY>
193
227
```
194
228
195
- Run tests:
196
- ```
197
- $ make test
229
+ To test the package locally, create a python file in a sibling directory and add the following:
230
+ ``` python
231
+ import os
232
+ import patch_api
233
+
234
+ # ..... your Patch API code goes here. See example below:
235
+
236
+ from patch_api.api.orders_api import OrdersApi as Orders
237
+
238
+ api_client = patch_api.ApiClient(api_key = os.environ.get(' SANDBOX_API_KEY' ))
239
+ orders = Orders(api_client = api_client)
240
+
241
+ list_orders = orders.retrieve_orders(opts = {' page' : 1 })
242
+
243
+ # Prints your organization's orders
244
+ print (list_orders)
198
245
```
0 commit comments