xrbp 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +103 -5
  3. data/examples/accounts.rb +13 -0
  4. data/examples/autoconnect_timeout.rb +5 -1
  5. data/examples/autorety.rb +7 -0
  6. data/examples/crawl_nodes.rb +32 -0
  7. data/examples/dsl/account.rb +16 -0
  8. data/examples/dsl/ledger.rb +7 -0
  9. data/examples/dsl/ledger_subscribe.rb +18 -0
  10. data/examples/dsl/validators.rb +8 -0
  11. data/examples/gateways.rb +8 -0
  12. data/examples/latest_account.rb +4 -0
  13. data/examples/ledger_multi_subscribe.rb +1 -1
  14. data/examples/ledger_subscribe.rb +2 -2
  15. data/examples/market.rb +13 -0
  16. data/examples/username.rb +12 -0
  17. data/examples/validator.rb +8 -0
  18. data/lib/xrbp.rb +5 -1
  19. data/lib/xrbp/common.rb +10 -0
  20. data/lib/xrbp/core_ext.rb +24 -0
  21. data/lib/xrbp/dsl.rb +25 -0
  22. data/lib/xrbp/dsl/accounts.rb +13 -0
  23. data/lib/xrbp/dsl/ledgers.rb +23 -0
  24. data/lib/xrbp/dsl/validators.rb +10 -0
  25. data/lib/xrbp/dsl/webclient.rb +8 -0
  26. data/lib/xrbp/dsl/websocket.rb +28 -0
  27. data/lib/xrbp/model.rb +4 -0
  28. data/lib/xrbp/model/account.rb +142 -1
  29. data/lib/xrbp/model/base.rb +1 -0
  30. data/lib/xrbp/model/gateway.rb +24 -0
  31. data/lib/xrbp/model/ledger.rb +30 -1
  32. data/lib/xrbp/model/market.rb +52 -0
  33. data/lib/xrbp/model/node.rb +131 -0
  34. data/lib/xrbp/model/parsers/account.rb +44 -0
  35. data/lib/xrbp/model/parsers/gateway.rb +40 -0
  36. data/lib/xrbp/model/parsers/market.rb +28 -0
  37. data/lib/xrbp/model/parsers/node.rb +19 -0
  38. data/lib/xrbp/model/parsers/quote.rb +47 -0
  39. data/lib/xrbp/model/parsers/validator.rb +25 -0
  40. data/lib/xrbp/model/validator.rb +24 -0
  41. data/lib/xrbp/plugins.rb +6 -0
  42. data/lib/xrbp/plugins/base.rb +10 -0
  43. data/lib/xrbp/plugins/has_plugin.rb +45 -0
  44. data/lib/xrbp/plugins/has_result_parsers.rb +27 -0
  45. data/lib/xrbp/plugins/plugin_registry.rb +20 -0
  46. data/lib/xrbp/plugins/result_parser.rb +19 -0
  47. data/lib/xrbp/terminatable.rb +19 -0
  48. data/lib/xrbp/thread_registry.rb +22 -0
  49. data/lib/xrbp/version.rb +1 -1
  50. data/lib/xrbp/webclient.rb +2 -0
  51. data/lib/xrbp/webclient/connection.rb +100 -0
  52. data/lib/xrbp/webclient/plugins.rb +8 -0
  53. data/lib/xrbp/webclient/plugins/autoretry.rb +54 -0
  54. data/lib/xrbp/webclient/plugins/result_parser.rb +23 -0
  55. data/lib/xrbp/websocket/client.rb +85 -24
  56. data/lib/xrbp/websocket/cmds/account_info.rb +4 -0
  57. data/lib/xrbp/websocket/cmds/account_lines.rb +5 -0
  58. data/lib/xrbp/websocket/cmds/account_objects.rb +4 -0
  59. data/lib/xrbp/websocket/cmds/account_offers.rb +5 -0
  60. data/lib/xrbp/websocket/cmds/account_tx.rb +4 -0
  61. data/lib/xrbp/websocket/cmds/book_offers.rb +4 -0
  62. data/lib/xrbp/websocket/cmds/ledger.rb +3 -0
  63. data/lib/xrbp/websocket/cmds/ledger_entry.rb +4 -0
  64. data/lib/xrbp/websocket/cmds/paginated.rb +4 -1
  65. data/lib/xrbp/websocket/cmds/server_info.rb +4 -0
  66. data/lib/xrbp/websocket/cmds/subscribe.rb +4 -0
  67. data/lib/xrbp/websocket/command.rb +11 -0
  68. data/lib/xrbp/websocket/connection.rb +75 -22
  69. data/lib/xrbp/websocket/message.rb +5 -2
  70. data/lib/xrbp/websocket/multi/fallback.rb +2 -4
  71. data/lib/xrbp/websocket/multi/multi_connection.rb +37 -2
  72. data/lib/xrbp/websocket/multi/parallel.rb +2 -4
  73. data/lib/xrbp/websocket/multi/prioritized.rb +2 -4
  74. data/lib/xrbp/websocket/multi/round_robin.rb +4 -0
  75. data/lib/xrbp/websocket/plugins.rb +1 -7
  76. data/lib/xrbp/websocket/plugins/autoconnect.rb +25 -5
  77. data/lib/xrbp/websocket/plugins/command_dispatcher.rb +5 -0
  78. data/lib/xrbp/websocket/plugins/command_paginator.rb +9 -8
  79. data/lib/xrbp/websocket/plugins/connection_timeout.rb +27 -16
  80. data/lib/xrbp/websocket/plugins/message_dispatcher.rb +60 -30
  81. data/lib/xrbp/websocket/plugins/result_parser.rb +19 -19
  82. data/lib/xrbp/websocket/socket.rb +23 -6
  83. metadata +118 -8
  84. data/lib/xrbp/network.rb +0 -6
  85. data/lib/xrbp/network/nodes.rb +0 -8
  86. data/lib/xrbp/websocket/has_plugin.rb +0 -30
