Class: Remit::SignedQuery

Inherits:
Relax::Query
  • Object
show all
Defined in:
lib/remit/common.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, secret_key, query = {}) ⇒ SignedQuery

Returns a new instance of SignedQuery.



59
60
61
62
63
# File 'lib/remit/common.rb', line 59

def initialize(uri, secret_key, query={})
  super(query)
  @uri = URI.parse(uri.to_s)
  @secret_key = secret_key
end

Class Method Details

.parse(uri, secret_key, query_string) ⇒ Object



76
77
78
79
80
81
82
83
84
85
# File 'lib/remit/common.rb', line 76

def parse(uri, secret_key, query_string)
  query = self.new(uri, secret_key)

  query_string.split('&').each do |parameter|
    key, value = parameter.split('=', 2)
    query[key] = unescape_value(value)
  end

  query
end

Instance Method Details

#signObject



65
66
67
68
# File 'lib/remit/common.rb', line 65

def sign
  delete(:awsSignature)
  store(:awsSignature, Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::SHA1.new, @secret_key, "#{@uri.path}?#{to_s(false)}".gsub('%20', '+'))).strip)
end

#to_s(signed = true) ⇒ Object



70
71
72
73
# File 'lib/remit/common.rb', line 70

def to_s(signed=true)
  sign if signed
  super()
end