Class: CgminerApiClient::Miner
- Inherits:
-
Object
- Object
- CgminerApiClient::Miner
- Includes:
- Commands, SocketWithTimeout
- Defined in:
- lib/cgminer_api_client/miner.rb,
lib/cgminer_api_client/miner/commands.rb
Defined Under Namespace
Modules: Commands
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#port ⇒ Object
Returns the value of attribute port.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Instance Method Summary collapse
- #available?(force_reload = false) ⇒ Boolean
-
#initialize(host = nil, port = nil, timeout = nil) ⇒ Miner
constructor
A new instance of Miner.
- #method_missing(name, *args) ⇒ Object
- #query(method, *params) ⇒ Object
Methods included from Commands::Privileged::System
#debug, #failover_only, #hotplug, #quit, #restart, #save, #setconfig, #zero
Methods included from Commands::Privileged::Pool
#addpool, #disablepool, #enablepool, #poolpriority, #poolquota, #removepool, #switchpool
Methods included from Commands::Privileged::Pga
#pgadisable, #pgaenable, #pgaidentify, #pgaset
Methods included from Commands::Privileged::Asc
#ascdisable, #ascenable, #ascidentify, #ascset
Methods included from Commands::ReadOnly
#asc, #asccount, #check, #coin, #config, #devdetails, #devs, #notify, #pga, #pgacount, #pools, #privileged, #stats, #summary, #usbstats, #version
Methods included from SocketWithTimeout
Constructor Details
#initialize(host = nil, port = nil, timeout = nil) ⇒ Miner
Returns a new instance of Miner.
11 12 13 14 15 |
# File 'lib/cgminer_api_client/miner.rb', line 11 def initialize(host = nil, port = nil, timeout = nil) @host = host ? host : CgminerApiClient.default_host @port = port ? port : CgminerApiClient.default_port @timeout = timeout ? timeout : CgminerApiClient.default_timeout end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
43 44 45 |
# File 'lib/cgminer_api_client/miner.rb', line 43 def method_missing(name, *args) query(name, *args) end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
9 10 11 |
# File 'lib/cgminer_api_client/miner.rb', line 9 def host @host end |
#port ⇒ Object
Returns the value of attribute port.
9 10 11 |
# File 'lib/cgminer_api_client/miner.rb', line 9 def port @port end |
#timeout ⇒ Object
Returns the value of attribute timeout.
9 10 11 |
# File 'lib/cgminer_api_client/miner.rb', line 9 def timeout @timeout end |
Instance Method Details
#available?(force_reload = false) ⇒ Boolean
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/cgminer_api_client/miner.rb', line 32 def available?(force_reload = false) @available = nil if force_reload @available ||= begin open_socket(@host, @port, @timeout).close true rescue false end end |
#query(method, *params) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/cgminer_api_client/miner.rb', line 17 def query(method, *params) if available? request = {command: method} unless params.length == 0 params = params.map { |p| p.to_s.gsub('\\', '\\\\').gsub(',', '\,') } request[:parameter] = params.join(',') end response = perform_request(request) data = sanitized(response) method.to_s.match('\+') ? data : data[method.to_sym] end end |