Class: SocialAvatarProxy::App

Inherits:
Object
  • Object
show all
Defined in:
lib/social_avatar_proxy/app.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



20
21
22
# File 'lib/social_avatar_proxy/app.rb', line 20

def options
  @options
end

#requestObject (readonly)

Returns the value of attribute request.



20
21
22
# File 'lib/social_avatar_proxy/app.rb', line 20

def request
  @request
end

Class Method Details

.call(env) ⇒ Object



12
13
14
# File 'lib/social_avatar_proxy/app.rb', line 12

def self.call(env)
  new.call(env)
end

.routesObject



16
17
18
# File 'lib/social_avatar_proxy/app.rb', line 16

def self.routes
  new.routes
end

Instance Method Details

#call(env) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# 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_prefixObject



33
34
35
# File 'lib/social_avatar_proxy/app.rb', line 33

def path_prefix
  ((request && request.env["SCRIPT_NAME"]) || "").gsub(/\/$/, "")
end

#responseObject



37
38
39
40
41
42
43
44
45
46
47
# 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

#routesObject



49
50
51
# File 'lib/social_avatar_proxy/app.rb', line 49

def routes
  Routes.new(self)
end