socket.io-client-simple 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ab9042c09b285423f80e10e4e72414f8baec5b45
4
+ data.tar.gz: a0065e0fdb5d0dd66ff456c345b19d18a6417682
5
+ SHA512:
6
+ metadata.gz: 31d37108d0c8f1e6d30e846f9bafdcd8a6ce30519bfde0d6c7f19a33008882fd3b758eebb5db01f3715b7ae803f05617ba67da01524be5e8498546d6dffc2075
7
+ data.tar.gz: 5c8b46848ab98204912670929e243aeffb31d230ee438df54f0ba18f7c0082db92c9d759f314e91eec676e224192dabfbe06b88fca80721196ed15053e057901
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *~
2
+ *#*
3
+ .DS_Store
4
+ *.gem
5
+ *.rbc
6
+ .bundle
7
+ .config
8
+ .yardoc
9
+ InstalledFiles
10
+ _yardoc
11
+ coverage
12
+ doc/
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in socket.io-client-simple.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,31 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ socket.io-client-simple (0.0.1)
5
+ event_emitter
6
+ httparty
7
+ json
8
+ websocket-client-simple
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ event_emitter (0.2.5)
14
+ httparty (0.12.0)
15
+ json (~> 1.8)
16
+ multi_xml (>= 0.5.2)
17
+ json (1.8.1)
18
+ multi_xml (0.5.5)
19
+ rake (10.1.1)
20
+ websocket (1.1.2)
21
+ websocket-client-simple (0.0.5)
22
+ event_emitter
23
+ websocket
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ bundler (~> 1.3)
30
+ rake
31
+ socket.io-client-simple!
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Sho Hashimoto
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # SocketIO::Client::Simple
2
+ A simple ruby client for node.js's socket.io. Supports only WebSocket.
3
+
4
+ - https://github.com/shokai/ruby-socket.io-client-simple
5
+ - https://rubygems.org/gems/ruby-socket.io-client-simple
6
+
7
+
8
+ ## Install
9
+
10
+ % gem install socket.io-client-simple
11
+
12
+
13
+ ## Usage
14
+
15
+ [samples/sample.rb](https://github.com/shokai/ruby-socket.io-client-simple/blob/master/samples/sample.rb)
16
+ ```ruby
17
+ require 'rubygems'
18
+ require 'socket.io-client-simple'
19
+
20
+ client = SocketIO::Client::Simple.connect 'http://localhost:3000'
21
+
22
+ client.on :connect do
23
+ puts "connect!!!"
24
+ end
25
+
26
+ client.on :disconnect do
27
+ puts "disconnected!!"
28
+ end
29
+
30
+ client.on :chat do |data|
31
+ puts "> " + data['msg']
32
+ end
33
+
34
+ puts "please input and press Enter key"
35
+ loop do
36
+ msg = STDIN.gets.strip
37
+ next if msg.empty?
38
+ client.emit :chat, {:msg => msg, :at => Time.now}
39
+ end
40
+ ```
41
+
42
+ sample.rb works with [samples/chat_server.js](https://github.com/shokai/ruby-socket.io-client-simple/blob/master/samples/chat_server.js).
43
+
44
+ ### start chat server
45
+
46
+ % npm install socket.io
47
+ % node samples/chat_server.js
48
+
49
+ => chat server start at localhost:3000
50
+
51
+
52
+ ### ruby sample.rb
53
+
54
+ % ruby samples/sample.rb
55
+
56
+
57
+ ## Contributing
58
+
59
+ 1. Fork it
60
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
61
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
62
+ 4. Push to the branch (`git push origin my-new-feature`)
63
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,20 @@
1
+ require 'json'
2
+ require 'httparty'
3
+ require 'websocket-client-simple'
4
+ require 'event_emitter'
5
+
6
+ require 'socket.io-client-simple/version'
7
+ require 'socket.io-client-simple/error'
8
+ require 'socket.io-client-simple/client'
9
+
10
+ module SocketIO
11
+ module Client
12
+ module Simple
13
+
14
+ def self.connect(url, opts={})
15
+ Client.new(url, opts)
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,71 @@
1
+ module SocketIO
2
+ module Client
3
+ module Simple
4
+
5
+ class Client
6
+ include EventEmitter
7
+ alias_method :__emit, :emit
8
+
9
+ attr_reader :websocket, :session_id, :heartbeat_timeout,
10
+ :connection_timeout, :transports
11
+
12
+ def initialize(url, opts={})
13
+ @url = url
14
+ @opts = opts
15
+ configure
16
+
17
+ @websocket = WebSocket::Client::Simple.connect "#{url}/socket.io/1/websocket/#{@session_id}"
18
+
19
+ this = self
20
+ @websocket.on :message do |msg|
21
+ code, body = msg.data.scan(/^(\d+):{2,3}(.*)$/)[0]
22
+ code = code.to_i
23
+ case code
24
+ when 0
25
+ this.__emit :disconnect
26
+ when 1
27
+ this.__emit :connect
28
+ when 2
29
+ send "2::" # heartbeat
30
+ when 3
31
+ when 4
32
+ when 5
33
+ data = JSON.parse body
34
+ this.__emit data['name'], *data['args']
35
+ when 6
36
+ when 7
37
+ this.__emit :error
38
+ end
39
+ end
40
+
41
+ @websocket.on :close do
42
+ this.emit :disconnect
43
+ end
44
+
45
+ @websocket.send "1::#{opts[:path]}"
46
+ end
47
+
48
+ def configure
49
+ res = HTTParty.get "#{@url}/socket.io/1/"
50
+ raise res.body unless res.code == 200
51
+
52
+ arr = res.body.split(':')
53
+ @session_id = arr.shift
54
+ @heartbeat_timeout = arr.shift.to_i
55
+ @connection_timeout = arr.shift.to_i
56
+ @transports = arr.shift.split(',')
57
+ unless @transports.include? 'websocket'
58
+ raise Error, "server #{@url} does not supports websocket!!"
59
+ end
60
+ end
61
+
62
+ def emit(event_name, *data)
63
+ emit_data = {:name => event_name, :args => data}.to_json
64
+ @websocket.send "5:::#{emit_data}"
65
+ end
66
+
67
+ end
68
+
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,10 @@
1
+ module SocketIO
2
+ module Client
3
+ module Simple
4
+
5
+ class Error < StandardError
6
+ end
7
+
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ module SocketIO
2
+ module Client
3
+ module Simple
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ // socket.io chat server
2
+
3
+ var io = require('socket.io').listen(3000);
4
+
5
+ io.sockets.on('connection', function(socket){
6
+ socket.emit('chat', {msg: 'hello world (from server)'});
7
+ socket.on('chat', function(data){
8
+ console.log(data);
9
+ socket.emit('chat', data); // echo
10
+ });
11
+ });
data/samples/sample.rb ADDED
@@ -0,0 +1,28 @@
1
+ $:.unshift File.expand_path '../lib', File.dirname(__FILE__)
2
+ require 'rubygems'
3
+ require 'socket.io-client-simple'
4
+
5
+ client = SocketIO::Client::Simple.connect 'http://localhost:3000'
6
+
7
+ #client.websocket.on :message do |msg|
8
+ # p msg.data
9
+ #end
10
+
11
+ client.on :connect do
12
+ puts "connect!!!"
13
+ end
14
+
15
+ client.on :disconnect do
16
+ puts "disconnected!!"
17
+ end
18
+
19
+ client.on :chat do |data|
20
+ puts "> " + data['msg']
21
+ end
22
+
23
+ puts "please input and press Enter key"
24
+ loop do
25
+ msg = STDIN.gets.strip
26
+ next if msg.empty?
27
+ client.emit :chat, {:msg => msg, :at => Time.now}
28
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'socket.io-client-simple/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "socket.io-client-simple"
8
+ spec.version = SocketIO::Client::Simple::VERSION
9
+ spec.authors = ["Sho Hashimoto"]
10
+ spec.email = ["hashimoto@shokai.org"]
11
+ spec.description = "A simple ruby client for node.js's socket.io. Supports only WebSocket."
12
+ spec.summary = spec.description
13
+ spec.homepage = "https://github.com/shokai/ruby-socket.io-client-simple"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_dependency "json"
25
+ spec.add_dependency "websocket-client-simple"
26
+ spec.add_dependency "httparty"
27
+ spec.add_dependency "event_emitter"
28
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: socket.io-client-simple
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sho Hashimoto
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
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: json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: websocket-client-simple
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: httparty
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: event_emitter
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: A simple ruby client for node.js's socket.io. Supports only WebSocket.
98
+ email:
99
+ - hashimoto@shokai.org
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - Gemfile
106
+ - Gemfile.lock
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - lib/socket.io-client-simple.rb
111
+ - lib/socket.io-client-simple/client.rb
112
+ - lib/socket.io-client-simple/error.rb
113
+ - lib/socket.io-client-simple/version.rb
114
+ - samples/chat_server.js
115
+ - samples/sample.rb
116
+ - socket.io-client-simple.gemspec
117
+ homepage: https://github.com/shokai/ruby-socket.io-client-simple
118
+ licenses:
119
+ - MIT
120
+ metadata: {}
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - '>='
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - '>='
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 2.0.14
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: A simple ruby client for node.js's socket.io. Supports only WebSocket.
141
+ test_files: []