kosmonaut 0.2.1 → 0.2.2

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.
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
@@ -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 = "0.2.1"
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"]
@@ -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
@@ -9,20 +9,48 @@ module Kosmonaut
9
9
  class Client < Socket
10
10
  include Kosmonaut
11
11
 
12
- REQUEST_TIMEOUT = 5 # in seconds
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, type)
25
- payload = ["OC", name, type]
52
+ def open_channel(name)
53
+ payload = ["OC", name]
26
54
  perform_request(payload)
27
55
  end
28
56
 
@@ -2,7 +2,7 @@ module Kosmonaut
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 2
5
- PATCH = 0
5
+ PATCH = 2
6
6
 
7
7
  def self.to_s
8
8
  [MAJOR, MINOR, PATCH].join('.')
@@ -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", 0)
21
+ @client.open_channel("foo")
22
22
  end
23
23
 
24
24
  def _test_open_channel_with_invalid_name
25
- @client.open_channel("%%%", 0)
25
+ @client.open_channel("%%%")
26
26
  assert false
27
27
  rescue Kosmonaut::InvalidChannelNameError
28
28
  end
@@ -21,7 +21,7 @@ class TestKosmonautWorker < MiniTest::Unit::TestCase
21
21
 
22
22
  def test_api
23
23
  Thread.new {
24
- sleep(15)
24
+ sleep(10)
25
25
  @worker.stop
26
26
  }
27
27
  @worker.listen
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: kosmonaut
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.1
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-17 00:00:00 Z
14
+ date: 2012-01-20 00:00:00 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: json