Last active
August 29, 2015 14:20
-
-
Save yutelin/91349c64b8e966dd8078 to your computer and use it in GitHub Desktop.
MaiCoin Api key/secret request header example
This file contains hidden or 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
def request_options (api_key, api_secret, verb, path, options={}) | |
base_uri = 'https://api.maicoin.com/v1' | |
nonce = options[:nonce] || (Time.now.to_f * 1e6).to_i | |
if [:get, :delete].include? verb | |
request_options = {} | |
path = "#{path}?#{URI.encode_www_form(options)}" if !options.empty? | |
hmac_message = nonce.to_s + base_uri + path | |
else | |
request_options = {body: options.to_json} | |
hmac_message = nonce.to_s + base_uri + path + options.to_json | |
end | |
signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), api_secret, hmac_message) | |
headers = { | |
'ACCESS_KEY' => api_key, | |
'ACCESS_SIGNATURE' => signature, | |
'ACCESS_NONCE' => nonce.to_s, | |
'Content-Type' => 'application/json', | |
} | |
request_options[:headers] = headers | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment