blather 0.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/CHANGELOG +2 -0
  2. data/Manifest +36 -33
  3. data/README.rdoc +11 -17
  4. data/Rakefile +4 -3
  5. data/blather.gemspec +9 -9
  6. data/examples/drb_client.rb +7 -0
  7. data/examples/echo.rb +9 -18
  8. data/lib/blather.rb +140 -31
  9. data/lib/blather/{core/errors.rb → errors.rb} +0 -0
  10. data/lib/blather/{core/jid.rb → jid.rb} +0 -0
  11. data/lib/blather/{core/roster.rb → roster.rb} +0 -0
  12. data/lib/blather/{core/roster_item.rb → roster_item.rb} +0 -0
  13. data/lib/blather/{core/stanza.rb → stanza.rb} +6 -14
  14. data/lib/blather/stanza/error.rb +31 -0
  15. data/lib/blather/{core/stanza → stanza}/iq.rb +2 -2
  16. data/lib/blather/stanza/iq/query.rb +50 -0
  17. data/lib/blather/{core/stanza → stanza}/iq/roster.rb +3 -3
  18. data/lib/blather/{core/stanza → stanza}/message.rb +6 -2
  19. data/lib/blather/{core/stanza → stanza}/presence.rb +10 -0
  20. data/lib/blather/{core/stanza → stanza}/presence/status.rb +8 -6
  21. data/lib/blather/{core/stanza → stanza}/presence/subscription.rb +1 -1
  22. data/lib/blather/{core/stream.rb → stream.rb} +1 -1
  23. data/lib/blather/{core/stream → stream}/parser.rb +0 -5
  24. data/lib/blather/{core/stream → stream}/resource.rb +0 -0
  25. data/lib/blather/{core/stream → stream}/sasl.rb +16 -5
  26. data/lib/blather/{core/stream → stream}/session.rb +0 -0
  27. data/lib/blather/{core/stream → stream}/tls.rb +0 -0
  28. data/lib/blather/{core/sugar.rb → sugar.rb} +4 -0
  29. data/lib/blather/{core/xmpp_node.rb → xmpp_node.rb} +1 -3
  30. data/spec/blather/{core/jid_spec.rb → jid_spec.rb} +16 -1
  31. data/spec/blather/{core/roster_item_spec.rb → roster_item_spec.rb} +1 -1
  32. data/spec/blather/{core/roster_spec.rb → roster_spec.rb} +11 -1
  33. data/spec/blather/stanza/iq/query_spec.rb +34 -0
  34. data/spec/blather/stanza/iq/roster_spec.rb +7 -0
  35. data/spec/blather/stanza/iq_spec.rb +11 -0
  36. data/spec/blather/stanza/message_spec.rb +52 -0
  37. data/spec/blather/stanza/presence/status_spec.rb +102 -0
  38. data/spec/blather/stanza/presence/subscription_spec.rb +74 -0
  39. data/spec/blather/stanza/presence_spec.rb +24 -0
  40. data/spec/blather/{core/stanza_spec.rb → stanza_spec.rb} +1 -1
  41. data/spec/blather/{core/stream_spec.rb → stream_spec.rb} +208 -9
  42. data/spec/blather/{core/xmpp_node_spec.rb → xmpp_node_spec.rb} +1 -1
  43. metadata +75 -69
  44. data/examples/shell_client.rb +0 -28
  45. data/lib/blather/callback.rb +0 -24
  46. data/lib/blather/client.rb +0 -81
  47. data/lib/blather/core/stanza/iq/query.rb +0 -42
  48. data/lib/blather/extensions.rb +0 -4
  49. data/lib/blather/extensions/last_activity.rb +0 -55
  50. data/lib/blather/extensions/version.rb +0 -85
data/CHANGELOG CHANGED
@@ -1 +1,3 @@
1
+ v0.2 Overhaul the DSL to look more like Sinatra
2
+
1
3
  v0.1 Initial release (birth!)
data/Manifest CHANGED
@@ -1,43 +1,46 @@
1
1
  CHANGELOG
2
+ examples/drb_client.rb
2
3
  examples/echo.rb
3
- examples/shell_client.rb
4
4
  lib/autotest/discover.rb
5
5
  lib/autotest/spec.rb
6
- lib/blather/callback.rb
7
- lib/blather/client.rb
8
- lib/blather/core/errors.rb
9
- lib/blather/core/jid.rb
10
- lib/blather/core/roster.rb
11
- lib/blather/core/roster_item.rb
12
- lib/blather/core/stanza/iq/query.rb
13
- lib/blather/core/stanza/iq/roster.rb
14
- lib/blather/core/stanza/iq.rb
15
- lib/blather/core/stanza/message.rb
16
- lib/blather/core/stanza/presence/status.rb
17
- lib/blather/core/stanza/presence/subscription.rb
18
- lib/blather/core/stanza/presence.rb
19
- lib/blather/core/stanza.rb
20
- lib/blather/core/stream/parser.rb
21
- lib/blather/core/stream/resource.rb
22
- lib/blather/core/stream/sasl.rb
23
- lib/blather/core/stream/session.rb
24
- lib/blather/core/stream/tls.rb
25
- lib/blather/core/stream.rb
26
- lib/blather/core/sugar.rb
27
- lib/blather/core/xmpp_node.rb
28
- lib/blather/extensions/last_activity.rb
29
- lib/blather/extensions/version.rb
30
- lib/blather/extensions.rb
6
+ lib/blather/errors.rb
7
+ lib/blather/jid.rb
8
+ lib/blather/roster.rb
9
+ lib/blather/roster_item.rb
10
+ lib/blather/stanza/error.rb
11
+ lib/blather/stanza/iq/query.rb
12
+ lib/blather/stanza/iq/roster.rb
13
+ lib/blather/stanza/iq.rb
14
+ lib/blather/stanza/message.rb
15
+ lib/blather/stanza/presence/status.rb
16
+ lib/blather/stanza/presence/subscription.rb
17
+ lib/blather/stanza/presence.rb
18
+ lib/blather/stanza.rb
19
+ lib/blather/stream/parser.rb
20
+ lib/blather/stream/resource.rb
21
+ lib/blather/stream/sasl.rb
22
+ lib/blather/stream/session.rb
23
+ lib/blather/stream/tls.rb
24
+ lib/blather/stream.rb
25
+ lib/blather/sugar.rb
26
+ lib/blather/xmpp_node.rb
31
27
  lib/blather.rb
32
28
  LICENSE
29
+ Manifest
33
30
  Rakefile
34
31
  README.rdoc
35
- spec/blather/core/jid_spec.rb
36
- spec/blather/core/roster_item_spec.rb
37
- spec/blather/core/roster_spec.rb
38
- spec/blather/core/stanza_spec.rb
39
- spec/blather/core/stream_spec.rb
40
- spec/blather/core/xmpp_node_spec.rb
32
+ spec/blather/jid_spec.rb
33
+ spec/blather/roster_item_spec.rb
34
+ spec/blather/roster_spec.rb
35
+ spec/blather/stanza/iq/query_spec.rb
36
+ spec/blather/stanza/iq/roster_spec.rb
37
+ spec/blather/stanza/iq_spec.rb
38
+ spec/blather/stanza/message_spec.rb
39
+ spec/blather/stanza/presence/status_spec.rb
40
+ spec/blather/stanza/presence/subscription_spec.rb
41
+ spec/blather/stanza/presence_spec.rb
42
+ spec/blather/stanza_spec.rb
43
+ spec/blather/stream_spec.rb
44
+ spec/blather/xmpp_node_spec.rb
41
45
  spec/build_safe.rb
42
46
  spec/spec_helper.rb
43
- Manifest
@@ -30,28 +30,22 @@ Jeff Smick <sprsquish@gmail.com>
30
30
 
31
31
  See the /examples directory for more advanced examples.
32
32
 
