Skip to content

Instantly share code, notes, and snippets.

@query-string
Created June 18, 2015 05:04
Show Gist options
  • Save query-string/888c791d1f34748a0cbf to your computer and use it in GitHub Desktop.
Save query-string/888c791d1f34748a0cbf to your computer and use it in GitHub Desktop.
Sunny Portal signature generation method
require "openssl"
require "base64"
require "cgi"
class SunnyPortal
def initialize
@api_service = "plantlist"
@key = ENV["KEY"]
@identifier = ENV["IDENTIFIER"]
@http_method = "GET"
@timestamp = DateTime.now.utc.strftime("%FT%T")
end
def signature
sig_string = @http_method.downcase + @api_service.downcase + @timestamp + @identifier.downcase
hmac_hash = OpenSSL::HMAC.digest("sha1", @key, sig_string)
base64_encoded_signature = Base64.strict_encode64(hmac_hash)
CGI::escape(base64_encoded_signature)
end
end
@query-string
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment