oshpark 0.0.7 → 0.0.10

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: 5d5f25d87af7fa429c3ac0963ccc7f02ece62a68
4
- data.tar.gz: f514b160f998dbe1c329bbf43d1aa1ca93ce2ff3
3
+ metadata.gz: 9c03c63de755a320ca2ff92012a6ee518224a36d
4
+ data.tar.gz: fb4a13cb27455eca130da96a42e00af4c8410741
5
5
  SHA512:
6
- metadata.gz: d465cfa91e925af53618e94d84694ac03e4de28b9899e5563cbc76651b37b2bb6b8d160468bb87ebaebb111250e4b878465c2c0a67933ffac6175f33036598fc
7
- data.tar.gz: fb3ac304346a04ff83ae49d325932146315df8d5ef2a36c854b1a112d90bec1d040e4185523fb4f00b7a0a7913522370e612cf942873a4b2b58ba41d23671366
6
+ metadata.gz: 6a82622645351c80fbb0728cafcbba2c1d887d3dd122cead3223a6b2bd98e9bc63bdc3a69938d671bd5aeae0d5e88cf78c8dd163019fb42ba99cfa9256fd3026
7
+ data.tar.gz: bb2392fedfcf1ea183e65c057536ea50ecfbab3a1f91586d3ae8825ab017398b523ee2f4c48812aa1f82bf0c37fb99e3a33ca67381a3206c5ee650c9595ea1be
data/.gitignore CHANGED
@@ -20,3 +20,4 @@ tmp
20
20
  *.a
21
21
  mkmf.log
22
22
  .ruby-version
23
+ .env
@@ -1,14 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- oshpark (0.0.7)
4
+ oshpark (0.0.10)
5
5
  micro_token
6
6
  thor
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- builder (3.2.2)
11
+ addressable (2.3.6)
12
12
  byebug (2.7.0)
13
13
  columnize (~> 0.3)
14
14
  debugger-linecache (~> 1.2)
@@ -16,18 +16,13 @@ GEM
16
16
  timers (~> 1.1.0)
17
17
  coderay (1.1.0)
18
18
  columnize (0.8.9)
19
- cucumber (1.3.15)
20
- builder (>= 2.1.2)
21
- diff-lcs (>= 1.1.3)
22
- gherkin (~> 2.12)
23
- multi_json (>= 1.7.5, < 2.0)
24
- multi_test (>= 0.1.1)
19
+ crack (0.4.2)
20
+ safe_yaml (~> 1.0.0)
25
21
  debugger-linecache (1.2.0)
26
22
  diff-lcs (1.2.5)
23
+ dotenv (1.0.2)
27
24
  ffi (1.9.3)
28
25
  formatador (0.2.5)
29
- gherkin (2.12.2)
30
- multi_json (~> 1.3)
31
26
  guard (2.6.1)
32
27
  formatador (>= 0.2.4)
33
28
  listen (~> 2.7)
@@ -37,9 +32,6 @@ GEM
37
32
  guard-bundler (2.0.0)
38
33
  bundler (~> 1.0)
39
34
  guard (~> 2.2)
40
- guard-cucumber (1.4.1)
41
- cucumber (>= 1.2.0)
42
- guard (>= 1.1.0)
43
35
  guard-rspec (4.2.9)
44
36
  guard (~> 2.1)
45
37
  rspec (>= 2.14, < 4.0)
@@ -50,8 +42,6 @@ GEM
50
42
  lumberjack (1.0.6)
51
43
  method_source (0.8.2)
52
44
  micro_token (0.0.3)
53
- multi_json (1.10.1)
54
- multi_test (0.1.1)
55
45
  pry (0.9.12.6)
56
46
  coderay (~> 1.0)
57
47
  method_source (~> 0.8)
@@ -75,9 +65,14 @@ GEM
75
65
  rspec-mocks (3.0.1)
76
66
  rspec-support (~> 3.0.0)
77
67
  rspec-support (3.0.0)
68
+ safe_yaml (1.0.3)
78
69
  slop (3.5.0)
79
70
  thor (0.19.1)
80
71
  timers (1.1.0)
72
+ vcr (2.9.3)
73
+ webmock (1.18.0)
74
+ addressable (>= 2.3.6)
75
+ crack (>= 0.3.2)
81
76
 
82
77
  PLATFORMS
83
78
  ruby
@@ -85,9 +80,8 @@ PLATFORMS
85
80
  DEPENDENCIES
86
81
  bundler (~> 1.6)
87
82
  byebug
88
- cucumber
83
+ dotenv
89
84
  guard-bundler
90
- guard-cucumber
91
85
  guard-rspec
92
86
  oshpark!
93
87
  pry
@@ -95,3 +89,5 @@ DEPENDENCIES
95
89
  rspec-core
96
90
  rspec-its
97
91
  rspec-mocks
92
+ vcr
93
+ webmock
data/Guardfile CHANGED
@@ -4,13 +4,6 @@ guard :rspec do
4
4
  watch('spec/spec_helper.rb') { "spec" }
5
5
  end
6
6
 
7
-
8
- guard 'cucumber' do
9
- watch(%r{^features/.+\.feature$})
10
- watch(%r{^features/support/.+$}) { 'features' }
11
- watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
12
- end
13
-
14
7
  guard :bundler do
15
8
  watch('Gemfile')
16
9
  watch(/^.+\.gemspec/)
@@ -3,6 +3,7 @@ require "oshpark/ext"
3
3
  require "oshpark/client"
4
4
  require "oshpark/connection"
5
5
  require "oshpark/model"
6
+ require "oshpark/remote_model"
6
7
  require "oshpark/stateful"
7
8
  require "oshpark/dimensionable"
8
9
  require "oshpark/order_option"
@@ -17,6 +18,7 @@ require "oshpark/upload"
17
18
  require "oshpark/token"
18
19
  require "oshpark/address"
19
20
  require "oshpark/shipping_rate"
21
+ require "oshpark/price"
20
22
  require "oshpark/order_item"
21
23
  require "oshpark/order_item_option_selection"
22
24
 
@@ -10,7 +10,10 @@ module Oshpark
10
10
  attrs.each {|a| attr_accessor a }
11
11
 
12
12
  def initialize args={}
13
- super check_args args
13
+ clean_json args do |json|
14
+ check_args json
15
+ reload_with json
16
+ end
14
17
  end
15
18
 
16
19
  def to_h
@@ -21,6 +24,10 @@ module Oshpark
21
24
  end
22
25
  end
23
26
 
27
+ def available_shipping_rates
28
+ ShippingRate.rates_for_address self
29
+ end
30
+
24
31
  private
25
32
 
26
33
  def check_args args
@@ -38,6 +38,12 @@ module Oshpark
38
38
  end
39
39
  end
40
40
 
41
+ # Abandon a previous authentication.
42
+ def abandon
43
+ self.token = nil
44
+ refresh_token
45
+ end
46
+
41
47
  # Retrieve a list of projects for the current user.
42
48
  def projects
43
49
  get_request 'projects'
@@ -77,6 +83,16 @@ module Oshpark
77
83
  true
78
84
  end
79
85
 
86
+ # Request a price estimate
87
+ #
88
+ # @param width In thousands of an Inch
89
+ # @param height In thousands of an Inch
90
+ # @param layers
91
+ # @param quantity Optional Defaults to the minimum quantity
92
+ def pricing width, height, pcb_layers, quantity = nil
93
+ post_request "pricing", {width_in_mils: width, height_in_mils: height, pcb_layers: pcb_layers, quantity: quantity}
94
+ end
95
+
80
96
  # List all the current user's orders, and their status.
81
97
  def orders
82
98
  get_request 'orders'
@@ -100,7 +116,7 @@ module Oshpark
100
116
  # @param project_id
101
117
  # @param quantity
102
118
  def add_order_item id, project_id, quantity
103
- put_request "orders/#{id}/add_item", {project_id: project_id, quantity: quantity}
119
+ post_request "orders/#{id}/add_item", {order: {project_id: project_id, quantity: quantity}}
104
120
  end
105
121
 
106
122
  # Set the delivery address for an Order
@@ -108,7 +124,7 @@ module Oshpark
108
124
  # @param id
109
125
  # @param address
110
126
  def set_order_address id, address
111
- put_request "orders/#{id}/set_address", address
127
+ post_request "orders/#{id}/set_address", {order: {address: address.to_h}}
112
128
  end
113
129
 
114
130
  def shipping_rates address_params
@@ -121,14 +137,14 @@ module Oshpark
121
137
  # @param carrier_name
122
138
  # @param service_name
123
139
  def set_order_shipping_rate id, carrier_name, service_name
124
- put_request "orders/#{id}/set_shipping_rate", {carrier_name: carrier_name, service_name: service_name}
140
+ post_request "orders/#{id}/set_shipping_rate", {order:{shipping_rate:{carrier_name: carrier_name, service_name: service_name}}}
125
141
  end
126
142
 
127
143
  # Checkout a specific order by ID.
128
144
  #
129
145
  # @param id
130
146
  def checkout_order id
131
- put_request "orders/#{id}/checkout"
147
+ post_request "orders/#{id}/checkout"
132
148
  end
133
149
 
134
150
  # Cancel a specific order by ID.
@@ -39,7 +39,11 @@ module Oshpark
39
39
 
40
40
  response = http.request(request)
41
41
 
42
- json = JSON.parse(response.body)
42
+ json = if response.body.size >= 2
43
+ JSON.parse(response.body)
44
+ else
45
+ {}
46
+ end
43
47
 
44
48
  case response.code.to_i
45
49
  when 401
@@ -53,7 +57,7 @@ module Oshpark
53
57
  json
54
58
 
55
59
  rescue JSON::ParserError => e
56
- raise ServerError, "Bad response from server"
60
+ raise ServerError, "Bad response from server: #{e.message}"
57
61
  end
58
62
 
59
63
  private
@@ -7,6 +7,7 @@ module Oshpark
7
7
  STATES = %w| WAITING RUNNING SUCCESS ERROR FAILED |
8
8
 
9
9
  include Model
10
+ include RemoteModel
10
11
  include Stateful
11
12
 
12
13
  def self.create url
@@ -11,25 +11,6 @@ module Oshpark
11
11
  @dirty_attributes.size > 0
12
12
  end
13
13
 
14
- def save!
15
- attrs = {}
16
- @dirty_attributes.map do |attr|
17
- attrs[attr] = public_send(attr)
18
- end
19
-
20
- Oshpark::client.public_send("update_#{object_name}", id, attrs)
21
- end
22
-
23
- def reload!
24
- json = Oshpark::client.public_send(object_name, id)[object_name]
25
- reload_with json
26
- end
27
-
28
- def destroy!
29
- Oshpark::client.public_send("destroy_#{object_name}", id)[object_name]
30
- nil
31
- end
32
-
33
14
  def self.included base
34
15
  base.send :extend, ClassMethods
35
16
 
@@ -55,16 +36,6 @@ module Oshpark
55
36
  []
56
37
  end
57
38
 
58
- def all
59
- Oshpark::client.public_send(object_names)[object_names].map do |json|
60
- self.from_json json
61
- end
62
- end
63
-
64
- def find id
65
- self.from_json(Oshpark::client.public_send(object_name, id)[object_name])
66
- end
67
-
68
39
  def object_name
69
40
  self.name.split('::').last.downcase
70
41
  end
@@ -72,7 +43,6 @@ module Oshpark
72
43
  def object_names
73
44
  "#{object_name}s"
74
45
  end
75
-
76
46
  end
77
47
 
78
48
  private
@@ -91,12 +61,22 @@ module Oshpark
91
61
  self.class.object_names
92
62
  end
93
63
 
64
+ def clean_json json
65
+ json = json[object_name] if json.has_key?(object_name) && (Hash === json[object_name])
66
+
67
+ yield json if block_given?
68
+ json
69
+ end
70
+
94
71
  def reload_with json
95
- guard_against_invalid_arguments json.keys
96
- json.each do |key,value|
97
- instance_variable_set "@#{key}", value
72
+ clean_json(json) do |json|
73
+ guard_against_invalid_arguments json.keys
74
+
75
+ json.each do |key,value|
76
+ instance_variable_set "@#{key}", value
77
+ end
78
+ @dirty_attributes = []
98
79
  end
99
- @dirty_attributes = []
100
80
  end
101
81
 
102
82
  def guard_against_invalid_arguments keys
@@ -105,6 +85,5 @@ module Oshpark
105
85
  end
106
86
  end
107
87
 
108
-
109
88
  end
110
89
  end
@@ -12,6 +12,7 @@ module Oshpark
12
12
  end
13
13
 
14
14
  include Model
15
+ include RemoteModel
15
16
  include Stateful
16
17
 
17
18
  def self.create
@@ -20,22 +21,28 @@ module Oshpark
20
21
 
21
22
  def add_item order_item, quantity
22
23
  json = Oshpark::client.add_order_item id, order_item.id, quantity
23
- reload_with json['order']
24
+ reload_with json
24
25
  end
25
26
 
26
27
  def set_address address
27
28
  json = Oshpark::client.set_order_address id, address
28
- reload_with json['order']
29
+ reload_with json
29
30
  end
30
31
 
31
- def set_shipping_rate carrier_name, service_name
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
32
39
  json = Oshpark::client.set_order_shipping_rate id, carrier_name, service_name
33
- reload_with json['order']
40
+ reload_with json
34
41
  end
35
42
 
36
43
  def checkout
37
44
  json = Oshpark::client.checkout_order id
38
- reload_with json['order']
45
+ reload_with json
39
46
  end
40
47
 
41
48
  def panel
@@ -9,6 +9,7 @@ module Oshpark
9
9
  end
10
10
 
11
11
  include Model
12
+ include RemoteModel
12
13
  include Stateful
13
14
 
14
15
  def scheduled_order_time
@@ -0,0 +1,15 @@
1
+ module Oshpark
2
+ class Price
3
+
4
+ def self.attrs
5
+ %w| width_in_mils height_in_mils pcb_layers quantity quantity_multiple minimum_quantity minimum_square_inches batches batch_cost subtotal |
6
+ end
7
+
8
+ include Model
9
+
10
+ def self.price_for width, height, pcb_layers, quantity = nil
11
+ json = Oshpark::client.pricing width, height, pcb_layers, quantity
12
+ from_json json['pricing']
13
+ end
14
+ end
15
+ end
@@ -11,6 +11,7 @@ module Oshpark
11
11
  end
12
12
 
13
13
  include Model
14
+ include RemoteModel
14
15
  include Stateful
15
16
  include Dimensionable
16
17
 
@@ -46,7 +47,7 @@ module Oshpark
46
47
 
47
48
  def approve!
48
49
  json = Oshpark::client.approve_project id
49
- reload_with(json['project'])
50
+ reload_with json
50
51
  end
51
52
 
52
53
  end
@@ -0,0 +1,41 @@
1
+ require 'time'
2
+
3
+ module Oshpark
4
+ module RemoteModel
5
+
6
+ def self.included base
7
+ base.extend ClassMethods
8
+ end
9
+
10
+ def save!
11
+ attrs = {}
12
+ @dirty_attributes.map do |attr|
13
+ attrs[attr] = public_send(attr)
14
+ end
15
+
16
+ Oshpark::client.public_send("update_#{object_name}", id, attrs)
17
+ end
18
+
19
+ def reload!
20
+ json = Oshpark::client.public_send(object_name, id)
21
+ reload_with json
22
+ end
23
+
24
+ def destroy!
25
+ Oshpark::client.public_send("destroy_#{object_name}", id)
26
+ nil
27
+ end
28
+
29
+ module ClassMethods
30
+ def all
31
+ Oshpark::client.public_send(object_names)[object_names].map do |json|
32
+ self.from_json json
33
+ end
34
+ end
35
+
36
+ def find id
37
+ self.from_json(Oshpark::client.public_send(object_name, id)[object_name])
38
+ end
39
+ end
40
+ end
41
+ end