33
- This will auto-accept any subscription requests and echo back any messages or presence notifications.
33
+ This will auto-accept any subscription requests and echo back any chat messages.
34
34
 
35
- require 'lib/blather/client'
35
+ %w[rubygems blather].each { |r| require r }
36
36
 
37
- class Echo < Blather::Client
38
- # Auto-approve subscription requests
39
- def receive_subscription(s)
40
- send_data(s.approve!) and true if s.request?
41
- end
37
+ setup 'echo@jabber.local', 'echo'
42
38
 
43
- # Echo presence
44
- def receive_status(status)
45
- set_status(status.state, status.message, status.from) if roster[status.from]
46
- end
47
-
48
- # Echo message
49
- def receive_message(message)
50
- send_data(message.reply) if message.type == :chat
51
- end
39
+ # Auto approve subscription requests
40
+ handle :subscription do |s|
41
+ write(s.approve!) if s.request?
52
42
  end
53
43
 
54
- Blather.run 'echo@jabber.local', 'echo', Echo.new
44
+ # Echo back what was said
45
+ handle :message do |m|
46
+ write(m.reply) if m.chat? && m.body
47
+ end
48
+
55
49
 
56
50
 
57
51
  = License
data/Rakefile CHANGED
@@ -1,16 +1,17 @@
1
1
  require 'echoe'
2
- require 'lib/blather'
3
2
  require 'hanna/rdoctask'
4
3
 
5
4
  Echoe.new('blather') do |p|
6
5
  p.author = 'Jeff Smick'
7
6
  p.email = 'sprsquish@gmail.com'
7
+ p.url = 'http://github.com/sprsquish/blather/tree/master'
8
8
 
9
9
  p.project = 'squishtech'
10
- p.version = Blather::VERSION
11
10
  p.summary = 'An evented XMPP library written on EventMachine and libxml-ruby'
12
11
 
13
- p.runtime_dependencies = ['eventmachine', 'libxml >=1.0.11']
12
+ p.runtime_dependencies = ['eventmachine', 'libxml-ruby >=0.9.2']
14
13
  p.rdoc_options += %w[-S -T hanna --main README.rdoc --exclude autotest]
14
+
15
15
  p.test_pattern = 'spec/**/*_spec.rb'
16
+ p.rcov_options = ['--exclude \/Library\/Ruby\/Gems,spec\/', '--xrefs']
16
17
  end
@@ -2,23 +2,23 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{blather}
5
- s.version = "0.1"
5
+ s.version = "0.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Jeff Smick"]
9
- s.date = %q{2008-11-27}
9
+ s.date = %q{2008-12-19}
10
10
  s.description = %q{An evented XMPP library written on EventMachine and libxml-ruby}
11
11
  s.email = %q{sprsquish@gmail.com}
