acidlabs/puntopagos-ruby

View on GitHub
lib/puntopagos/authorization.rb

Summary

Maintainability
A
0 mins
Test Coverage
require 'base64'
require 'openssl'

module PuntoPagos
  
  # Public: This class manage the signing of a message using
  # the secret and api-key defined in puntopagos.yml
  class Authorization
    def initialize env = nil
      @@config ||= PuntoPagos::Config.new(env)
    end

    # Public: Signs a string using the secret and api-key defined in puntopagos.yml
    #
    # string - The String to be signed
    # Returns the signed String.
    def sign(string)
      encoded_string = Base64.encode64(OpenSSL::HMAC.digest('sha1',@@config.puntopagos_secret, string)).chomp
      "PP "+@@config.puntopagos_key+":"+ encoded_string
    end
  end
end