class Peatio::Decredcoin::Client
Constants
- ConnectionError
- Error
Public Class Methods
new(endpoint, is_secure = false)
click to toggle source
# File lib/peatio/decredcoin/client.rb, line 26 def initialize(endpoint, is_secure = false) @json_rpc_endpoint = URI.parse(endpoint) @is_secure = is_secure end
Public Instance Methods
json_rpc(method, params = [])
click to toggle source
# File lib/peatio/decredcoin/client.rb, line 31 def json_rpc(method, params = []) response = connection.post \ '/', { jsonrpc: '2.0', method: method, params: params }.to_json, { 'Accept' => 'application/json', 'Content-Type' => 'application/json' } response.assert_2xx! response = JSON.parse(response.body) response['error'].tap do |e| raise ResponseError.new(e['code'], e['message']) if e end response.fetch('result') rescue Faraday::Error => e raise ConnectionError, e end
Private Instance Methods
connection()
click to toggle source
# File lib/peatio/decredcoin/client.rb, line 49 def connection @connection ||= Faraday.new(@json_rpc_endpoint) do |f| f.adapter :net_http_persistent, pool_size: 5 f.ssl[:verify] = @is_secure end.tap do |connection| unless @json_rpc_endpoint.user.blank? connection.basic_auth(@json_rpc_endpoint.user, @json_rpc_endpoint.password) end end end