Class: Peatio::Decredcoin::Client
- Inherits:
-
Object
- Object
- Peatio::Decredcoin::Client
- Extended by:
- Memoist
- Defined in:
- lib/peatio/decredcoin/client.rb
Defined Under Namespace
Classes: ResponseError
Constant Summary collapse
- Error =
Class.new(StandardError)
- ConnectionError =
Class.new(Error)
Instance Method Summary collapse
-
#initialize(endpoint, is_secure = false) ⇒ Client
constructor
A new instance of Client.
- #json_rpc(method, params = []) ⇒ Object
Constructor Details
#initialize(endpoint, is_secure = false) ⇒ Client
Returns a new instance of Client.
26 27 28 29 |
# 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 |
Instance Method Details
#json_rpc(method, params = []) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# 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 |