shopify_api 3.1.2 → 3.1.3

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.
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ == Version 3.1.3
2
+
3
+ * Expose `complete` action on Fulfillment
4
+
1
5
  == Version 3.1.2
2
6
 
3
7
  * Includes port in domain URI (when other than http/80 or https/443)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- shopify_api (3.1.2)
4
+ shopify_api (3.1.3)
5
5
  activeresource (>= 3.0.0)
6
6
  thor (>= 0.14.4)
7
7
 
@@ -1,9 +1,11 @@
1
1
  module ShopifyAPI
2
2
  module Limits
3
+ class LimitUnavailable < StandardError; end
4
+
3
5
  def self.included(klass)
4
6
  klass.send(:extend, ClassMethods)
5
7
  end
6
-
8
+
7
9
  module ClassMethods
8
10
 
9
11
  # Takes form num_requests_executed/max_requests
@@ -20,7 +22,7 @@ module ShopifyAPI
20
22
  credit_limit(:shop) - credit_used(:shop)
21
23
  end
22
24
  alias_method :available_calls, :credit_left
23
-
25
+
24
26
  ##
25
27
  # Have I reached my API call limit?
26
28
  # @return {Boolean}
@@ -29,7 +31,7 @@ module ShopifyAPI
29
31
  credit_left <= 0
30
32
  end
31
33
  alias_method :maxed?, :credit_maxed?
32
-
34
+
33
35
  ##
34
36
  # How many total API calls can I make?
35
37
  # NOTE: subtracting 1 from credit_limit because I think ShopifyAPI cuts off at 299 or shop limits.
@@ -38,7 +40,7 @@ module ShopifyAPI
38
40
  #
39
41
  def credit_limit(scope=:shop)
40
42
  @api_credit_limit ||= {}
41
- @api_credit_limit[scope] ||= api_credit_limit_param(scope).pop.to_i - 1
43
+ @api_credit_limit[scope] ||= api_credit_limit_param(scope).pop.to_i - 1
42
44
  end
43
45
  alias_method :call_limit, :credit_limit
44
46
 
@@ -51,7 +53,7 @@ module ShopifyAPI
51
53
  api_credit_limit_param(scope).shift.to_i
52
54
  end
53
55
  alias_method :call_count, :credit_used
54
-
56
+
55
57
  ##
56
58
  # @return {HTTPResonse}
57
59
  #
@@ -65,9 +67,11 @@ module ShopifyAPI
65
67
  ##
66
68
  # @return {Array}
67
69
  #
68
- def api_credit_limit_param(scope)
69
- response[CREDIT_LIMIT_HEADER_PARAM[scope]].split('/')
70
- end
70
+ def api_credit_limit_param(scope)
71
+ header = response[CREDIT_LIMIT_HEADER_PARAM[scope]]
72
+ raise LimitUnavailable unless header
73
+ header.split('/')
74
+ end
71
75
  end
72
76
  end
73
77
  end
@@ -3,5 +3,6 @@ module ShopifyAPI
3
3
  self.prefix = "/admin/orders/:order_id/"
4
4
 
5
5
  def cancel; load_attributes_from_response(post(:cancel, {}, only_id)); end
6
+ def complete; load_attributes_from_response(post(:complete, {}, only_id)); end
6
7
  end
7
8
  end
@@ -1,3 +1,3 @@
1
1
  module ShopifyAPI
2
- VERSION = "3.1.2"
2
+ VERSION = "3.1.3"
3
3
  end