12
- s.extra_rdoc_files = ["CHANGELOG", "lib/autotest/discover.rb", "lib/autotest/spec.rb", "lib/blather/callback.rb", "lib/blather/client.rb", "lib/blather/core/errors.rb", "lib/blather/core/jid.rb", "lib/blather/core/roster.rb", "lib/blather/core/roster_item.rb", "lib/blather/core/stanza/iq/query.rb", "lib/blather/core/stanza/iq/roster.rb", "lib/blather/core/stanza/iq.rb", "lib/blather/core/stanza/message.rb", "lib/blather/core/stanza/presence/status.rb", "lib/blather/core/stanza/presence/subscription.rb", "lib/blather/core/stanza/presence.rb", "lib/blather/core/stanza.rb", "lib/blather/core/stream/parser.rb", "lib/blather/core/stream/resource.rb", "lib/blather/core/stream/sasl.rb", "lib/blather/core/stream/session.rb", "lib/blather/core/stream/tls.rb", "lib/blather/core/stream.rb", "lib/blather/core/sugar.rb", "lib/blather/core/xmpp_node.rb", "lib/blather/extensions/last_activity.rb", "lib/blather/extensions/version.rb", "lib/blather/extensions.rb", "lib/blather.rb", "LICENSE", "README.rdoc"]
13
- s.files = ["CHANGELOG", "examples/echo.rb", "examples/shell_client.rb", "lib/autotest/discover.rb", "lib/autotest/spec.rb", "lib/blather/callback.rb", "lib/blather/client.rb", "lib/blather/core/errors.rb", "lib/blather/core/jid.rb", "lib/blather/core/roster.rb", "lib/blather/core/roster_item.rb", "lib/blather/core/stanza/iq/query.rb", "lib/blather/core/stanza/iq/roster.rb", "lib/blather/core/stanza/iq.rb", "lib/blather/core/stanza/message.rb", "lib/blather/core/stanza/presence/status.rb", "lib/blather/core/stanza/presence/subscription.rb", "lib/blather/core/stanza/presence.rb", "lib/blather/core/stanza.rb", "lib/blather/core/stream/parser.rb", "lib/blather/core/stream/resource.rb", "lib/blather/core/stream/sasl.rb", "lib/blather/core/stream/session.rb", "lib/blather/core/stream/tls.rb", "lib/blather/core/stream.rb", "lib/blather/core/sugar.rb", "lib/blather/core/xmpp_node.rb", "lib/blather/extensions/last_activity.rb", "lib/blather/extensions/version.rb", "lib/blather/extensions.rb", "lib/blather.rb", "LICENSE", "Rakefile", "README.rdoc", "spec/blather/core/jid_spec.rb", "spec/blather/core/roster_item_spec.rb", "spec/blather/core/roster_spec.rb", "spec/blather/core/stanza_spec.rb", "spec/blather/core/stream_spec.rb", "spec/blather/core/xmpp_node_spec.rb", "spec/build_safe.rb", "spec/spec_helper.rb", "Manifest", "blather.gemspec"]
12
+ s.extra_rdoc_files = ["CHANGELOG", "lib/autotest/discover.rb", "lib/autotest/spec.rb", "lib/blather/errors.rb", "lib/blather/jid.rb", "lib/blather/roster.rb", "lib/blather/roster_item.rb", "lib/blather/stanza/error.rb", "lib/blather/stanza/iq/query.rb", "lib/blather/stanza/iq/roster.rb", "lib/blather/stanza/iq.rb", "lib/blather/stanza/message.rb", "lib/blather/stanza/presence/status.rb", "lib/blather/stanza/presence/subscription.rb", "lib/blather/stanza/presence.rb", "lib/blather/stanza.rb", "lib/blather/stream/parser.rb", "lib/blather/stream/resource.rb", "lib/blather/stream/sasl.rb", "lib/blather/stream/session.rb", "lib/blather/stream/tls.rb", "lib/blather/stream.rb", "lib/blather/sugar.rb", "lib/blather/xmpp_node.rb", "lib/blather.rb", "LICENSE", "README.rdoc"]
13
+ s.files = ["CHANGELOG", "examples/drb_client.rb", "examples/echo.rb", "lib/autotest/discover.rb", "lib/autotest/spec.rb", "lib/blather/errors.rb", "lib/blather/jid.rb", "lib/blather/roster.rb", "lib/blather/roster_item.rb", "lib/blather/stanza/error.rb", "lib/blather/stanza/iq/query.rb", "lib/blather/stanza/iq/roster.rb", "lib/blather/stanza/iq.rb", "lib/blather/stanza/message.rb", "lib/blather/stanza/presence/status.rb", "lib/blather/stanza/presence/subscription.rb", "lib/blather/stanza/presence.rb", "lib/blather/stanza.rb", "lib/blather/stream/parser.rb", "lib/blather/stream/resource.rb", "lib/blather/stream/sasl.rb", "lib/blather/stream/session.rb", "lib/blather/stream/tls.rb", "lib/blather/stream.rb", "lib/blather/sugar.rb", "lib/blather/xmpp_node.rb", "lib/blather.rb", "LICENSE", "Manifest", "Rakefile", "README.rdoc", "spec/blather/jid_spec.rb", "spec/blather/roster_item_spec.rb", "spec/blather/roster_spec.rb", "spec/blather/stanza/iq/query_spec.rb", "spec/blather/stanza/iq/roster_spec.rb", "spec/blather/stanza/iq_spec.rb", "spec/blather/stanza/message_spec.rb", "spec/blather/stanza/presence/status_spec.rb", "spec/blather/stanza/presence/subscription_spec.rb", "spec/blather/stanza/presence_spec.rb", "spec/blather/stanza_spec.rb", "spec/blather/stream_spec.rb", "spec/blather/xmpp_node_spec.rb", "spec/build_safe.rb", "spec/spec_helper.rb", "blather.gemspec"]
14
14
  s.has_rdoc = true
