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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 92361edaa1feff8405d57bd715093cd1211d0adb2b0175f5d3f6493542526c3c
4
- data.tar.gz: a9a9d1e8a6d1c2682f8e4c685ca0c7f73da74b37bee211af2afc39ac53600cd9
3
+ metadata.gz: 30fb389dec1e019a299501a035cb5131332fec5b3cc192f24be9ad280aaf60e4
4
+ data.tar.gz: 8bec54f51b34ebbee7a2f433191d6dbe72e07fb3d2c60c1d3caa0b818c4da1f8
5
5
  SHA512:
6
- metadata.gz: 7e327415d681a20d7e9d5abdbaf5d0e052a7562124f83a8171645fda5321b2a692be042d8230881c4a3cd13c032c661aa2c6566b87574aabf16482a0d436fc8c
7
- data.tar.gz: b26cfa8b7a106f15385d4210e1b8972771c3400e57721f72095f1a2f84504cd6e91d0a22fb2f2a958c17e37e22652cf6041c10196f732a58788aab72eab1497f
6
+ metadata.gz: f62bb3b3c347d42c29f227afd7398257078b6a30996a82f06d0952a337dcea495b33707a8430432c9945214d0609efde2c73a37472a23dfdeba9ab4ee13aebe3
7
+ data.tar.gz: d156f474e8d54a4583f3b41516caa9fb6e55d1c1d7edc6d04838f7066e93a560b48485880bdd2b1cf15b7aeb05c93087542dbf1ad80e5f8620a24dee16592e5f
@@ -0,0 +1 @@
1
+ --no-private
@@ -10,4 +10,5 @@ Signal.trap("INT") {
10
10
  connection.force_quit!
11
11
  }
12
12
 
13
- XRBP::Model::Account.all(:connection => connection)
13
+ XRBP::Model::Account.all(:connection => connection,
14
+ :replay => true)
@@ -1,5 +1,6 @@
1
1
  require 'event_emitter'
2
2
 
3
+ require 'xrbp/json'
3
4
  require 'xrbp/common'
4
5
  require 'xrbp/terminatable'
5
6
  require 'xrbp/plugins'
@@ -0,0 +1,7 @@
1
+ # Attempt to use yajl bindings,
2
+ # else fallback to stock json
3
+ begin
4
+ require 'yajl/json_gem'
5
+ rescue LoadError
6
+ require 'json'
7
+ end
@@ -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
- DATE_FORMAT = "%Y-%m-%dT%H:%M:%SZ"
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
- File.read("#{cache}/start") :
61
- GENESIS_TIME.strftime(DATE_FORMAT)
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}&limit=1000&marker=#{marker}"
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 || "genesis"}"
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 marker
115
+ accounts.last[:inception]) unless connection.force_quit? ||
116
+ accounts.empty? ||
117
+ marker
99
118
 
100
119
  accounts
101
120
  end
@@ -32,7 +32,7 @@ module XRBP
32
32
  cls = plugin_namespace.plugins[plg]
33
33
  plugins.find { |_plg|
34
34
  (plg.is_a?(Class) && _plg.kind_of?(plg)) ||
35
- (cls.is_a?(Class) && _plg.class.kind_of?(cls))
35
+ (cls.is_a?(Class) && _plg.kind_of?(cls))
36
36
  }
37
37
  end
38
38
 
@@ -1,3 +1,3 @@
1
1
  module XRBP
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.3'
3
3
  end # module XRBP
@@ -109,7 +109,7 @@ module XRBP
109
109
  def handshake!
110
110
  socket.write handshake.to_s
111
111
 
112
- until handshaked?
112
+ until handshaked? || closed? #|| connection.force_quit?
113
113
  socket.read_next handshake
114
114
  @handshaked = handshake.finished?
115
115
  end
@@ -1,5 +1,3 @@
1
- require 'json'
2
-
3
1
  module XRBP
4
2
  module WebSocket
5
3
  class Command < Message
@@ -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
- context "command specified" do
3
- subject { described_class.new(command: 'test') }
2
+ subject { described_class.new(command: 'test') }
4
3
 
5
- it 'returns command' do
6
- expect(subject.requesting).to eq 'test'
7
- end
4
+ it 'returns command being requested' do
5
+ expect(subject.requesting).to eq 'test'
6
+ end
8
7
 
9
- it 'is requesting' do
10
- expect(subject).to be_requesting('test')
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
- expect(subject.signal).to be(subject)
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
- it 'returns proc which waites for signal' do
22
- expect(subject.bl.call).to be(subject)
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(SecureRandom).to receive(:random_bytes).with(4).and_return('1234')
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.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-03-27 00:00:00.000000000 Z
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