expedition 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +43 -1
- data/lib/expedition/client.rb +33 -1
- data/lib/expedition/version.rb +1 -1
- data/spec/expedition/client_spec.rb +109 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0cef207a11eed24a6983827999f5035ac80fdcf4
|
4
|
+
data.tar.gz: eb87eedfe67d6885d5d65e070027155bbf2fb797
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9b37bc91c9ef1a071ced968e5b591429b95d430d15ca52d902f1d201d44534efff3610e0c980e215bac31952d3d55f85e61604e3f8305dc992430a378bc1987
|
7
|
+
data.tar.gz: 3299a161b09dfd39249d36c4f1652af2552e66f78068b525f84c7730466f7f1c29b3f0b84467919c9bad435edb8f13c04d21190c39e423a32ad1062392677782
|
data/README.md
CHANGED
@@ -34,7 +34,49 @@ Or install it yourself as:
|
|
34
34
|
|
35
35
|
## Usage
|
36
36
|
|
37
|
-
|
37
|
+
A client can be initialized with an optional host and port (defaulting to
|
38
|
+
`localhost`, port `4028`):
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
client = Expedition.new(host, port)
|
42
|
+
```
|
43
|
+
|
44
|
+
Querying is done by calling the method you wish to send:
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
response = client.pools
|
48
|
+
# => #<Expedition::Response ...>
|
49
|
+
|
50
|
+
response.body
|
51
|
+
# => [{"pool"=>0,
|
52
|
+
# "url"=>"stratum+tcp://pool.example.com:3333",
|
53
|
+
# "status"=>"alive"
|
54
|
+
# ...}]
|
55
|
+
|
56
|
+
response.status
|
57
|
+
# => #<Expedition::Status
|
58
|
+
# @code=7
|
59
|
+
# @description="sgminer 4.1.153",
|
60
|
+
# @executed_at=2014-05-13 17:51:53 -0700,
|
61
|
+
# @message="1 Pool(s)",
|
62
|
+
# @severity=:success>>
|
63
|
+
|
64
|
+
response.ok?
|
65
|
+
# => true
|
66
|
+
```
|
67
|
+
|
68
|
+
## Supported API Methods
|
69
|
+
|
70
|
+
Expedition overrides `#method_missing` to allow sending *any* method to a
|
71
|
+
running miner. For convenience and additional sugar, the following methods are
|
72
|
+
implemented which offer parsed timestamps, and more consistent responses:
|
73
|
+
|
74
|
+
* `#devices` - Detailed information about devices.
|
75
|
+
* `#metrics` - Detailed statistics for all devices.
|
76
|
+
* `#pools` - Pool information and statistics.
|
77
|
+
|
78
|
+
In need of another method?
|
79
|
+
[Open an issue](https://github.com/gevans/expedition/issues/new).
|
38
80
|
|
39
81
|
## Contributing
|
40
82
|
|
data/lib/expedition/client.rb
CHANGED
@@ -29,6 +29,12 @@ module Expedition
|
|
29
29
|
@port = port
|
30
30
|
end
|
31
31
|
|
32
|
+
##
|
33
|
+
# Sends the `devdetails` command, returning an array of devices found in the
|
34
|
+
# service's response.
|
35
|
+
#
|
36
|
+
# @return [Response]
|
37
|
+
# An array of devices.
|
32
38
|
def devices
|
33
39
|
send(:devdetails) do |body|
|
34
40
|
body[:devdetails].collect { |attrs|
|
@@ -39,12 +45,30 @@ module Expedition
|
|
39
45
|
end
|
40
46
|
end
|
41
47
|
|
48
|
+
##
|
49
|
+
# Sends the `devs` command, returning an array of metrics found in the
|
50
|
+
# service's response.
|
51
|
+
#
|
52
|
+
# @return [Response]
|
53
|
+
# An array of metrics.
|
42
54
|
def metrics
|
43
55
|
send(:devs) do |body|
|
44
56
|
body[:devs].collect(&method(:parse_metrics))
|
45
57
|
end
|
46
58
|
end
|
47
59
|
|
60
|
+
##
|
61
|
+
# Sends the `pools` command, returning an array of pools found in the
|
62
|
+
# service's response.
|
63
|
+
#
|
64
|
+
# @return [Response]
|
65
|
+
# An array of pools.
|
66
|
+
def pools
|
67
|
+
send(:pools) do |body|
|
68
|
+
body[:pools].collect(&method(:parse_pool))
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
48
72
|
##
|
49
73
|
# Sends the supplied `command` with optionally supplied `parameters` to the
|
50
74
|
# service and returns the result, if any.
|
@@ -61,7 +85,7 @@ module Expedition
|
|
61
85
|
# @return [Response]
|
62
86
|
# The service's response.
|
63
87
|
def send(command, *parameters, &block)
|
64
|
-
socket = TCPSocket.
|
88
|
+
socket = TCPSocket.open(host, port)
|
65
89
|
socket.puts command_json(command, *parameters)
|
66
90
|
|
67
91
|
parse(socket.gets, &block)
|
@@ -97,5 +121,13 @@ module Expedition
|
|
97
121
|
khs: attrs.delete("khs_#{interval}")
|
98
122
|
)
|
99
123
|
end
|
124
|
+
|
125
|
+
def parse_pool(attrs)
|
126
|
+
attrs.merge!(
|
127
|
+
status: attrs[:status].downcase,
|
128
|
+
long_poll: attrs[:long_poll] != 'N',
|
129
|
+
last_share_time: (Time.at(attrs[:last_share_time]) rescue attrs[:last_share_time]),
|
130
|
+
)
|
131
|
+
end
|
100
132
|
end # Client
|
101
133
|
end # Expedition
|
data/lib/expedition/version.rb
CHANGED
@@ -42,7 +42,7 @@ describe Expedition::Client do
|
|
42
42
|
end
|
43
43
|
|
44
44
|
before do
|
45
|
-
allow(TCPSocket).to receive(:
|
45
|
+
allow(TCPSocket).to receive(:open).and_return(socket)
|
46
46
|
end
|
47
47
|
|
48
48
|
it 'sends supplied command and parameters to configured host and port' do
|
@@ -121,7 +121,7 @@ describe Expedition::Client do
|
|
121
121
|
end
|
122
122
|
|
123
123
|
before do
|
124
|
-
allow(TCPSocket).to receive(:
|
124
|
+
allow(TCPSocket).to receive(:open).and_return(socket)
|
125
125
|
allow(socket).to receive(:puts)
|
126
126
|
allow(socket).to receive(:gets).and_return(response)
|
127
127
|
end
|
@@ -177,7 +177,7 @@ describe Expedition::Client do
|
|
177
177
|
'STATUS' => 'S',
|
178
178
|
'When' => 1399419744,
|
179
179
|
'Code' => 9,
|
180
|
-
'Msg' => '
|
180
|
+
'Msg' => '1 GPU(s)',
|
181
181
|
'Description' => 'sgminer 4.1.153'
|
182
182
|
}
|
183
183
|
],
|
@@ -221,7 +221,7 @@ describe Expedition::Client do
|
|
221
221
|
end
|
222
222
|
|
223
223
|
before do
|
224
|
-
allow(TCPSocket).to receive(:
|
224
|
+
allow(TCPSocket).to receive(:open).and_return(socket)
|
225
225
|
allow(socket).to receive(:puts)
|
226
226
|
allow(socket).to receive(:gets).and_return(response)
|
227
227
|
end
|
@@ -262,4 +262,109 @@ describe Expedition::Client do
|
|
262
262
|
])
|
263
263
|
end
|
264
264
|
end
|
265
|
+
|
266
|
+
describe '#pools' do
|
267
|
+
|
268
|
+
subject(:pools) do
|
269
|
+
client.pools
|
270
|
+
end
|
271
|
+
|
272
|
+
let(:client) do
|
273
|
+
described_class.new
|
274
|
+
end
|
275
|
+
|
276
|
+
let(:socket) do
|
277
|
+
double(TCPSocket)
|
278
|
+
end
|
279
|
+
|
280
|
+
let(:response) do
|
281
|
+
{
|
282
|
+
'STATUS' => [
|
283
|
+
{
|
284
|
+
'STATUS' => 'S',
|
285
|
+
'When' => 1400026784,
|
286
|
+
'Code' => 7,
|
287
|
+
'Msg' => '1 Pool(s)',
|
288
|
+
'Description' => 'sgminer 4.1.153'
|
289
|
+
}
|
290
|
+
],
|
291
|
+
'POOLS' => [
|
292
|
+
{
|
293
|
+
'POOL' => 0,
|
294
|
+
'URL' => 'stratum+tcp://us-west2.multipool.us:3352',
|
295
|
+
'Status' => 'Alive',
|
296
|
+
'Priority' => 0,
|
297
|
+
'Quota' => 1,
|
298
|
+
'Long Poll' => 'N',
|
299
|
+
'Getworks' => 31,
|
300
|
+
'Accepted' => 413,
|
301
|
+
'Rejected' => 0,
|
302
|
+
'Works' => 206,
|
303
|
+
'Discarded' => 1256,
|
304
|
+
'Stale' => 0,
|
305
|
+
'Get Failures' => 0,
|
306
|
+
'Remote Failures' => 0,
|
307
|
+
'User' => 'nobody',
|
308
|
+
'Last Share Time' => 1400026781,
|
309
|
+
'Diff1 Shares' => 52523,
|
310
|
+
'Proxy Type' => '',
|
311
|
+
'Proxy' => '',
|
312
|
+
'Difficulty Accepted' => 52864.0,
|
313
|
+
'Difficulty Rejected' => 0.0,
|
314
|
+
'Difficulty Stale' => 0.0,
|
315
|
+
'Last Share Difficulty' => 128.0,
|
316
|
+
'Has Stratum' => true,
|
317
|
+
'Stratum Active' => true,
|
318
|
+
'Stratum URL' => 'us-west2.multipool.us',
|
319
|
+
'Has GBT' => false,
|
320
|
+
'Best Share' => 22673,
|
321
|
+
'Pool Rejected%' => 0.0,
|
322
|
+
'Pool Stale%' => 0.0
|
323
|
+
}
|
324
|
+
],
|
325
|
+
'id' => 1
|
326
|
+
}.to_json
|
327
|
+
end
|
328
|
+
|
329
|
+
before do
|
330
|
+
allow(TCPSocket).to receive(:open).and_return(socket)
|
331
|
+
allow(socket).to receive(:puts)
|
332
|
+
allow(socket).to receive(:gets).and_return(response)
|
333
|
+
end
|
334
|
+
|
335
|
+
specify do
|
336
|
+
expect(pools.body).to eq([
|
337
|
+
'pool' => 0,
|
338
|
+
'url' => 'stratum+tcp://us-west2.multipool.us:3352',
|
339
|
+
'status' => 'alive',
|
340
|
+
'priority' => 0,
|
341
|
+
'quota' => 1,
|
342
|
+
'long_poll' => false,
|
343
|
+
'getworks' => 31,
|
344
|
+
'accepted' => 413,
|
345
|
+
'rejected' => 0,
|
346
|
+
'works' => 206,
|
347
|
+
'discarded' => 1256,
|
348
|
+
'stale' => 0,
|
349
|
+
'get_failures' => 0,
|
350
|
+
'remote_failures' => 0,
|
351
|
+
'user' => 'nobody',
|
352
|
+
'last_share_time' => Time.utc(2014, 05, 14, 0, 19, 41),
|
353
|
+
'diff1_shares' => 52523,
|
354
|
+
'proxy_type' => '',
|
355
|
+
'proxy' => '',
|
356
|
+
'difficulty_accepted' => 52864.0,
|
357
|
+
'difficulty_rejected' => 0.0,
|
358
|
+
'difficulty_stale' => 0.0,
|
359
|
+
'last_share_difficulty' => 128.0,
|
360
|
+
'has_stratum' => true,
|
361
|
+
'stratum_active' => true,
|
362
|
+
'stratum_url' => 'us-west2.multipool.us',
|
363
|
+
'has_gbt' => false,
|
364
|
+
'best_share' => 22673,
|
365
|
+
'pool_rejected_percent' => 0.0,
|
366
|
+
'pool_stale_percent' => 0.0
|
367
|
+
])
|
368
|
+
end
|
369
|
+
end
|
265
370
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: expedition
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabe Evans
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|