15
- s.homepage = %q{}
15
+ s.homepage = %q{http://github.com/sprsquish/blather/tree/master}
16
16
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Blather", "--main", "README.rdoc", "-S", "-T", "hanna", "--main", "README.rdoc", "--exclude", "autotest"]
17
17
  s.require_paths = ["lib"]
18
18
  s.rubyforge_project = %q{squishtech}
19
19
  s.rubygems_version = %q{1.3.1}
20
20
  s.summary = %q{An evented XMPP library written on EventMachine and libxml-ruby}
21
- s.test_files = ["spec/blather/core/jid_spec.rb", "spec/blather/core/roster_item_spec.rb", "spec/blather/core/roster_spec.rb", "spec/blather/core/stanza_spec.rb", "spec/blather/core/stream_spec.rb", "spec/blather/core/xmpp_node_spec.rb"]
21
+ s.test_files = ["spec/blather/jid_spec.rb", "spec/blather/roster_item_spec.rb", "spec/blather/roster_spec.rb", "spec/blather/stanza/iq/query_spec.rb", "spec/blather/stanza/iq/roster_spec.rb", "spec/blather/stanza/iq_spec.rb", "spec/blather/stanza/message_spec.rb", "spec/blather/stanza/presence/status_spec.rb", "spec/blather/stanza/presence/subscription_spec.rb", "spec/blather/stanza/presence_spec.rb", "spec/blather/stanza_spec.rb", "spec/blather/stream_spec.rb", "spec/blather/xmpp_node_spec.rb"]
22
22
 
23
23
  if s.respond_to? :specification_version then
24
24
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
@@ -26,16 +26,16 @@ Gem::Specification.new do |s|
26
26
 
27
27
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
28
28
  s.add_runtime_dependency(%q<eventmachine>, [">= 0"])
29
- s.add_runtime_dependency(%q<libxml>, [">= 1.0.11"])
29
+ s.add_runtime_dependency(%q<libxml-ruby>, [">= 0.9.2"])
30
30
  s.add_development_dependency(%q<echoe>, [">= 0"])
31
31
  else
32
32
  s.add_dependency(%q<eventmachine>, [">= 0"])
33
- s.add_dependency(%q<libxml>, [">= 1.0.11"])
33
+ s.add_dependency(%q<libxml-ruby>, [">= 0.9.2"])
34
34
  s.add_dependency(%q<echoe>, [">= 0"])
35
35
  end
36
36
  else
37
37
  s.add_dependency(%q<eventmachine>, [">= 0"])
38
- s.add_dependency(%q<libxml>, [">= 1.0.11"])
38
+ s.add_dependency(%q<libxml-ruby>, [">= 0.9.2"])
39
39
  s.add_dependency(%q<echoe>, [">= 0"])
40
40
  end
41
41
  end
@@ -0,0 +1,7 @@
1
+ %w[rubygems lib/blather drb/drb].each { |r| require r }
2
+
3
+ setup 'drb_client@jabber.local', 'drb_client'
4
+
5
+ handle :ready do
6
+ DRb.start_service 'druby://localhost:99843', self
7
+ end
@@ -1,22 +1,13 @@
1
- require 'lib/blather/client'
2
- include Blather
1
+ %w[rubygems lib/blather].each { |r| require r }
3
2
 
4
- class Echo < Client
5
- # Auto-approve subscription requests
6
- def receive_subscription(s)
7
- send_data(s.approve!) and true if s.request?
8
- end
3
+ setup 'echo@jabber.local', 'echo'
9
4
 
10
- # Echo presence
11
- def receive_status(status)
12
- set_status(status.state, status.message, status.from) if roster[status.from]
13
- end
14
-
15
- # Echo message
16
- def receive_message(message)
17
- send_data(message.reply) if message.type == :chat
18
- end
5
+ # Auto approve subscription requests
6
+ handle :subscription do |s|
7
+ write(s.approve!) if s.request?
19
8
  end
20
9
 
21
- #handle :version do run Extensions::VersionHandler.new('Echo', '1.0'); end
22
- run 'sprsquish@jabber.local/Blather', 'iq150150', Echo.new
10
+ # Echo back what was said
11
+ handle :message do |m|
12
+ write(m.reply) if m.chat? && m.body
13
+ end
@@ -7,40 +7,149 @@ $:.unshift File.dirname(__FILE__)
7
7
  digest/md5
8
8
  logger
9
9
 
10
- blather/callback
11
-
12
- blather/core/errors
13
- blather/core/jid
14
- blather/core/roster
15
- blather/core/roster_item
16
- blather/core/sugar
17
- blather/core/xmpp_node
18
-
19
- blather/core/stanza
20
- blather/core/stanza/iq
21
- blather/core/stanza/iq/query
22
- blather/core/stanza/iq/roster
23
- blather/core/stanza/message
24
- blather/core/stanza/presence
25
- blather/core/stanza/presence/status
26
- blather/core/stanza/presence/subscription
27
-
28
- blather/core/stream
29
- blather/core/stream/parser
30
- blather/core/stream/resource
31
- blather/core/stream/sasl
32
- blather/core/stream/session
33
- blather/core/stream/tls
10
+ blather/errors
11
+ blather/jid
12
+ blather/roster
13
+ blather/roster_item
14
+ blather/sugar
15
+ blather/xmpp_node
16
+
17
+ blather/stanza
18
+ blather/stanza/error
19
+ blather/stanza/iq
20
+ blather/stanza/iq/query
21
+ blather/stanza/iq/roster
22
+ blather/stanza/message
23
+ blather/stanza/presence
24
+ blather/stanza/presence/status
25
+ blather/stanza/presence/subscription
26
+
27
+ blather/stream
28
+ blather/stream/parser
29
+ blather/stream/resource
30
+ blather/stream/sasl
31
+ blather/stream/session
32
+ blather/stream/tls
34
33
  ].each { |r| require r }
35
34
 
36
- XML::Parser.indent_tree_output = false
35
+ XML.indent_tree_output = false
37
36
 
38
37
  module Blather
39
- VERSION = '0.1'
40
- LOG = Logger.new STDOUT
38
+ LOG = Logger.new(STDOUT)
39
+
40
+ class Client
41
+ attr_accessor :jid,
42
+ :roster
43
+
44
+ def initialize
45
+ @state = :initializing
46
+
47
+ @status = Stanza::Presence::Status.new
48
+ @handlers = Hash.new { |h,k| h[k] = [] }
49
+ @roster = Roster.new self
50
+
51
+ setup_initial_handlers
52
+ end
53
+
54
+ def register_handler(type, &handler)
55
+ @handlers[type] << handler
56
+ end
57
+
58
+ def status
59
+ @status.state
60
+ end
61
+
62
+ def status=(state)
63
+ state, msg, to = state
64
+
65
+ status = Stanza::Presence::Status.new state, msg
66
+ status.to = to
67
+ @status = status unless to
68
+
69
+ write status
70
+ end
71
+
72
+ def write(data)
73
+ @stream.send(data) if @stream
74
+ end
75
+
76
+ def stream_started(stream)
77
+ @stream = stream
78
+
79
+ #retreive roster
80
+ write Stanza::Iq::Roster.new
81
+ end
82
+
83
+ def call(stanza)
84
+ stanza.handler_heirarchy.each do |type|
85
+ break if call_handler_for(type, stanza) && stanza.type == :iq
86
+ end
87
+ end
88
+
89
+ def call_handler_for(type, stanza)
90
+ if @handlers[type]
91
+ @handlers[type].each { |handler| handler.call(stanza) }
92
+ true
93
+ end
94
+ end
95
+
96
+ protected
97
+ def setup_initial_handlers
98
+ register_handler :iq do |iq|
99
+ write(Stanza::Error.new_from(iq, 'service-unavailable', 'cancel').reply!) if [:set, :get].include?(iq.type)
100
+ end
101
+
102
+ register_handler :status do |status|
103
+ roster[status.from].status = status if roster[status.from]
104
+ end
105
+
106
+ register_handler :roster do |node|
107
+ roster.process node
108
+ if @state == :initializing
109
+ @state = :ready
110
+ write @status
111
+ call_handler_for :ready, nil
112
+ end
113
+ end
114
+ end
115
+
116
+ end #Client
117
+
118
+ module Application
119
+ @@client = Blather::Client.new
120
+
121
+ def setup(jid, password, host = nil, port = 5222)
122
+ at_exit do
123
+ trap(:INT) { EM.stop }
124
+ EM.run { Blather::Stream.start @@client, Blather::JID.new(jid), password, host, port }
125
+ end
126
+ end
127
+
128
+ def daemonize
129
+ @daemonize = true
130
+ end
131
+
132
+ def handle(stanza_type, &block)
133
+ @@client.register_handler stanza_type, &block
134
+ end
135
+
136
+ def status(state = nil, msg = nil)
137
+ @@client.status = state, msg
138
+ end
139
+
140
+ def roster
141
+ @@client.roster
142
+ end
143
+
144
+ def write(stanza)
145
+ @@client.write(stanza)
146
+ end
147
+
148
+ def say(to, msg)
149
+ @@client.write Blather::Stanza::Message.new(to, msg)
150
+ end
151
+ end #Application
41
152
 
