class Midpay::SignableHash

Public Instance Methods

algorithm_const(algorithm) click to toggle source
# File lib/midpay/signable_hash.rb, line 32
def algorithm_const algorithm
  algorithm = self[algorithm] if key?(algorithm) && self[algorithm]
  begin
    ::Digest.const_get(algorithm.to_s.upcase)
  rescue
    #
  end
end
merge_if!(hash) click to toggle source
# File lib/midpay/signable_hash.rb, line 25
def merge_if! hash
  hash.each do |i|
    self[i[0]] = i[1] unless self.key?(i[0])
  end if hash.respond_to?(:each)
  self
end
sign(algorithm) { |dup| ... } click to toggle source
# File lib/midpay/signable_hash.rb, line 7
def sign algorithm, &block
  data = yield(self.dup)
  begin
    algorithm_const(algorithm).send(:hexdigest, data)
  rescue
    nil
  end
end
sign!(key, algorithm, &block) click to toggle source
# File lib/midpay/signable_hash.rb, line 16
def sign! key, algorithm, &block
  self[key] = self.sign(algorithm, &block)
  self
end
to_query() click to toggle source
# File lib/midpay/signable_hash.rb, line 21
def to_query
  collect{|k,v| "#{::URI.encode_www_form_component(k.to_s)}=#{::URI.encode_www_form_component(v.to_s)}" }.sort.join("&")
end