Class: Peatio::Ripple::Client
- Inherits:
-
Object
- Object
- Peatio::Ripple::Client
- Extended by:
- Memoist
- Defined in:
- lib/peatio/ripple/client.rb
Defined Under Namespace
Classes: ResponseError
Constant Summary collapse
- Error =
Class.new(StandardError)
- ConnectionError =
Class.new(Error)
Instance Method Summary collapse
-
#initialize(endpoint) ⇒ Client
constructor
A new instance of Client.
- #json_rpc(method, params = []) ⇒ Object
Constructor Details
#initialize(endpoint) ⇒ Client
Returns a new instance of Client.
24 25 26 27 |
# File 'lib/peatio/ripple/client.rb', line 24 def initialize(endpoint) @json_rpc_endpoint = URI.parse(endpoint) @json_rpc_call_id = 0 end |
Instance Method Details
#json_rpc(method, params = []) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/peatio/ripple/client.rb', line 29 def json_rpc(method, params = []) response = connection.post \ '/', { jsonrpc: '2.0', id: rpc_call_id, method: method, params: params }.to_json, { 'Accept' => 'application/json', 'Content-Type' => 'application/json' } response.assert_2xx! response = JSON.parse(response.body) response.fetch('result').tap do |result| raise ResponseError.new(result['error_code'], result['error_message']) if result['status'] == 'error' end response.fetch('result') rescue Faraday::Error => e raise ConnectionError, e end |