hybridgroup-celluloid-websocket-client 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f7e673bc787d5295036d3974c03619b545d21625
4
+ data.tar.gz: 957cc1ceb5fb4bee4933469a9444632447549621
5
+ SHA512:
6
+ metadata.gz: 4fd57b0c21bd21c4d3a74ffa4ca4e1156358773ffb4d6050b4c90b2399abdd269c37b44ba8ed762071786a22b3250804fb0a874d4b8ed2cb66e0a657393b69b6
7
+ data.tar.gz: 6c47aff4b747aee959138b453689b6dfa01d11137f084644685a148794e1376f397e690be7f57329a86a810b159a7919c4a6bbc0fba48e8baefe72f4d946fbcb
@@ -0,0 +1,15 @@
1
+ require 'websocket/driver'
2
+ require 'celluloid'
3
+ require 'celluloid/io'
4
+
5
+ module Celluloid
6
+ module WebSocket
7
+ module Client
8
+ def self.new(*args)
9
+ Connection.new(*args)
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+ require 'celluloid/websocket/client/connection'
@@ -0,0 +1,56 @@
1
+ require 'forwardable'
2
+
3
+ module Celluloid
4
+ module WebSocket
5
+ module Client
6
+ class Connection
7
+ include Celluloid::IO
8
+ extend Forwardable
9
+
10
+ def initialize(url, handler=nil)
11
+ @url = url
12
+ uri = URI.parse(url)
13
+ port = uri.port || (uri.scheme == "ws" ? 80 : 443)
14
+ @socket = Celluloid::IO::TCPSocket.new(uri.host, port)
15
+ @client = ::WebSocket::Driver.client(self)
16
+ @handler = handler
17
+
18
+ start
19
+ end
20
+
21
+ attr_reader :url
22
+ attr_accessor :handler
23
+
24
+ def start
25
+ async.run if handler
26
+ end
27
+
28
+ def run
29
+ @client.on('open') do |event|
30
+ @handler.async.on_open if @handler.respond_to?(:on_open)
31
+ end
32
+ @client.on('message') do |event|
33
+ @handler.async.on_message(event.data) if @handler.respond_to?(:on_message)
34
+ end
35
+ @client.on('close') do |event|
36
+ @handler.async.on_close(event.code, event.reason) if @handler.respond_to?(:on_close)
37
+ end
38
+
39
+ @client.start
40
+
41
+ loop do
42
+ @client.parse(@socket.readpartial(1024))
43
+ end
44
+ end
45
+
46
+ def_delegators :@client, :text, :binary, :ping, :close, :protocol
47
+
48
+ def write(buffer)
49
+ @socket.write buffer
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hybridgroup-celluloid-websocket-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Jeremy Deininger
8
+ - Tim Carey-Smith
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: websocket-driver
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '>='
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '>='
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: celluloid-io
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: pry
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ description:
57
+ email:
58
+ - jeremydeininger@gmail.com
59
+ - tim@spork.in
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - lib/celluloid/websocket/client/connection.rb
65
+ - lib/celluloid/websocket/client.rb
66
+ homepage:
67
+ licenses: []
68
+ metadata: {}
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 2.0.3
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: websocket client using celluloid-io
89
+ test_files: []