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