Class: Peatio::Litecoin::Client
- Inherits:
-
Object
- Object
- Peatio::Litecoin::Client
- Extended by:
- Memoist
- Defined in:
- lib/peatio/litecoin/client.rb
Defined Under Namespace
Classes: ConnectionError, ResponseError
Constant Summary collapse
- Error =
Class.new(StandardError)
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 |
# File 'lib/peatio/litecoin/client.rb', line 24 def initialize(endpoint) @json_rpc_endpoint = URI.parse(endpoint) end |
Instance Method Details
#json_rpc(method, params = []) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/peatio/litecoin/client.rb', line 28 def json_rpc(method, params = []) response = post(method, params) 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 |