@@ -36,11 +36,11 @@ After installing the package, you'll have to configure it with your API key whic
36
36
37
37
``` javascript
38
38
// ES6+
39
- import Patch from ' @patch-technology/patch' ;
40
- const patch = Patch (' key_test_1234' );
39
+ import Patch from ' @patch-technology/patch'
40
+ const patch = Patch (' key_test_1234' )
41
41
42
42
// ES5
43
- var patch = require (' @patch-technology/patch' ).default (' key_test_1234' );
43
+ var patch = require (' @patch-technology/patch' ).default (' key_test_1234' )
44
44
```
45
45
46
46
### Orders
@@ -56,8 +56,16 @@ In Patch, orders represent a purchase of carbon offsets or negative emissions by
56
56
const mass = 1000000 // Pass in the mass in grams (i.e. 1 metric tonne)
57
57
patch .orders .createOrder ({ mass_g: mass })
58
58
59
+ // You can also specify a project-id field (optional) to be used instead of the preferred one
60
+ const projectId = ' pro_test_1234' // Pass in the project's ID
61
+ patch .orders .createOrder ({ mass_g: mass, project_id: projectId })
62
+
63
+ // Orders also accept a metadata field (optional)
64
+ const metadata = { user: ' john doe' }
65
+ patch .orders .createOrder ({ mass_g: mass, metadata: metadata })
66
+
59
67
// Retrieve an order
60
- orderId = ' ord_test_1234' // Pass in the order's id
68
+ const orderId = ' ord_test_1234' // Pass in the order's id
61
69
patch .orders .retrieveOrder (orderId)
62
70
63
71
// Place an order
@@ -83,16 +91,20 @@ Estimates allow API users to get a quote for the cost of compensating a certain
83
91
84
92
``` javascript
85
93
// Create an estimate
86
- const mass = 1000000 ; // Pass in the mass in grams (i.e. 1 metric tonne)
87
- patch .estimates .createMassEstimate ({ mass_g: mass });
94
+ const mass = 1000000 // Pass in the mass in grams (i.e. 1 metric tonne)
95
+ patch .estimates .createMassEstimate ({ mass_g: mass })
96
+
97
+ // You can also specify a project-id field (optional) to be used instead of the preferred one
98
+ const projectId = ' pro_test_1234' // Pass in the project's ID
99
+ patch .estimates .createMassEstimate ({ mass_g: mass, project_id: projectId })
88
100
89
101
// Retrieve an estimate
90
- const estimateId = ' est_test_1234' ;
91
- patch .estimates .retrieveEstimate (estimate_id);
102
+ const estimateId = ' est_test_1234'
103
+ patch .estimates .retrieveEstimate (estimate_id)
92
104
93
105
// Retrieve a list of estimates
94
- const page = 1 ; // Pass in which page of estimates you'd like
95
- patch .estimates .retrieveEstimates ({ page });
106
+ const page = 1 // Pass in which page of estimates you'd like
107
+ patch .estimates .retrieveEstimates ({ page })
96
108
```
97
109
98
110
### Projects
@@ -105,12 +117,12 @@ Projects are the ways Patch takes CO2 out of the air. They can represent refores
105
117
106
118
``` javascript
107
119
// Retrieve a project
108
- const projectId = ' pro_test_1234' ; // Pass in the project's ID
109
- patch .projects .retrieveProject (projectId);
120
+ const projectId = ' pro_test_1234' // Pass in the project's ID
121
+ patch .projects .retrieveProject (projectId)
110
122
111
123
// Retrieve a list of projects
112
- const page = 1 ; // Pass in which page of projects you'd like
113
- patch .projects .retrieveProjects ({ page });
124
+ const page = 1 // Pass in which page of projects you'd like
125
+ patch .projects .retrieveProjects ({ page })
114
126
```
115
127
116
128
### Preferences
@@ -123,18 +135,44 @@ Preferences are how you route your orders in Patch. If you don't have a preferen
123
135
124
136
``` javascript
125
137
// Create a preference
126
- const projectId = ' pro_test_1234' ; // Pass in the project_id for your preference
127
- patch .preferences .createPreference (( project_id: projectId));
138
+ const projectId = ' pro_test_1234' // Pass in the project_id for your preference
139
+ patch .preferences .createPreference ({ project_id: projectId })
128
140
129
141
// Retrieve a preference
130
- const preferenceId = ' pre_test_1234' ; // Pass in the preferences's id
131
- patch .preferences .retrievePreference (preferenceId);
142
+ const preferenceId = ' pre_test_1234' // Pass in the preferences's id
143
+ patch .preferences .retrievePreference (preferenceId)
132
144
133
145
// Delete a preference
134
- const preferenceId = ' pre_test_1234' ; // Pass in the preferences's id
135
- patch .preferences .deletePreference (preferenceId);
146
+ const preferenceId = ' pre_test_1234' // Pass in the preferences's id
147
+ patch .preferences .deletePreference (preferenceId)
136
148
137
149
// Retrieve a list of preferences
138
- const page = 1 ; // Pass in which page of preferences you'd like
139
- patch .preferences .retrievePreferences ({ page });
150
+ const page = 1 // Pass in which page of preferences you'd like
151
+ patch .preferences .retrievePreferences ({ page })
152
+ ```
153
+
154
+ ## Development
155
+
156
+ Install node modules
157
+
158
+ ```
159
+ $ npm install
160
+ ```
161
+
162
+ Set required environment variables:
163
+
164
+ ```
165
+ $ export SANDBOX_API_KEY=<SANDBOX API KEY>
166
+ ```
167
+
168
+ Build:
169
+
170
+ ```
171
+ $ npm run build
172
+ ```
173
+
174
+ Run tests:
175
+
176
+ ```
177
+ $ npm test
140
178
```
0 commit comments