Class: OpenID::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/openid/interface.rb

Overview

Request objects are used by both the consumer and server APIs to signal and represent various HTTP requests.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args, http_method, authentication = nil) ⇒ Request

args is a hash of HTTP arguments. http_method should be set to “POST” or “GET” authentication is an unused passthrough field that will remain attatched to the request. A NoOpenIDArgs exception will be raised if args contains no openid.* arguments.

Raises:



36
37
38
39
40
41
42
43
44
45
# File 'lib/openid/interface.rb', line 36

def initialize(args, http_method, authentication=nil)
  @args = args
  @http_method = http_method.upcase
  @authentication = authentication
  
  @args.each_key { |key|
    return if key.index('openid.') == 0
  }
  raise NoOpenIDArgs
end

Instance Attribute Details

#argsObject

Returns the value of attribute args.



28
29
30
# File 'lib/openid/interface.rb', line 28

def args
  @args
end

#authenticationObject (readonly)

Returns the value of attribute authentication.



28
29
30
# File 'lib/openid/interface.rb', line 28

def authentication
  @authentication
end

#http_methodObject

Returns the value of attribute http_method.



28
29
30
# File 'lib/openid/interface.rb', line 28

def http_method
  @http_method
end

Instance Method Details

#[](key) ⇒ Object

The preferred method for getting OpenID args out of the request. Raises a ProtoclError if the argument does not exist.



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/openid/interface.rb', line 48

def [](key)
  result = get(key)
  if result == nil
    if key == 'trust_root'
      return self['return_to']
    else
      raise ProtocolError, "Query argument #{key} not found", caller
    end
  end
  return result
end

#get(key, default = nil) ⇒ Object



60
61
62
# File 'lib/openid/interface.rb', line 60

def get(key, default=nil)
  return @args.fetch('openid.' + key, default)
end