shopify_api 2.0.0 → 2.1.0

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,8 @@
1
+ == Version 2.1.0
2
+
3
+ * Fix JSON errors handling
4
+ * Remove global limit from ShopifyAPI::Limits
5
+
1
6
  == Version 2.0.0
2
7
 
3
8
  * Bump to 2.0.0 as this release breaks Rails 2 compatibility; we're now officially only supporting Rails 3. Rails 2 devs can follow the rails2 tag in this repo to know where we broke off
@@ -0,0 +1,3 @@
1
+ API limits code
2
+
3
+ * Contributed by Chris Scott, https://github.com/christocracy/shopify-api-limits
@@ -0,0 +1,21 @@
1
+ require 'active_resource/base'
2
+
3
+ module ActiveResource
4
+ class Errors < ActiveModel::Errors
5
+ def from_hash(messages, save_cache = false)
6
+ clear unless save_cache
7
+
8
+ messages.each do |key,errors|
9
+ errors.each do |error|
10
+ add(key, error)
11
+ end
12
+ end
13
+ end
14
+
15
+ # Grabs errors from a json response.
16
+ def from_json(json, save_cache = false)
17
+ hash = ActiveSupport::JSON.decode(json)['errors'] || {} rescue {}
18
+ from_hash hash, save_cache
19
+ end
20
+ end
21
+ end
@@ -7,6 +7,7 @@ require 'base64'
7
7
  require 'active_resource/connection_ext'
8
8
  require 'shopify_api/limits'
9
9
  require 'shopify_api/json_format'
10
+ require 'active_resource/json_errors'
10
11
 
11
12
  module ShopifyAPI
12
13
  include Limits
@@ -9,7 +9,6 @@ module ShopifyAPI
9
9
  # Takes form num_requests_executed/max_requests
10
10
  # Eg: 101/3000
11
11
  CREDIT_LIMIT_HEADER_PARAM = {
12
- :global => 'http_x_shopify_api_call_limit',
13
12
  :shop => 'http_x_shopify_shop_api_call_limit'
14
13
  }
15
14
 
@@ -18,9 +17,7 @@ module ShopifyAPI
18
17
  # @return {Integer}
19
18
  #
20
19
  def credit_left
21
- shop = credit_limit(:shop) - credit_used(:shop)
22
- global = credit_limit(:global) - credit_used(:global)
23
- shop < global ? shop : global
20
+ credit_limit(:shop) - credit_used(:shop)
24
21
  end
25
22
  alias_method :available_calls, :credit_left
26
23
 
@@ -35,8 +32,8 @@ module ShopifyAPI
35
32
 
36
33
  ##
37
34
  # How many total API calls can I make?
38
- # NOTE: subtracting 1 from credit_limit because I think ShopifyAPI cuts off at 299/2999 or shop/global limits.
39
- # @param {Symbol} scope [:shop|:global]
35
+ # NOTE: subtracting 1 from credit_limit because I think ShopifyAPI cuts off at 299 or shop limits.
36
+ # @param {Symbol} scope [:shop]
40
37
  # @return {Integer}
41
38
  #
42
39
  def credit_limit(scope=:shop)
@@ -47,7 +44,7 @@ module ShopifyAPI
47
44
 
48
45
  ##
49
46
  # How many API calls have I made?
50
- # @param {Symbol} scope [:shop|:global]
47
+ # @param {Symbol} scope [:shop]
51
48
  # @return {Integer}
52
49
  #
53
50
  def credit_used(scope=:shop)
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{shopify_api}
5
- s.version = "2.0.0"
5
+ s.version = "2.1.0"
6
6
  s.author = "Shopify"
7
7
 
8
8
  s.summary = %q{The Shopify API gem is a lightweight gem for accessing the Shopify admin REST web services}
@@ -4,20 +4,17 @@ require 'mocha'
4
4
  class LimitsTest < Test::Unit::TestCase
5
5
  def setup
6
6
  ShopifyAPI::Base.site = "test.myshopify.com"
7
- @header_hash = {'http_x_shopify_api_call_limit' => '150/3000',
8
- 'http_x_shopify_shop_api_call_limit' => '100/300'}
7
+ @header_hash = {'http_x_shopify_shop_api_call_limit' => '100/300'}
9
8
  ShopifyAPI::Base.connection.expects(:response).at_least(0).returns(@header_hash)
10
9
  end
11
10
 
12
11
  context "Limits" do
13
12
  should "fetch limit total" do
14
13
  assert_equal(299, ShopifyAPI.credit_limit(:shop))
15
- assert_equal(2999, ShopifyAPI.credit_limit(:global))
16
14
  end
17
15
 
18
16
  should "fetch used calls" do
19
17
  assert_equal(100, ShopifyAPI.credit_used(:shop))
20
- assert_equal(150, ShopifyAPI.credit_used(:global))
21
18
  end
22
19
 
23
20
  should "calculate remaining calls" do
@@ -26,12 +23,9 @@ class LimitsTest < Test::Unit::TestCase
26
23
 
27
24
  should "flag maxed out credits" do
28
25
  assert !ShopifyAPI.maxed?
29
- @header_hash = {'http_x_shopify_api_call_limit' => '2999/3000',
30
- 'http_x_shopify_shop_api_call_limit' => '299/300'}
26
+ @header_hash = {'http_x_shopify_shop_api_call_limit' => '299/300'}
31
27
  ShopifyAPI::Base.connection.expects(:response).at_least(1).returns(@header_hash)
32
28
  assert ShopifyAPI.maxed?
33
29
  end
34
30
  end
35
-
36
-
37
- end
31
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shopify_api
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
+ - 1
8
9
  - 0
9
- - 0
10
- version: 2.0.0
10
+ version: 2.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Shopify
@@ -15,7 +15,8 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-09-20 00:00:00 Z
18
+ date: 2011-10-17 00:00:00 -04:00
19
+ default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: activeresource
@@ -78,12 +79,14 @@ files:
78
79
  - .document
79
80
  - .gitignore
80
81
  - CHANGELOG
82
+ - CONTRIBUTORS
81
83
  - LICENSE
82
84
  - README.rdoc
83
85
  - RELEASING
84
86
  - Rakefile
85
87
  - bin/shopify
86
88
  - lib/active_resource/connection_ext.rb
89
+ - lib/active_resource/json_errors.rb
87
90
  - lib/shopify_api.rb
88
91
  - lib/shopify_api/cli.rb
89
92
  - lib/shopify_api/countable.rb
@@ -139,6 +142,7 @@ files:
139
142
  - test/order_test.rb
140
143
  - test/shopify_api_test.rb
141
144
  - test/test_helper.rb
145
+ has_rdoc: true
142
146
  homepage: http://www.shopify.com/partners/apps
143
147
  licenses:
144
148
  - MIT
@@ -168,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
172
  requirements: []
169
173
 
170
174
  rubyforge_project:
171
- rubygems_version: 1.8.10
175
+ rubygems_version: 1.6.2
172
176
  signing_key:
173
177
  specification_version: 3
174
178
  summary: ShopifyAPI is a lightweight gem for accessing the Shopify admin REST web services