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