oshpark 0.0.5 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/oshpark.rb +1 -0
- data/lib/oshpark/address.rb +2 -14
- data/lib/oshpark/client.rb +5 -1
- data/lib/oshpark/connection.rb +0 -1
- data/lib/oshpark/import.rb +4 -1
- data/lib/oshpark/order.rb +8 -5
- data/lib/oshpark/order_item.rb +4 -0
- data/lib/oshpark/panel.rb +3 -0
- data/lib/oshpark/project.rb +4 -1
- data/lib/oshpark/shipping_rate.rb +7 -0
- data/lib/oshpark/stateful.rb +11 -0
- data/lib/oshpark/upload.rb +12 -1
- data/lib/oshpark/version.rb +1 -1
- data/spec/lib/oshpark/client_spec.rb +10 -1
- data/spec/lib/oshpark/order_spec.rb +6 -6
- data/spec/lib/oshpark/shipping_rate_spec.rb +34 -0
- data/spec/support/http_client.rb +1 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d5f25d87af7fa429c3ac0963ccc7f02ece62a68
|
4
|
+
data.tar.gz: f514b160f998dbe1c329bbf43d1aa1ca93ce2ff3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d465cfa91e925af53618e94d84694ac03e4de28b9899e5563cbc76651b37b2bb6b8d160468bb87ebaebb111250e4b878465c2c0a67933ffac6175f33036598fc
|
7
|
+
data.tar.gz: fb3ac304346a04ff83ae49d325932146315df8d5ef2a36c854b1a112d90bec1d040e4185523fb4f00b7a0a7913522370e612cf942873a4b2b58ba41d23671366
|
data/Gemfile.lock
CHANGED
data/lib/oshpark.rb
CHANGED
data/lib/oshpark/address.rb
CHANGED
@@ -10,11 +10,7 @@ module Oshpark
|
|
10
10
|
attrs.each {|a| attr_accessor a }
|
11
11
|
|
12
12
|
def initialize args={}
|
13
|
-
|
14
|
-
Address.attrs.each do |a|
|
15
|
-
v = args.fetch(a, nil)
|
16
|
-
public_send :"#{a}=", v
|
17
|
-
end
|
13
|
+
super check_args args
|
18
14
|
end
|
19
15
|
|
20
16
|
def to_h
|
@@ -31,16 +27,8 @@ module Oshpark
|
|
31
27
|
unless (args.keys.map(&:to_s) & REQUIRED_ARGS) == REQUIRED_ARGS
|
32
28
|
raise ArgumentError, "Missing required arguments #{(REQUIRED_ARGS - args.keys).join(' ')}"
|
33
29
|
end
|
34
|
-
|
35
|
-
stingify_hash_keys args
|
30
|
+
args
|
36
31
|
end
|
37
32
|
|
38
|
-
def stingify_hash_keys hash
|
39
|
-
{}.tap do |h|
|
40
|
-
hash.each do |k, v|
|
41
|
-
h[k.to_s] = v
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
33
|
end
|
46
34
|
end
|
data/lib/oshpark/client.rb
CHANGED
@@ -108,7 +108,11 @@ module Oshpark
|
|
108
108
|
# @param id
|
109
109
|
# @param address
|
110
110
|
def set_order_address id, address
|
111
|
-
put_request "orders/#{id}/set_address", address
|
111
|
+
put_request "orders/#{id}/set_address", address
|
112
|
+
end
|
113
|
+
|
114
|
+
def shipping_rates address_params
|
115
|
+
post_request "shipping_rates", {address: address_params}
|
112
116
|
end
|
113
117
|
|
114
118
|
# Set the delivery address for an Order
|
data/lib/oshpark/connection.rb
CHANGED
data/lib/oshpark/import.rb
CHANGED
@@ -4,10 +4,13 @@ module Oshpark
|
|
4
4
|
%w| id state original_url original_filename error_message queued_at started_at completed_at errored_at failed_at project_id |
|
5
5
|
end
|
6
6
|
|
7
|
+
STATES = %w| WAITING RUNNING SUCCESS ERROR FAILED |
|
8
|
+
|
7
9
|
include Model
|
10
|
+
include Stateful
|
8
11
|
|
9
12
|
def self.create url
|
10
|
-
self.from_json(Oshpark::client.create_import(url))
|
13
|
+
self.from_json(Oshpark::client.create_import(url)['import'])
|
11
14
|
end
|
12
15
|
|
13
16
|
def project
|
data/lib/oshpark/order.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module Oshpark
|
2
2
|
class Order
|
3
3
|
|
4
|
+
STATES = %w| EMPTY NEW RECEIVED PROCESSING SHIPPED CANCELLED |
|
5
|
+
|
4
6
|
def self.attrs
|
5
7
|
%w| id board_cost cancellation_reason cancelled_at ordered_at
|
6
8
|
payment_provider payment_received_at project_name quantity
|
@@ -10,29 +12,30 @@ module Oshpark
|
|
10
12
|
end
|
11
13
|
|
12
14
|
include Model
|
15
|
+
include Stateful
|
13
16
|
|
14
17
|
def self.create
|
15
|
-
self.from_json(Oshpark::client.create_order)
|
18
|
+
self.from_json(Oshpark::client.create_order['order'])
|
16
19
|
end
|
17
20
|
|
18
21
|
def add_item order_item, quantity
|
19
22
|
json = Oshpark::client.add_order_item id, order_item.id, quantity
|
20
|
-
reload_with json
|
23
|
+
reload_with json['order']
|
21
24
|
end
|
22
25
|
|
23
26
|
def set_address address
|
24
27
|
json = Oshpark::client.set_order_address id, address
|
25
|
-
reload_with json
|
28
|
+
reload_with json['order']
|
26
29
|
end
|
27
30
|
|
28
31
|
def set_shipping_rate carrier_name, service_name
|
29
32
|
json = Oshpark::client.set_order_shipping_rate id, carrier_name, service_name
|
30
|
-
reload_with json
|
33
|
+
reload_with json['order']
|
31
34
|
end
|
32
35
|
|
33
36
|
def checkout
|
34
37
|
json = Oshpark::client.checkout_order id
|
35
|
-
reload_with json
|
38
|
+
reload_with json['order']
|
36
39
|
end
|
37
40
|
|
38
41
|
def panel
|
data/lib/oshpark/order_item.rb
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
module Oshpark
|
2
2
|
class OrderItem
|
3
|
+
|
4
|
+
STATES = %w| NEW AWAITING_PANEL PANELIZED ORDERED FABBED SHIPPED CANCELLED |
|
5
|
+
|
3
6
|
def self.attrs
|
4
7
|
%w| name batches batch_cost sub_total price quantity state confirmed_at panelized_at
|
5
8
|
ordered_at fabbed_at shipped_at project_id panel_id order_item_option_selections |
|
6
9
|
end
|
7
10
|
|
8
11
|
include Model
|
12
|
+
include Stateful
|
9
13
|
|
10
14
|
def project
|
11
15
|
Oshpark::Project.find @project_id if @project_id
|
data/lib/oshpark/panel.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
module Oshpark
|
2
2
|
class Panel
|
3
|
+
STATES = %w| OPEN ORDERED RECEIVED |
|
4
|
+
|
3
5
|
def self.attrs
|
4
6
|
%w| pcb_layers scheduled_order_time expected_receive_time
|
5
7
|
id ordered_at received_at state service total_orders
|
@@ -7,6 +9,7 @@ module Oshpark
|
|
7
9
|
end
|
8
10
|
|
9
11
|
include Model
|
12
|
+
include Stateful
|
10
13
|
|
11
14
|
def scheduled_order_time
|
12
15
|
time_from @scheduled_order_time if @scheduled_order_time
|
data/lib/oshpark/project.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
module Oshpark
|
2
2
|
class Project
|
3
|
+
STATES = %w| NEW APPROVED AWAITING_REMOVAL |
|
4
|
+
|
3
5
|
def self.attrs
|
4
6
|
%w| id design_file_url name description top_image bottom_image width_in_mils height_in_mils pcb_layers state layers order_options is_shared |
|
5
7
|
end
|
@@ -9,6 +11,7 @@ module Oshpark
|
|
9
11
|
end
|
10
12
|
|
11
13
|
include Model
|
14
|
+
include Stateful
|
12
15
|
include Dimensionable
|
13
16
|
|
14
17
|
alias shared? is_shared
|
@@ -43,7 +46,7 @@ module Oshpark
|
|
43
46
|
|
44
47
|
def approve!
|
45
48
|
json = Oshpark::client.approve_project id
|
46
|
-
reload_with(json)
|
49
|
+
reload_with(json['project'])
|
47
50
|
end
|
48
51
|
|
49
52
|
end
|
data/lib/oshpark/upload.rb
CHANGED
@@ -4,16 +4,27 @@ module Oshpark
|
|
4
4
|
%w| id state original_filename error_message queued_at started_at completed_at errored_at failed_at project_id |
|
5
5
|
end
|
6
6
|
|
7
|
+
STATES = %w| WAITING RUNNING SUCCESS ERROR FAILED |
|
8
|
+
|
7
9
|
include Model
|
10
|
+
include Stateful
|
8
11
|
|
9
12
|
def self.create file
|
10
|
-
self.from_json(Oshpark::client.create_upload(file))
|
13
|
+
self.from_json(Oshpark::client.create_upload(file)['upload'])
|
11
14
|
end
|
12
15
|
|
13
16
|
def project
|
14
17
|
Project.find project_id
|
15
18
|
end
|
16
19
|
|
20
|
+
def processing?
|
21
|
+
waiting? || running?
|
22
|
+
end
|
23
|
+
|
24
|
+
def finished?
|
25
|
+
success? || error? || failed?
|
26
|
+
end
|
27
|
+
|
17
28
|
def queued_at
|
18
29
|
time_from @queued_at
|
19
30
|
end
|
data/lib/oshpark/version.rb
CHANGED
@@ -88,13 +88,22 @@ describe Oshpark::Client do
|
|
88
88
|
|
89
89
|
describe '#set_order_address' do
|
90
90
|
let(:token) { 'abcd1234' }
|
91
|
-
let(:address) {
|
91
|
+
let(:address) { {"name" => "Bob", "company_name" => nil, "address_line_1" => "8 Nelson Street", "address_line_2" => "Petone", "city" => "Lower Hutt", "state" => nil, "zip_or_postal_code" => nil, "country" => "New Zealand", "phone_number" => nil, "is_business" => nil} }
|
92
92
|
it "set the delivery address for an order" do
|
93
93
|
subject.set_order_address token, address
|
94
94
|
expect(connection.requests.last).to eq([:put, "orders/#{token}/set_address", {"name" => "Bob", "company_name" => nil, "address_line_1" => "8 Nelson Street", "address_line_2" => "Petone", "city" => "Lower Hutt", "state" => nil, "zip_or_postal_code" => nil, "country" => "New Zealand", "phone_number" => nil, "is_business" => nil}])
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
98
|
+
describe "#shipping_rates" do
|
99
|
+
let(:token) { 'abcd1234' }
|
100
|
+
let(:address) { {"name" => "Bob", "company_name" => nil, "address_line_1" => "8 Nelson Street", "address_line_2" => "Petone", "city" => "Lower Hutt", "state" => nil, "zip_or_postal_code" => nil, "country" => "New Zealand", "phone_number" => nil, "is_business" => nil} }
|
101
|
+
it "returns shipping rates" do
|
102
|
+
subject.shipping_rates address
|
103
|
+
expect(connection.requests.last).to eq([:post, "shipping_rates", {:address => {"name" => "Bob", "company_name" => nil, "address_line_1" => "8 Nelson Street", "address_line_2" => "Petone", "city" => "Lower Hutt", "state" => nil, "zip_or_postal_code" => nil, "country" => "New Zealand", "phone_number" => nil, "is_business" => nil}}])
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
98
107
|
describe '#set_order_shipping_rate' do
|
99
108
|
let(:token) { 'abcd1234' }
|
100
109
|
let(:service_provider) { 'Bobs Mail'}
|
@@ -29,7 +29,7 @@ describe Oshpark::Order do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
describe '.create' do
|
32
|
-
before { expect(Oshpark::client).to receive(:create_order).and_return({id: "abcd1234", state: 'New'}) }
|
32
|
+
before { expect(Oshpark::client).to receive(:create_order).and_return({'order' => {id: "abcd1234", state: 'New'}}) }
|
33
33
|
subject { Oshpark::Order.create }
|
34
34
|
|
35
35
|
it 'creates a new Order' do
|
@@ -49,7 +49,7 @@ describe Oshpark::Order do
|
|
49
49
|
allow(subject).to receive(:id).and_return('abcd1234')
|
50
50
|
|
51
51
|
expect(item).to receive(:id).and_return('1234abcd')
|
52
|
-
expect(Oshpark::client).to receive(:add_order_item).with("abcd1234", "1234abcd", 6).and_return({id: "abcd1234"})
|
52
|
+
expect(Oshpark::client).to receive(:add_order_item).with("abcd1234", "1234abcd", 6).and_return({'order' => {id: "abcd1234"}})
|
53
53
|
subject.add_item item, quantity
|
54
54
|
end
|
55
55
|
end
|
@@ -59,18 +59,18 @@ describe Oshpark::Order do
|
|
59
59
|
it 'sets the delivery Address for an Order' do
|
60
60
|
allow(subject).to receive(:id).and_return('abcd1234')
|
61
61
|
|
62
|
-
expect(Oshpark::client).to receive(:set_order_address).with("abcd1234", address).and_return({id: "abcd1234"})
|
62
|
+
expect(Oshpark::client).to receive(:set_order_address).with("abcd1234", address).and_return({'order' => {id: "abcd1234"}})
|
63
63
|
subject.set_address address
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
67
|
describe '#set_shipping_rate' do
|
68
68
|
let(:carrier_name) { 'Bobs Mail'}
|
69
|
-
let(:service_name)
|
69
|
+
let(:service_name) { 'Overnight Delivery' }
|
70
70
|
it 'sets the shipping rate for an Order' do
|
71
71
|
allow(subject).to receive(:id).and_return('abcd1234')
|
72
72
|
|
73
|
-
expect(Oshpark::client).to receive(:set_order_shipping_rate).with("abcd1234", "Bobs Mail", "Overnight Delivery").and_return({id: "abcd1234"})
|
73
|
+
expect(Oshpark::client).to receive(:set_order_shipping_rate).with("abcd1234", "Bobs Mail", "Overnight Delivery").and_return({'order' => {id: "abcd1234"}})
|
74
74
|
subject.set_shipping_rate carrier_name, service_name
|
75
75
|
end
|
76
76
|
end
|
@@ -79,7 +79,7 @@ describe Oshpark::Order do
|
|
79
79
|
it 'checks out the order' do
|
80
80
|
allow(subject).to receive(:id).and_return('abcd1234')
|
81
81
|
|
82
|
-
expect(Oshpark::client).to receive(:checkout_order).and_return({id: "abcd1234"})
|
82
|
+
expect(Oshpark::client).to receive(:checkout_order).and_return({'order' => {id: "abcd1234"}})
|
83
83
|
subject.checkout
|
84
84
|
end
|
85
85
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Oshpark::ShippingRate do
|
4
|
+
before do
|
5
|
+
Oshpark::client url: 'blarg', connection: FakeClient.new("foo")
|
6
|
+
end
|
7
|
+
|
8
|
+
subject { Oshpark::ShippingRate.new({}) }
|
9
|
+
it { should be_an Oshpark::Model }
|
10
|
+
|
11
|
+
describe 'rates_for_address' do
|
12
|
+
let(:address_params) { {name: "Bob", address_line_1: "8 Nelson Street", address_line_2: "Petone", city: "Lower Hutt", country: "New Zealand"} }
|
13
|
+
let(:address) { Oshpark::Address.new address_params }
|
14
|
+
subject { Oshpark::ShippingRate.rates_for_address address }
|
15
|
+
|
16
|
+
before do
|
17
|
+
expect(Oshpark::client).to receive(:shipping_rates).
|
18
|
+
with({"name" => "Bob", "company_name" => nil, "address_line_1" => "8 Nelson Street", "address_line_2" => "Petone", "city" => "Lower Hutt", "state" => nil, "zip_or_postal_code" => nil, "country" => "New Zealand", "phone_number" => nil, "is_business" => nil}).
|
19
|
+
and_return({'shipping_rates' => [:carrier_name => "Pete's Post", :service_name => "Pony Express", :price => "$25.95"]})
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returns a list of shipping rates for the Order" do
|
23
|
+
expect(subject).to be_an Array
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns ShippingRate objects" do
|
27
|
+
expect(subject.first).to be_an Oshpark::ShippingRate
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
|
data/spec/support/http_client.rb
CHANGED
@@ -8,6 +8,7 @@ class FakeClient
|
|
8
8
|
'projects/abcd1234/approve' => { 'project' => {} },
|
9
9
|
'orders' => { 'orders' => [{}] },
|
10
10
|
'orders/abcd1234' => { 'order' => {} },
|
11
|
+
'shipping_rates' => { 'shipping_rates' => [{}] },
|
11
12
|
'panels' => { 'panels' => [{}] },
|
12
13
|
'panels/abcd1234' => { 'panel' => {} },
|
13
14
|
}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oshpark
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Harton
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-12-
|
12
|
+
date: 2014-12-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -228,6 +228,7 @@ files:
|
|
228
228
|
- lib/oshpark/project.rb
|
229
229
|
- lib/oshpark/rubymotion.rb
|
230
230
|
- lib/oshpark/shipping_rate.rb
|
231
|
+
- lib/oshpark/stateful.rb
|
231
232
|
- lib/oshpark/token.rb
|
232
233
|
- lib/oshpark/upload.rb
|
233
234
|
- lib/oshpark/user.rb
|
@@ -242,6 +243,7 @@ files:
|
|
242
243
|
- spec/lib/oshpark/order_spec.rb
|
243
244
|
- spec/lib/oshpark/panel_spec.rb
|
244
245
|
- spec/lib/oshpark/project_spec.rb
|
246
|
+
- spec/lib/oshpark/shipping_rate_spec.rb
|
245
247
|
- spec/lib/oshpark/upload_spec.rb
|
246
248
|
- spec/spec_helper.rb
|
247
249
|
- spec/support/http_client.rb
|
@@ -279,6 +281,7 @@ test_files:
|
|
279
281
|
- spec/lib/oshpark/order_spec.rb
|
280
282
|
- spec/lib/oshpark/panel_spec.rb
|
281
283
|
- spec/lib/oshpark/project_spec.rb
|
284
|
+
- spec/lib/oshpark/shipping_rate_spec.rb
|
282
285
|
- spec/lib/oshpark/upload_spec.rb
|
283
286
|
- spec/spec_helper.rb
|
284
287
|
- spec/support/http_client.rb
|