rest 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +2 -2
- data/lib/rest/client.rb +12 -8
- data/lib/rest/version.rb +1 -1
- data/rest.gemspec +1 -1
- data/test/test_base.rb +2 -2
- data/test/test_rest.rb +5 -0
- data/test/tmp.rb +14 -0
- metadata +11 -9
data/Gemfile.lock
CHANGED
data/lib/rest/client.rb
CHANGED
@@ -60,18 +60,20 @@ module Rest
|
|
60
60
|
def choose_best_gem
|
61
61
|
begin
|
62
62
|
raise LoadError
|
63
|
-
require 'typhoeus'
|
64
|
-
|
63
|
+
#require 'typhoeus'
|
64
|
+
#@gem = :client
|
65
65
|
rescue LoadError => ex
|
66
66
|
begin
|
67
67
|
# try net-http-persistent
|
68
|
-
require 'net/http/persistent'
|
69
|
-
|
68
|
+
#require 'net/http/persistent'
|
69
|
+
#@gem = :net_http_persistent
|
70
70
|
rescue LoadError => ex
|
71
|
-
require 'rest_client'
|
72
|
-
@gem = :rest_client
|
73
71
|
end
|
74
72
|
end
|
73
|
+
if @gem.nil?
|
74
|
+
require 'rest_client'
|
75
|
+
@gem = :rest_client
|
76
|
+
end
|
75
77
|
end
|
76
78
|
|
77
79
|
def get(url, req_hash={})
|
@@ -82,6 +84,8 @@ module Rest
|
|
82
84
|
return res
|
83
85
|
end
|
84
86
|
|
87
|
+
# This will attempt to perform the operation with an exponential backoff on 503 errors.
|
88
|
+
# Amazon services throw 503
|
85
89
|
def perform_op(&blk)
|
86
90
|
max_retries = @options[:max_retries] || 5
|
87
91
|
current_retry = 0
|
@@ -97,9 +101,9 @@ module Rest
|
|
97
101
|
s = Random.rand * pow
|
98
102
|
#puts 's=' + s.to_s
|
99
103
|
sleep_secs = 1.0 * s / 1000.0
|
100
|
-
|
104
|
+
puts 'sleep for ' + sleep_secs.to_s
|
101
105
|
current_retry += 1
|
102
|
-
@logger.debug "503
|
106
|
+
@logger.debug "503 Received. Retrying #{current_retry} out of #{max_retries} max in #{sleep_secs} seconds."
|
103
107
|
sleep sleep_secs
|
104
108
|
else
|
105
109
|
break
|
data/lib/rest/version.rb
CHANGED
data/rest.gemspec
CHANGED
@@ -17,13 +17,13 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.required_rubygems_version = ">= 1.3.6"
|
18
18
|
gem.required_ruby_version = Gem::Requirement.new(">= 1.9")
|
19
19
|
gem.add_runtime_dependency "rest-client", ">= 0.3.0"
|
20
|
-
gem.add_runtime_dependency "net-http-persistent"
|
21
20
|
|
22
21
|
gem.add_development_dependency "test-unit"
|
23
22
|
gem.add_development_dependency "rake"
|
24
23
|
gem.add_development_dependency "uber_config"
|
25
24
|
gem.add_development_dependency "typhoeus"
|
26
25
|
gem.add_development_dependency "quicky"
|
26
|
+
gem.add_development_dependency "net-http-persistent"
|
27
27
|
|
28
28
|
end
|
29
29
|
|
data/test/test_base.rb
CHANGED
@@ -13,8 +13,8 @@ class TestBase < Test::Unit::TestCase
|
|
13
13
|
def setup
|
14
14
|
puts 'setup'
|
15
15
|
#@config = YAML::load_file(File.expand_path(File.join("~", "Dropbox", "configs", "rest", "test", "config.yml")))
|
16
|
-
@rest = Rest::Client.new
|
17
|
-
|
16
|
+
@rest = Rest::Client.new(:gem=>:rest_client)
|
17
|
+
@rest.logger.level = Logger::DEBUG
|
18
18
|
|
19
19
|
end
|
20
20
|
end
|
data/test/test_rest.rb
CHANGED
@@ -19,7 +19,12 @@ class TestTests < TestBase
|
|
19
19
|
assert response.code == 200
|
20
20
|
#p response.body
|
21
21
|
assert response.body.include?("Social Coding")
|
22
|
+
end
|
22
23
|
|
24
|
+
def test_backoff
|
25
|
+
response = @rest.get("http://rest-test.iron.io/code/503?switch_after=3&switch_to=200")
|
26
|
+
p response
|
27
|
+
p response.code
|
23
28
|
end
|
24
29
|
|
25
30
|
def test_gets
|
data/test/tmp.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
begin
|
3
|
+
require File.join(File.dirname(__FILE__), '../lib/rest')
|
4
|
+
rescue Exception => ex
|
5
|
+
puts "Could NOT load gem: " + ex.message
|
6
|
+
raise ex
|
7
|
+
end
|
8
|
+
|
9
|
+
@rest = Rest::Client.new # (:gem=>:rest_client)
|
10
|
+
@rest.logger.level = Logger::DEBUG
|
11
|
+
|
12
|
+
response = @rest.get("http://smooth-sword-1395.herokuapp.com/code/503?switch_after=3&switch_to=200")
|
13
|
+
p response
|
14
|
+
p response.code
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07-
|
12
|
+
date: 2012-07-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
@@ -28,14 +28,14 @@ dependencies:
|
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: 0.3.0
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
|
-
name:
|
31
|
+
name: test-unit
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
none: false
|
34
34
|
requirements:
|
35
35
|
- - ! '>='
|
36
36
|
- !ruby/object:Gem::Version
|
37
37
|
version: '0'
|
38
|
-
type: :
|
38
|
+
type: :development
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
@@ -44,7 +44,7 @@ dependencies:
|
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
47
|
+
name: rake
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|
@@ -60,7 +60,7 @@ dependencies:
|
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
|
-
name:
|
63
|
+
name: uber_config
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
65
65
|
none: false
|
66
66
|
requirements:
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
78
|
- !ruby/object:Gem::Dependency
|
79
|
-
name:
|
79
|
+
name: typhoeus
|
80
80
|
requirement: !ruby/object:Gem::Requirement
|
81
81
|
none: false
|
82
82
|
requirements:
|
@@ -92,7 +92,7 @@ dependencies:
|
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: '0'
|
94
94
|
- !ruby/object:Gem::Dependency
|
95
|
-
name:
|
95
|
+
name: quicky
|
96
96
|
requirement: !ruby/object:Gem::Requirement
|
97
97
|
none: false
|
98
98
|
requirements:
|
@@ -108,7 +108,7 @@ dependencies:
|
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '0'
|
110
110
|
- !ruby/object:Gem::Dependency
|
111
|
-
name:
|
111
|
+
name: net-http-persistent
|
112
112
|
requirement: !ruby/object:Gem::Requirement
|
113
113
|
none: false
|
114
114
|
requirements:
|
@@ -147,6 +147,7 @@ files:
|
|
147
147
|
- test/test_base.rb
|
148
148
|
- test/test_performance.rb
|
149
149
|
- test/test_rest.rb
|
150
|
+
- test/tmp.rb
|
150
151
|
homepage: https://github.com/iron-io/rest
|
151
152
|
licenses: []
|
152
153
|
post_install_message:
|
@@ -175,3 +176,4 @@ test_files:
|
|
175
176
|
- test/test_base.rb
|
176
177
|
- test/test_performance.rb
|
177
178
|
- test/test_rest.rb
|
179
|
+
- test/tmp.rb
|