Class: Bitcoiner::Client
- Inherits:
-
Object
- Object
- Bitcoiner::Client
- Defined in:
- lib/bitcoiner/client.rb
Defined Under Namespace
Classes: JSONRPCError
Constant Summary collapse
- DEFAULT_ID =
'jsonrpc'.freeze
- LOG_PREFIX =
"[bitcoiner]".freeze
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
Returns the value of attribute endpoint.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#password ⇒ Object
Returns the value of attribute password.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
- #accounts ⇒ Object
- #balance ⇒ Object
-
#initialize(user, pass, host, logger: nil) ⇒ Client
constructor
A new instance of Client.
- #inspect ⇒ Object
- #request(method_or_array_of_methods, *args) ⇒ Object
Constructor Details
#initialize(user, pass, host, logger: nil) ⇒ Client
Returns a new instance of Client.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/bitcoiner/client.rb', line 11 def initialize(user, pass, host, logger: nil) uri = Addressable::URI.heuristic_parse(host) self.username = uri.user || user self.password = uri.password || pass uri.user = uri.password = nil self.endpoint = uri.to_s self.logger = logger end |
Instance Attribute Details
#endpoint ⇒ Object
Returns the value of attribute endpoint.
9 10 11 |
# File 'lib/bitcoiner/client.rb', line 9 def endpoint @endpoint end |
#logger ⇒ Object
Returns the value of attribute logger.
9 10 11 |
# File 'lib/bitcoiner/client.rb', line 9 def logger @logger end |
#password ⇒ Object
Returns the value of attribute password.
9 10 11 |
# File 'lib/bitcoiner/client.rb', line 9 def password @password end |
#username ⇒ Object
Returns the value of attribute username.
9 10 11 |
# File 'lib/bitcoiner/client.rb', line 9 def username @username end |
Instance Method Details
#accounts ⇒ Object
26 27 28 29 |
# File 'lib/bitcoiner/client.rb', line 26 def accounts balance_hash = request 'listaccounts' AccountHash.new self, balance_hash end |
#balance ⇒ Object
22 23 24 |
# File 'lib/bitcoiner/client.rb', line 22 def balance request 'getbalance' end |
#inspect ⇒ Object
41 42 43 |
# File 'lib/bitcoiner/client.rb', line 41 def inspect "#<Bitcoiner::Client #{endpoint.inspect} #{username}:#{password} >" end |
#request(method_or_array_of_methods, *args) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/bitcoiner/client.rb', line 31 def request(method_or_array_of_methods, *args) if method_or_array_of_methods.is_a?(Array) log("#{method_or_array_of_methods}") batch_request(method_or_array_of_methods) else log("#{method_or_array_of_methods}; args: #{args.inspect}") single_request(method_or_array_of_methods, *args) end end |