fork download
  1. require 'net/http'
  2. require 'uri'
  3. require 'json'
  4.  
  5. class GilRPC
  6. def initialize( service_url )
  7. @uri = URI.parse( service_url )
  8. end
  9.  
  10. def method_missing( name , *args )
  11. post_body = { 'method' => name , 'params' => args , 'id' => 'jsonrpc' }.to_json
  12. resp = JSON.parse( http_post_request( post_body ) )
  13. raise JSONRPCError , rest['error'] if resp['error']
  14. resp['result']
  15. end
  16.  
  17. def http_post_request( post_body )
  18. http = Net::HTTP.new( @uri.host , @uri.port )
  19. request = Net::HTTP::Post.new( @uri.request_uri )
  20. request.basic_auth @uri.user , @uri.password
  21. request.content_type = 'application/json'
  22. request.body = post_body
  23. http.request( request ).body
  24. end
  25.  
  26. class JSONRPCError < RuntimeError; end
  27. end
  28.  
  29. h = GilRPC.new( 'http://test001:*****@127.0.0.1:4443' )
  30.  
  31. f = File.open( "b.txt" )
  32.  
  33. ha = Hash.new
  34.  
  35. f.each_line{ |line| l2 = line.chomp()
  36. ha[l2] = 0.0003838 }
  37.  
  38. h.sendmany( "stock" , ha )
  39.  
Runtime error #stdin #stdout #stderr 0.06s 10048KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
prog.rb:31:in `initialize': No such file or directory - b.txt (Errno::ENOENT)
	from prog.rb:31:in `open'
	from prog.rb:31:in `<main>'