xrbp 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +1 -0
- data/examples/accounts.rb +2 -1
- data/lib/xrbp.rb +1 -0
- data/lib/xrbp/json.rb +7 -0
- data/lib/xrbp/model/account.rb +26 -7
- data/lib/xrbp/plugins/has_plugin.rb +1 -1
- data/lib/xrbp/version.rb +1 -1
- data/lib/xrbp/websocket/client.rb +1 -1
- data/lib/xrbp/websocket/command.rb +0 -2
- data/lib/xrbp/websocket/plugins/message_dispatcher.rb +7 -0
- data/spec/xrbp/websocket/command_spec.rb +6 -8
- data/spec/xrbp/websocket/message_spec.rb +17 -4
- data/spec/xrbp/websocket/plugins/cmd_dispatcher_spec.rb +2 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30fb389dec1e019a299501a035cb5131332fec5b3cc192f24be9ad280aaf60e4
|
4
|
+
data.tar.gz: 8bec54f51b34ebbee7a2f433191d6dbe72e07fb3d2c60c1d3caa0b818c4da1f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f62bb3b3c347d42c29f227afd7398257078b6a30996a82f06d0952a337dcea495b33707a8430432c9945214d0609efde2c73a37472a23dfdeba9ab4ee13aebe3
|
7
|
+
data.tar.gz: d156f474e8d54a4583f3b41516caa9fb6e55d1c1d7edc6d04838f7066e93a560b48485880bdd2b1cf15b7aeb05c93087542dbf1ad80e5f8620a24dee16592e5f
|
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--no-private
|
data/examples/accounts.rb
CHANGED
data/lib/xrbp.rb
CHANGED
data/lib/xrbp/json.rb
ADDED
data/lib/xrbp/model/account.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'date'
|
1
2
|
require 'fileutils'
|
2
3
|
require_relative './parsers/account'
|
3
4
|
|
@@ -6,7 +7,7 @@ module XRBP
|
|
6
7
|
class Account < Base
|
7
8
|
extend Base::ClassMethods
|
8
9
|
|
9
|
-
|
10
|
+
DATE_FORMAT = "%Y-%m-%dT%H:%M:%SZ"
|
10
11
|
|
11
12
|
attr_accessor :id
|
12
13
|
|
@@ -17,11 +18,15 @@ module XRBP
|
|
17
18
|
|
18
19
|
# All cached accounts
|
19
20
|
def self.cached
|
20
|
-
Dir.glob("#{cache}/*").collect { |f|
|
21
|
+
Dir.glob("#{cache}/*").sort.collect { |f|
|
21
22
|
next nil if f == "#{cache}marker" ||
|
22
23
|
f == "#{cache}start"
|
23
24
|
begin
|
24
25
|
JSON.parse(File.read(f))
|
26
|
+
.collect { |acct|
|
27
|
+
# convert string keys to symbols
|
28
|
+
Hash[acct.map { |k,v| [k.intern, v] }]
|
29
|
+
}
|
25
30
|
rescue
|
26
31
|
nil
|
27
32
|
end
|
@@ -51,14 +56,20 @@ module XRBP
|
|
51
56
|
set_opts(opts)
|
52
57
|
FileUtils.mkdir_p(cache) unless File.exist?(cache)
|
53
58
|
|
59
|
+
cached.each { |acct|
|
60
|
+
break if connection.force_quit?
|
61
|
+
connection.emit :account, acct
|
62
|
+
} if opts[:replay]
|
63
|
+
|
54
64
|
# start at last marker
|
55
65
|
marker = File.exist?("#{cache}/marker") ?
|
56
66
|
File.read("#{cache}/marker") : nil
|
67
|
+
marker = nil if marker.strip.empty?
|
57
68
|
|
58
69
|
# load start time, if set
|
59
70
|
start = File.exist?("#{cache}/start") ?
|
60
|
-
|
61
|
-
GENESIS_TIME
|
71
|
+
DateTime.parse(File.read("#{cache}/start")) :
|
72
|
+
GENESIS_TIME
|
62
73
|
|
63
74
|
# Parse results
|
64
75
|
connection.add_plugin :result_parser unless connection.plugin?(:result_parser)
|
@@ -70,11 +81,14 @@ module XRBP
|
|
70
81
|
until finished || connection.force_quit?
|
71
82
|
# HTTP request
|
72
83
|
connection.url = "https://data.ripple.com/v2/accounts/?"\
|
73
|
-
"start=#{start}&
|
84
|
+
"start=#{start.strftime(DATE_FORMAT)}&"\
|
85
|
+
"limit=1000&marker=#{marker}"
|
74
86
|
res = connection.perform
|
87
|
+
break if connection.force_quit?
|
88
|
+
break unless res[:accounts] && !res[:accounts].empty?
|
75
89
|
|
76
90
|
# Cache data
|
77
|
-
cache_file = "#{cache}/#{marker || "
|
91
|
+
cache_file = "#{cache}/#{marker || start.strftime("%Y%m%d%H%M%S")}"
|
78
92
|
File.write(cache_file, res[:accounts].to_json)
|
79
93
|
|
80
94
|
# Emit signal
|
@@ -94,8 +108,13 @@ module XRBP
|
|
94
108
|
end
|
95
109
|
|
96
110
|
# Store state for next run
|
111
|
+
# FIXME: results in an overlap, accounts created
|
112
|
+
# at this inception will also be retrieved
|
113
|
+
# during next run
|
97
114
|
File.write("#{cache}/start",
|
98
|
-
accounts.last[:inception]) unless
|
115
|
+
accounts.last[:inception]) unless connection.force_quit? ||
|
116
|
+
accounts.empty? ||
|
117
|
+
marker
|
99
118
|
|
100
119
|
accounts
|
101
120
|
end
|
data/lib/xrbp/version.rb
CHANGED
@@ -119,6 +119,13 @@ module XRBP
|
|
119
119
|
true
|
120
120
|
end
|
121
121
|
|
122
|
+
# FIXME: I *believe* there is issue causing deadlock at process
|
123
|
+
# termination where subsequent pages in paginated cmds
|
124
|
+
# are timing out. Since when retrieving messages
|
125
|
+
# synchronously, the first message block will be used
|
126
|
+
# to wait for the results and on timeout cancel_message
|
127
|
+
# will be called with the _latest_ message, the wait
|
128
|
+
# block never gets unlocked.
|
122
129
|
def cancel_message(msg)
|
123
130
|
connection.state_mutex.synchronize {
|
124
131
|
messages.delete(msg)
|
@@ -1,13 +1,11 @@
|
|
1
1
|
describe XRBP::WebSocket::Command do
|
2
|
-
|
3
|
-
subject { described_class.new(command: 'test') }
|
2
|
+
subject { described_class.new(command: 'test') }
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
it 'returns command being requested' do
|
5
|
+
expect(subject.requesting).to eq 'test'
|
6
|
+
end
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
end
|
8
|
+
it 'returns bool indicating if we are request command' do
|
9
|
+
expect(subject).to be_requesting('test')
|
12
10
|
end
|
13
11
|
end
|
@@ -4,21 +4,34 @@ describe XRBP::WebSocket::Message do
|
|
4
4
|
subject { described_class.new 'Test message' }
|
5
5
|
let(:connection) { XRBP::WebSocket::Connection.new "*" }
|
6
6
|
|
7
|
+
before(:each) do
|
8
|
+
subject.connection = connection
|
9
|
+
end
|
10
|
+
|
7
11
|
it 'returns message text' do
|
8
12
|
expect(subject.to_s).to eq 'Test message'
|
9
13
|
end
|
10
14
|
|
11
15
|
it 'waits for signal' do
|
12
|
-
|
16
|
+
Thread.new {
|
17
|
+
sleep(0.1)
|
18
|
+
subject.signal
|
19
|
+
}
|
20
|
+
subject.wait
|
13
21
|
end
|
14
22
|
|
15
23
|
it 'waits for connection close' do
|
16
24
|
expect(connection).to receive(:closed?).and_return true
|
17
|
-
subject.connection = connection
|
18
25
|
expect(subject.wait).to be_nil
|
19
26
|
end
|
20
27
|
|
21
|
-
|
22
|
-
|
28
|
+
describe "#bl" do
|
29
|
+
it 'defaults to callback which signals wait condition' do
|
30
|
+
Thread.new {
|
31
|
+
sleep(0.1)
|
32
|
+
subject.bl.call
|
33
|
+
}
|
34
|
+
subject.wait
|
35
|
+
end
|
23
36
|
end
|
24
37
|
end
|
@@ -11,7 +11,8 @@
|
|
11
11
|
# Camcorder.intercept_constructor XRBP::WebSocket::Socket
|
12
12
|
#
|
13
13
|
# # XXX fix random
|
14
|
-
# allow(
|
14
|
+
# allow(handshake.instance_variable_get(:@handler)).to receive(:rand).with(255).and_return(100)
|
15
|
+
# #allow(SecureRandom).to receive(:random_bytes).with(4).and_return('1234')
|
15
16
|
# end
|
16
17
|
#
|
17
18
|
# after(:each) do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xrbp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dev Null Productions
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-04-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -115,6 +115,7 @@ executables: []
|
|
115
115
|
extensions: []
|
116
116
|
extra_rdoc_files: []
|
117
117
|
files:
|
118
|
+
- ".yardopts"
|
118
119
|
- LICENSE.txt
|
119
120
|
- README.md
|
120
121
|
- examples/accounts.rb
|
@@ -148,6 +149,7 @@ files:
|
|
148
149
|
- lib/xrbp/dsl/validators.rb
|
149
150
|
- lib/xrbp/dsl/webclient.rb
|
150
151
|
- lib/xrbp/dsl/websocket.rb
|
152
|
+
- lib/xrbp/json.rb
|
151
153
|
- lib/xrbp/model.rb
|
152
154
|
- lib/xrbp/model/account.rb
|
153
155
|
- lib/xrbp/model/base.rb
|