Ruby
#!/usr/bin/env ruby
require 'digest/hmac'
require 'net/http'
require 'uri'
require 'openssl'
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
class String
def hex2bin
scan(/../).map { |x| x.to_i(16).chr }.join
end
end
# put your keys below
apid = ""
secret = ""
command='{ "command" : "test/copy/1" , "data1" : "THIS IS A TEST"}'
time=Time.now.to_i
hash = Digest::HMAC.hexdigest("#{time}#{command}", secret.hex2bin, Digest::SHA1)
uri = URI("https://api.researchforgood.com/API?apid=#{apid}&time=#{time}&hash=#{hash}")
Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
req = Net::HTTP::Post.new uri
req.body = command
req.content_type = 'application/json'
response = http.request req
puts response.body
end