Created
June 18, 2015 05:04
-
-
Save query-string/888c791d1f34748a0cbf to your computer and use it in GitHub Desktop.
Sunny Portal signature generation method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://www.sunnyportal.com API signature generation
C# implementation: https://gist.github.com/query-string/fe9f33e1abea73dd1b1d