libwebsocket 0.1.6.1 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.7 / 2012-11-29
4
+
5
+ - Restore behaviour of LibWebSocket::OpeningHandshake::Client#url
6
+
3
7
  ## 0.1.6.1 / 2012-11-19
4
8
 
5
9
  - Fix `uninitialized constant LibWebSocket::OpeningHandshake::Forwardable` error
data/lib/libwebsocket.rb CHANGED
@@ -4,7 +4,8 @@ require 'websocket'
4
4
  # or clients to provide WebSocket support.
5
5
  module LibWebSocket
6
6
 
7
- autoload :Frame, "#{File.dirname(__FILE__)}/libwebsocket/frame"
7
+ autoload :Frame, "#{File.dirname(__FILE__)}/libwebsocket/frame"
8
8
  autoload :OpeningHandshake, "#{File.dirname(__FILE__)}/libwebsocket/opening_handshake"
9
+ autoload :URL, "#{File.dirname(__FILE__)}/libwebsocket/url"
9
10
 
10
11
  end
@@ -34,12 +34,18 @@ module LibWebSocket
34
34
  # h.done? # Returns true
35
35
  class Client < OpeningHandshake
36
36
 
37
- def_delegator :controller, :uri, :url
37
+ def_delegator :controller, :uri
38
38
 
39
39
  def initialize(hash = {})
40
40
  @controller = ::WebSocket::Handshake::Client.new({:version => 76}.merge(hash))
41
41
  end
42
42
 
43
+ def url
44
+ lws_url = LibWebSocket::URL.new
45
+ lws_url.parse(uri)
46
+ lws_url
47
+ end
48
+
43
49
  end
44
50
  end
45
51
  end
@@ -0,0 +1,68 @@
1
+ require 'addressable/uri'
2
+
3
+ module LibWebSocket
4
+ # Construct or parse a WebSocket URL.
5
+ class URL
6
+
7
+ attr_accessor :secure, :host, :port, :resource_name
8
+
9
+ def initialize(hash = {})
10
+ hash.each do |k,v|
11
+ instance_variable_set("@#{k}",v)
12
+ end
13
+
14
+ @secure ||= false
15
+ end
16
+
17
+ # Parse a WebSocket URL.
18
+ # @example Parse
19
+ # url = LibWebSocket::URL.new
20
+ # url.parse('wss://example.com:3000')
21
+ # url.host # => example.com
22
+ # url.port # => 3000
23
+ # url.secure # => true
24
+ def parse(string)
25
+ return nil unless string.is_a?(String)
26
+
27
+ uri = Addressable::URI.parse(string)
28
+
29
+ scheme = uri.scheme
30
+ return nil unless scheme
31
+
32
+ self.secure = true if scheme.match(/ss\Z/m)
33
+
34
+ host = uri.host
35
+ host = '/' unless host && host != ''
36
+ self.host = host
37
+ self.port = uri.port.to_s if uri.port
38
+
39
+ request_uri = uri.path
40
+ request_uri = '/' unless request_uri && request_uri != ''
41
+ request_uri += "?" + uri.query if uri.query
42
+ self.resource_name = request_uri
43
+
44
+ return self
45
+ end
46
+
47
+ # Construct a WebSocket URL.
48
+ # @example Construct
49
+ # url = LibWebSocket::URL.new
50
+ # url.host = 'example.com'
51
+ # url.port = '3000'
52
+ # url.secure = true
53
+ # url.to_s # => 'wss://example.com:3000'
54
+ def to_s
55
+ string = ''
56
+
57
+ string += 'ws'
58
+ string += 's' if self.secure
59
+ string += '://'
60
+ string += self.host
61
+ string += ':' + self.port.to_s if self.port
62
+ string += self.resource_name || '/'
63
+
64
+ return string
65
+ end
66
+
67
+ end
68
+ end
@@ -1,3 +1,3 @@
1
1
  module LibWebSocket
2
- VERSION = '0.1.6.1'
2
+ VERSION = '0.1.7'
3
3
  end
data/libwebsocket.gemspec CHANGED
@@ -13,6 +13,7 @@ Gem::Specification.new do |s|
13
13
  s.description = %q{Universal Ruby library to handle WebSocket protocol}
14
14
 
15
15
  s.add_dependency 'websocket'
16
+ s.add_dependency 'addressable'
16
17
  s.add_development_dependency 'rake'
17
18
 
18
19
  s.files = `git ls-files`.split("\n")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libwebsocket
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6.1
4
+ version: 0.1.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-19 00:00:00.000000000 Z
12
+ date: 2012-11-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: websocket
@@ -27,6 +27,22 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: addressable
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
30
46
  - !ruby/object:Gem::Dependency
31
47
  name: rake
32
48
  requirement: !ruby/object:Gem::Requirement
@@ -63,6 +79,7 @@ files:
63
79
  - lib/libwebsocket/opening_handshake.rb
64
80
  - lib/libwebsocket/opening_handshake/client.rb
65
81
  - lib/libwebsocket/opening_handshake/server.rb
82
+ - lib/libwebsocket/url.rb
66
83
  - lib/libwebsocket/version.rb
67
84
  - libwebsocket.gemspec
68
85
  - test/libwebsocket/opening_handshake/test_client.rb
@@ -81,18 +98,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
81
98
  - - ! '>='
82
99
  - !ruby/object:Gem::Version
83
100
  version: '0'
84
- segments:
85
- - 0
86
- hash: -2175210411594514962
87
101
  required_rubygems_version: !ruby/object:Gem::Requirement
88
102
  none: false
89
103
  requirements:
90
104
  - - ! '>='
91
105
  - !ruby/object:Gem::Version
92
106
  version: '0'
93
- segments:
94
- - 0
95
- hash: -2175210411594514962
96
107
  requirements: []
97
108
  rubyforge_project:
98
109
  rubygems_version: 1.8.24