socket.io-client-simple 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ab9042c09b285423f80e10e4e72414f8baec5b45
4
- data.tar.gz: a0065e0fdb5d0dd66ff456c345b19d18a6417682
3
+ metadata.gz: 2afed194d20af9d81e21b0048f1c056f12736ea1
4
+ data.tar.gz: 6113d9b1854c2a2a9e97fe37f682be60fa634e52
5
5
  SHA512:
6
- metadata.gz: 31d37108d0c8f1e6d30e846f9bafdcd8a6ce30519bfde0d6c7f19a33008882fd3b758eebb5db01f3715b7ae803f05617ba67da01524be5e8498546d6dffc2075
7
- data.tar.gz: 5c8b46848ab98204912670929e243aeffb31d230ee438df54f0ba18f7c0082db92c9d759f314e91eec676e224192dabfbe06b88fca80721196ed15053e057901
6
+ metadata.gz: 0a7d3e056498915bb1ab326dc070962cc2d84127799af6f65670e3c7fa35b8684e574538d2aa420da0d4449493c6b1559e34af69df7fbdb74e34927710021551
7
+ data.tar.gz: b3f08e4f17e8cb4075b2e16d29a77a1c486e8508383c315a20ede5cd8caeeb616922c955e8e4370e1ebed34ed99b92dfb9851762c16a7cbfa94434116f3430e4
data/.gitignore CHANGED
@@ -17,3 +17,4 @@ spec/reports
17
17
  test/tmp
18
18
  test/version_tmp
19
19
  tmp
20
+ node_modules
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ node_js:
3
+ - "0.10"
4
+ rvm:
5
+ - 1.9.3
6
+ - 2.0.0
7
+ - jruby-head
8
+ before_script:
9
+ - npm install
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- socket.io-client-simple (0.0.1)
4
+ socket.io-client-simple (0.0.2)
5
5
  event_emitter
6
6
  httparty
7
7
  json
@@ -15,6 +15,7 @@ GEM
15
15
  json (~> 1.8)
16
16
  multi_xml (>= 0.5.2)
17
17
  json (1.8.1)
18
+ minitest (5.2.1)
18
19
  multi_xml (0.5.5)
19
20
  rake (10.1.1)
20
21
  websocket (1.1.2)
@@ -27,5 +28,6 @@ PLATFORMS
27
28
 
28
29
  DEPENDENCIES
29
30
  bundler (~> 1.3)
31
+ minitest
30
32
  rake
31
33
  socket.io-client-simple!
data/History.txt ADDED
@@ -0,0 +1,8 @@
1
+ === 0.0.2 2014-1-18
2
+
3
+ * bugfix "disconnect" event
4
+
5
+ === 0.0.1 2014-1-15
6
+
7
+ * first release
8
+ * implemented "emit" and "on"
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
  A simple ruby client for node.js's socket.io. Supports only WebSocket.
3
3
 
4
4
  - https://github.com/shokai/ruby-socket.io-client-simple
5
- - https://rubygems.org/gems/ruby-socket.io-client-simple
5
+ - https://rubygems.org/gems/socket.io-client-simple
6
6
 
7
7
 
8
8
  ## Install
@@ -17,17 +17,17 @@ A simple ruby client for node.js's socket.io. Supports only WebSocket.
17
17
  require 'rubygems'
18
18
  require 'socket.io-client-simple'
19
19
 
20
- client = SocketIO::Client::Simple.connect 'http://localhost:3000'
20
+ socket = SocketIO::Client::Simple.connect 'http://localhost:3000'
21
21
 
22
- client.on :connect do
22
+ socket.on :connect do
23
23
  puts "connect!!!"
24
24
  end
25
25
 
26
- client.on :disconnect do
26
+ socket.on :disconnect do
27
27
  puts "disconnected!!"
28
28
  end
29
29
 
30
- client.on :chat do |data|
30
+ socket.on :chat do |data|
31
31
  puts "> " + data['msg']
32
32
  end
