Class: ClientRPC::Connect
- Inherits:
-
Object
- Object
- ClientRPC::Connect
- Defined in:
- lib/rpc.rb
Defined Under Namespace
Classes: Error
Constant Summary collapse
- DEFAULTS =
{ host: "localhost", port: 18332, # dev: true, }.freeze
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#ssl ⇒ Object
Returns the value of attribute ssl.
-
#uri ⇒ Object
Returns the value of attribute uri.
Instance Method Summary collapse
-
#initialize(host) ⇒ Connect
constructor
A new instance of Connect.
- #ping_node ⇒ Object
- #request(name, *args) ⇒ Object
Constructor Details
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
23 24 25 |
# File 'lib/rpc.rb', line 23 def @options end |
#ssl ⇒ Object
Returns the value of attribute ssl.
23 24 25 |
# File 'lib/rpc.rb', line 23 def ssl @ssl end |
#uri ⇒ Object
Returns the value of attribute uri.
23 24 25 |
# File 'lib/rpc.rb', line 23 def uri @uri end |
Instance Method Details
#ping_node ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/rpc.rb', line 53 def ping_node user = uri.user pass = uri.password http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true if @ssl request = Net::HTTP::Get.new(uri.request_uri) request.basic_auth(user, pass) request.body = request_body("", nil) request["Content-Type"] = "application/json".freeze response = http.request(request) @pingres = (response.code).to_i.dup end |
#request(name, *args) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rpc.rb', line 36 def request(name, *args) puts "\n> #{name}: #{args.join(",")}" if [:dev] response = request_http_post(name, args) puts "< #{response.code} #{response.}" if [:dev] raise Error, response. unless (200...300).cover?(response.code.to_i) begin response = Oj.load(response.body, symbol_keys: true, bigdecimal_load: true) rescue StandardError => e puts "WARN < Failed to parse JSON response: #{e}" if [:dev] raise end puts "\n> #{name}: #{args.join(",")}" if [:dev] puts response[:result] if [:dev] raise Error, response[:error] if response[:error] response[:result] end |