class SocialAvatarProxy::App

Attributes

options[R]
request[R]

Public Class Methods

call(env) click to toggle source
# File lib/social_avatar_proxy/app.rb, line 12
def self.call(env)
  new.call(env)
end
routes() click to toggle source
# File lib/social_avatar_proxy/app.rb, line 16
def self.routes
  new.routes
end

Public Instance Methods

call(env) click to toggle source
# File lib/social_avatar_proxy/app.rb, line 22
def call(env)
  @request = Rack::Request.new(env)
  begin
    response.finish
  rescue TimeoutError => e
    timeout
  rescue TooManyRedirectsError => e
    bad_gateway
  end
end
path_prefix() click to toggle source
# File lib/social_avatar_proxy/app.rb, line 33
def path_prefix
  ((request && request.env["SCRIPT_NAME"]) || "").gsub(/\/$/, "")
end
response() click to toggle source
# File lib/social_avatar_proxy/app.rb, line 37
def response
  # ensure this is a valid avatar request
  unless request.path =~ /^#{path_prefix}\/(facebook|twitter)\/([\w\-\.]+)(\.(jpe?g|png|gif|bmp))?$/i
    return not_found
  end
  # create our response
  SocialAvatarProxy::Response.build({
    service: $1,
    identifier: $2
  })
end
routes() click to toggle source
# File lib/social_avatar_proxy/app.rb, line 49
def routes
  Routes.new(self)
end

Private Instance Methods

bad_gateway() click to toggle source
# File lib/social_avatar_proxy/app.rb, line 62
def bad_gateway
  Rack::Response.new("Bad Gateway: Too many redirects", 502)
end
not_found() click to toggle source
# File lib/social_avatar_proxy/app.rb, line 54
def not_found
  Rack::Response.new("Not Found", 404)
end
timeout() click to toggle source
# File lib/social_avatar_proxy/app.rb, line 58
def timeout
  Rack::Response.new("Gateway Timeout", 504)
end