retentiongrid 0.2.3 → 0.2.4
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24fb32635d2a74736c03ef77f1da24fe73b68a79
|
4
|
+
data.tar.gz: 20292022dc0b3f0814184b84ac11a990dd1cd526
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5654c2ec32d372aad12587ab0d93e08c653779028312d3ab92c21702ceec21d8b5ecd9d62fa9086710caa6b97c8f7137b143299987e13cbbb8ff0e5a7f8d1110
|
7
|
+
data.tar.gz: accbccc386f6587cefb87901d6c616ea36baf8343b97e000e0d75d47d6a78fbfbf9d97fb78fbe773fc30dfce69128b1a186dedf744012d5636f4e1605c188ee5
|
data/lib/retentiongrid/api.rb
CHANGED
@@ -32,7 +32,12 @@ module Retentiongrid
|
|
32
32
|
# @raise [Retentiongrid::ServerError] (500) in case something went wrong on the retentiongrid server
|
33
33
|
# @return [Httparty::Response]
|
34
34
|
def get_with_response_check(*args)
|
35
|
-
|
35
|
+
begin
|
36
|
+
check_response_codes(get_without_response_check(*args))
|
37
|
+
rescue TooManyRequests => e
|
38
|
+
sleep 1
|
39
|
+
retry
|
40
|
+
end
|
36
41
|
end
|
37
42
|
alias_method :get_without_response_check, :get
|
38
43
|
alias_method :get, :get_with_response_check
|
@@ -45,7 +50,12 @@ module Retentiongrid
|
|
45
50
|
# @raise [Retentiongrid::ServerError] (500) in case something went wrong on the retentiongrid server
|
46
51
|
# @return [Httparty::Response]
|
47
52
|
def post_with_response_check(*args)
|
48
|
-
|
53
|
+
begin
|
54
|
+
check_response_codes(post_without_response_check(*args))
|
55
|
+
rescue TooManyRequests => e
|
56
|
+
sleep 1
|
57
|
+
retry
|
58
|
+
end
|
49
59
|
end
|
50
60
|
alias_method :post_without_response_check, :post
|
51
61
|
alias_method :post, :post_with_response_check
|
@@ -58,7 +68,12 @@ module Retentiongrid
|
|
58
68
|
# @raise [Retentiongrid::ServerError] (500) in case something went wrong on the retentiongrid server
|
59
69
|
# @return [Httparty::Response]
|
60
70
|
def delete_with_response_check(*args)
|
61
|
-
|
71
|
+
begin
|
72
|
+
check_response_codes(delete_without_response_check(*args))
|
73
|
+
rescue TooManyRequests => e
|
74
|
+
sleep 1
|
75
|
+
retry
|
76
|
+
end
|
62
77
|
end
|
63
78
|
alias_method :delete_without_response_check, :delete
|
64
79
|
alias_method :delete, :delete_with_response_check
|
@@ -78,6 +93,7 @@ module Retentiongrid
|
|
78
93
|
when 405 then raise MethodNotAllowed.new(body)
|
79
94
|
when 410 then raise Gone.new(body)
|
80
95
|
when 422 then raise UnprocessableEntity.new(body)
|
96
|
+
when 429 then raise TooManyRequests.new(body)
|
81
97
|
when 500 then raise ServerError, 'Internal Server Error'
|
82
98
|
when 503 then raise Unavailable, 'Service Unavailable'
|
83
99
|
else raise "Unknown response code: #{response.code}"
|
data/lib/retentiongrid/errors.rb
CHANGED
@@ -30,6 +30,9 @@ module Retentiongrid
|
|
30
30
|
# The request was well-formed but was unable to be followed due to semantic errors.
|
31
31
|
class UnprocessableEntity < HTTParty::Error; end # 422
|
32
32
|
|
33
|
+
# The request was ok, but you sent too many after each other
|
34
|
+
class TooManyRequests < HTTParty::Error; end # 429
|
35
|
+
|
33
36
|
# Unspecified API server error.
|
34
37
|
class ServerError < HTTParty::Error; end # 500
|
35
38
|
|
@@ -7,7 +7,7 @@ module Retentiongrid
|
|
7
7
|
ATTRIBUTES_NAMES = [ :product_id, :available, :metadata,
|
8
8
|
:title, :image_url, :currency, :price,
|
9
9
|
:sale_price, :cost_price, :product_url,
|
10
|
-
:product_created_at, :product_updated_at
|
10
|
+
:product_created_at, :product_updated_at
|
11
11
|
].freeze
|
12
12
|
|
13
13
|
ATTRIBUTES_NAMES.each do |attrib|
|
@@ -36,6 +36,13 @@ RSpec.describe Product do
|
|
36
36
|
Product.find('123')
|
37
37
|
end
|
38
38
|
|
39
|
+
it "should retry upon 429 TooManyRequests" do
|
40
|
+
stub_request(:get, "http://retentiongrid.apiary-mock.com/products/123").
|
41
|
+
to_return(:status => 429, :body => '429 Too Many Requests (5 request/s on average allowed. Burst of max 10/s require you to wait 1 second.)', :headers => {'Content-Type' => 'text/plain'}).then.
|
42
|
+
to_return(:status => 200, :body => valid_order, :headers => {'Content-Type' => 'application/json'})
|
43
|
+
Product.find('123')
|
44
|
+
end
|
45
|
+
|
39
46
|
it "should build a Product from API response" do
|
40
47
|
expect(subject.class).to eql Retentiongrid::Product
|
41
48
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: retentiongrid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christoph Bünte
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -181,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
181
181
|
version: '0'
|
182
182
|
requirements: []
|
183
183
|
rubyforge_project:
|
184
|
-
rubygems_version: 2.2.
|
184
|
+
rubygems_version: 2.2.2
|
185
185
|
signing_key:
|
186
186
|
specification_version: 4
|
187
187
|
summary: A ruby client for retentiongrid.com API.
|