Skip to content

Commit da99e9c

Browse files
committed
Update makefile and readme examples
1 parent 672df0c commit da99e9c

File tree

3 files changed

+82
-35
lines changed

3 files changed

+82
-35
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
SHELL = /bin/bash
22

33
build:
4-
pip install -r requirements.txt
4+
pip install -r requirements.txt \
5+
python setup.py install
56

67
test:
78
pip install -r test-requirements.txt && \

README.md

Lines changed: 80 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -63,41 +63,45 @@ fulfill the order for you.
6363

6464
#### Examples
6565
```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+
6672
# Create an order - you can create an order
6773
# providing either mass_g or total_price_cents_usd, but not both
6874

69-
from patch_api.api.orders_api import OrdersApi as Orders
70-
7175
# 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)
7377

7478
# Create an order with maximum total price
7579
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})
7781

7882
## You can also specify a project-id field (optional) to be used instead of the preferred one
7983
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})
8185

8286
## Orders also accept a metadata field (optional)
8387
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})
8589

8690
# Retrieve an order
8791
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)
8993

9094
# Place an order
9195
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)
9397

9498
# Cancel an order
9599
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)
97101

98102
# Retrieve a list of orders
99103
page = 1 # Pass in which page of orders you'd like
100-
Orders.retrieve_orders(page=page)
104+
orders_api.retrieve_orders(page=page)
101105
```
102106

103107
### Estimates
@@ -107,23 +111,28 @@ Estimates allow API users to get a quote for the cost of compensating a certain
107111

108112
#### Examples
109113
```python
110-
# Create an estimate
114+
import patch_api
111115
from patch_api.api.estimates_api import EstimatesApi as Estimates
112116

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+
113122
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})
115124

116125
## You can also specify a project-id field (optional) to be used instead of the preferred one
117126
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})
119128

120129
# Retrieve an estimate
121130
estimate_id = 'est_test_1234'
122-
Estimates.retrieve_estimate(id=estimate_id)
131+
estimates_api.retrieve_estimate(id=estimate_id)
123132

124133
# Retrieve a list of estimates
125134
page = 1 # Pass in which page of estimates you'd like
126-
Estimates.retrieve_estimates(page=page)
135+
estimates_api.retrieve_estimates(page=page)
127136
```
128137

129138
### Projects
@@ -133,15 +142,19 @@ Projects are the ways Patch takes CO2 out of the air. They can represent refores
133142

134143
#### Examples
135144
```python
145+
import patch_api
136146
from patch_api.api.projects_api import ProjectsApi as Projects
137147

148+
api_client = patch_api.ApiClient(api_key=os.environ.get('SANDBOX_API_KEY'))
149+
projects_api = Projects(api_client=api_client)
150+
138151
# Retrieve a project
139152
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)
141154

142155
# Retrieve a list of projects
143156
page = 1 # Pass in which page of projects you'd like
144-
Projects.retrieve_projects(page=page)
157+
projects_api.retrieve_projects(page=page)
145158
```
146159

147160
### Preferences
@@ -151,48 +164,82 @@ Preferences are how you route your orders in Patch. If you don't have a preferen
151164

152165
#### Examples
153166
```python
154-
# Create a preference
167+
import patch_api
155168
from patch_api.api.preferences_api import PreferencesApi as Preferences
156169

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+
157175
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})
159177

160178
# Retrieve a preference
161179
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)
163181

164182
# Delete a preference
165183
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)
167185

168186
# Retrieve a list of preferences
169187
page = 1 # Pass in which page of preferences you'd like
170-
Preferences.retrieve_preferences(page=page)
188+
preferences_api.retrieve_preferences(page=page)
171189
```
172190

173191
## Development
174192

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+
175212
To build the library locally, run:
176213
```
177214
$ make build
178215
```
179216

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:
186218

187-
# ..... your Patch API code goes here
219+
```
220+
$ touch patch.py
221+
$ pip install ../patch-python
188222
```
189223

190-
Set up required environment variables:
224+
Set up the required environment variable:
191225
```
192226
$ export SANDBOX_API_KEY=<SANDBOX API KEY>
193227
```
194228

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)
198245
```

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@ python_dateutil >= 2.5.3
44
setuptools >= 21.0.0
55
urllib3 >= 1.15.1
66
pre-commit >= 2.9.3
7-
autopep8 >= 1.5.4

0 commit comments

Comments
 (0)