class Peatio::Bitcoincash::Client
Constants
- Error
Public Class Methods
new(endpoint)
click to toggle source
# File lib/peatio/bitcoincash/client.rb, line 25 def initialize(endpoint) @json_rpc_endpoint = URI.parse(endpoint) @path = @json_rpc_endpoint.path.empty? ? "/" : @json_rpc_endpoint.path @idle_timeout = idle_timeout end
Public Instance Methods
json_rpc(method, params = [])
click to toggle source
# File lib/peatio/bitcoincash/client.rb, line 31 def json_rpc(method, params = []) response = connection.post \ @path, { jsonrpc: '1.0', method: method, params: params }.to_json, { 'Accept' => 'application/json', 'coin-name' => 'bitcoincash', 'Content-Type' => 'application/json' } response.assert_2xx! response = JSON.parse(response.body) response['error'].tap { |e| raise ResponseError.new(e['code'], e['message']) if e } response.fetch('result') 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/bitcoincash/client.rb, line 54 def connection @connection ||= Faraday.new(@json_rpc_endpoint) do |f| f.adapter :net_http_persistent, pool_size: 5 end.tap do |connection| unless @json_rpc_endpoint.user.blank? connection.basic_auth(@json_rpc_endpoint.user, @json_rpc_endpoint.password) end end end