42
- def run(jid, password, client, host = nil, port = 5222)
43
- EM.run { Stream.start client, JID.new(jid), password, host, port }
44
- end
45
- module_function :run
46
153
  end
154
+
155
+ include Blather::Application
File without changes
@@ -2,13 +2,7 @@ module Blather
2
2
  ##
3
3
  # Base XMPP Stanza
4
4
  class Stanza < XMPPNode
5
- @@registered_callbacks = []
6
-
7
- def self.registered_callbacks
8
- @@registered_callbacks
9
- end
10
-
11
- class_inheritable_array :callback_heirarchy
5
+ class_inheritable_array :handler_heirarchy
12
6
 
13
7
  ##
14
8
  # Registers a callback onto the callback heirarchy stack
@@ -17,13 +11,11 @@ module Blather
17
11
  # that inherits Stanza can register a callback for itself
18
12
  # which is added to a list and iterated over when looking for
19
13
  # a callback to use
20
- def self.register(callback_type, name = nil, xmlns = nil)
21
- @@registered_callbacks << callback_type
22
-
23
- self.callback_heirarchy ||= []
24
- self.callback_heirarchy.unshift callback_type
14
+ def self.register(type, name = nil, xmlns = nil)
15
+ self.handler_heirarchy ||= []
16
+ self.handler_heirarchy.unshift type
25
17
 
26
- name = name || self.name || callback_type
18
+ name = name || self.name || type
27
19
  super name, xmlns
28
20
  end
29
21
 
@@ -109,7 +101,7 @@ module Blather
109
101
  ##
110
102
  # returns:: a symbol of the type
111
103
  def type
112
- self['type'].to_sym if self['type']
104
+ self['type'].to_sym unless self['type'].nil? || self['type'].empty?
113
105
  end
114
106
 
115
107
  end