oshpark 0.0.10 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +192 -39
- data/lib/oshpark/client.rb +5 -5
- data/lib/oshpark/connection.rb +12 -6
- data/lib/oshpark/model.rb +1 -0
- data/lib/oshpark/order.rb +9 -15
- data/lib/oshpark/project.rb +2 -3
- data/lib/oshpark/shipping_rate.rb +5 -0
- data/lib/oshpark/version.rb +1 -1
- data/oshpark.gemspec +1 -1
- data/spec/acceptance/workflow_spec.rb +3 -4
- data/spec/fixtures/cassettes/RSpec_ExampleGroups_APIWorkflow.yml +15547 -1451
- data/spec/fixtures/cassettes/RSpec_ExampleGroups_OshparkClient_Authenicate_WithAPassword_WithAValidPassword_Token_2.yml +128 -0
- data/spec/fixtures/cassettes/RSpec_ExampleGroups_OshparkClient_Authenicate_WithAPassword_WithAnInvalidPassword.yml +121 -0
- data/spec/fixtures/cassettes/RSpec_ExampleGroups_OshparkClient_Authenicate_WithAnAPISecret_WithAValidAPISecret_Token_2.yml +129 -0
- data/spec/fixtures/cassettes/RSpec_ExampleGroups_OshparkClient_Authenicate_WithAnAPISecret_WithAnInvalidAPISecret.yml +122 -0
- data/spec/fixtures/cassettes/RSpec_ExampleGroups_OshparkClient_Token.yml +64 -0
- data/spec/lib/oshpark/client_spec.rb +2 -3
- data/spec/lib/oshpark/import_spec.rb +1 -0
- data/spec/lib/oshpark/order_spec.rb +4 -4
- data/spec/lib/oshpark/panel_spec.rb +1 -0
- data/spec/lib/oshpark/project_spec.rb +1 -0
- data/spec/lib/oshpark/upload_spec.rb +1 -0
- metadata +13 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2834c0fd61a309e742ba08525f37bae1684edbf7
|
4
|
+
data.tar.gz: 2451a5be624a54730515bf42e9d3ea6aaf341485
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c7c9ecd5dc76fb44de77dff1f164201214094fab534d67e28aa72d8445570864041f3928377e660b27a0e124e09ba16ff0d40a44d1ec45625b24c8d676fa2386
|
7
|
+
data.tar.gz: ad0be34d9762b290fc4676459a139c858a01123a740038b2d02e056d1398ac0f702af3348d7a3dc72200d1533988d1e9f4bbf7039e309bf88475579ef4a6701a
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,78 +1,231 @@
|
|
1
|
-
#
|
1
|
+
# OSH Park
|
2
2
|
##An electric ecosystem
|
3
3
|
|
4
4
|
[ ![Codeship Status for OSHPark/ruby-api-client](https://codeship.io/projects/a0abc8d0-d247-0131-3eb6-7653b9bc7be9/status?branch=master)](https://codeship.io/projects/23318)
|
5
5
|
|
6
6
|
[OSH Park](https://oshpark.com) is a community printed circuit board (PCB) order.
|
7
|
-
The
|
7
|
+
The OSH Park gem allows developers to easily access the OSH Park API. Developer resources can be found at [https://oshpark.com/developer](https://oshpark.com/developer)
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
11
11
|
Add this line to your application's Gemfile:
|
12
12
|
|
13
|
-
|
13
|
+
```ruby
|
14
|
+
gem 'oshpark'
|
15
|
+
```
|
14
16
|
|
15
17
|
And then execute:
|
16
18
|
|
17
|
-
|
19
|
+
```sh
|
20
|
+
$ bundle
|
21
|
+
```
|
18
22
|
|
19
23
|
Or install it yourself as:
|
20
24
|
|
21
|
-
|
25
|
+
```sh
|
26
|
+
$ gem install oshpark
|
27
|
+
```
|
22
28
|
|
23
29
|
## Usage
|
24
30
|
|
25
|
-
Before you begin you need to have an [
|
31
|
+
Before you begin you need to have an [OSH Park account](http://oshpark.com/users/sign_up) and then request access to the OSH Park API. Do this by contacting [OSH Park support](mailto:support@oshpark.com)
|
26
32
|
|
27
|
-
This gem provides two interfaces to the
|
33
|
+
This gem provides two interfaces to the OSH Park API.
|
28
34
|
|
29
35
|
### Low level API
|
30
36
|
|
31
|
-
For use when you have an ORM, framework or pre-exsiting classes that you want to load the
|
37
|
+
For use when you have an ORM, framework or pre-exsiting classes that you want to load the OSH Park data into.
|
32
38
|
|
33
|
-
The API consists of a number of methods that map to the methods exposed by the
|
39
|
+
The API consists of a number of methods that map to the methods exposed by the OSH Park REST API. These methods take Ruby hashes representing the request data and return hashes of the API responses. Refer to [https://oshpark.com/developer/resources](https://oshpark.com/developer/resources) for details.
|
34
40
|
|
35
|
-
First create an Oshpark::client object and authenticate;
|
41
|
+
First create an `Oshpark::client` object and authenticate;
|
36
42
|
|
37
|
-
|
38
|
-
|
43
|
+
```ruby
|
44
|
+
client = Oshpark::client
|
45
|
+
client.authenticate 'jane@resistor.io', with_password: 'secret'
|
46
|
+
```
|
39
47
|
|
40
|
-
Then you can can use this object to interact with
|
48
|
+
Then you can can use this object to interact with OSH Park;
|
41
49
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
50
|
+
```ruby
|
51
|
+
file = File.open('my_pcb.zip', 'r')
|
52
|
+
upload = client.create_upload file
|
53
|
+
# ...
|
54
|
+
my_projects = client.projects
|
55
|
+
# ...
|
56
|
+
project = client.project 'id'
|
57
|
+
client.update_project project["id"], {"name" => "my awesome project"}
|
58
|
+
# ...
|
59
|
+
new_order = client.create_order
|
60
|
+
# ...
|
61
|
+
```
|
52
62
|
|
53
|
-
All low level methods will call to
|
63
|
+
All low level methods will call to OSH Park's servers. Refer to the [source documentation](http://www.rubydoc.info/github/OSHPark/ruby-api-client/master) for more detailed information on each of the available methods.
|
54
64
|
|
55
65
|
### High Level API
|
56
66
|
|
57
|
-
This is more suited to when you are writing a script or application and you want to use Ruby objects to represent the
|
67
|
+
This is more suited to when you are writing a script or application and you want to use Ruby objects to represent the OSH Park data. It uses the Low Level API underneath but wraps the return data in nice Ruby objects.
|
58
68
|
|
59
|
-
|
69
|
+
#### Authenticate
|
60
70
|
|
61
|
-
|
62
|
-
|
71
|
+
```ruby
|
72
|
+
client = Oshpark::client
|
73
|
+
client.authenticate 'jane@resistor.io', with_password: 'secret'
|
74
|
+
```
|
63
75
|
|
64
|
-
|
65
|
-
upload = Oshpark::Upload.create file
|
66
|
-
...
|
67
|
-
my_projects = Oshpark::Project.all
|
68
|
-
...
|
69
|
-
project = Oshpark::Project.find 'id'
|
70
|
-
project.name = "my awesome project"
|
71
|
-
project.save!
|
72
|
-
...
|
73
|
-
new_order = Oshpark::Order.create
|
74
|
-
...
|
76
|
+
or with your API secret if you have one:
|
75
77
|
|
78
|
+
```ruby
|
79
|
+
client = Oshpark::client
|
80
|
+
client.authenticate 'jane@resistor.io', with_api_secret: 'secret'
|
81
|
+
```
|
82
|
+
|
83
|
+
##### Creating Your Project
|
84
|
+
|
85
|
+
Next you need to get your project into OSH Park. This is done by either
|
86
|
+
uploading a file or importing a file from a URL.
|
87
|
+
|
88
|
+
###### Upload
|
89
|
+
|
90
|
+
To upload a file directly to the API you create an `Oshpark::Upload` object by
|
91
|
+
passing in an `IO` object:
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
file = File.open 'my_pcb.zip'
|
95
|
+
upload = Oshpark::Upload.create file
|
96
|
+
file.close
|
97
|
+
```
|
98
|
+
|
99
|
+
You now need to wait for processing of the file to complete:
|
100
|
+
|
101
|
+
```ruby
|
102
|
+
until upload.finished?
|
103
|
+
sleep 1
|
104
|
+
upload.reload!
|
105
|
+
end
|
106
|
+
```
|
107
|
+
|
108
|
+
Now you can access your project via the upload's `project` method:
|
109
|
+
|
110
|
+
```ruby
|
111
|
+
project = upload.project
|
112
|
+
```
|
113
|
+
|
114
|
+
###### Import
|
115
|
+
|
116
|
+
Importing from a remote URL is almost exactly the same as uploading, except
|
117
|
+
that you create an instance of the `Oshpark::Import` object, and monitor it
|
118
|
+
in much the same was as upload:
|
119
|
+
|
120
|
+
```ruby
|
121
|
+
import = Oshpark::Upload.create 'https://example.com/my_pcb.zip'
|
122
|
+
```
|
123
|
+
|
124
|
+
You now need to wait for processing of the file to complete:
|
125
|
+
|
126
|
+
```ruby
|
127
|
+
until import.finished?
|
128
|
+
sleep 1
|
129
|
+
import.reload!
|
130
|
+
end
|
131
|
+
```
|
132
|
+
|
133
|
+
Now you can access your project via the import's `project` method:
|
134
|
+
|
135
|
+
```ruby
|
136
|
+
project = import.project
|
137
|
+
```
|
138
|
+
|
139
|
+
##### Verifying your project
|
140
|
+
|
141
|
+
Next you need to verify that your board has been processed as expected.
|
142
|
+
Start by verifying that the `top_image` and `bottom_image` match your
|
143
|
+
expectations and verify that all the `layers` that you expect are present
|
144
|
+
with their image files.
|
145
|
+
|
146
|
+
Once you are certain that we have processed your board correctly, then you
|
147
|
+
can approve it for ordering:
|
148
|
+
|
149
|
+
```ruby
|
150
|
+
project.approve
|
151
|
+
```
|
152
|
+
|
153
|
+
##### Ordering your project
|
154
|
+
|
155
|
+
There are a few steps to go through before you can order your board (or boards)
|
156
|
+
via the API:
|
157
|
+
|
158
|
+
###### Create a new order
|
159
|
+
|
160
|
+
The first step is to create a new, empty order into which you will add your items:
|
161
|
+
|
162
|
+
```ruby
|
163
|
+
order = Oshpark::Order.create
|
164
|
+
```
|
165
|
+
|
166
|
+
###### Add your project(s) to your order
|
167
|
+
|
168
|
+
Next you need to add your project(s) to your order, specifying their quantity.
|
169
|
+
Remember that for prototype services quantities must be in multiples of three.
|
170
|
+
|
171
|
+
```ruby
|
172
|
+
order.add_item project, 3
|
173
|
+
```
|
174
|
+
|
175
|
+
###### Create an address
|
176
|
+
|
177
|
+
Create an address object with your delivery details:
|
178
|
+
|
179
|
+
```ruby
|
180
|
+
address = Oshpark::Address.new \
|
181
|
+
name: 'Jane Doe',
|
182
|
+
company_name: 'Resistor Ltd',
|
183
|
+
address_line_1: 'Level One, 83-85 Victoria Road',
|
184
|
+
address_line_2: 'Devonport',
|
185
|
+
city: 'Auckland',
|
186
|
+
zip_or_postal_code: '0624',
|
187
|
+
country: 'nz'
|
188
|
+
```
|
189
|
+
|
190
|
+
###### Set your order address
|
191
|
+
|
192
|
+
Once you have generated your address, you can set it on the order:
|
193
|
+
|
194
|
+
```ruby
|
195
|
+
order.set_address address
|
196
|
+
```
|
197
|
+
|
198
|
+
###### Get and set the shipping rates
|
199
|
+
|
200
|
+
As our shipping providers generate individual pricing for each destination
|
201
|
+
address you need to ask the API to retrieve all the available rates for your
|
202
|
+
address. The available rates will always include the USPS free shipping
|
203
|
+
options.
|
204
|
+
|
205
|
+
```ruby
|
206
|
+
rates = address.available_shipping_rates
|
207
|
+
```
|
208
|
+
|
209
|
+
Set your order to one of the provided shipping rates:
|
210
|
+
|
211
|
+
```ruby
|
212
|
+
order.set_shipping_rate rates.first
|
213
|
+
```
|
214
|
+
|
215
|
+
###### Checkout your order
|
216
|
+
|
217
|
+
Next you should be able to checkout your order:
|
218
|
+
|
219
|
+
```ruby
|
220
|
+
order.checkout
|
221
|
+
```
|
222
|
+
|
223
|
+
If you are an invoiced customer then your order will immediately be placed in
|
224
|
+
the queue ready for panelization, otherwise you will get an email asking for
|
225
|
+
payment before the order can continue. We can't accept credit card payments
|
226
|
+
via the API at this time.
|
227
|
+
|
228
|
+
If you are not, but would like to be an invoiced customer then contact [OSH Park support](mailto:support@oshpark.com).
|
76
229
|
|
77
230
|
## Contributing
|
78
231
|
|
data/lib/oshpark/client.rb
CHANGED
@@ -59,7 +59,6 @@ module Oshpark
|
|
59
59
|
# Approve a particular project from the current user's collection by ID.
|
60
60
|
# We strongly suggest that you allow the user to view the rendered images
|
61
61
|
# in Project#top_image, Project#bottom_image and Project#layers[]#image
|
62
|
-
# You should probably call Project#approve! instead.
|
63
62
|
#
|
64
63
|
# @param id
|
65
64
|
def approve_project id
|
@@ -123,6 +122,7 @@ module Oshpark
|
|
123
122
|
#
|
124
123
|
# @param id
|
125
124
|
# @param address
|
125
|
+
# An Address object or a Hash with at least the required keys: :name :address_line_1 :address_line_2 :city :country
|
126
126
|
def set_order_address id, address
|
127
127
|
post_request "orders/#{id}/set_address", {order: {address: address.to_h}}
|
128
128
|
end
|
@@ -134,10 +134,10 @@ module Oshpark
|
|
134
134
|
# Set the delivery address for an Order
|
135
135
|
#
|
136
136
|
# @param id
|
137
|
-
# @param
|
138
|
-
#
|
139
|
-
def set_order_shipping_rate id,
|
140
|
-
post_request "orders/#{id}/set_shipping_rate", {order:{shipping_rate:
|
137
|
+
# @param shipping_rate
|
138
|
+
# A ShippingRate object or a Hash with the following keys: :carrier_name :service_name
|
139
|
+
def set_order_shipping_rate id, shipping_rate
|
140
|
+
post_request "orders/#{id}/set_shipping_rate", {order:{shipping_rate: shipping_rate.to_h}}
|
141
141
|
end
|
142
142
|
|
143
143
|
# Checkout a specific order by ID.
|
data/lib/oshpark/connection.rb
CHANGED
@@ -4,9 +4,11 @@ require 'net/http'
|
|
4
4
|
require 'micro_token'
|
5
5
|
|
6
6
|
module Oshpark
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
HttpError = Class.new RuntimeError
|
8
|
+
Unauthorized = Class.new HttpError
|
9
|
+
NotFound = Class.new HttpError
|
10
|
+
ServerError = Class.new HttpError
|
11
|
+
Unprocessable = Class.new HttpError
|
10
12
|
|
11
13
|
class Connection
|
12
14
|
def initialize endpoint_url
|
@@ -47,11 +49,15 @@ module Oshpark
|
|
47
49
|
|
48
50
|
case response.code.to_i
|
49
51
|
when 401
|
50
|
-
raise Unauthorized,
|
52
|
+
raise Unauthorized, json['error']
|
51
53
|
when 404
|
52
|
-
raise NotFound,
|
54
|
+
raise NotFound, json['error']
|
55
|
+
when 422
|
56
|
+
raise Unprocessable, json['error']
|
57
|
+
when 400...499
|
58
|
+
raise HttpError, json['error']
|
53
59
|
when 500...599
|
54
|
-
raise ServerError,
|
60
|
+
raise ServerError, json['error']
|
55
61
|
end
|
56
62
|
|
57
63
|
json
|
data/lib/oshpark/model.rb
CHANGED
data/lib/oshpark/order.rb
CHANGED
@@ -20,29 +20,23 @@ module Oshpark
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def add_item order_item, quantity
|
23
|
-
|
24
|
-
reload_with json
|
23
|
+
reload_with Oshpark::client.add_order_item id, order_item.id, quantity
|
25
24
|
end
|
26
25
|
|
27
26
|
def set_address address
|
28
|
-
|
29
|
-
reload_with json
|
27
|
+
reload_with Oshpark::client.set_order_address id, address
|
30
28
|
end
|
31
29
|
|
32
|
-
def set_shipping_rate
|
33
|
-
|
34
|
-
rate = args.first
|
35
|
-
[rate.carrier_name, rate.service_name]
|
36
|
-
else
|
37
|
-
args
|
38
|
-
end
|
39
|
-
json = Oshpark::client.set_order_shipping_rate id, carrier_name, service_name
|
40
|
-
reload_with json
|
30
|
+
def set_shipping_rate shipping_rate
|
31
|
+
reload_with Oshpark::client.set_order_shipping_rate id, shipping_rate
|
41
32
|
end
|
42
33
|
|
43
34
|
def checkout
|
44
|
-
|
45
|
-
|
35
|
+
reload_with Oshpark.client.checkout_order id
|
36
|
+
end
|
37
|
+
|
38
|
+
def cancel
|
39
|
+
reload_with Oshpark.client.cancel_order id
|
46
40
|
end
|
47
41
|
|
48
42
|
def panel
|
data/lib/oshpark/project.rb
CHANGED
data/lib/oshpark/version.rb
CHANGED
data/oshpark.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["james@resistor.io", "henry@resistor.io"]
|
11
11
|
spec.summary = %q{API and command line client for oshpark.com}
|
12
12
|
spec.description = %q{API and command line client for PCB fabrication via oshpark.com}
|
13
|
-
spec.homepage = ""
|
13
|
+
spec.homepage = "https://github.com/oshpark/ruby-api-client"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
@@ -35,7 +35,7 @@ describe 'API Workflow' do
|
|
35
35
|
expect(project.layers.size).to eq 7
|
36
36
|
expect(project.layers.all? { |l| l.class == Oshpark::Layer }).to eq true
|
37
37
|
|
38
|
-
project.approve
|
38
|
+
project.approve
|
39
39
|
|
40
40
|
expect(project).to be_approved
|
41
41
|
|
@@ -64,8 +64,7 @@ describe 'API Workflow' do
|
|
64
64
|
order.set_shipping_rate rates.first
|
65
65
|
expect(order.shipping_rate).to be
|
66
66
|
|
67
|
-
|
68
|
-
|
69
|
-
puts Oshpark.client.checkout_order(order.id).inspect
|
67
|
+
order.checkout
|
68
|
+
expect(order).to be_received
|
70
69
|
end
|
71
70
|
end
|