social-avatar-proxy 1.0.1 → 1.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/README.md CHANGED
@@ -2,10 +2,12 @@
2
2
 
3
3
  This gem acts as a proxy for avatars on Twitter & Facebook.
4
4
 
5
- [![Build Status][2]][1]
5
+ [![Build Status][2]][1] [![Code Climate][3]][4]
6
6
 
7
7
  [1]: http://travis-ci.org/platformq/social-avatar-proxy
8
8
  [2]: https://secure.travis-ci.org/platformq/social-avatar-proxy.png?branch=master
9
+ [3]: https://codeclimate.com/badge.png
10
+ [4]: https://codeclimate.com/github/platformq/social-avatar-proxy
9
11
 
10
12
  ## Installation
11
13
 
@@ -1,6 +1,8 @@
1
1
  require "social_avatar_proxy/facebook_avatar"
2
2
  require "social_avatar_proxy/twitter_avatar"
3
3
  require "social_avatar_proxy/routes"
4
+ require "social_avatar_proxy/timeout_error"
5
+ require "social_avatar_proxy/too_many_redirects_error"
4
6
  require "rack"
5
7
 
6
8
  module SocialAvatarProxy
@@ -28,8 +30,13 @@ module SocialAvatarProxy
28
30
 
29
31
  def call(env)
30
32
  @request = Rack::Request.new(env)
31
- # return the response
32
- response.finish
33
+ begin
34
+ response.finish
35
+ rescue TimeoutError => e
36
+ timeout
37
+ rescue TooManyRedirectsError => e
38
+ bad_gateway
39
+ end
33
40
  end
34
41
 
35
42
  def path_prefix
@@ -77,6 +84,14 @@ module SocialAvatarProxy
77
84
  Rack::Response.new("Not Found", 404)
78
85
  end
79
86
 
87
+ def timeout
88
+ Rack::Response.new("Remote server timeout", 504)
89
+ end
90
+
91
+ def bad_gateway
92
+ Rack::Response.new("Bad response from remote server", 502)
93
+ end
94
+
80
95
  def routes
81
96
  Routes.new(self)
82
97
  end
@@ -1,16 +1,15 @@
1
+ require "social_avatar_proxy/timeout_error"
2
+ require "social_avatar_proxy/too_many_redirects_error"
1
3
  require "net/https"
2
4
  require "net/http"
3
5
  require "uri"
4
6
  require "timeout"
5
7
 
6
- module SocialAvatarProxy
7
- class TooManyRedirects < StandardError; end
8
- class TimeoutError < Timeout::Error; end
9
-
8
+ module SocialAvatarProxy
10
9
  class RemoteFileResolver
11
10
  def initialize(url, limit = 5)
12
11
  # timeout if we have no redirects left
13
- raise TooManyRedirects if limit <= 0
12
+ raise TooManyRedirectsError if limit <= 0
14
13
  # store the limit and URL
15
14
  @url, @redirect_limit = url, limit
16
15
  end
@@ -0,0 +1,5 @@
1
+ require "timeout"
2
+
3
+ module SocialAvatarProxy
4
+ class TimeoutError < Timeout::Error; end
5
+ end
@@ -0,0 +1,3 @@
1
+ module SocialAvatarProxy
2
+ class TooManyRedirectsError < StandardError; end
3
+ end
@@ -1,3 +1,3 @@
1
1
  module SocialAvatarProxy
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -64,6 +64,26 @@ describe SocialAvatarProxy::App do
64
64
  end
65
65
 
66
66
  context "given a valid path" do
67
+ context "when the remote server times out" do
68
+ before(:each) do
69
+ app.should_receive(:response).and_raise(SocialAvatarProxy::TimeoutError)
70
+ end
71
+
72
+ it "should return a 504 response" do
73
+ expect(subject.get("/facebook/61413673").status).to eq(504)
74
+ end
75
+ end
76
+
77
+ context "when the remote server has too many redirects" do
78
+ before(:each) do
79
+ app.should_receive(:response).and_raise(SocialAvatarProxy::TooManyRedirectsError)
80
+ end
81
+
82
+ it "should return a 502 response" do
83
+ expect(subject.get("/facebook/61413673").status).to eq(502)
84
+ end
85
+ end
86
+
67
87
  context "that finds an existing avatar" do
68
88
  let(:response) { successful_response }
69
89
  let(:path) { "/facebook/61413673" }
@@ -29,7 +29,7 @@ describe SocialAvatarProxy::RemoteFileResolver do
29
29
  it "should throw an exception" do
30
30
  expect {
31
31
  subject.resolve
32
- }.to raise_error(SocialAvatarProxy::TooManyRedirects)
32
+ }.to raise_error(SocialAvatarProxy::TooManyRedirectsError)
33
33
  end
34
34
  end
35
35
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: social-avatar-proxy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
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-10-03 00:00:00.000000000 Z
12
+ date: 2012-10-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
@@ -131,6 +131,8 @@ files:
131
131
  - lib/social_avatar_proxy/path_helpers.rb
132
132
  - lib/social_avatar_proxy/remote_file_resolver.rb
133
133
  - lib/social_avatar_proxy/routes.rb
134
+ - lib/social_avatar_proxy/timeout_error.rb
135
+ - lib/social_avatar_proxy/too_many_redirects_error.rb
134
136
  - lib/social_avatar_proxy/twitter_avatar.rb
135
137
  - lib/social_avatar_proxy/version.rb
136
138
  - social-avatar-proxy.gemspec
@@ -158,21 +160,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
158
160
  - - ! '>='
159
161
  - !ruby/object:Gem::Version
160
162
  version: '0'
161
- segments:
162
- - 0
163
- hash: 1989247330318419261
164
163
  required_rubygems_version: !ruby/object:Gem::Requirement
165
164
  none: false
166
165
  requirements:
167
166
  - - ! '>='
168
167
  - !ruby/object:Gem::Version
169
168
  version: '0'
170
- segments:
171
- - 0
172
- hash: 1989247330318419261
173
169
  requirements: []
174
170
  rubyforge_project:
175
- rubygems_version: 1.8.24
171
+ rubygems_version: 1.8.23
176
172
  signing_key:
177
173
  specification_version: 3
178
174
  summary: This gem acts as a proxy for avatars on Twitter & Facebook.