Bitcoin Forum
July 08, 2024, 10:27:43 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Help on Vircurex API Ruby code.  (Read 688 times)
jjbeam (OP)
Newbie
*
Offline Offline

Activity: 8
Merit: 0


View Profile
March 17, 2014, 09: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 `<main>': 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 `<main>': uninitialized constant Order (NameError)
 # Order.call_https("https://api.vircurex.com","/api/create_order.json?account=#{user_name}&id=#{trx_id}&token=#{tok}&timestamp=#{t}&ordertype=sell&amount=10&currency1=btc&unitprice=50&currency2=nmc")
#
# 2. Change: added class Order to avoid error: in `<main>': 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}&timestamp=#{t}&ordertype=sell&amount=10&currency1=btc&unitprice=50&currency2=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 `<main>'
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!