nem_websocket_client 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +47 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/nem_websocket_client.rb +11 -0
- data/lib/nem_websocket_client/client.rb +265 -0
- data/lib/nem_websocket_client/version.rb +3 -0
- data/nem_websocket_client.gemspec +40 -0
- metadata +145 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 85b5c4757dbaad89b2026eb02a968ce8144600c3
|
4
|
+
data.tar.gz: 14b3ca89cf00d534ec80ee7ccbf07b417e5f40bf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: aec24e34af924ca9b4f35403933adece0761afc9473218520cac79d04bbdc1471e0a39ad0a34b3f7ec87cbf20b7ebc6f0a3ea2cc4cbcce9fae43bae994b1eeca
|
7
|
+
data.tar.gz: c4f2773d921a5209437d2a29ceecde54dbef330e75b3af673383e749b93e1cebb305fae321107b31cbcd95ab38e237a88fe58c618e53bae1a4d454efb2f06e70
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at hse9795@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
nem_websocket_client (0.1.0)
|
5
|
+
stomp_parser (~> 1.0.0)
|
6
|
+
websocket-client-simple (~> 0.3.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
diff-lcs (1.3)
|
12
|
+
event_emitter (0.2.6)
|
13
|
+
eventmachine (1.2.5)
|
14
|
+
eventmachine (1.2.5-x64-mingw32)
|
15
|
+
rake (11.3.0)
|
16
|
+
rspec (3.7.0)
|
17
|
+
rspec-core (~> 3.7.0)
|
18
|
+
rspec-expectations (~> 3.7.0)
|
19
|
+
rspec-mocks (~> 3.7.0)
|
20
|
+
rspec-core (3.7.1)
|
21
|
+
rspec-support (~> 3.7.0)
|
22
|
+
rspec-expectations (3.7.0)
|
23
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
24
|
+
rspec-support (~> 3.7.0)
|
25
|
+
rspec-mocks (3.7.0)
|
26
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
27
|
+
rspec-support (~> 3.7.0)
|
28
|
+
rspec-support (3.7.1)
|
29
|
+
stomp_parser (1.0.0)
|
30
|
+
websocket (1.2.5)
|
31
|
+
websocket-client-simple (0.3.0)
|
32
|
+
event_emitter
|
33
|
+
websocket
|
34
|
+
|
35
|
+
PLATFORMS
|
36
|
+
ruby
|
37
|
+
x64-mingw32
|
38
|
+
|
39
|
+
DEPENDENCIES
|
40
|
+
bundler (~> 1.16)
|
41
|
+
eventmachine (~> 1.2.5)
|
42
|
+
nem_websocket_client!
|
43
|
+
rake (~> 11.0)
|
44
|
+
rspec (~> 3.0)
|
45
|
+
|
46
|
+
BUNDLED WITH
|
47
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 5hyn3
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# NemWebsocketClient
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/nem_websocket_client`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'nem_websocket_client'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install nem_websocket_client
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/nem_websocket_client. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
40
|
+
|
41
|
+
## Code of Conduct
|
42
|
+
|
43
|
+
Everyone interacting in the NemWebsocketClient project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/nem_websocket_client/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "nem_websocket_client"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,265 @@
|
|
1
|
+
module NemWebsocketClient
|
2
|
+
|
3
|
+
def self.connect(url, port)
|
4
|
+
client = ::NemWebsocketClient::Client.new(url,port)
|
5
|
+
client.connect
|
6
|
+
return client
|
7
|
+
end
|
8
|
+
|
9
|
+
class Client
|
10
|
+
@@block_path = "/blocks"
|
11
|
+
@@block_height_path = "/blocks/new"
|
12
|
+
@@owned_namespace_path = "/account/namespace/owned/"
|
13
|
+
@@owned_mosaic_path = "/account/mosaic/owned/"
|
14
|
+
@@owned_mosaic_definition_path = "/account/mosaic/owned/definition/"
|
15
|
+
@@transaction_path = "/transactions/"
|
16
|
+
@@unconfirmed_transaction_path = "/unconfirmed/"
|
17
|
+
@@recenttransactions_path = "/recenttransactions/"
|
18
|
+
@@account_path = "/account/"
|
19
|
+
|
20
|
+
@@send_owned_namespace_path = "/w/api/account/namespace/owned"
|
21
|
+
@@send_owned_mosaic_path = "/w/api/account/mosaic/owned"
|
22
|
+
@@send_owned_mosaic_definition_path = "/w/api/account/mosaic/owned/definition"
|
23
|
+
@@send_recenttransactions_path = "/w/api/account/transfers/all"
|
24
|
+
@@send_account_path = "/w/api/account/get"
|
25
|
+
|
26
|
+
def initialize(url,port)
|
27
|
+
host = url
|
28
|
+
port = port
|
29
|
+
path = "/w/messages/"
|
30
|
+
server = format("%0#{3}d", SecureRandom.random_number(10**3))
|
31
|
+
strings = [('a'..'z'), ('0'..'5')].map { |i| i.to_a }.flatten
|
32
|
+
session = (0...8).map { strings[rand(strings.length)] }.join
|
33
|
+
@endpoint = host + ":" + port.to_s + path + server.to_s + "/" +session + "/websocket/"
|
34
|
+
@is_connected = false
|
35
|
+
@sub_id_count = 0
|
36
|
+
end
|
37
|
+
|
38
|
+
def connected(&fun)
|
39
|
+
@ws.connected_func = fun
|
40
|
+
end
|
41
|
+
|
42
|
+
def heatbeat(&fun)
|
43
|
+
@ws.heatbeat_func = fun
|
44
|
+
end
|
45
|
+
|
46
|
+
def errors(&fun)
|
47
|
+
@ws.errors_func = fun
|
48
|
+
end
|
49
|
+
|
50
|
+
def closed(&fun)
|
51
|
+
@ws.closed_func = fun
|
52
|
+
end
|
53
|
+
|
54
|
+
def subscribe_block(&fun)
|
55
|
+
@ws.subscribe_block_func = fun
|
56
|
+
send_subscribe_stomp(@@block_path)
|
57
|
+
end
|
58
|
+
|
59
|
+
def subscribe_block_height(&fun)
|
60
|
+
@ws.subscribe_block_height_func = fun
|
61
|
+
send_subscribe_stomp(@@block_height_path)
|
62
|
+
end
|
63
|
+
|
64
|
+
def subscribe_owned_namespace(address,&fun)
|
65
|
+
@ws.subscribe_owned_namespace_func = fun
|
66
|
+
send_subscribe_stomp(@@owned_namespace_path + address)
|
67
|
+
end
|
68
|
+
|
69
|
+
def subscribe_owned_mosaic(address,&fun)
|
70
|
+
@ws.subscribe_owned_mosaic_func = fun
|
71
|
+
send_subscribe_stomp(@@owned_mosaic_path + address)
|
72
|
+
end
|
73
|
+
|
74
|
+
def subscribe_owned_mosaic_definition(address,&fun)
|
75
|
+
@ws.subscribe_owned_mosaic_definition_func = fun
|
76
|
+
send_subscribe_stomp(@@owned_mosaic_definition_path + address)
|
77
|
+
end
|
78
|
+
|
79
|
+
def subscribe_transaction(address,&fun)
|
80
|
+
@ws.subscribe_transaction_func = fun
|
81
|
+
send_subscribe_stomp(@@transaction_path + address)
|
82
|
+
end
|
83
|
+
|
84
|
+
def subscribe_unconfirmed_transaction(address,&fun)
|
85
|
+
@ws.subscribe_unconfirmed_transaction_func = fun
|
86
|
+
send_subscribe_stomp(@@unconfirmed_transaction_path + address)
|
87
|
+
end
|
88
|
+
|
89
|
+
def subscribe_recenttransactions(address,&fun)
|
90
|
+
@ws.subscribe_recenttransactions_func = fun
|
91
|
+
send_subscribe_stomp(@@recenttransactions_path + address)
|
92
|
+
end
|
93
|
+
|
94
|
+
def subscribe_account(address,&fun)
|
95
|
+
@ws.subscribe_account_func = fun
|
96
|
+
send_subscribe_stomp(@@account_path + address)
|
97
|
+
end
|
98
|
+
|
99
|
+
def request_account(address)
|
100
|
+
send_send_stomp(@@send_account_path,address)
|
101
|
+
end
|
102
|
+
|
103
|
+
def request_owned_namespace(address)
|
104
|
+
send_send_stomp(@@send_owned_namespace_path,address)
|
105
|
+
end
|
106
|
+
|
107
|
+
def request_owned_mosaic(address)
|
108
|
+
send_send_stomp(@@send_owned_mosaic_path,address)
|
109
|
+
end
|
110
|
+
|
111
|
+
def request_owned_mosaic_definition(address)
|
112
|
+
send_send_stomp(@@send_owned_mosaic_definition_path,address)
|
113
|
+
end
|
114
|
+
|
115
|
+
def request_recenttransactions(address)
|
116
|
+
send_send_stomp(@@send_recenttransactions_path,address)
|
117
|
+
end
|
118
|
+
|
119
|
+
def close
|
120
|
+
@ws.close
|
121
|
+
end
|
122
|
+
|
123
|
+
def connect
|
124
|
+
@ws = WebSocket::Client::Simple.connect(@endpoint)
|
125
|
+
ws_init
|
126
|
+
@ws.on :error do |e|
|
127
|
+
errors_func.call(e)
|
128
|
+
end
|
129
|
+
|
130
|
+
@ws.on :close do |e|
|
131
|
+
closed_func.call(e)
|
132
|
+
end
|
133
|
+
|
134
|
+
@ws.on :open do
|
135
|
+
connect_header = {"accept-version":"1.1,1.0","heart-beat":"10000,10000"}
|
136
|
+
stomp_connect = '["' + StompParser::Frame.new("CONNECT", connect_header,"").to_str + '"]'
|
137
|
+
send(stomp_connect)
|
138
|
+
end
|
139
|
+
|
140
|
+
@ws.on :message do |msg|
|
141
|
+
if msg.data[0] == "o"
|
142
|
+
|
143
|
+
end
|
144
|
+
|
145
|
+
if msg.data[0] == "h"
|
146
|
+
heatbeat_func.call
|
147
|
+
end
|
148
|
+
if msg.data[0] == "a"
|
149
|
+
data = msg.data
|
150
|
+
data.slice!(0,data.index("[")+2)
|
151
|
+
data.slice!(data.rindex("]")-1,data.length)
|
152
|
+
data.gsub!("\\n","\n")
|
153
|
+
data.gsub!("\\r","\r")
|
154
|
+
data.gsub!("\\/","\/")
|
155
|
+
data.gsub!("\\u0000","\u0000")
|
156
|
+
data.gsub!("\\\"","\"")
|
157
|
+
parser = StompParser::Parser.new(1024 * 100)
|
158
|
+
parser.parse(data) do |frame|
|
159
|
+
if frame.command == "CONNECTED"
|
160
|
+
connected_func.call unless connected_func.nil?
|
161
|
+
@is_connected = true
|
162
|
+
unless subscribe_stomps.empty?
|
163
|
+
subscribe_stomps.each do |stomp|
|
164
|
+
send(stomp)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
unless send_stomps.empty?
|
168
|
+
send_stomps.each do |stomp|
|
169
|
+
send(stomp)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
if frame.command == "MESSAGE"
|
174
|
+
result = JSON.parse(frame.body)
|
175
|
+
destination = frame.headers["destination"]
|
176
|
+
address = destination.match(/\w{40}/)
|
177
|
+
destination.slice!(address.to_s) unless address.nil?
|
178
|
+
case destination
|
179
|
+
when @@block_path
|
180
|
+
subscribe_block_func.call(result)
|
181
|
+
when @@block_height_path
|
182
|
+
subscribe_block_height_func.call(result)
|
183
|
+
when @@unconfirmed_transaction_path
|
184
|
+
subscribe_unconfirmed_transaction_func.call(result,address)
|
185
|
+
when @@recenttransactions_path
|
186
|
+
subscribe_recenttransactions_func.call(result,address)
|
187
|
+
when @@account_path
|
188
|
+
subscribe_account_func.call(result,address)
|
189
|
+
when @@owned_namespace_path
|
190
|
+
subscribe_owned_namespace_func.call(result,address)
|
191
|
+
when @@owned_mosaic_path
|
192
|
+
subscribe_owned_mosaic_func.call(result,address)
|
193
|
+
when @@owned_mosaic_definition_path
|
194
|
+
subscribe_owned_mosaic_definition_func.call(result,address)
|
195
|
+
when @@transaction_path
|
196
|
+
subscribe_owned_mosaic_func.call(result,address)
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
private
|
205
|
+
def ws_init
|
206
|
+
@ws.singleton_class.class_eval{ attr_accessor :connected_func }
|
207
|
+
@ws.singleton_class.class_eval{ attr_accessor :subscribe_block_func }
|
208
|
+
@ws.singleton_class.class_eval{ attr_accessor :heartbeat_func }
|
209
|
+
@ws.singleton_class.class_eval{ attr_accessor :subscribe_block_height_func }
|
210
|
+
@ws.singleton_class.class_eval{ attr_accessor :subscribe_owned_namespace_func }
|
211
|
+
@ws.singleton_class.class_eval{ attr_accessor :subscribe_owned_mosaic_func }
|
212
|
+
@ws.singleton_class.class_eval{ attr_accessor :subscribe_owned_mosaic_definition_func }
|
213
|
+
@ws.singleton_class.class_eval{ attr_accessor :subscribe_transaction_func }
|
214
|
+
@ws.singleton_class.class_eval{ attr_accessor :subscribe_unconfirmed_transaction_func }
|
215
|
+
@ws.singleton_class.class_eval{ attr_accessor :subscribe_recenttransactions_func }
|
216
|
+
@ws.singleton_class.class_eval{ attr_accessor :subscribe_account_func }
|
217
|
+
@ws.singleton_class.class_eval{ attr_accessor :errors_func }
|
218
|
+
@ws.singleton_class.class_eval{ attr_accessor :closed_func }
|
219
|
+
@ws.singleton_class.class_eval{ attr_accessor :subscribe_stomps }
|
220
|
+
@ws.singleton_class.class_eval{ attr_accessor :send_stomps }
|
221
|
+
@ws.subscribe_stomps = []
|
222
|
+
@ws.send_stomps = []
|
223
|
+
end
|
224
|
+
|
225
|
+
def generate_sub_id
|
226
|
+
sub_id = "sub-" + @sub_id_count.to_s
|
227
|
+
@sub_id_count += 1
|
228
|
+
return sub_id
|
229
|
+
end
|
230
|
+
|
231
|
+
def generate_subscribe_stomp(path)
|
232
|
+
header = {"id":generate_sub_id,"destination":path}
|
233
|
+
stomp = '["' + StompParser::Frame.new("SUBSCRIBE", header, "").to_str + '"]'
|
234
|
+
return stomp
|
235
|
+
end
|
236
|
+
|
237
|
+
def generate_send_stomp(path,address)
|
238
|
+
header = {"destination":path}
|
239
|
+
stomp = '["' + StompParser::Frame.new("SEND", header, "{'account':'#{address}'}").to_str + '"]'
|
240
|
+
return stomp
|
241
|
+
end
|
242
|
+
|
243
|
+
def send_stomp(stomp)
|
244
|
+
if @is_connected
|
245
|
+
@ws.send(stomp)
|
246
|
+
else
|
247
|
+
if stomp.include?("SUBSCRIBE")
|
248
|
+
@ws.subscribe_stomps.push(stomp)
|
249
|
+
elsif stomp.include?("SEND")
|
250
|
+
@ws.send_stomps.push(stomp)
|
251
|
+
end
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
def send_subscribe_stomp(path)
|
256
|
+
stomp = generate_subscribe_stomp(path)
|
257
|
+
send_stomp(stomp)
|
258
|
+
end
|
259
|
+
|
260
|
+
def send_send_stomp(path,address)
|
261
|
+
stomp = generate_send_stomp(path,address)
|
262
|
+
send_stomp(stomp)
|
263
|
+
end
|
264
|
+
end
|
265
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "nem_websocket_client/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "nem_websocket_client"
|
8
|
+
spec.version = NemWebsocketClient::VERSION
|
9
|
+
spec.authors = ["shyne"]
|
10
|
+
spec.email = ["shyne9795@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{NEM's WebSocket Client.}
|
13
|
+
spec.description = %q{This is NEM's WebSocket client.t will be able to handle NEM's WebSocket API without knowledge of WebSocket or STOMP.}
|
14
|
+
spec.homepage = "https://github.com/5hyn3/nem_websocket_client"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
"public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_dependency "stomp_parser", "~>1.0.0"
|
34
|
+
spec.add_dependency "websocket-client-simple", "~>0.3.0"
|
35
|
+
|
36
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
37
|
+
spec.add_development_dependency "rake", "~> 11.0"
|
38
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
39
|
+
spec.add_development_dependency "eventmachine", "~>1.2.5"
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nem_websocket_client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- shyne
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-03-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: stomp_parser
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: websocket-client-simple
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.3.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.3.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.16'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.16'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '11.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '11.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: eventmachine
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.2.5
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.2.5
|
97
|
+
description: This is NEM's WebSocket client.t will be able to handle NEM's WebSocket
|
98
|
+
API without knowledge of WebSocket or STOMP.
|
99
|
+
email:
|
100
|
+
- shyne9795@gmail.com
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rspec"
|
107
|
+
- ".travis.yml"
|
108
|
+
- CODE_OF_CONDUCT.md
|
109
|
+
- Gemfile
|
110
|
+
- Gemfile.lock
|
111
|
+
- LICENSE.txt
|
112
|
+
- README.md
|
113
|
+
- Rakefile
|
114
|
+
- bin/console
|
115
|
+
- bin/setup
|
116
|
+
- lib/nem_websocket_client.rb
|
117
|
+
- lib/nem_websocket_client/client.rb
|
118
|
+
- lib/nem_websocket_client/version.rb
|
119
|
+
- nem_websocket_client.gemspec
|
120
|
+
homepage: https://github.com/5hyn3/nem_websocket_client
|
121
|
+
licenses:
|
122
|
+
- MIT
|
123
|
+
metadata:
|
124
|
+
allowed_push_host: https://rubygems.org
|
125
|
+
post_install_message:
|
126
|
+
rdoc_options: []
|
127
|
+
require_paths:
|
128
|
+
- lib
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
requirements: []
|
140
|
+
rubyforge_project:
|
141
|
+
rubygems_version: 2.5.2.1
|
142
|
+
signing_key:
|
143
|
+
specification_version: 4
|
144
|
+
summary: NEM's WebSocket Client.
|
145
|
+
test_files: []
|