faye-client 0.1.0 → 0.2.0

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -0,0 +1,73 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "faye-client"
8
+ s.version = "0.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Brian Goff"]
12
+ s.date = "2012-09-08"
13
+ s.description = "Quickly and easily connect your app to a Faye server"
14
+ s.email = "cpuguy83@gmail.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "faye-client.gemspec",
28
+ "lib/faye-client.rb",
29
+ "lib/faye_client/channel_handlers/default_channel_handler.rb",
30
+ "lib/faye_client/faye_client.rb",
31
+ "test/helper.rb",
32
+ "test/test_faye-client.rb"
33
+ ]
34
+ s.homepage = "http://github.com/cpuguy83/faye-client"
35
+ s.licenses = ["MIT"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = "1.8.24"
38
+ s.summary = "Quickly and easily connect your app to a Faye server"
39
+
40
+ if s.respond_to? :specification_version then
41
+ s.specification_version = 3
42
+
43
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
+ s.add_runtime_dependency(%q<faye>, [">= 0"])
45
+ s.add_runtime_dependency(%q<eventmachine>, [">= 0"])
46
+ s.add_runtime_dependency(%q<sidekiq>, [">= 0"])
47
+ s.add_runtime_dependency(%q<active_support>, [">= 0"])
48
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
49
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
50
+ s.add_development_dependency(%q<bundler>, ["~> 1.1.1"])
51
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
52
+ else
53
+ s.add_dependency(%q<faye>, [">= 0"])
54
+ s.add_dependency(%q<eventmachine>, [">= 0"])
55
+ s.add_dependency(%q<sidekiq>, [">= 0"])
56
+ s.add_dependency(%q<active_support>, [">= 0"])
57
+ s.add_dependency(%q<shoulda>, [">= 0"])
58
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
59
+ s.add_dependency(%q<bundler>, ["~> 1.1.1"])
60
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
61
+ end
62
+ else
63
+ s.add_dependency(%q<faye>, [">= 0"])
64
+ s.add_dependency(%q<eventmachine>, [">= 0"])
65
+ s.add_dependency(%q<sidekiq>, [">= 0"])
66
+ s.add_dependency(%q<active_support>, [">= 0"])
67
+ s.add_dependency(%q<shoulda>, [">= 0"])
68
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
69
+ s.add_dependency(%q<bundler>, ["~> 1.1.1"])
70
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
71
+ end
72
+ end
73
+
@@ -1,4 +1,27 @@
1
1
  module FayeClient
2
+ # extend FayeClient in your class to use
3
+ # the "start" method spins off the EM instance with the Faye client to it's own thread
4
+ # You can access the the client itself or the thread using the class accessor methods "messaging_client" and "messaging_client_thread", respectively
5
+ # You must specify a :messaging_server_url and :messaging_channels using the available class accessors
6
+ # You should also supply a default_channel_handler_class_name and a default_channel_handler_method or it will default to the built-in handler, which is useless
7
+ # Alternatively (or in addition to), you can specify a Hash for your channel which would specify which class/method to use to handler the incoming message
8
+ # Example:
9
+ #
10
+ # class MyClientClass
11
+ # extend FayeClient
12
+ # self.messaging_server_url = 'http://myserver/faye'
13
+ # self.messaging_channels = ['/foo', '/bar', {name: '/foofoo', handler_class_name: FooFooHandlerClass, handler_method_name: 'foofoo_handler_method' }]
14
+ # self.default_channel_handler_class_name = 'MyDefaultHandlerClass'
15
+ # self.default_channel_handler_method = 'my_default_handler_method'
16
+ # end
17
+ #
18
+ # MyClient.start
19
+ #
20
+ # Channels for '/foo' and '/bar' in the above example will use the default class/method combo specified
21
+ # Channel '/foofoo' will use the specified class/method, assuming they are defined
22
+
23
+
24
+
2
25
  attr_accessor :messaging_client, :messaging_client_thread, :messaging_server_url, :messaging_channels
3
26
  attr_accessor :default_channel_handler_class_name, :default_channel_handler_method
4
27
 
@@ -24,11 +47,20 @@ module FayeClient
24
47
  end
25
48
  end
26
49
 
50
+ # Publish a :message to a :channel
51
+ def publish(options)
52
+ raise 'NoChannelProvided' unless options[:channel]
53
+ raise 'NoMessageProvided' unless options[:message]
54
+ messaging_client.publish(options[:channel], options[:message])
55
+ end
56
+
57
+ # Stop the running client
27
58
  def stop
28
59
  raise "NotRunning" if !running?
29
- EM.stop
60
+ self.messaging_client.disconnect
30
61
  end
31
62
 
63
+ # Restart the running client
32
64
  def restart
33
65
  stop
34
66
  start
@@ -37,9 +69,14 @@ module FayeClient
37
69
 
38
70
  # Is the client running?
39
71
  def running?
40
- EM.reactor_running?
72
+ if self.messaging_client and self.messaging_client.state == :CONNECTED
73
+ true
74
+ else
75
+ false
76
+ end
41
77
  end
42
78
 
79
+ # Set the handler class/method to be used for a given channel
43
80
  def get_channel_handler(channel)
44
81
  if channel.is_a? String
45
82
  parsed_channel_name = channel.gsub(/^\//, '').gsub('/','::')
@@ -47,7 +84,7 @@ module FayeClient
47
84
  handler[:name] = channel
48
85
  elsif channel.is_a? Hash
49
86
  # Can provide a Hash to get full customization of handler names/methods
50
- handler = get_channel_handler_for_hash
87
+ handler = get_channel_handler_for_hash(channel)
51
88
  handler[:name] = channel[:name]
52
89
  else
53
90
  raise TypeError, 'Channel Must be a String or a Hash'
@@ -56,6 +93,7 @@ module FayeClient
56
93
  handler
57
94
  end
58
95
 
96
+ # If just a string is provided for a channel
59
97
  def get_channel_handler_for_string(channel)
60
98
  handler = {}
61
99
  # Set handler class
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faye-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
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-09-02 00:00:00.000000000 Z
12
+ date: 2012-09-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faye
@@ -154,6 +154,7 @@ files:
154
154
  - README.rdoc
155
155
  - Rakefile
156
156
  - VERSION
157
+ - faye-client.gemspec
157
158
  - lib/faye-client.rb
158
159
  - lib/faye_client/channel_handlers/default_channel_handler.rb
159
160
  - lib/faye_client/faye_client.rb
@@ -174,7 +175,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
174
175
  version: '0'
175
176
  segments:
176
177
  - 0
177
- hash: -1052917701805139625
178
+ hash: -1692075111458930586
178
179
  required_rubygems_version: !ruby/object:Gem::Requirement
179
180
  none: false
180
181
  requirements: