Class: Avalon::Btcguild
- Inherits:
-
Node
- Object
- Node
- Avalon::Btcguild
show all
- Defined in:
- lib/avalon/btcguild.rb
Overview
Extracts Btcguild pool info
Constant Summary
collapse
- API_URL =
'http://www.btcguild.com'
- API_PATH =
'api.php?api_key='
Instance Attribute Summary
Attributes inherited from Node
#data, #ip
Instance Method Summary
collapse
Methods inherited from Node
#[], #[]=, create, #num, #pool_hash, #reset, #unit_hash
Methods included from Utils
#alarm, #duration, #find_file, #ping, #play, #system
Constructor Details
#initialize(monitor, ping_url, api_key) ⇒ Btcguild
Returns a new instance of Btcguild.
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/avalon/btcguild.rb', line 12
def initialize monitor, ping_url, api_key
@ping_url, @api_key = ping_url, api_key
@conn ||= Faraday.new(:url => API_URL) do |faraday|
faraday.adapter Faraday.default_adapter end
super()
end
|
Instance Method Details
#access(key1, key2, precision = nil, divider = 1) ⇒ Object
Convenience data accessors
60
61
62
63
64
65
66
67
68
|
# File 'lib/avalon/btcguild.rb', line 60
def access key1, key2, precision=nil, divider=1
if @data[key1] && @data[key1][key2]
if precision
(@data[key1][key2]/divider).round(precision)
else
(@data[key1][key2]/divider)
end
end
end
|
#diff ⇒ Object
90
91
92
|
# File 'lib/avalon/btcguild.rb', line 90
def diff
access :pool, :difficulty, 1, 1000_000.0
end
|
#get ⇒ Object
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/avalon/btcguild.rb', line 23
def get
reply = @conn.get "#{API_PATH}#{@api_key}"
if reply.success? && !(reply.body =~ /too many API requests/)
JSON.parse(reply.body, :symbolize_names => true)
else
{}
end
rescue Faraday::Error::TimeoutError
{}
end
|
#past24 ⇒ Object
70
71
72
|
# File 'lib/avalon/btcguild.rb', line 70
def past24
access :user, :past_24h_rewards, 2
end
|
#past24_nmc ⇒ Object
78
79
80
|
# File 'lib/avalon/btcguild.rb', line 78
def past24_nmc
access :user, :past_24h_rewards_nmc, 1
end
|
#poll(verbose = true) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/avalon/btcguild.rb', line 34
def poll verbose=true
@data[:ping] = ping @ping_url
if @data[:ping]
@data.merge!(get || {})
if @data[:workers] && @data[:workers].keys.include?(:'1')
@data[:workers] = Hash[*@data[:workers].map {|_, h| [h.delete(:worker_name), h]}.flatten]
end
end
puts "#{self}" if verbose
end
|
#pool_speed ⇒ Object
86
87
88
|
# File 'lib/avalon/btcguild.rb', line 86
def pool_speed
access :pool, :pool_speed, 1, 1000.0
end
|
#report ⇒ Object
Check for any exceptional situations, sound alarm if any
47
48
49
50
51
52
|
# File 'lib/avalon/btcguild.rb', line 47
def report
if self[:ping].nil?
alarm "BTC Guild not responding to ping"
else
end
end
|
#to_s ⇒ Object
54
55
56
57
|
# File 'lib/avalon/btcguild.rb', line 54
def to_s
"\nBTC Guild: #{pool_speed}TH/s ping:#{self[:ping]} diff:#{diff}M " +
"unpaid(24h) btc: #{unpaid}(#{past24}) nmc: #{unpaid_nmc}(#{past24_nmc})"
end
|
#unpaid ⇒ Object
74
75
76
|
# File 'lib/avalon/btcguild.rb', line 74
def unpaid
access :user, :unpaid_rewards, 3
end
|
#unpaid_nmc ⇒ Object
82
83
84
|
# File 'lib/avalon/btcguild.rb', line 82
def unpaid_nmc
access :user, :unpaid_rewards_nmc, 2
end
|