Author

Topic: Help on Vircurex API Ruby code. (Read 699 times)

newbie
Activity: 8
Merit: 0
March 17, 2014, 04:54:01 PM
#1
Hello,

I hope this is the right forum.

I'm trying to make the vircurex API code work in Ruby but at no avail. I have amended it, so at least it is syntactically correct and the strings my_url and my_params, together, when copied into a web-brower, do work. But unfortunately the rest doesn't.  Please find my adjusted code attached, I have commented, what I changed. What am I missing?

thanks. in advance,

JJ

Quote
#original example modified
#1. Change: added necessary libs to avoid error like: in `
': uninitialized constant Digest (NameError)
require 'digest'
require 'open-uri'
require 'net/http'
require 'openssl'
#end of libs


 t = Time.now.gmtime.strftime("%Y-%m-%dT%H:%M:%S")
 trx_id = Digest::SHA2.hexdigest("#{t}-#{rand}")
 user_name = "MY_USER_NAME"
 secret_word = "123456789"
 


 tok = Digest::SHA2.hexdigest("#{secret_word};#{user_name};#{t};#{trx_id};create_order;sell;10;btc;50;nmc")
 # 3. Change: move this Order call down behind the definition to avoid error orig.rb:15:in `
': uninitialized constant Order (NameError)
 # Order.call_https("https://api.vircurex.com","/api/create_order.json?account=#{user_name}&id=#{trx_id}&token=#{tok}×tamp=#{t}&ordertype=sell&amount=10¤cy1=btc&unitprice=50¤cy2=nmc")
#
# 2. Change: added class Order to avoid error: in `
': uninitialized constant Order (NameError)

class Order
 def self.call_https(my_url,my_params)
 # output what would be sent:
  puts my_url+ my_params
  # this output, when put into web-brower, works!
  uri = URI.parse(my_url)
  http = Net::HTTP.new(uri.host, '443')
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_PEER
  response=""
  resp=""
  http.start do |http|
   cmd = my_params
   req = Net::HTTP::Get.new(cmd)
   response = http.request(req)
   resp = response.body
  end
  return ActiveSupport::JSON.decode(resp)
 end
end #of class Order

#execute order
 Order.call_https("https://api.vircurex.com","/api/create_order.json?account=#{user_name}&id=#{trx_id}&token=#{tok}×tamp=#{t}&ordertype=sell&amount=10¤cy1=btc&unitprice=50¤cy2=nmc")


the error I'm getting is:

Quote
C:/Ruby200/lib/ruby/2.0.0/net/http.rb:918:in `connect': SSL_connect returned=1 e
rrno=0 state=SSLv3 read server certificate B: certificate verify failed (OpenSSL
::SSL::SSLError)
        from C:/Ruby200/lib/ruby/2.0.0/net/http.rb:918:in `block in connect'
        from C:/Ruby200/lib/ruby/2.0.0/timeout.rb:52:in `timeout'
        from C:/Ruby200/lib/ruby/2.0.0/net/http.rb:918:in `connect'
        from C:/Ruby200/lib/ruby/2.0.0/net/http.rb:862:in `do_start'
        from C:/Ruby200/lib/ruby/2.0.0/net/http.rb:851:in `start'
        from test.rb:35:in `call_https'
        from test.rb:45:in `
'
Jump to: