shopify_api 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +5 -0
- data/CONTRIBUTORS +3 -0
- data/lib/active_resource/json_errors.rb +21 -0
- data/lib/shopify_api.rb +1 -0
- data/lib/shopify_api/limits.rb +4 -7
- data/shopify_api.gemspec +1 -1
- data/test/limits_test.rb +3 -9
- metadata +9 -5
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
|
data/CONTRIBUTORS
ADDED
@@ -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
|
data/lib/shopify_api.rb
CHANGED
data/lib/shopify_api/limits.rb
CHANGED
@@ -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
|
-
|
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
|
39
|
-
# @param {Symbol} scope [:shop
|
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
|
47
|
+
# @param {Symbol} scope [:shop]
|
51
48
|
# @return {Integer}
|
52
49
|
#
|
53
50
|
def credit_used(scope=:shop)
|
data/shopify_api.gemspec
CHANGED
data/test/limits_test.rb
CHANGED
@@ -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 = {'
|
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 = {'
|
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:
|
4
|
+
hash: 11
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 2
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
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-
|
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.
|
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
|