Class: Rack::Facebook::SignedRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/facebook/signed_request.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, options, &condition) ⇒ SignedRequest

Returns a new instance of SignedRequest.



12
13
14
15
16
# File 'lib/rack/facebook/signed_request.rb', line 12

def initialize(app, options, &condition)
  @app = app
  @condition = condition
  @options = options
end

Instance Method Details

#call(env) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rack/facebook/signed_request.rb', line 18

def call(env)
  @env = env
  @request = Rack::Request.new(env)

  # RESTify the default POST request from Facebook
  if request.POST['signed_request']
    env['HTTP_METHOD'] = 'GET'
  end

  app_id, secret = [@options.fetch(:app_id), @options.fetch(:secret)]
  facebook_params = resolve_from_signed_request!(secret) || resolve_from_cookie!(app_id, secret)
  request.params['facebook_params'] = facebook_params if facebook_params
  env['rack.request.query_hash'] = request.params

  unless @options[:inject_facebook]
    @app.call(env)
  else
    inject_facebook_script
  end
end