Class: Carpool::Passenger

Inherits:
Object
  • Object
show all
Includes:
Mixins::Core
Defined in:
lib/carpool/passenger.rb

Class Attribute Summary collapse

Instance Method Summary collapse

Methods included from Mixins::Core

included

Constructor Details

#initialize(app) {|Carpool::Passenger| ... } ⇒ Passenger

Returns a new instance of Passenger.

Yields:



15
16
17
18
19
20
# File 'lib/carpool/passenger.rb', line 15

def initialize(app)
  @app = app
  Carpool.acts_as = :passenger
  yield Carpool::Passenger if block_given?
  self
end

Class Attribute Details

.driver_uriObject

Returns the value of attribute driver_uri.



10
11
12
# File 'lib/carpool/passenger.rb', line 10

def driver_uri
  @driver_uri
end

.secretObject

Returns the value of attribute secret.



11
12
13
# File 'lib/carpool/passenger.rb', line 11

def secret
  @secret
end

Instance Method Details

#call(env) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/carpool/passenger.rb', line 22

def call(env)
  @env = env
  @params = CGI.parse(env['QUERY_STRING'])
  cookies[:scope] = "passenger"
  
  # If this isn't an authorize request from the driver, just ignore it.
  return @app.call(env) unless valid_request? && valid_referrer?
  
  # If we can't find our payload, then we need to abort.      
  return [500, {}, 'Invalid seatbelt.'] if @params['seatbelt'].nil? or @params['seatbelt'].blank?
  
  # Set a custom HTTP header for our payload and send the request to the user's /sso/authorize handler.
  env['X-CARPOOL-PAYLOAD'] = @params['seatbelt']
  return @app.call(env)
  
end