rubyfox-client 0.1.0-java → 0.2.0-java

Sign up to get free protection for your applications and to get access to all the features.
data/examples/any.rb ADDED
@@ -0,0 +1,43 @@
1
+ require 'rubyfox/client'
2
+
3
+ unless ARGV.size == 3
4
+ abort "usage: #{$0} username password zone"
5
+ end
6
+
7
+ unless ENV['SF_DIR']
8
+ abort "Point SF_DIR to your SmartFox installation"
9
+ end
10
+
11
+ Rubyfox::Client.require_libs(ENV['SF_DIR'] + "/lib")
12
+ Rubyfox::Client.boot!
13
+
14
+ Rubyfox::Client.new(:debug => true) do |client|
15
+ client.on_event :connection do
16
+ client.send :login, *ARGV
17
+ end
18
+
19
+ client.on_event :connection_attempt_http, :connection_resume, :connection_retry do |event|
20
+ end
21
+
22
+ client.on_event :login do |event|
23
+ p :login => event
24
+ client.send_extension "KeepAlive"
25
+ end
26
+
27
+ client.on_event :login_error, :connection_lost, :logout do |event|
28
+ p :out => event
29
+ client.exit
30
+ end
31
+
32
+ client.on_extension "KeepAlive" do |request|
33
+ client.disconnect
34
+ end
35
+
36
+ client.on_event :any do |event|
37
+ p :any_event => event
38
+ end
39
+
40
+ client.on_extension :any do |request|
41
+ p :any_request => request
42
+ end
43
+ end
@@ -20,25 +20,34 @@ module Rubyfox
20
20
 
21
21
  def add(*names, &block)
22
22
  names.each do |name|
23
- type = Event[name]
24
- @handler[type] << block
23
+ @handler[event_type(name)] << block
25
24
  end
26
25
  end
27
26
 
28
27
  def remove(*names)
29
28
  names.each do |name|
30
- type = Event[name]
31
- @handler[type].clear
29
+ @handler[event_type(name)].clear
32
30
  end
33
31
  end
34
32
 
35
33
  def dispatch(event)
36
34
  type = event.type
37
35
 
38
- @handler[type].each do |handler|
36
+ handlers = @handler[:any] + @handler[type]
37
+ handlers.each do |handler|
39
38
  handler.call(event)
40
39
  end
41
40
  end
41
+
42
+ private
43
+
44
+ def event_type(name)
45
+ if name == :any
46
+ name
47
+ else
48
+ Event[name]
49
+ end
50
+ end
42
51
  end
43
52
  end
44
53
  end
@@ -21,23 +21,34 @@ module Rubyfox
21
21
 
22
22
  def add(*names, &block)
23
23
  names.each do |name|
24
- @handler[name.to_s] << block
24
+ @handler[resolve_command(name)] << block
25
25
  end
26
26
  end
27
27
 
28
28
  def remove(*names)
29
29
  names.each do |name|
30
- @handler[name.to_s].clear
30
+ @handler[resolve_command(name)].clear
31
31
  end
32
32
  end
33
33
 
34
34
  def dispatch(request)
35
35
  command = request.command
36
36
 
37
- @handler[command].each do |handler|
37
+ handlers = @handler[:any] + @handler[command]
38
+ handlers.each do |handler|
38
39
  handler.call(request)
39
40
  end
40
41
  end
42
+
43
+ private
44
+
45
+ def resolve_command(name)
46
+ if name == :any
47
+ name
48
+ else
49
+ name.to_s
50
+ end
51
+ end
41
52
  end
42
53
  end
43
54
  end
@@ -1,5 +1,5 @@
1
1
  module Rubyfox
2
2
  module Client
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: rubyfox-client
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.0
5
+ version: 0.2.0
6
6
  platform: java
7
7
  authors:
8
8
  - Peter Suschlik
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-11-09 00:00:00.000000000 Z
13
+ date: 2012-11-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -95,6 +95,7 @@ files:
95
95
  - Gemfile
96
96
  - README.rdoc
97
97
  - Rakefile
98
+ - examples/any.rb
98
99
  - examples/keep_alive.rb
99
100
  - examples/simple.rb
100
101
  - lib/rubyfox/client.rb