@@ -0,0 +1,49 @@
1
+ {
2
+ "fulfillment": {
3
+ "created_at": "2013-11-01T16:06:08-04:00",
4
+ "id": 255858046,
5
+ "order_id": 450789469,
6
+ "service": "manual",
7
+ "status": "pending",
8
+ "tracking_company": null,
9
+ "updated_at": "2013-11-01T16:06:08-04:00",
10
+ "tracking_number": "1Z2345",
11
+ "tracking_numbers": [
12
+ "1Z2345"
13
+ ],
14
+ "tracking_url": "http://www.google.com/search?q=1Z2345",
15
+ "tracking_urls": [
16
+ "http://www.google.com/search?q=1Z2345"
17
+ ],
18
+ "receipt": {
19
+ "testcase": true,
20
+ "authorization": "123456"
21
+ },
22
+ "line_items": [
23
+ {
24
+ "fulfillment_service": "manual",
25
+ "fulfillment_status": null,
26
+ "grams": 200,
27
+ "id": 466157049,
28
+ "price": "199.00",
29
+ "product_id": 632910392,
30
+ "quantity": 1,
31
+ "requires_shipping": true,
32
+ "sku": "IPOD2008GREEN",
33
+ "title": "IPod Nano - 8gb",
34
+ "variant_id": 39072856,
35
+ "variant_title": "green",
36
+ "vendor": null,
37
+ "name": "IPod Nano - 8gb - green",
38
+ "variant_inventory_management": "shopify",
39
+ "properties": [
40
+ {
41
+ "name": "Custom Engraving",
42
+ "value": "Happy Birthday"
43
+ }
44
+ ],
45
+ "product_exists": true
46
+ }
47
+ ]
48
+ }
49
+ }
@@ -0,0 +1,38 @@
1
+ require 'test_helper'
2
+
3
+ class FulFillmentTest < Test::Unit::TestCase
4
+ def setup
5
+ fake "orders/450789469/fulfillments/255858046", :method => :get, :body => load_fixture('fulfillment')
6
+ end
7
+
8
+ context "Fulfillment" do
9
+ context "#complete" do
10
+ should "be able to complete fulfillment" do
11
+ fulfillment = ShopifyAPI::Fulfillment.find(255858046, :params => {:order_id => 450789469})
12
+
13
+ success = ActiveSupport::JSON.decode(load_fixture('fulfillment'))
14
+ success['fulfillment']['status'] = 'success'
15
+ fake "orders/450789469/fulfillments/255858046/complete", :method => :post, :body => ActiveSupport::JSON.encode(success)
16
+
17
+ assert_equal 'pending', fulfillment.status
18
+ assert fulfillment.complete
19
+ assert_equal 'success', fulfillment.status
20
+ end
21
+ end
22
+
23
+ context "#cancel" do
24
+ should "be able to cancel fulfillment" do
25
+ fulfillment = ShopifyAPI::Fulfillment.find(255858046, :params => {:order_id => 450789469})
26
+
27
+ cancelled = ActiveSupport::JSON.decode(load_fixture('fulfillment'))
28
+ cancelled['fulfillment']['status'] = 'cancelled'
29
+ fake "orders/450789469/fulfillments/255858046/cancel", :method => :post, :body => ActiveSupport::JSON.encode(cancelled)
30
+
31
+ assert_equal 'pending', fulfillment.status
32
+ assert fulfillment.cancel
33
+ assert_equal 'cancelled', fulfillment.status
34
+ end
35
+ end
36
+ end
37
+
38
+ end
@@ -7,25 +7,33 @@ class LimitsTest < Test::Unit::TestCase
7
7
  @header_hash = {'http_x_shopify_shop_api_call_limit' => '100/300'}
8
8
  ShopifyAPI::Base.connection.expects(:response).at_least(0).returns(@header_hash)
9
9
  end
10
-
10
+
11
11
  context "Limits" do
12
12
  should "fetch limit total" do
13
13
  assert_equal(299, ShopifyAPI.credit_limit(:shop))
14
14
  end
15
-
15
+
16
16
  should "fetch used calls" do
17
17
  assert_equal(100, ShopifyAPI.credit_used(:shop))
18
18
  end
19
-
19
+
20
20
  should "calculate remaining calls" do
21
21
  assert_equal(199, ShopifyAPI.credit_left)
22
22
  end
23
-
23
+
24
24
  should "flag maxed out credits" do
25
25
  assert !ShopifyAPI.maxed?
26
26
  @header_hash = {'http_x_shopify_shop_api_call_limit' => '299/300'}
27
27
  ShopifyAPI::Base.connection.expects(:response).at_least(1).returns(@header_hash)
28
28
  assert ShopifyAPI.maxed?
29
29
  end
30
+
31
+ should "raise error when header doesn't exist" do
32
+ @header_hash = {}
33
+ ShopifyAPI::Base.connection.expects(:response).at_least(1).returns(@header_hash)
34
+ assert_raise ShopifyAPI::Limits::LimitUnavailable do
35
+ ShopifyAPI.credit_left
36
+ end
37
+ end
30
38
  end
31
39
  end
metadata CHANGED
@@ -1,18 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shopify_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.2
4
+ version: 3.1.3
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Shopify
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-10-29 00:00:00.000000000 Z
12
+ date: 2013-11-07 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: activeresource
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
19
  - - ! '>='
18
20
  - !ruby/object:Gem::Version
@@ -20,6 +22,7 @@ dependencies:
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
27
  - - ! '>='
25
28
  - !ruby/object:Gem::Version
@@ -27,6 +30,7 @@ dependencies:
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: thor
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
35
  - - ! '>='
32
36
  - !ruby/object:Gem::Version
@@ -34,6 +38,7 @@ dependencies:
34
38
  type: :runtime
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
43
  - - ! '>='
39
44
  - !ruby/object:Gem::Version
@@ -41,6 +46,7 @@ dependencies:
41
46
  - !ruby/object:Gem::Dependency
42
47
  name: mocha
43
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
44
50
  requirements:
45
51
  - - ! '>='
46
52
  - !ruby/object:Gem::Version
@@ -48,6 +54,7 @@ dependencies:
48
54
  type: :development
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
51
58
  requirements:
52
59
  - - ! '>='
53
60
  - !ruby/object:Gem::Version
@@ -55,6 +62,7 @@ dependencies:
55
62
  - !ruby/object:Gem::Dependency
56
63
  name: fakeweb
57
64
  requirement: !ruby/object:Gem::Requirement
65
+ none: false
58
66
  requirements:
59
67
  - - ! '>='
60
68
  - !ruby/object:Gem::Version
@@ -62,6 +70,7 @@ dependencies:
62
70
  type: :development
63
71
  prerelease: false
64
72
  version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
65
74
  requirements:
66
75
  - - ! '>='
67
76
  - !ruby/object:Gem::Version
@@ -69,6 +78,7 @@ dependencies:
69
78
  - !ruby/object:Gem::Dependency
70
79
  name: rake
71
80
  requirement: !ruby/object:Gem::Requirement
81
+ none: false
72
82
  requirements:
73
83
  - - ! '>='
74
84
  - !ruby/object:Gem::Version
@@ -76,6 +86,7 @@ dependencies:
76
86
  type: :development
77
87
  prerelease: false
78
88
  version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
79
90
  requirements:
80
91
  - - ! '>='
81
92
  - !ruby/object:Gem::Version
@@ -181,12 +192,14 @@ files:
181
192
  - test/fixtures/customer_saved_search.json
182
193
  - test/fixtures/customer_saved_search_customers.json
183
194
  - test/fixtures/events.json
195
+ - test/fixtures/fulfillment.json
184
196
  - test/fixtures/metafield.json
185
197
  - test/fixtures/metafields.json
186
198
  - test/fixtures/product.json
187
199
  - test/fixtures/shop.json
188
200
  - test/fixtures/variant.json
189
201
  - test/fixtures/variants.json
202
+ - test/fulfillment_test.rb
190
203
  - test/limits_test.rb
191
204
  - test/order_test.rb
192
205
  - test/product_test.rb
@@ -197,27 +210,34 @@ files:
197
210
  homepage: http://www.shopify.com/partners/apps
198
211
  licenses:
199
212
  - MIT
200
- metadata: {}
201
213
  post_install_message:
202
214
  rdoc_options:
203
215
  - --charset=UTF-8
204
216
  require_paths:
205
217
  - lib
206
218
  required_ruby_version: !ruby/object:Gem::Requirement
219
+ none: false
207
220
  requirements:
208
221
  - - ! '>='
209
222
  - !ruby/object:Gem::Version
210
223
  version: '0'
224
+ segments:
225
+ - 0
226
+ hash: -273779937676150409
211
227
  required_rubygems_version: !ruby/object:Gem::Requirement
228
+ none: false
212
229
  requirements:
213
230
  - - ! '>='
214
231
  - !ruby/object:Gem::Version
215
232
  version: '0'
233
+ segments:
234
+ - 0
235
+ hash: -273779937676150409
216
236
  requirements: []
217
237
  rubyforge_project:
218
- rubygems_version: 2.1.5
238
+ rubygems_version: 1.8.23
219
239
  signing_key:
220
- specification_version: 4
240
+ specification_version: 3
221
241
  summary: ShopifyAPI is a lightweight gem for accessing the Shopify admin REST web
222
242
  services
223
243
  test_files: []
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- Yjk3NThmNmE5YjE3NjgyNTBkNjQ0MmY0MDQ4MmJkN2YwZGMyZWU3MQ==
5
- data.tar.gz: !binary |-
6
- NDlhZjI5MGZmNTM0ZTlmOGE4ODY4YTFmYjQ5OTAyMGYxY2Y2NTBiOQ==
7
- SHA512:
8
- metadata.gz: !binary |-
9
- NjIzNTA3MmZkZTllOWJiMGZhYWI3NWYwZDliNWJiYTNlM2NhYTI0MDQ1MzQ5
10
- MWYzZTRjNjM4NzJjNzliOWEzMGYzNTA1NmFkNGM0YjY2NDhhYjNiYzZkODNl
11
- NDkzNzVjNjcxY2E2YmY1NzM3YjQxZmI0YzcwNmNlOWExNTRmZjg=
12
- data.tar.gz: !binary |-
13
- YjlkODc5YjJjNDg3Nzk0NzkyZWJmYzBiZDg1N2RhOTgwYzYzOTk0NDEwOGU3
14
- ZTI5YjBkMDNkZjk5MjE3NjNhN2ZhNGE2ZGJmM2YxMGE2YzRiOTA0N2JlYmZk
15
- YzAzZWZkM2E2ZTYwYzQ2ZjVlYWNmMDdhMDRhNzk5ZDBlZWM0ZDY=