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.
30 31 32 33 34 35 36 37 38 |
# File 'lib/hungrytable/request_header.rb', line 30 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.
28 29 30 |
# File 'lib/hungrytable/request_header.rb', line 28 def method @method end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
28 29 30 |
# File 'lib/hungrytable/request_header.rb', line 28 def @options end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
28 29 30 |
# File 'lib/hungrytable/request_header.rb', line 28 def params @params end |
Class Method Details
.decode(value) ⇒ Object
24 25 26 |
# File 'lib/hungrytable/request_header.rb', line 24 def self.decode(value) CGI.unescape(value.to_s) end |
.default_options ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/hungrytable/request_header.rb', line 8 def self. { nonce: OpenSSL::Random.random_bytes(16).unpack1('H*'), 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
20 21 22 |
# File 'lib/hungrytable/request_header.rb', line 20 def self.encode(value) CGI.escape(value.to_s).gsub('+', '%20').gsub('%7E', '~') end |
Instance Method Details
#signed_attributes ⇒ Object
58 59 60 |
# File 'lib/hungrytable/request_header.rb', line 58 def signed_attributes attributes.merge(oauth_signature: signature) end |
#to_s ⇒ Object
46 47 48 |
# File 'lib/hungrytable/request_header.rb', line 46 def to_s %(OAuth realm="http://www.opentable.com/", #{normalized_attributes}) end |
#url ⇒ Object
40 41 42 43 44 |
# File 'lib/hungrytable/request_header.rb', line 40 def url uri = @uri.dup uri.query = nil uri.to_s end |
#valid?(secrets = {}) ⇒ Boolean
50 51 52 53 54 55 56 |
# File 'lib/hungrytable/request_header.rb', line 50 def valid?(secrets = {}) = .dup .merge!(secrets) valid = [:signature] == signature .replace() valid end |