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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9c03c63de755a320ca2ff92012a6ee518224a36d
4
- data.tar.gz: fb4a13cb27455eca130da96a42e00af4c8410741
3
+ metadata.gz: 2834c0fd61a309e742ba08525f37bae1684edbf7
4
+ data.tar.gz: 2451a5be624a54730515bf42e9d3ea6aaf341485
5
5
  SHA512:
6
- metadata.gz: 6a82622645351c80fbb0728cafcbba2c1d887d3dd122cead3223a6b2bd98e9bc63bdc3a69938d671bd5aeae0d5e88cf78c8dd163019fb42ba99cfa9256fd3026
7
- data.tar.gz: bb2392fedfcf1ea183e65c057536ea50ecfbab3a1f91586d3ae8825ab017398b523ee2f4c48812aa1f82bf0c37fb99e3a33ca67381a3206c5ee650c9595ea1be
6
+ metadata.gz: c7c9ecd5dc76fb44de77dff1f164201214094fab534d67e28aa72d8445570864041f3928377e660b27a0e124e09ba16ff0d40a44d1ec45625b24c8d676fa2386
7
+ data.tar.gz: ad0be34d9762b290fc4676459a139c858a01123a740038b2d02e056d1398ac0f702af3348d7a3dc72200d1533988d1e9f4bbf7039e309bf88475579ef4a6701a
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- oshpark (0.0.10)
4
+ oshpark (1.0.0)
5
5
  micro_token
6
6
  thor
7
7
 
data/README.md CHANGED
@@ -1,78 +1,231 @@
1
- # Oshpark
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 Oshpark gem allows developers to easily access the Oshpark API. Developer resources can be found at [https://oshpark.com/developer](https://oshpark.com/developer)
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
- gem 'oshpark'
13
+ ```ruby
14
+ gem 'oshpark'
15
+ ```
14
16
 
15
17
  And then execute:
16
18
 
17
- $ bundle
19
+ ```sh
20
+ $ bundle
21
+ ```
18
22
 
19
23
  Or install it yourself as:
20
24
 
21
- $ gem install oshpark
25
+ ```sh
26
+ $ gem install oshpark
27
+ ```
22
28
 
23
29
  ## Usage
24
30
 
25
- Before you begin you need to have an [Oshpark account](http://oshpark.com/users/sign_up) and then request access to the Oshpark API. Do this by contacting ????
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 OShpark API.
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 Oshpark data into.
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 Oshpark 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.
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
- client = Oshpark::client
38
- client.authenticate 'jane@resistor.io', {with_password: 'secret'}
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 Oshpark;
48
+ Then you can can use this object to interact with OSH Park;
41
49
 
42
- file = File.open('my_pcb.zip', 'r')
43
- upload = client.create_upload file
44
- ...
45
- my_projects = client.projects
46
- ...
47
- project = client.project 'id'
48
- client.update_project project["id"], {"name" => "my awesome project"}
49
- ...
50
- new_order = client.create_order
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 Oshpark'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.
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 Oshpark data. It uses the Low Level API underneath but wraps the return data in nice Ruby objects.
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
- Again begin by creating an Oshpark::client and authenticating;
69
+ #### Authenticate
60
70
 
61
- client = Oshpark::client
62
- client.authenticate 'jane@resistor.io', {with_password: 'secret'}
71
+ ```ruby
72
+ client = Oshpark::client
73
+ client.authenticate 'jane@resistor.io', with_password: 'secret'
74
+ ```
63
75
 
64
- file = File.open('my_pcb.zip', 'r')
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
 
@@ -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 carrier_name
138
- # @param service_name
139
- def set_order_shipping_rate id, carrier_name, service_name
140
- post_request "orders/#{id}/set_shipping_rate", {order:{shipping_rate:{carrier_name: carrier_name, service_name: service_name}}}
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.
@@ -4,9 +4,11 @@ require 'net/http'
4
4
  require 'micro_token'
5
5
 
6
6
  module Oshpark
7
- Unauthorized = Class.new(RuntimeError)
8
- NotFound = Class.new(RuntimeError)
9
- ServerError = Class.new(RuntimeError)
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, json['error']
52
+ raise Unauthorized, json['error']
51
53
  when 404
52
- raise NotFound, json['error']
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, json['error']
60
+ raise ServerError, json['error']
55
61
  end
56
62
 
57
63
  json
@@ -77,6 +77,7 @@ module Oshpark
77
77
  end
78
78
  @dirty_attributes = []
79
79
  end
80
+ self
80
81
  end
81
82
 
82
83
  def guard_against_invalid_arguments keys
@@ -20,29 +20,23 @@ module Oshpark
20
20
  end
21
21
 
22
22
  def add_item order_item, quantity
23
- json = Oshpark::client.add_order_item id, order_item.id, quantity
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
- json = Oshpark::client.set_order_address id, address
29
- reload_with json
27
+ reload_with Oshpark::client.set_order_address id, address
30
28
  end
31
29
 
32
- def set_shipping_rate *args
33
- carrier_name, service_name = if Oshpark::ShippingRate === args.first
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
- json = Oshpark::client.checkout_order id
45
- reload_with json
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
@@ -45,9 +45,8 @@ module Oshpark
45
45
  @height_in_mils || 0
46
46
  end
47
47
 
48
- def approve!
49
- json = Oshpark::client.approve_project id
50
- reload_with json
48
+ def approve
49
+ reload_with Oshpark::client.approve_project id
51
50
  end
52
51
 
53
52
  end
@@ -14,5 +14,10 @@ module Oshpark
14
14
  from_json shipping_rate_json
15
15
  end
16
16
  end
17
+
18
+ def to_h
19
+ {carrier_name: carrier_name, service_name: service_name}
20
+ end
21
+
17
22
  end
18
23
  end
@@ -1,3 +1,3 @@
1
1
  module Oshpark
2
- VERSION = "0.0.10"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -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
- # order.checkout
68
- # expect(order).to be_processing
69
- puts Oshpark.client.checkout_order(order.id).inspect
67
+ order.checkout
68
+ expect(order).to be_received
70
69
  end
71
70
  end