@@ -40,14 +40,13 @@ import patch_api
40
40
api_client = patch_api.ApiClient(api_key = os.environ.get(' SANDBOX_API_KEY' ))
41
41
```
42
42
43
- The ` api_client ` will be used to instantiate other API objects for Patch resources, for example the ` OrdersApi ` :
43
+ The ` api_client ` will be used to to make calls to the Patch API :
44
44
45
45
```
46
46
import patch_api
47
- from patch_api.api.orders_api import OrdersApi as Orders
48
47
49
- api_client = patch_api.ApiClient(api_key=os.environ.get('SANDBOX_API_KEY'))
50
- orders_api = Orders(api_client=api_client )
48
+ patch = patch_api.ApiClient(api_key=os.environ.get('SANDBOX_API_KEY'))
49
+ orders = patch.orders.retrieve_orders( )
51
50
```
52
51
53
52
### Orders
@@ -64,44 +63,42 @@ fulfill the order for you.
64
63
#### Examples
65
64
``` python
66
65
import patch_api
67
- from patch_api.api.orders_api import OrdersApi as Orders
68
66
69
- api_client = patch_api.ApiClient(api_key = os.environ.get(' SANDBOX_API_KEY' ))
70
- orders_api = Orders(api_client = api_client)
67
+ patch = patch_api.ApiClient(api_key = os.environ.get(' SANDBOX_API_KEY' ))
71
68
72
69
# Create an order - you can create an order
73
70
# providing either mass_g or total_price_cents_usd, but not both
74
71
75
72
# Create order with mass
76
- orders_api .create_order(opts = {' mass_g' : 1_000_000 }) # Pass in the mass in grams (i.e. 1 metric tonne)
73
+ patch.orders .create_order(opts = {' mass_g' : 1_000_000 }) # Pass in the mass in grams (i.e. 1 metric tonne)
77
74
78
75
# Create an order with maximum total price
79
76
total_price_cents_usd = 5_00 # Pass in the total price in cents (i.e. 5 dollars)
80
- orders_api .create_order(opts = {' total_price_cents_usd' : total_price_cents_usd})
77
+ patch.orders .create_order(opts = {' total_price_cents_usd' : total_price_cents_usd})
81
78
82
79
# # You can also specify a project-id field (optional) to be used instead of the preferred one
83
80
project_id = ' pro_test_1234' # Pass in the project's ID
84
- orders_api .create_order(opts = {' project_id' : project_id, ' mass_g' : mass_g})
81
+ patch.orders .create_order(opts = {' project_id' : project_id, ' mass_g' : mass_g})
85
82
86
83
# # Orders also accept a metadata field (optional)
87
84
metadata = {user: " john doe" }
88
- orders_api .create_order(opts = {' metadata' : metadata, ' mass_g' : mass_g})
85
+ patch.orders .create_order(opts = {' metadata' : metadata, ' mass_g' : mass_g})
89
86
90
87
# Retrieve an order
91
88
order_id = ' ord_test_1234' # Pass in the order's id
92
- orders_api .retrieve_order(id = order_id)
89
+ patch.orders .retrieve_order(id = order_id)
93
90
94
91
# Place an order
95
92
order_id = ' ord_test_1234' # Pass in the order's id
96
- orders_api .place_order(id = order_id)
93
+ patch.orders .place_order(id = order_id)
97
94
98
95
# Cancel an order
99
96
order_id = ' ord_test_1234' # Pass in the order's id
100
- orders_api .cancel_order(id = order_id)
97
+ patch.orders .cancel_order(id = order_id)
101
98
102
99
# Retrieve a list of orders
103
100
page = 1 # Pass in which page of orders you'd like
104
- orders_api .retrieve_orders(page = page)
101
+ patch.orders .retrieve_orders(page = page)
105
102
```
106
103
107
104
### Estimates
@@ -112,27 +109,25 @@ Estimates allow API users to get a quote for the cost of compensating a certain
112
109
#### Examples
113
110
``` python
114
111
import patch_api
115
- from patch_api.api.estimates_api import EstimatesApi as Estimates
116
112
117
- api_client = patch_api.ApiClient(api_key = os.environ.get(' SANDBOX_API_KEY' ))
118
- estimates_api = Estimates(api_client = api_client)
113
+ patch = patch_api.ApiClient(api_key = os.environ.get(' SANDBOX_API_KEY' ))
119
114
120
115
# Create an estimate
121
116
122
117
mass_g = 1_000_000 # Pass in the mass in grams (i.e. 1 metric tonne)
123
- estimates_api .create_estimate(opts = {' mass_g' : mass_g})
118
+ patch.estimates .create_estimate(opts = {' mass_g' : mass_g})
124
119
125
120
# # You can also specify a project-id field (optional) to be used instead of the preferred one
126
121
project_id = ' pro_test_1234' # Pass in the project's ID
127
- estimates_api .create_estimate(opts = {' mass_g' : mass_g, ' project_id' : project_id})
122
+ patch.estimates .create_estimate(opts = {' mass_g' : mass_g, ' project_id' : project_id})
128
123
129
124
# Retrieve an estimate
130
125
estimate_id = ' est_test_1234'
131
- estimates_api .retrieve_estimate(id = estimate_id)
126
+ patch.estimates .retrieve_estimate(id = estimate_id)
132
127
133
128
# Retrieve a list of estimates
134
129
page = 1 # Pass in which page of estimates you'd like
135
- estimates_api .retrieve_estimates(page = page)
130
+ patch.estimates .retrieve_estimates(page = page)
136
131
```
137
132
138
133
### Projects
@@ -143,18 +138,16 @@ Projects are the ways Patch takes CO2 out of the air. They can represent refores
143
138
#### Examples
144
139
``` python
145
140
import patch_api
146
- from patch_api.api.projects_api import ProjectsApi as Projects
147
141
148
- api_client = patch_api.ApiClient(api_key = os.environ.get(' SANDBOX_API_KEY' ))
149
- projects_api = Projects(api_client = api_client)
142
+ patch = patch_api.ApiClient(api_key = os.environ.get(' SANDBOX_API_KEY' ))
150
143
151
144
# Retrieve a project
152
145
project_id = ' pro_test_1234' # Pass in the project's ID
153
- projects_api .retrieve_project(id = project_id)
146
+ patch.projects .retrieve_project(id = project_id)
154
147
155
148
# Retrieve a list of projects
156
149
page = 1 # Pass in which page of projects you'd like
157
- projects_api .retrieve_projects(page = page)
150
+ patch.projects .retrieve_projects(page = page)
158
151
```
159
152
160
153
### Preferences
@@ -165,27 +158,25 @@ Preferences are how you route your orders in Patch. If you don't have a preferen
165
158
#### Examples
166
159
``` python
167
160
import patch_api
168
- from patch_api.api.preferences_api import PreferencesApi as Preferences
169
161
170
- api_client = patch_api.ApiClient(api_key = os.environ.get(' SANDBOX_API_KEY' ))
171
- preferences_api = Preferences(api_client = api_client)
162
+ patch = patch_api.ApiClient(api_key = os.environ.get(' SANDBOX_API_KEY' ))
172
163
173
164
# Create a preference
174
165
175
166
project_id = ' pro_test_1234' # Pass in the project_id for your preference
176
- preferences_api .create_preference(opts = {' project_id' : project_id})
167
+ patch.preferences .create_preference(opts = {' project_id' : project_id})
177
168
178
169
# Retrieve a preference
179
170
preference_id = ' pre_test_1234' # Pass in the preferences's id
180
- preferences_api .retrieve_preference(preference_id = preference_id)
171
+ patch.preferences .retrieve_preference(preference_id = preference_id)
181
172
182
173
# Delete a preference
183
174
preference_id = ' pre_test_1234' # Pass in the preferences's id
184
- preferences_api .delete_preference(preference_id = preference_id)
175
+ patch.preferences .delete_preference(preference_id = preference_id)
185
176
186
177
# Retrieve a list of preferences
187
178
page = 1 # Pass in which page of preferences you'd like
188
- preferences_api .retrieve_preferences(page = page)
179
+ patch.preferences .retrieve_preferences(page = page)
189
180
```
190
181
191
182
## Development
@@ -231,15 +222,8 @@ To test the package locally, create a python file in a sibling directory and add
231
222
import os
232
223
import patch_api
233
224
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 })
225
+ patch = patch_api.ApiClient(api_key = os.environ.get(' SANDBOX_API_KEY' ))
226
+ orders = patch.orders.retrieve_orders(opts = {' page' : 1 })
242
227
243
- # Prints your organization's orders
244
- print (list_orders)
228
+ print (orders)
245
229
```
0 commit comments