kosmonaut 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +9 -0
- data/NEWS +5 -2
- data/kosmonaut.gemspec +2 -1
- data/lib/kosmonaut.rb +7 -0
- data/lib/kosmonaut/client.rb +31 -3
- data/lib/kosmonaut/version.rb +1 -1
- data/test/test_kosmonaut_client.rb +2 -2
- data/test/test_kosmonaut_worker.rb +1 -1
- metadata +2 -2
data/ChangeLog
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
2012-01-20 Krzysztof Kowalik <chris@nu7hat.ch>
|
2
|
+
|
3
|
+
* test/test_kosmonaut_worker.rb: shortened test time
|
4
|
+
|
5
|
+
2012-01-18 Krzysztof Kowalik <chris@nu7hat.ch>
|
6
|
+
|
7
|
+
* lib/kosmonaut.rb: added documentation
|
8
|
+
* lib/kosmonaut/client.rb: added docs for part of the methods
|
9
|
+
|
1
10
|
2012-01-16 Krzysztof Kowalik <chris@nu7hat.ch>
|
2
11
|
|
3
12
|
* lib/kosmonaut/socket.rb: base for worker and client
|
data/NEWS
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
Releases
|
2
2
|
========
|
3
3
|
|
4
|
+
v0.2.1
|
5
|
+
------
|
6
|
+
* Fixed behaviour of the worker's listener.
|
7
|
+
|
4
8
|
v0.2.0
|
5
9
|
------
|
6
|
-
* Pure ruby implementation of the client and worker using
|
7
|
-
majordomo pattern.
|
10
|
+
* Pure ruby implementation of the client and worker using majordomo pattern.
|
8
11
|
* Tests for the API
|
data/kosmonaut.gemspec
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
# -*- ruby -*-
|
2
2
|
require 'rubygems'
|
3
|
+
require File.expand_path("../lib/kosmonaut/version", __FILE__)
|
3
4
|
|
4
5
|
Gem::Specification.new do |s|
|
5
6
|
s.name = "kosmonaut"
|
6
|
-
s.version =
|
7
|
+
s.version = Kosmonaut.version
|
7
8
|
s.summary = "Ruby client for the WebRocket backend"
|
8
9
|
s.description = "The WebRocket server backend client for ruby programming language"
|
9
10
|
s.authors = ["Krzysztof Kowalik", "Cubox"]
|
data/lib/kosmonaut.rb
CHANGED
@@ -6,8 +6,15 @@ require 'kosmonaut/version'
|
|
6
6
|
|
7
7
|
module Kosmonaut
|
8
8
|
extend self
|
9
|
+
|
10
|
+
# Public: The debug mode switch. If true, then debug messages will
|
11
|
+
# be printed out.
|
9
12
|
attr_accessor :debug
|
10
13
|
|
14
|
+
# Internal: Simple logging method used to display debug information
|
15
|
+
#
|
16
|
+
# msg - The debug message to be displayed
|
17
|
+
#
|
11
18
|
def log(msg)
|
12
19
|
print("DEBUG: ", msg, "\n") if Kosmonaut.debug
|
13
20
|
end
|
data/lib/kosmonaut/client.rb
CHANGED
@@ -9,20 +9,48 @@ module Kosmonaut
|
|
9
9
|
class Client < Socket
|
10
10
|
include Kosmonaut
|
11
11
|
|
12
|
-
|
12
|
+
# Maximum number of seconds to wait for the request to being processed.
|
13
|
+
REQUEST_TIMEOUT = 5
|
13
14
|
|
15
|
+
# Public: The Client constructor. Pre-configures the client instance. See
|
16
|
+
# also the Kosmonaut::Socket#initialize for the details.
|
17
|
+
#
|
18
|
+
# url - The WebRocket backend endpoint URL to connect to.
|
19
|
+
#
|
20
|
+
# The endpoint's URL must have the following format:
|
21
|
+
#
|
22
|
+
# [scheme]://[secret]@[host]:[port]/[vhost]
|
23
|
+
#
|
24
|
+
# Examples
|
25
|
+
#
|
26
|
+
# c = Kosmonaut::Client.new("wr://f343...fa4a@myhost.com:8080/hello")
|
27
|
+
# c.broadcast("room", "status", {"message" => "is going to the beach!"})
|
28
|
+
#
|
14
29
|
def initialize(url)
|
15
30
|
super(url)
|
16
31
|
@mtx = Mutex.new
|
17
32
|
end
|
18
33
|
|
34
|
+
# Public: Broadcasts a event with attached data on the specified channel.
|
35
|
+
# The data attached to the event must be a hash!
|
36
|
+
#
|
37
|
+
# channel - A name of the channel to broadcast to.
|
38
|
+
# event - A name of the event to be triggered.
|
39
|
+
# data - The data attached to the event.
|
40
|
+
#
|
41
|
+
# Examples
|
42
|
+
#
|
43
|
+
# c.broadcast("room", "away", {"message" => "on the meeting"})
|
44
|
+
# c.broadcast("room". "message", {"content" => "Hello World!"})
|
45
|
+
# c.broadcast("room". "status", {"message" => "is saying hello!"})
|
46
|
+
#
|
19
47
|
def broadcast(channel, event, data)
|
20
48
|
payload = ["BC", channel, event, data.to_json]
|
21
49
|
perform_request(payload)
|
22
50
|
end
|
23
51
|
|
24
|
-
def open_channel(name
|
25
|
-
payload = ["OC", name
|
52
|
+
def open_channel(name)
|
53
|
+
payload = ["OC", name]
|
26
54
|
perform_request(payload)
|
27
55
|
end
|
28
56
|
|
data/lib/kosmonaut/version.rb
CHANGED
@@ -18,11 +18,11 @@ class TestKosmonautClient < MiniTest::Unit::TestCase
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def _test_open_channel
|
21
|
-
@client.open_channel("foo"
|
21
|
+
@client.open_channel("foo")
|
22
22
|
end
|
23
23
|
|
24
24
|
def _test_open_channel_with_invalid_name
|
25
|
-
@client.open_channel("%%%"
|
25
|
+
@client.open_channel("%%%")
|
26
26
|
assert false
|
27
27
|
rescue Kosmonaut::InvalidChannelNameError
|
28
28
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: kosmonaut
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.2.
|
5
|
+
version: 0.2.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Krzysztof Kowalik
|
@@ -11,7 +11,7 @@ autorequire:
|
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
|
14
|
-
date: 2012-01-
|
14
|
+
date: 2012-01-20 00:00:00 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: json
|