Class: SocialAvatarProxy::RemoteFileResolver
- Inherits:
-
Object
- Object
- SocialAvatarProxy::RemoteFileResolver
- Defined in:
- lib/social_avatar_proxy/remote_file_resolver.rb
Instance Method Summary collapse
-
#initialize(url, limit = 5) ⇒ RemoteFileResolver
constructor
A new instance of RemoteFileResolver.
- #resolve ⇒ Object
Constructor Details
#initialize(url, limit = 5) ⇒ RemoteFileResolver
Returns a new instance of RemoteFileResolver.
10 11 12 13 14 15 |
# File 'lib/social_avatar_proxy/remote_file_resolver.rb', line 10 def initialize(url, limit = 5) # timeout if we have no redirects left raise TooManyRedirectsError if limit <= 0 # store the limit and URL @url, @redirect_limit = url, limit end |
Instance Method Details
#resolve ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/social_avatar_proxy/remote_file_resolver.rb', line 17 def resolve response = Timeout::timeout(30) do perform_request end # if this is a redirect if response.kind_of?(Net::HTTPRedirection) # follow the redirect resolver = self.class.new(response["location"], @redirect_limit - 1) resolver.resolve # if this is not a redirect else # return the response response end rescue Timeout::Error => e raise TimeoutError, e., e.backtrace end |