@@ -1,27 +1,27 @@
1
1
  module XRBP
2
2
  module WebSocket
3
3
  module Plugins
4
- class ResultParser
5
- attr_accessor :parser, :connection
4
+ # Plugin to automatically parse and convert websocket results,
5
+ # before returning.
6
+ #
7
+ # @example parse json
8
+ # connection = WebClient::Connection.new "wss://s1.ripple.com:443"
9
+ # connection.add_plugin :command_dispatcher, :result_parser
10
+ #
11
+ # connection.parse_results do |res|
12
+ # JSON.parse(res)
13
+ # end
14
+ #
15
+ # puts connection.cmd(WebSocket::Cmds::ServerInfo.new)["result"]["info"]["build_version"]
16
+ class ResultParser < ResultParserBase
17
+ def parser=(p)
18
+ super(p)
6
19
 
7
- def initialize(connection)
8
- @connection = connection
9
- end
10
-
11
- def added
12
- plugin = self
13
- connection.define_instance_method(:parse_results) do |&bl|
14
- plugin.parser = bl
15
-
16
- self.connections.each { |conn|
17
- conn.parse_results &bl
18
- } if self.kind_of?(MultiConnection)
19
- end
20
- end
20
+ self.connection.connections.each { |conn|
21
+ conn.parse_results &p
22
+ } if self.connection.kind_of?(MultiConnection)
21
23
 
22
- def parse_result(res)
23
- return res unless parser
24
- parser.call(res)
24
+ p
25
25
  end
26
26
  end # class ResultParser
27
27
 
@@ -4,6 +4,10 @@ require 'openssl'
4
4
 
5
5
  module XRBP
6
6
  module WebSocket
7
+ # Low level wrapper around TCPSocket operations, providing
8
+ # mechanisms to negotiate base websocket connection.
9
+ #
10
+ # @private
7
11
  class Socket
8
12
  DEFAULT_PORTS = {:ws => 80,
9
13
  :http => 80,
@@ -11,19 +15,27 @@ module XRBP
11
15
  :https => 443}
12
16
 
13
17
 
14
- attr_reader :connection, :socket, :pipe_broken
18
+ attr_reader :pipe_broken
19
+
20
+ attr_accessor :client
21
+
22
+ private
23
+
24
+ attr_reader :socket
25
+
26
+ public
15
27
 
16
28
  def options
17
- connection.options
29
+ client.options
18
30
  end
19
31
 
20
- def initialize(connection)
21
- @connection = connection
32
+ def initialize(client)
33
+ @client = client
22
34
  @pipe_broken = false
23
35
  end
24
36
 
25
37
  def connect
26
- uri = URI.parse connection.url
38
+ uri = URI.parse client.url
27
39
  host = uri.host
28
40
  port = uri.port || DEFAULT_PORTS[uri.scheme.intern]
29
41
 
@@ -31,8 +43,11 @@ module XRBP
31
43
  socket.setsockopt(::Socket::IPPROTO_TCP, ::Socket::TCP_NODELAY, 1)
32
44
 
33
45
  init_ssl_socket if ['https', 'wss'].include? uri.scheme
46
+ nil
34
47
  end
35
48
 
49
+ private
50
+
36
51
  def init_ssl_socket
37
52
  ssl_context = options[:ssl_context] || begin
38
53
  ctx = OpenSSL::SSL::SSLContext.new
@@ -55,6 +70,8 @@ module XRBP
55
70
 
56
71
  ###
57
72
 
73
+ public
74
+
58
75
  def close
59
76
  socket.close if socket
60
77
  end
@@ -87,7 +104,7 @@ module XRBP
87
104
 
88
105
  def read_next(dest)
89
106
  begin
90
- read_sockets, _, _ = IO.select([socket], nil, nil, 10)
107
+ read_sockets, _, _ = IO.select([socket], nil, nil, 0.1)
91
108
 
92
109
  if read_sockets && read_sockets[0]
93
110
  dest << socket.read_nonblock(1024)
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xrbp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
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-13 00:00:00.000000000 Z
11
+ date: 2019-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: websocket
14
+ name: json
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.2'
19
+ version: '2.1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.2'
26
+ version: '2.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: event_emitter
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +38,76 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: concurrent-ruby
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: websocket
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.2'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: curb
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.9'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.9'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.8'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.8'
97
+ - !ruby/object:Gem::Dependency
98
+ name: camcorder
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.0.5
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.0.5
41
111
  description: Ruby XRP Tools
42
112
  email:
43
113
  - devnullproductions@gmail.com
@@ -47,24 +117,65 @@ extra_rdoc_files: []
47
117
  files:
48
118
  - LICENSE.txt
49
119
  - README.md
120
+ - examples/accounts.rb
50
121
  - examples/autoconnect_timeout.rb
122
+ - examples/autorety.rb
51
123
  - examples/cmd.rb
124
+ - examples/crawl_nodes.rb
125
+ - examples/dsl/account.rb
126
+ - examples/dsl/ledger.rb
127
+ - examples/dsl/ledger_subscribe.rb
128
+ - examples/dsl/validators.rb
129
+ - examples/gateways.rb
130
+ - examples/latest_account.rb
52
131
  - examples/ledger.rb
53
132
  - examples/ledger_multi_subscribe.rb
54
133
  - examples/ledger_subscribe.rb
134
+ - examples/market.rb
55
135
  - examples/multi.rb
56
136
  - examples/paginate.rb
57
137
  - examples/prioritized.rb
58
138
  - examples/round_robin.rb
139
+ - examples/username.rb
140
+ - examples/validator.rb
59
141
  - examples/websocket.rb
60
142
  - lib/xrbp.rb
143
+ - lib/xrbp/common.rb
144
+ - lib/xrbp/core_ext.rb
145
+ - lib/xrbp/dsl.rb
146
+ - lib/xrbp/dsl/accounts.rb
147
+ - lib/xrbp/dsl/ledgers.rb
148
+ - lib/xrbp/dsl/validators.rb
149
+ - lib/xrbp/dsl/webclient.rb
150
+ - lib/xrbp/dsl/websocket.rb
61
151
  - lib/xrbp/model.rb
62
152
  - lib/xrbp/model/account.rb
63
153
  - lib/xrbp/model/base.rb
154
+ - lib/xrbp/model/gateway.rb
64
155
  - lib/xrbp/model/ledger.rb
65
- - lib/xrbp/network.rb
66
- - lib/xrbp/network/nodes.rb
156
+ - lib/xrbp/model/market.rb
157
+ - lib/xrbp/model/node.rb
158
+ - lib/xrbp/model/parsers/account.rb
159
+ - lib/xrbp/model/parsers/gateway.rb
160
+ - lib/xrbp/model/parsers/market.rb
161
+ - lib/xrbp/model/parsers/node.rb
162
+ - lib/xrbp/model/parsers/quote.rb
163
+ - lib/xrbp/model/parsers/validator.rb
164
+ - lib/xrbp/model/validator.rb
165
+ - lib/xrbp/plugins.rb
166
+ - lib/xrbp/plugins/base.rb
167
+ - lib/xrbp/plugins/has_plugin.rb
168
+ - lib/xrbp/plugins/has_result_parsers.rb
169
+ - lib/xrbp/plugins/plugin_registry.rb
170
+ - lib/xrbp/plugins/result_parser.rb
171
+ - lib/xrbp/terminatable.rb
172
+ - lib/xrbp/thread_registry.rb
67
173
  - lib/xrbp/version.rb
174
+ - lib/xrbp/webclient.rb
175
+ - lib/xrbp/webclient/connection.rb
176
+ - lib/xrbp/webclient/plugins.rb
177
+ - lib/xrbp/webclient/plugins/autoretry.rb
178
+ - lib/xrbp/webclient/plugins/result_parser.rb
68
179
  - lib/xrbp/websocket.rb
69
180
  - lib/xrbp/websocket/client.rb
70
181
  - lib/xrbp/websocket/cmds.rb
@@ -81,7 +192,6 @@ files:
81
192
  - lib/xrbp/websocket/cmds/subscribe.rb
82
193
  - lib/xrbp/websocket/command.rb
83
194
  - lib/xrbp/websocket/connection.rb
84
- - lib/xrbp/websocket/has_plugin.rb
85
195
  - lib/xrbp/websocket/message.rb
86
196
  - lib/xrbp/websocket/multi/fallback.rb
87
197
  - lib/xrbp/websocket/multi/multi_connection.rb
data/lib/xrbp/network.rb DELETED
@@ -1,6 +0,0 @@
1
- # TODO implement these http based synchronization targets (w/ robust common http logic)
2
- #require_relative './network/nodes'
3
- #require_relative './network/validators'
4
- #require_relative './network/gateways'
5
- #require_relative './network/valuations'
6
- #require_relative './network/tips'
@@ -1,8 +0,0 @@
1
- module XRBP
2
- module Network
3
- class Node
4
- # TODO retrieve individual node peers &
5
- # iterator-based mechanism to crawl nodes
6
- end
7
- end # module Network
8
- end # module XRBP
@@ -1,30 +0,0 @@
1
- module XRBP
2
- module WebSocket
3
- module HasPlugin
4
- def plugins
5
- @plugins ||= []
6
- end
7
-
8
- def add_plugin(*plgs)
9
- plgs.each { |plg|
10
- plg = WebSocket.plugins[plg] if plg.is_a?(Symbol)
11
- raise ArgumentError unless !!plg
12
- plg = plg.new(self)
13
- plugins << plg
14
- plg.added if plg.respond_to?(:added)
15
- }
16
- end
17
-
18
- def plugin?(plg)
19
- plugins.collect { |plg| plg.class }.include?(plg)
20
- end
21
-
22
- def define_instance_method(name, &block)
23
- (class << self; self; end).class_eval do
24
- define_method name, &block
25
- end
26
- end
27
-
28
- end # module HasPlugin
29
- end # module WebSocket
30
- end # module XRBP