Class: Summon::Transport::Headers
- Includes:
- Qstring
- Defined in:
- lib/summon/transport/headers.rb
Instance Method Summary collapse
- #digest ⇒ Object
-
#initialize(options = {}) ⇒ Headers
constructor
A new instance of Headers.
- #qstr ⇒ Object
Methods included from Qstring
#encode_param, #from_query_string, #to_query_string, #urldecode, #urlencode
Constructor Details
#initialize(options = {}) ⇒ Headers
Returns a new instance of Headers.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/summon/transport/headers.rb', line 10 def initialize( = {}) @params = [:params] || {} @url = [:url] @uri = URI.parse(@url) @access_id = [:access_id] @client_key = [:client_key] @secret_key = [:secret_key] @session_id = [:session_id] @log = Summon::Log.new([:log]) @accept = "application/#{[:accept] || 'json'}" @time = Time.now.httpdate validate! merge!({ "Content-Type" => "application/x-www-form-urlencoded; charset=utf8", "Accept" => @accept, "x-summon-date" => @time, "x-summon-session-id" => @session_id, "Authorization" => "Summon #{[@access_id, @client_key, digest].reject {|o| o.nil?}.join(';')}", "Host" => "#{@uri.host}:#{@uri.port}" }).reject! {|k,v| v.nil?} @log.debug { "#{self.class.name}\n#{self.map {|k,v| "#{k}: #{v}"}.join("\n")}" } end |
Instance Method Details
#digest ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/summon/transport/headers.rb', line 35 def digest id = [@accept, @time, "#{@uri.host}:#{@uri.port}", @uri.path, qstr].join("\n") + "\n" Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::SHA1.new, @secret_key, id)).chomp.tap {|digest| # @log.debug {"ID: #{id.inspect}"} # @log.debug {"DIGEST: #{digest}\n"} } end |
#qstr ⇒ Object
43 44 45 |
# File 'lib/summon/transport/headers.rb', line 43 def qstr to_query_string(@params, false) end |