Skip to content

Instantly share code, notes, and snippets.

@skord
Created April 2, 2017 00:43
Show Gist options
  • Save skord/51a4605c0fe4c56fb324cc8cf66bbfcb to your computer and use it in GitHub Desktop.
Save skord/51a4605c0fe4c56fb324cc8cf66bbfcb to your computer and use it in GitHub Desktop.
module Mettlr
class Signature
def initialize(request)
@request = request
end
def concat_string
@request.method.to_s.upcase +
"http://api.mettl.com" +
@request.path +
param_values
end
def param_values
"\n" + @request.params.values.join("\n")
end
def signature
hmac = OpenSSL::HMAC.digest('sha1', Mettlr::METTL_PRIVATE_KEY, concat_string)
Faraday::Utils.escape(Base64.encode64(hmac).chomp)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment