class Fondy::Signature
Attributes
params[R]
password[R]
Public Class Methods
build(*args)
click to toggle source
# File lib/fondy/signature.rb, line 4 def self.build(*args) new(*args).build end
new(params:, password:)
click to toggle source
# File lib/fondy/signature.rb, line 12 def initialize(params:, password:) @params = params @password = password end
verify(*args)
click to toggle source
# File lib/fondy/signature.rb, line 8 def self.verify(*args) new(*args).verify end
Public Instance Methods
build()
click to toggle source
# File lib/fondy/signature.rb, line 17 def build filtered_params = params.reject do |k, v| %w(signature response_signature_string).include?(k.to_s) || v.to_s.empty? end params_str = filtered_params.sort_by(&:first).map(&:last).join('|') Digest::SHA1.hexdigest("#{password}|#{params_str}") end
verify()
click to toggle source
# File lib/fondy/signature.rb, line 25 def verify unless params[:signature] raise Fondy::InvalidSignatureError, 'Response signature not found' end signature = build unless params[:signature] == signature raise Fondy::InvalidSignatureError, 'Invalid response signature' end true end