ruby-satisfaction 0.6.5 → 0.6.7
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/Gemfile.lock +5 -0
- data/README.markdown +8 -0
- data/lib/satisfaction/exceptions.rb +2 -0
- data/lib/satisfaction/loader.rb +15 -5
- data/lib/satisfaction/version.rb +1 -1
- data/spec/satisfaction/loader_spec.rb +60 -3
- metadata +4 -4
data/Gemfile.lock
CHANGED
@@ -47,9 +47,14 @@ PLATFORMS
|
|
47
47
|
ruby
|
48
48
|
|
49
49
|
DEPENDENCIES
|
50
|
+
activesupport (~> 2.3)
|
50
51
|
bundler (>= 1.0.0)
|
51
52
|
fakeweb (~> 1.3)
|
52
53
|
gemcutter (>= 0.6.1)
|
54
|
+
json (>= 1.4.6)
|
55
|
+
memcache-client (>= 1.5.0)
|
56
|
+
nokogiri (>= 1.4.2)
|
57
|
+
oauth (>= 0.3.5)
|
53
58
|
open_gem (>= 1.4)
|
54
59
|
rr (= 1.0.2)
|
55
60
|
rspec (~> 2.2)
|
data/README.markdown
CHANGED
@@ -11,6 +11,14 @@ For questions, please visit the [Get Satisfaction API community][3]
|
|
11
11
|
|
12
12
|
Changelog
|
13
13
|
=========
|
14
|
+
0.6.7
|
15
|
+
|
16
|
+
* Fixed Sfn::Loader#get so it uses cached content when a 304 Not Modified is received.
|
17
|
+
|
18
|
+
0.6.6
|
19
|
+
|
20
|
+
* Handle HTTP 502/504 for unicorn.
|
21
|
+
|
14
22
|
0.6.5
|
15
23
|
|
16
24
|
* Fixed a divide-by-zero bug.
|
data/lib/satisfaction/loader.rb
CHANGED
@@ -36,17 +36,19 @@ class Sfn::Loader
|
|
36
36
|
http = Net::HTTP.new(uri.host, uri.port)
|
37
37
|
add_authentication(request, http, options)
|
38
38
|
response = execute(http, request)
|
39
|
-
|
39
|
+
|
40
40
|
case response
|
41
41
|
when Net::HTTPSuccess
|
42
42
|
cache.put(uri, response)
|
43
43
|
[:ok, response.body]
|
44
|
+
when Net::HTTPNotModified
|
45
|
+
[:ok, cache_record.body]
|
44
46
|
when Net::HTTPMovedPermanently, Net::HTTPMovedTemporarily
|
45
47
|
limit = options[:redirect_limit] || 3
|
46
48
|
raise Sfn::TooManyRedirects, "Too many redirects" unless limit > 0
|
47
49
|
get(response['location'], options.merge(:redirect_limit => limit - 1))
|
48
50
|
when Net::HTTPBadRequest
|
49
|
-
raise Sfn::BadRequest, "Bad request. Response body:\n
|
51
|
+
raise Sfn::BadRequest, "Bad request. Response body:\n#{response.body}"
|
50
52
|
when Net::HTTPForbidden, Net::HTTPUnauthorized
|
51
53
|
message = "Not authorized"
|
52
54
|
if restricted_provider = response['X-Sfn-Restricted-Identity-Provider']
|
@@ -60,8 +62,12 @@ class Sfn::Loader
|
|
60
62
|
raise Sfn::NotFound, "Not found"
|
61
63
|
when Net::HTTPServiceUnavailable
|
62
64
|
raise Sfn::SiteMaintenance, maintenance_message(response.body)
|
65
|
+
when Net::HTTPBadGateway
|
66
|
+
raise Sfn::BadGateway, "Bad Gateway"
|
67
|
+
when Net::HTTPGatewayTimeOut
|
68
|
+
raise Sfn::GatewayTimeOut, "Gateway TimeOut"
|
63
69
|
else
|
64
|
-
raise Sfn::Error, "Encountered error. Body of response:\n
|
70
|
+
raise Sfn::Error, "Encountered error. Body of response:\n#{response.body}"
|
65
71
|
end
|
66
72
|
end
|
67
73
|
|
@@ -96,7 +102,7 @@ class Sfn::Loader
|
|
96
102
|
when Net::HTTPNotFound
|
97
103
|
raise Sfn::NotFound, "Not found"
|
98
104
|
when Net::HTTPBadRequest
|
99
|
-
raise Sfn::BadRequest, "Bad request. Response body:\n
|
105
|
+
raise Sfn::BadRequest, "Bad request. Response body:\n#{response.body}"
|
100
106
|
when Net::HTTPSuccess
|
101
107
|
[:ok, response.body]
|
102
108
|
when Net::HTTPMethodNotAllowed
|
@@ -107,8 +113,12 @@ class Sfn::Loader
|
|
107
113
|
raise Sfn::MethodNotAllowed, "Method not allowed"
|
108
114
|
when Net::HTTPServiceUnavailable
|
109
115
|
raise Sfn::SiteMaintenance, maintenance_message(response.body)
|
116
|
+
when Net::HTTPBadGateway
|
117
|
+
raise Sfn::BadGateway, "Bad Gateway"
|
118
|
+
when Net::HTTPGatewayTimeOut
|
119
|
+
raise Sfn::GatewayTimeOut, "Gateway TimeOut"
|
110
120
|
else
|
111
|
-
raise Sfn::Error, "Encountered error. Body of response:\n
|
121
|
+
raise Sfn::Error, "Encountered error. Body of response:\n#{response.body}"
|
112
122
|
end
|
113
123
|
end
|
114
124
|
|
data/lib/satisfaction/version.rb
CHANGED
@@ -8,6 +8,7 @@ describe Sfn::Loader do
|
|
8
8
|
before(:each) do
|
9
9
|
@response = nil
|
10
10
|
@status_code = '200'
|
11
|
+
@loader = Sfn::Loader.new
|
11
12
|
@get = lambda do
|
12
13
|
FakeWeb.register_uri(
|
13
14
|
:get,
|
@@ -15,9 +16,8 @@ describe Sfn::Loader do
|
|
15
16
|
:body => @response_body,
|
16
17
|
:status => [@status_code]
|
17
18
|
)
|
18
|
-
loader
|
19
|
-
|
20
|
-
@response = loader.get('http://test')
|
19
|
+
stub(@loader).add_authentication {}
|
20
|
+
@response = @loader.get('http://test')
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -33,6 +33,21 @@ describe Sfn::Loader do
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
+
describe "when the status is not modified (304)" do
|
37
|
+
before(:each) do
|
38
|
+
@status_code = '304'
|
39
|
+
@cached_body = {:id => "123", :domain => "foo.bar"}.to_json
|
40
|
+
@response_body = nil
|
41
|
+
stub(@loader.cache).get(anything) { Sfn::Loader::CacheRecord.new('http://test', 'etag-foo', @cached_body) }
|
42
|
+
|
43
|
+
@get.call
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should return a status of :ok and the cached response body" do
|
47
|
+
@response.should == [:ok, @cached_body]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
36
51
|
describe "when we are in a redirect loop" do
|
37
52
|
attr_reader :loader
|
38
53
|
|
@@ -154,6 +169,27 @@ describe Sfn::Loader do
|
|
154
169
|
end
|
155
170
|
end
|
156
171
|
end
|
172
|
+
|
173
|
+
# ---- GATEWAY -----------------------------------------------------------------------------------------------
|
174
|
+
describe "when the status is 502 (Bad Gateway, returned when a Unicorn worker is killed)" do
|
175
|
+
before(:each) do
|
176
|
+
@status_code = '502'
|
177
|
+
end
|
178
|
+
|
179
|
+
it "should raise an Sfn::BadGateway error" do
|
180
|
+
@get.should raise_error(Sfn::BadGateway, "Bad Gateway")
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
describe "when the status is 504 (GatewayTimeOut)" do
|
185
|
+
before(:each) do
|
186
|
+
@status_code = '504'
|
187
|
+
end
|
188
|
+
|
189
|
+
it "should raise an Sfn::GatewayTimeOut error" do
|
190
|
+
@get.should raise_error(Sfn::GatewayTimeOut, "Gateway TimeOut")
|
191
|
+
end
|
192
|
+
end
|
157
193
|
end
|
158
194
|
|
159
195
|
# ==== POST ==================================================================================================
|
@@ -302,6 +338,27 @@ describe Sfn::Loader do
|
|
302
338
|
end
|
303
339
|
end
|
304
340
|
|
341
|
+
# ---- GATEWAY -----------------------------------------------------------------------------------------------
|
342
|
+
describe "when the status is 502 (Bad Gateway, returned when a Unicorn worker is killed)" do
|
343
|
+
before(:each) do
|
344
|
+
@status_code = '502'
|
345
|
+
end
|
346
|
+
|
347
|
+
it "should raise an Sfn::BadGateway error" do
|
348
|
+
@post.should raise_error(Sfn::BadGateway, "Bad Gateway")
|
349
|
+
end
|
350
|
+
end
|
351
|
+
|
352
|
+
describe "when the status is 504 (GatewayTimeOut)" do
|
353
|
+
before(:each) do
|
354
|
+
@status_code = '504'
|
355
|
+
end
|
356
|
+
|
357
|
+
it "should raise an Sfn::GatewayTimeOut error" do
|
358
|
+
@post.should raise_error(Sfn::GatewayTimeOut, "Gateway TimeOut")
|
359
|
+
end
|
360
|
+
end
|
361
|
+
|
305
362
|
end
|
306
363
|
|
307
364
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-satisfaction
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 9
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 6
|
9
|
-
-
|
10
|
-
version: 0.6.
|
9
|
+
- 7
|
10
|
+
version: 0.6.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Get Satisfaction
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-07-08 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|