tamashii-client 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a57eb1ba451079455f62b8ddf5ae3dc426f8070d
4
+ data.tar.gz: 459efd6811a65e156a0edc476cd0262d6fccd886
5
+ SHA512:
6
+ metadata.gz: b5f9a314e6d792de8a9a934a9ce5448bc1220e819b5f03123562c6fdf556f3d4d7cc2b8bb16d54b6d61e87769b860936efd803af16a92dee02cd052a4b9149b3
7
+ data.tar.gz: ed7b1cb8340d8494b5fe4e8d9fadfe6607ff767849d08b0db600cc271d9cd0adcc2d3432442d0a3ecd48af88ed35ebd3de65805d88f13a2785c9890d2abc4134
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ # Vim related
2
+ /.bundle/
3
+ *.swp
4
+ /.yardoc
5
+ *.swo
6
+ /Gemfile.lock
7
+
8
+ /_yardoc/
9
+ .byebug_history
10
+ /coverage/
11
+ .ruby-version
12
+ /doc/
13
+ /pkg/
14
+ /spec/reports/
15
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.13.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tamashii-common.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,70 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features) \
6
+ # .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
7
+
8
+ ## Note: if you are using the `directories` clause above and you are not
9
+ ## watching the project directory ('.'), then you will want to move
10
+ ## the Guardfile to a watched dir and symlink it back, e.g.
11
+ #
12
+ # $ mkdir config
13
+ # $ mv Guardfile config/
14
+ # $ ln -s config/Guardfile .
15
+ #
16
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
17
+
18
+ # Note: The cmd option is now required due to the increasing number of ways
19
+ # rspec may be run, below are examples of the most common uses.
20
+ # * bundler: 'bundle exec rspec'
21
+ # * bundler binstubs: 'bin/rspec'
22
+ # * spring: 'bin/rspec' (This will use spring if running and you have
23
+ # installed the spring binstubs per the docs)
24
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
25
+ # * 'just' rspec: 'rspec'
26
+
27
+ guard :rspec, cmd: "bundle exec rspec" do
28
+ require "guard/rspec/dsl"
29
+ dsl = Guard::RSpec::Dsl.new(self)
30
+
31
+ # Feel free to open issues for suggestions and improvements
32
+
33
+ # RSpec files
34
+ rspec = dsl.rspec
35
+ watch(rspec.spec_helper) { rspec.spec_dir }
36
+ watch(rspec.spec_support) { rspec.spec_dir }
37
+ watch(rspec.spec_files)
38
+
39
+ # Ruby files
40
+ ruby = dsl.ruby
41
+ dsl.watch_spec_files_for(ruby.lib_files)
42
+
43
+ # Rails files
44
+ rails = dsl.rails(view_extensions: %w(erb haml slim))
45
+ dsl.watch_spec_files_for(rails.app_files)
46
+ dsl.watch_spec_files_for(rails.views)
47
+
48
+ watch(rails.controllers) do |m|
49
+ [
50
+ rspec.spec.call("routing/#{m[1]}_routing"),
51
+ rspec.spec.call("controllers/#{m[1]}_controller"),
52
+ rspec.spec.call("acceptance/#{m[1]}")
53
+ ]
54
+ end
55
+
56
+ # Rails config changes
57
+ watch(rails.spec_helper) { rspec.spec_dir }
58
+ watch(rails.routes) { "#{rspec.spec_dir}/routing" }
59
+ watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
60
+
61
+ # Capybara features specs
62
+ watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
63
+ watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
64
+
65
+ # Turnip features and steps
66
+ watch(%r{^spec/acceptance/(.+)\.feature$})
67
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
68
+ Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
69
+ end
70
+ end
data/LICENSE.md ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright {yyyy} {name of copyright owner}
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1 @@
1
+ # Tamashii::Client
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "tamashii/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
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,284 @@
1
+ require 'concurrent'
2
+ require 'nio'
3
+ require 'openssl'
4
+ require 'socket'
5
+ require 'timeout'
6
+ require 'websocket/driver'
7
+
8
+
9
+ require "tamashii/common"
10
+ require "tamashii/client/config"
11
+
12
+ module Tamashii
13
+ module Client
14
+ class Base
15
+
16
+ attr_reader :url
17
+
18
+ def logger
19
+ Client.logger
20
+ end
21
+
22
+ def initialize
23
+ @url = "#{Config.use_ssl ? "wss" : "ws"}://#{Config.host}:#{Config.port}/#{Config.entry_point}"
24
+
25
+ @callbacks = {}
26
+
27
+ @write_head = nil
28
+ @write_buffer = Queue.new
29
+
30
+ @nio = NIO::Selector.new
31
+ @todo = Queue.new
32
+ @stopping = false
33
+ @closing = false
34
+ @opened = false
35
+ @thread = Thread.new {run}
36
+ end
37
+
38
+ def close
39
+ @closing = true
40
+ if opened?
41
+ close_driver
42
+ else
43
+ logger.info "Closing: server is not connected, close immediately"
44
+ abort_open_socket_task
45
+ stop
46
+ end
47
+ wait_for_worker_thread if worker_running?
48
+ end
49
+
50
+ def close_driver
51
+ post { @driver.close }
52
+ end
53
+
54
+ def post(task = nil, &block)
55
+ task ||= block
56
+ @todo << block
57
+ wakeup
58
+ end
59
+
60
+ def abort_open_socket_task
61
+ @open_socket_task&.cancel
62
+ end
63
+
64
+ def closing?
65
+ @closing
66
+ end
67
+
68
+ def opened?
69
+ @opened
70
+ end
71
+
72
+ def stopped?
73
+ @stopping
74
+ end
75
+
76
+ def worker_running?
77
+ @worker_running
78
+ end
79
+
80
+ # called from user
81
+ def transmit(data)
82
+ if opened?
83
+ data = data.unpack("C*") if data.is_a?(String)
84
+ post { @driver.binary(data) }
85
+ true
86
+ else
87
+ logger.error "Server not opened. Cannot transmit data!"
88
+ false
89
+ end
90
+ end
91
+
92
+ # called from ws driver
93
+ def write(data)
94
+ @write_buffer << data
95
+ post do
96
+ begin
97
+ @monitor&.interests = :rw
98
+ rescue EOFError => e
99
+ # Monitor is closed
100
+ logger.error "Error when writing: #{e.message}"
101
+ end
102
+ end
103
+ end
104
+
105
+ def on(event, callable = nil, &block)
106
+ logger.warn "Multiple callbacks detected, ignore the block" if callable && block
107
+ if callable
108
+ @callbacks[event] = callable
109
+ else
110
+ @callbacks[event] = block
111
+ end
112
+ end
113
+
114
+ def kill_worker_thread
115
+ @thread.exit
116
+ worker_cleanup(false)
117
+ end
118
+
119
+ def wait_for_worker_thread
120
+ if !@thread.join(Config.closing_timeout)
121
+ logger.error "Unable to stop worker thread in #{Config.closing_timeout} second! Force kill the worker thread"
122
+ kill_worker_thread
123
+ end
124
+ end
125
+
126
+ def wakeup
127
+ @nio.wakeup
128
+ rescue
129
+ logger.error "Select cannot be wakeup"
130
+ end
131
+
132
+ def open_socket
133
+ Timeout::timeout(Config.opening_timeout) do
134
+ if Config.use_ssl
135
+ OpenSSL::SSL::SSLSocket.new(TCPSocket.new(Config.host, Config.port)).connect
136
+ else
137
+ TCPSocket.new(Config.host, Config.port)
138
+ end
139
+ end
140
+ rescue Timeout::Error => e
141
+ logger.error "Opening timeout after #{Config.opening_timeout} seconds"
142
+ nil
143
+ rescue => e
144
+ nil
145
+ end
146
+
147
+ def open_socket_runner
148
+ logger.info "Trying to open the socket..."
149
+ if @io = open_socket
150
+ logger.info "Socket opened!"
151
+ call_callback(:socket_opened)
152
+ post do
153
+ @monitor = @nio.register(@io, :r)
154
+ @opened = true
155
+ start_websocket_driver
156
+ end
157
+ else
158
+ logger.error "Cannot open socket, retry later"
159
+ open_socket_async
160
+ end
161
+ end
162
+
163
+ def open_socket_async
164
+ if !closing? && !stopped?
165
+ @open_socket_task = Concurrent::ScheduledTask.execute(Config.opening_retry_interval, &method(:open_socket_runner))
166
+ else
167
+ logger.warn "Client is closing, no longer need to create socket"
168
+ end
169
+ end
170
+
171
+ def flush_write_buffer
172
+ loop do
173
+ return true if @write_buffer.empty? && @write_head.nil?
174
+ @write_head = @write_buffer.pop if @write_head.nil?
175
+ return false unless process_flush
176
+ end
177
+ end
178
+
179
+ def process_flush
180
+ written = @io.write_nonblock(@write_head, exception: false)
181
+ case written
182
+ when @write_head.bytesize
183
+ @write_head = nil
184
+ return true
185
+ when :wait_writable then return false
186
+ else
187
+ @write_head = @write_head.byteslice(written, @write_head.bytesize)
188
+ return false
189
+ end
190
+ end
191
+
192
+ def call_callback(event, *args, &block)
193
+ @callbacks[event]&.call(*args, &block)
194
+ end
195
+
196
+ def start_websocket_driver
197
+ @driver = WebSocket::Driver.client(self)
198
+ @driver.on :open, proc { |e|
199
+ @opened = true
200
+ logger.info "WebSocket Server opened"
201
+ call_callback(:open)
202
+ }
203
+ @driver.on :close, proc { |e|
204
+ logger.info "WebSocket Server closed"
205
+ call_callback(:close)
206
+ server_gone
207
+ }
208
+ @driver.on :message, proc { |e|
209
+ logger.debug("Message from server: #{e.data}")
210
+ call_callback(:message, e.data)
211
+ }
212
+ @driver.on :error, proc { |e|
213
+ logger.error("WebSocket error: #{e.message}")
214
+ call_callback(:error, e)
215
+ }
216
+ @driver.start
217
+ end
218
+
219
+ def run
220
+ @worker_running = true
221
+ logger.info "Worker Create!"
222
+ open_socket_async
223
+ loop do
224
+ if stopped?
225
+ @nio.close
226
+ break
227
+ end
228
+
229
+ @todo.pop(true).call until @todo.empty?
230
+
231
+ monitors = @nio.select
232
+ next unless monitors
233
+ monitors.each do |monitor|
234
+ if monitor.writable?
235
+ monitor.interests = :r if flush_write_buffer
236
+ end
237
+ if monitor.readable?
238
+ read
239
+ end
240
+ end
241
+ end
242
+ worker_cleanup(true)
243
+ end
244
+
245
+ def worker_cleanup(normally)
246
+ @worker_running = false
247
+ logger.debug "Worker terminales #{normally ? 'normally' : 'abnormally'}"
248
+ end
249
+
250
+ def read
251
+ incoming = @io.read_nonblock(4096, exception: false)
252
+ case incoming
253
+ when :wait_readable then false
254
+ when nil then server_gone
255
+ else
256
+ @driver.parse(incoming)
257
+ end
258
+ rescue
259
+ server_gone
260
+ end
261
+
262
+ def server_gone
263
+ logger.info "Socket closed"
264
+ @opened = false
265
+ @io.close
266
+ @nio.deregister @io
267
+ call_callback(:socket_closed)
268
+ if closing?
269
+ # client should stop the thread
270
+ stop
271
+ else
272
+ # closing is not issued by client, re-open
273
+ open_socket_async
274
+ end
275
+ end
276
+
277
+ # this is hard stop, will not issue a websocket close message!
278
+ def stop
279
+ @stopping = true
280
+ wakeup
281
+ end
282
+ end
283
+ end
284
+ end
@@ -0,0 +1,21 @@
1
+ require 'tamashii/common'
2
+ module Tamashii
3
+ module Client
4
+ class Config < Tamashii::Config
5
+ register :log_file, STDOUT
6
+
7
+ register :use_ssl, false
8
+ register :entry_point, "/tamashii"
9
+ register :host, "localhost"
10
+ register :port, 3000
11
+ register :opening_timeout, 5
12
+ register :opening_retry_interval, 1
13
+ register :closing_timeout, 5
14
+
15
+ def log_level(level = nil)
16
+ return Client.logger.level if level.nil?
17
+ Client.logger.level = level
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,5 @@
1
+ module Tamashii
2
+ module Client
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,20 @@
1
+ require "tamashii/common"
2
+ require "tamashii/client/version"
3
+ require "tamashii/client/config"
4
+
5
+ module Tamashii
6
+ module Client
7
+ autoload :Base, "tamashii/client/base"
8
+
9
+ def self.config(&block)
10
+ return Config.class_eval(&block) if block_given?
11
+ Config
12
+ end
13
+
14
+ def self.logger
15
+ @logger ||= Tamashii::Logger.new(Config.log_file).tap do |logger|
16
+ logger.progname = "WebSocket Client"
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,44 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'tamashii/client/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "tamashii-client"
8
+ spec.version = Tamashii::Client::VERSION
9
+ spec.authors = ["蒼時弦也", "Liang-Chi Tseng", "五倍紅寶石"]
10
+ spec.email = ["elct9620@frost.tw", "lctseng@cs.nctu.edu.tw", "hi@5xruby.tw"]
11
+
12
+ spec.summary = %q{The WebSocket client of Tamashii framework}
13
+ spec.description = %q{The WebSocket client of Tamashii framework}
14
+ spec.homepage = "https://github.com/5xruby/tamashii-client"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against " \
22
+ "public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_runtime_dependency "websocket-driver"
33
+ spec.add_runtime_dependency "nio4r"
34
+ spec.add_runtime_dependency "logger-colors"
35
+ spec.add_runtime_dependency "tamashii-common"
36
+ spec.add_runtime_dependency "concurrent-ruby"
37
+
38
+ spec.add_development_dependency "bundler", "~> 1.13"
39
+ spec.add_development_dependency "rake", "~> 10.0"
40
+ spec.add_development_dependency "rspec", "~> 3.0"
41
+ spec.add_development_dependency "simplecov"
42
+ spec.add_development_dependency "guard"
43
+ spec.add_development_dependency "guard-rspec"
44
+ end
metadata ADDED
@@ -0,0 +1,216 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tamashii-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - 蒼時弦也
8
+ - Liang-Chi Tseng
9
+ - 五倍紅寶石
10
+ autorequire:
11
+ bindir: exe
12
+ cert_chain: []
13
+ date: 2017-09-06 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: websocket-driver
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: nio4r
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: logger-colors
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ - !ruby/object:Gem::Dependency
58
+ name: tamashii-common
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ type: :runtime
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ - !ruby/object:Gem::Dependency
72
+ name: concurrent-ruby
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ type: :runtime
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ - !ruby/object:Gem::Dependency
86
+ name: bundler
87
+ requirement: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - "~>"
90
+ - !ruby/object:Gem::Version
91
+ version: '1.13'
92
+ type: :development
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - "~>"
97
+ - !ruby/object:Gem::Version
98
+ version: '1.13'
99
+ - !ruby/object:Gem::Dependency
100
+ name: rake
101
+ requirement: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - "~>"
104
+ - !ruby/object:Gem::Version
105
+ version: '10.0'
106
+ type: :development
107
+ prerelease: false
108
+ version_requirements: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - "~>"
111
+ - !ruby/object:Gem::Version
112
+ version: '10.0'
113
+ - !ruby/object:Gem::Dependency
114
+ name: rspec
115
+ requirement: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - "~>"
118
+ - !ruby/object:Gem::Version
119
+ version: '3.0'
120
+ type: :development
121
+ prerelease: false
122
+ version_requirements: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - "~>"
125
+ - !ruby/object:Gem::Version
126
+ version: '3.0'
127
+ - !ruby/object:Gem::Dependency
128
+ name: simplecov
129
+ requirement: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ - !ruby/object:Gem::Dependency
142
+ name: guard
143
+ requirement: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ type: :development
149
+ prerelease: false
150
+ version_requirements: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ - !ruby/object:Gem::Dependency
156
+ name: guard-rspec
157
+ requirement: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ type: :development
163
+ prerelease: false
164
+ version_requirements: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ description: The WebSocket client of Tamashii framework
170
+ email:
171
+ - elct9620@frost.tw
172
+ - lctseng@cs.nctu.edu.tw
173
+ - hi@5xruby.tw
174
+ executables: []
175
+ extensions: []
176
+ extra_rdoc_files: []
177
+ files:
178
+ - ".gitignore"
179
+ - ".rspec"
180
+ - ".travis.yml"
181
+ - Gemfile
182
+ - Guardfile
183
+ - LICENSE.md
184
+ - README.md
185
+ - Rakefile
186
+ - bin/console
187
+ - bin/setup
188
+ - lib/tamashii/client.rb
189
+ - lib/tamashii/client/base.rb
190
+ - lib/tamashii/client/config.rb
191
+ - lib/tamashii/client/version.rb
192
+ - tamashii-client.gemspec
193
+ homepage: https://github.com/5xruby/tamashii-client
194
+ licenses: []
195
+ metadata: {}
196
+ post_install_message:
197
+ rdoc_options: []
198
+ require_paths:
199
+ - lib
200
+ required_ruby_version: !ruby/object:Gem::Requirement
201
+ requirements:
202
+ - - ">="
203
+ - !ruby/object:Gem::Version
204
+ version: '0'
205
+ required_rubygems_version: !ruby/object:Gem::Requirement
206
+ requirements:
207
+ - - ">="
208
+ - !ruby/object:Gem::Version
209
+ version: '0'
210
+ requirements: []
211
+ rubyforge_project:
212
+ rubygems_version: 2.5.1
213
+ signing_key:
214
+ specification_version: 4
215
+ summary: The WebSocket client of Tamashii framework
216
+ test_files: []