class Peatio::Tron::Client
Constants
- Error
Public Class Methods
new(endpoint)
click to toggle source
# File lib/peatio/tron/client.rb, line 25 def initialize(endpoint) @json_rpc_endpoint = URI.parse(endpoint) end
Public Instance Methods
json_rpc(path:, params: {})
click to toggle source
# File lib/peatio/tron/client.rb, line 29 def json_rpc(path:, params: {}) response = connection.post do |req| req.url path req.body = params.to_json end response.assert_2xx! response = JSON.parse(response.body) response['Error'].tap { |error| raise ResponseError.new(200, error) if error } response rescue => e if e.is_a?(Error) raise e elsif e.is_a?(Faraday::Error) raise ConnectionError, e else raise Error, e end end
Private Instance Methods
connection()
click to toggle source
# File lib/peatio/tron/client.rb, line 50 def connection @connection ||= Faraday.new(@json_rpc_endpoint) do |f| f.adapter :net_http_persistent, pool_size: 5, idle_timeout: @idle_timeout end.tap do |connection| unless @json_rpc_endpoint.user.blank? connection.basic_auth(@json_rpc_endpoint.user, @json_rpc_endpoint.password) end end end