websocket-connection 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +34 -0
- data/README.md +21 -0
- data/Rakefile +14 -0
- data/lib/websocket/connection.rb +61 -0
- data/lib/websocket/connection/version.rb +5 -0
- data/test/connection_test.rb +7 -0
- data/test/test_helper.rb +32 -0
- data/websocket-connection.gemspec +25 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: db1332dac133cbcbbc24148295c64102e6490d6a
|
4
|
+
data.tar.gz: 5d78a0174183e49b19e19f37cecb697bc0735ab3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0141dc17469fe648c31cfbfbf21da71b250681f277ec3f1b1ed8c1bf542077ac085a226f2067d0cf757396a7970937736eec5ceeb6c9f1b17433102bc3287d7a
|
7
|
+
data.tar.gz: 2b965e75455ff1608fe48620b65d52e276fb2a09ef0c1f032c545c5b2cdc5544b2373fbedbc8a97f417e08f76f2ce08bddbc69a1e9f7ec38b6e4f3c8cca121d1
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
websocket-connection (1.0.0)
|
5
|
+
websocket-driver (>= 0.6.5)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
ansi (1.5.0)
|
11
|
+
builder (3.2.3)
|
12
|
+
minitest (5.10.2)
|
13
|
+
minitest-reporters (1.1.14)
|
14
|
+
ansi
|
15
|
+
builder
|
16
|
+
minitest (>= 5.0)
|
17
|
+
ruby-progressbar
|
18
|
+
rake (12.0.0)
|
19
|
+
ruby-progressbar (1.8.1)
|
20
|
+
websocket-driver (0.6.5)
|
21
|
+
websocket-extensions (>= 0.1.0)
|
22
|
+
websocket-extensions (0.1.2)
|
23
|
+
|
24
|
+
PLATFORMS
|
25
|
+
ruby
|
26
|
+
|
27
|
+
DEPENDENCIES
|
28
|
+
minitest (= 5.10.2)
|
29
|
+
minitest-reporters (= 1.1.14)
|
30
|
+
rake
|
31
|
+
websocket-connection!
|
32
|
+
|
33
|
+
BUNDLED WITH
|
34
|
+
1.14.4
|
data/README.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# websocket-connection
|
2
|
+
|
3
|
+
Create and use Websocket's without needing to use EventMachine.
|
4
|
+
|
5
|
+
# Usage
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
require 'websocket/connection'
|
9
|
+
|
10
|
+
connection = WebSocket::Connection.start('ws://example.com')
|
11
|
+
connection.on(:message) do |event|
|
12
|
+
puts event.data
|
13
|
+
connection.close
|
14
|
+
end
|
15
|
+
|
16
|
+
connection.send("example message")
|
17
|
+
|
18
|
+
while connection.open?
|
19
|
+
connection.read
|
20
|
+
end
|
21
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
Bundler.require(:development)
|
4
|
+
|
5
|
+
require 'fileutils'
|
6
|
+
require "rake/testtask"
|
7
|
+
|
8
|
+
# Test Task
|
9
|
+
Rake::TestTask.new do |t|
|
10
|
+
t.libs << 'lib' << 'test'
|
11
|
+
t.test_files = FileList['test/**/*_test.rb']
|
12
|
+
# t.warning = true
|
13
|
+
# t.verbose = true
|
14
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'socket'
|
2
|
+
require 'websocket/driver'
|
3
|
+
|
4
|
+
class WebSocket::Connection
|
5
|
+
|
6
|
+
attr_reader :url
|
7
|
+
|
8
|
+
def initialize(url, options = {})
|
9
|
+
@url = url
|
10
|
+
@driver = ::WebSocket::Driver.client(self, options)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.start(url, options = {})
|
14
|
+
connection = self.new(url, options)
|
15
|
+
connection.start
|
16
|
+
connection
|
17
|
+
end
|
18
|
+
|
19
|
+
def connect
|
20
|
+
uri = URI.parse(url)
|
21
|
+
@stream = ::Socket.tcp(uri.host, uri.port)
|
22
|
+
@driver.start
|
23
|
+
end
|
24
|
+
alias_method :start, :connect
|
25
|
+
|
26
|
+
def close
|
27
|
+
@driver.close
|
28
|
+
@stream.close
|
29
|
+
end
|
30
|
+
|
31
|
+
def closed?
|
32
|
+
@stream.closed?
|
33
|
+
end
|
34
|
+
|
35
|
+
def open?
|
36
|
+
!@stream.closed?
|
37
|
+
end
|
38
|
+
|
39
|
+
def on(event, callable = nil, &block)
|
40
|
+
@driver.on(event, callable, &block)
|
41
|
+
end
|
42
|
+
|
43
|
+
def send(message)
|
44
|
+
case message
|
45
|
+
when Numeric then @driver.text(message.to_s)
|
46
|
+
when String then @driver.text(message)
|
47
|
+
when Array then @driver.binary(message)
|
48
|
+
else false
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def write(data)
|
53
|
+
@stream.write(data)
|
54
|
+
end
|
55
|
+
|
56
|
+
def read
|
57
|
+
@driver.parse(@stream.recv(256))
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# require 'simplecov'
|
2
|
+
# SimpleCov.start
|
3
|
+
|
4
|
+
# To make testing/debugging easier, test within this source tree versus an
|
5
|
+
# installed gem
|
6
|
+
$LOAD_PATH << File.expand_path('../lib', __FILE__)
|
7
|
+
|
8
|
+
require "minitest/autorun"
|
9
|
+
require 'minitest/unit'
|
10
|
+
require 'minitest/reporters'
|
11
|
+
|
12
|
+
require 'websocket/connection'
|
13
|
+
|
14
|
+
Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
|
15
|
+
|
16
|
+
class Minitest::Test
|
17
|
+
|
18
|
+
# File 'lib/active_support/testing/declarative.rb'
|
19
|
+
def self.test(name, &block)
|
20
|
+
test_name = "test_#{name.gsub(/\s+/, '_')}".to_sym
|
21
|
+
defined = method_defined? test_name
|
22
|
+
raise "#{test_name} is already defined in #{self}" if defined
|
23
|
+
if block_given?
|
24
|
+
define_method(test_name, &block)
|
25
|
+
else
|
26
|
+
define_method(test_name) do
|
27
|
+
skip "No implementation provided for #{name}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.expand_path("../lib/websocket/connection/version", __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = 'websocket-connection'
|
5
|
+
s.version = WebSocket::Connection::VERSION
|
6
|
+
s.summary = 'WebSocket client without EventMachine'
|
7
|
+
s.authors = ["Jon Bracy"]
|
8
|
+
s.email = ["jonbracy@gmail.com"]
|
9
|
+
s.homepage = 'http://github.com/malomalo/websocket-connection'
|
10
|
+
s.licenses = ['MIT']
|
11
|
+
|
12
|
+
s.extra_rdoc_files = %w[README.md]
|
13
|
+
s.rdoc_options = %w[--main README.md --markup markdown]
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = %w[lib]
|
19
|
+
|
20
|
+
s.add_dependency 'websocket-driver', '>= 0.6.5'
|
21
|
+
|
22
|
+
s.add_development_dependency 'rake'
|
23
|
+
s.add_development_dependency 'minitest', '5.10.2'
|
24
|
+
s.add_development_dependency 'minitest-reporters', '1.1.14'
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: websocket-connection
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jon Bracy
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-06-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: websocket-driver
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.6.5
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.6.5
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 5.10.2
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 5.10.2
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest-reporters
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.1.14
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.1.14
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- jonbracy@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files:
|
75
|
+
- README.md
|
76
|
+
files:
|
77
|
+
- Gemfile
|
78
|
+
- Gemfile.lock
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- lib/websocket/connection.rb
|
82
|
+
- lib/websocket/connection/version.rb
|
83
|
+
- test/connection_test.rb
|
84
|
+
- test/test_helper.rb
|
85
|
+
- websocket-connection.gemspec
|
86
|
+
homepage: http://github.com/malomalo/websocket-connection
|
87
|
+
licenses:
|
88
|
+
- MIT
|
89
|
+
metadata: {}
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options:
|
92
|
+
- "--main"
|
93
|
+
- README.md
|
94
|
+
- "--markup"
|
95
|
+
- markdown
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.5.1
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: WebSocket client without EventMachine
|
114
|
+
test_files:
|
115
|
+
- test/connection_test.rb
|
116
|
+
- test/test_helper.rb
|