33
33
 
@@ -35,7 +35,7 @@ puts "please input and press Enter key"
35
35
  loop do
36
36
  msg = STDIN.gets.strip
37
37
  next if msg.empty?
38
- client.emit :chat, {:msg => msg, :at => Time.now}
38
+ socket.emit :chat, {:msg => msg, :at => Time.now}
39
39
  end
40
40
  ```
41
41
 
@@ -43,7 +43,7 @@ sample.rb works with [samples/chat_server.js](https://github.com/shokai/ruby-soc
43
43
 
44
44
  ### start chat server
45
45
 
46
- % npm install socket.io
46
+ % npm install
47
47
  % node samples/chat_server.js
48
48
 
49
49
  => chat server start at localhost:3000
data/Rakefile CHANGED
@@ -1 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.pattern = "test/test_*.rb"
6
+ end
7
+
8
+ task :default => :test
@@ -39,7 +39,7 @@ module SocketIO
39
39
  end
40
40
 
41
41
  @websocket.on :close do
42
- this.emit :disconnect
42
+ this.__emit :disconnect
43
43
  end
44
44
 
45
45
  @websocket.send "1::#{opts[:path]}"
@@ -1,7 +1,7 @@
1
1
  module SocketIO
2
2
  module Client
3
3
  module Simple
4
- VERSION = "0.0.1"
4
+ VERSION = "0.0.2"
5
5
  end
6
6
  end
7
7
  end
data/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "ruby-socket.io-client-simple",
3
+ "description": "A simple ruby client for node.js's socket.io. Supports only WebSocket.",
4
+ "private": true,
5
+ "author": "Sho Hashimoto <hashimoto@shokai.org>",
6
+ "license": "MIT",
7
+ "homepage": "https://github.com/shokai/ruby-socket.io-client-simple",
8
+ "dependencies": {
9
+ "socket.io": "~0.9.16"
10
+ },
11
+ "devDependencies": {},
12
+ "scripts": {
13
+ "start": "node samples/chat_server.js"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git://github.com/shokai/ruby-socket.io-client-simple.git"
18
+ },
19
+ "bugs": {
20
+ "url": "https://github.com/shokai/ruby-socket.io-client-simple/issues"
21
+ }
22
+ }
@@ -1,6 +1,8 @@
1
1
  // socket.io chat server
2
+ var port = (process.env.PORT || 3000) - 0;
2
3
 
3
- var io = require('socket.io').listen(3000);
4
+ var io = require('socket.io').listen(port);
5
+ console.log("socket.io server start - port:"+port);
4
6
 
5
7
  io.sockets.on('connection', function(socket){
6
8
  socket.emit('chat', {msg: 'hello world (from server)'});
@@ -9,3 +11,10 @@ io.sockets.on('connection', function(socket){
9
11
  socket.emit('chat', data); // echo
10
12
  });
11
13
  });
14
+
15
+
16
+ if(!!process.env.EXIT_AT){
17
+ setTimeout(function(){
18
+ process.exit();
19
+ }, process.env.EXIT_AT-0);
20
+ }
data/samples/sample.rb CHANGED
@@ -2,21 +2,21 @@ $:.unshift File.expand_path '../lib', File.dirname(__FILE__)
2
2
  require 'rubygems'
3
3
  require 'socket.io-client-simple'
4
4
 
5
- client = SocketIO::Client::Simple.connect 'http://localhost:3000'
5
+ socket = SocketIO::Client::Simple.connect 'http://localhost:3000'
6
6
 
7
- #client.websocket.on :message do |msg|
7
+ #socket.websocket.on :message do |msg| ## inspect websocket data
8
8
  # p msg.data
9
9
  #end
10
10
 
11
- client.on :connect do
11
+ socket.on :connect do
12
12
  puts "connect!!!"
13
13
  end
14
14
 
15
- client.on :disconnect do
15
+ socket.on :disconnect do
16
16
  puts "disconnected!!"
17
17
  end
18
18
 
19
- client.on :chat do |data|
19
+ socket.on :chat do |data|
20
20
  puts "> " + data['msg']
21
21
  end
22
22
 
@@ -24,5 +24,5 @@ puts "please input and press Enter key"
24
24
  loop do
25
25
  msg = STDIN.gets.strip
26
26
  next if msg.empty?
27
- client.emit :chat, {:msg => msg, :at => Time.now}
27
+ socket.emit :chat, {:msg => msg, :at => Time.now}
28
28
  end
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "minitest"
23
24
 
24
25
  spec.add_dependency "json"
25
26
  spec.add_dependency "websocket-client-simple"
data/test/server.rb ADDED
@@ -0,0 +1,16 @@
1
+ class TestServer
2
+
3
+ def self.port
4
+ (ENV['PORT'] || 13000).to_i
5
+ end
6
+
7
+ def self.start(exit_at=4000)
8
+ system "PORT=#{port} EXIT_AT=#{exit_at} npm start > /dev/null &"
9
+ sleep 1
10
+ end
11
+
12
+ def self.url
13
+ "http://localhost:#{port}"
14
+ end
15
+
16
+ end
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'minitest/autorun'
4
+
5
+ require File.expand_path 'server', File.dirname(__FILE__)
6
+
7
+ $:.unshift File.expand_path '../lib', File.dirname(__FILE__)
8
+ require 'socket.io-client-simple'
@@ -0,0 +1,35 @@
1
+ require File.expand_path 'test_helper', File.dirname(__FILE__)
2
+
3
+ class TestSocketIOClientSimple < MiniTest::Test
4
+
5
+ def setup
6
+ TestServer.start
7
+ end
8
+
9
+ def test_connect
10
+ socket = SocketIO::Client::Simple.connect TestServer.url
11
+ result = false
12
+ socket.on :connect do
13
+ result = true
14
+ end
15
+ sleep 0.5
16
+ assert result
17
+ end
18
+
19
+ def test_emit_on
20
+ socket = SocketIO::Client::Simple.connect TestServer.url
21
+ result = nil
22
+ socket.on :chat do |data| ## receive echo
23
+ result = data
24
+ end
25
+
26
+ post_data = {"msg" => "hello", "at" => Time.now.to_s}
27
+ socket.on :connect do
28
+ socket.emit :chat, post_data
29
+ end
30
+
31
+ sleep 0.5
32
+ assert_equal post_data, result
33
+ end
34
+
35
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: socket.io-client-simple
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sho Hashimoto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-15 00:00:00.000000000 Z
11
+ date: 2014-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
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: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: json
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -102,8 +116,10 @@ extensions: []
102
116
  extra_rdoc_files: []
103
117
  files:
104
118
  - .gitignore
119
+ - .travis.yml
105
120
  - Gemfile
106
121
  - Gemfile.lock
122
+ - History.txt
107
123
  - LICENSE.txt
108
124
  - README.md
109
125
  - Rakefile
@@ -111,9 +127,13 @@ files:
111
127
  - lib/socket.io-client-simple/client.rb
112
128
  - lib/socket.io-client-simple/error.rb
113
129
  - lib/socket.io-client-simple/version.rb
130
+ - package.json
114
131
  - samples/chat_server.js
115
132
  - samples/sample.rb
116
133
  - socket.io-client-simple.gemspec
134
+ - test/server.rb
135
+ - test/test_helper.rb
136
+ - test/test_socket.io.rb
117
137
  homepage: https://github.com/shokai/ruby-socket.io-client-simple
118
138
  licenses:
119
139
  - MIT
@@ -138,4 +158,7 @@ rubygems_version: 2.0.14
138
158
  signing_key:
139
159
  specification_version: 4
140
160
  summary: A simple ruby client for node.js's socket.io. Supports only WebSocket.
141
- test_files: []
161
+ test_files:
162
+ - test/server.rb
163
+ - test/test_helper.rb
164
+ - test/test_socket.io.rb