Class: Hungrytable::RequestHeader
- Inherits:
-
Object
- Object
- Hungrytable::RequestHeader
- Defined in:
- lib/hungrytable/request_header.rb
Constant Summary collapse
- ATTRIBUTE_KEYS =
%w(consumer_key nonce signature_method timestamp token version).map(&:to_sym)
Instance Attribute Summary collapse
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(method, url, params, oauth = {}) ⇒ RequestHeader
constructor
A new instance of RequestHeader.
- #signed_attributes ⇒ Object
- #to_s ⇒ Object
- #url ⇒ Object
- #valid?(secrets = {}) ⇒ Boolean
Constructor Details
#initialize(method, url, params, oauth = {}) ⇒ RequestHeader
Returns a new instance of RequestHeader.
29 30 31 32 33 34 35 36 37 |
# File 'lib/hungrytable/request_header.rb', line 29 def initialize(method, url, params, oauth = {}) @method = method.to_s.upcase @uri = URI.parse(url.to_s) @uri.scheme = @uri.scheme.downcase @uri.normalize! @uri.fragment = nil @params = params @options = self.class..merge(oauth) end |
Instance Attribute Details
#method ⇒ Object (readonly)
Returns the value of attribute method.
27 28 29 |
# File 'lib/hungrytable/request_header.rb', line 27 def method @method end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
27 28 29 |
# File 'lib/hungrytable/request_header.rb', line 27 def @options end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
27 28 29 |
# File 'lib/hungrytable/request_header.rb', line 27 def params @params end |
Class Method Details
.decode(value) ⇒ Object
23 24 25 |
# File 'lib/hungrytable/request_header.rb', line 23 def self.decode(value) URI.decode(value.to_s) end |
.default_options ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/hungrytable/request_header.rb', line 7 def self. { :nonce => OpenSSL::Random.random_bytes(16).unpack('H*')[0], :signature_method => 'HMAC-SHA1', :timestamp => Time.now.to_i.to_s, :version => '1.0', :consumer_key => Hungrytable::Config.oauth_key, :consumer_secret => Hungrytable::Config.oauth_secret, :token => '' } end |
.encode(value) ⇒ Object
19 20 21 |
# File 'lib/hungrytable/request_header.rb', line 19 def self.encode(value) URI.encode(value.to_s, /[^a-z0-9\-\.\_\~]/i) end |
Instance Method Details
#signed_attributes ⇒ Object
57 58 59 |
# File 'lib/hungrytable/request_header.rb', line 57 def signed_attributes attributes.merge(:oauth_signature => signature) end |
#to_s ⇒ Object
45 46 47 |
# File 'lib/hungrytable/request_header.rb', line 45 def to_s %Q(OAuth realm="http://www.opentable.com/", #{normalized_attributes}) end |
#url ⇒ Object
39 40 41 42 43 |
# File 'lib/hungrytable/request_header.rb', line 39 def url uri = @uri.dup uri.query = nil uri.to_s end |
#valid?(secrets = {}) ⇒ Boolean
49 50 51 52 53 54 55 |
# File 'lib/hungrytable/request_header.rb', line 49 def valid?(secrets = {}) = .dup .merge!(secrets) valid = [:signature] == signature .replace() valid end |