Skip to content

Instantly share code, notes, and snippets.

@tranvictor
Created June 21, 2018 04:52
Show Gist options
  • Select an option

  • Save tranvictor/37944aa9012deb94f9f3c924886a90cb to your computer and use it in GitHub Desktop.

Select an option

Save tranvictor/37944aa9012deb94f9f3c924886a90cb to your computer and use it in GitHub Desktop.
def callUpdateToKyberAPI(email, addresses, timestamps)
key = Rails.application.secrets.kyber_key
nonce = (Time.now.to_f * 1000).to_i
msg = URI.encode_www_form(
[[:addresses, addresses], [:nonce, nonce], [:timestamps, timestamps], [:user, email]])
uri = URI.parse("https://mainnet-data.kyber.network/update-user-addresses")
https = Net::HTTP.new(uri.host,uri.port)
https.use_ssl = true
req = Net::HTTP::Post.new(
uri.path, initheader = {
'Content-Type' => 'application/x-www-form-urlencoded',
'signed' => OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha512'), key, msg)
})
req.body = msg
res = https.request(req)
JSON.parse(res.body)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment