troystribling-agent_xmpp 0.0.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.
Files changed (39) hide show
  1. data/.document +5 -0
  2. data/.gitignore +9 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +7 -0
  5. data/Rakefile +62 -0
  6. data/VERSION +1 -0
  7. data/agent_xmpp.gemspec +89 -0
  8. data/bin/agent_xmpp +56 -0
  9. data/lib/agent_xmpp/app/boot.rb +64 -0
  10. data/lib/agent_xmpp/app/chat_message_body_controller.rb +16 -0
  11. data/lib/agent_xmpp/app/controller.rb +44 -0
  12. data/lib/agent_xmpp/app/format.rb +41 -0
  13. data/lib/agent_xmpp/app/map.rb +45 -0
  14. data/lib/agent_xmpp/app/routes.rb +77 -0
  15. data/lib/agent_xmpp/app/view.rb +49 -0
  16. data/lib/agent_xmpp/app.rb +7 -0
  17. data/lib/agent_xmpp/client/client.rb +197 -0
  18. data/lib/agent_xmpp/client/connection.rb +314 -0
  19. data/lib/agent_xmpp/client/parser.rb +71 -0
  20. data/lib/agent_xmpp/client.rb +3 -0
  21. data/lib/agent_xmpp/patches/standard_library_patches/array.rb +40 -0
  22. data/lib/agent_xmpp/patches/standard_library_patches/float.rb +25 -0
  23. data/lib/agent_xmpp/patches/standard_library_patches/hash.rb +28 -0
  24. data/lib/agent_xmpp/patches/standard_library_patches/object.rb +30 -0
  25. data/lib/agent_xmpp/patches/standard_library_patches/string.rb +25 -0
  26. data/lib/agent_xmpp/patches/standard_library_patches.rb +5 -0
  27. data/lib/agent_xmpp/patches/xmpp4r_patches/command.rb +26 -0
  28. data/lib/agent_xmpp/patches/xmpp4r_patches/iq.rb +26 -0
  29. data/lib/agent_xmpp/patches/xmpp4r_patches/x_data.rb +116 -0
  30. data/lib/agent_xmpp/patches/xmpp4r_patches.rb +3 -0
  31. data/lib/agent_xmpp/patches.rb +3 -0
  32. data/lib/agent_xmpp/utils/logger.rb +24 -0
  33. data/lib/agent_xmpp/utils/roster.rb +23 -0
  34. data/lib/agent_xmpp/utils.rb +2 -0
  35. data/lib/agent_xmpp/version.rb +6 -0
  36. data/lib/agent_xmpp.rb +16 -0
  37. data/test/agent_xmpp_test.rb +7 -0
  38. data/test/test_helper.rb +10 -0
  39. metadata +131 -0
@@ -0,0 +1,71 @@
1
+ ##############################################################################################################
2
+ module AgentXmpp
3
+
4
+ #####-------------------------------------------------------------------------------------------------------
5
+ module Parser
6
+
7
+ #---------------------------------------------------------------------------------------------------------
8
+ include EventMachine::XmlPushParser
9
+ #---------------------------------------------------------------------------------------------------------
10
+
11
+ #---------------------------------------------------------------------------------------------------------
12
+ attr_reader :stream_features, :stream_mechanisms
13
+ #---------------------------------------------------------------------------------------------------------
14
+
15
+ #---------------------------------------------------------------------------------------------------------
16
+ # EventMachine::XmlPushParser callbacks
17
+ #.........................................................................................................
18
+ def start_document
19
+ end
20
+
21
+ #.........................................................................................................
22
+ def start_element(name, attrs)
23
+ e = REXML::Element.new(name)
24
+ e.add_attributes(attrs)
25
+ @current = @current.nil? ? e : @current.add_element(e)
26
+ if @current.xpath == 'stream:stream'
27
+ process
28
+ @current = nil
29
+ end
30
+ end
31
+
32
+ #.........................................................................................................
33
+ def end_element(name)
34
+ if @current.parent
35
+ @current = @current.parent
36
+ else
37
+ process
38
+ @current = nil
39
+ end
40
+ end
41
+
42
+ #.........................................................................................................
43
+ def characters(text)
44
+ @current.text = @current.text.to_s + text if @current
45
+ end
46
+
47
+ #.........................................................................................................
48
+ def error(*args)
49
+ AgentXmpp.logger.error *args
50
+ end
51
+
52
+ #.........................................................................................................
53
+ def process
54
+ @current.add_namespace(@streamns) if @current.namespace('').to_s.eql?('')
55
+ begin
56
+ stanza = Jabber::XMPPStanza::import(@current)
57
+ rescue Jabber::NoNameXmlnsRegistered
58
+ stanza = @current
59
+ end
60
+ if @current.xpath.eql?('stream:stream')
61
+ @streamns = @current.namespace('') if @current.namespace('')
62
+ end
63
+ receive(stanza) if respond_to?(:receive)
64
+ end
65
+
66
+ #### Parser
67
+ end
68
+
69
+ #### AgentXmpp
70
+ end
71
+
@@ -0,0 +1,3 @@
1
+ require 'agent_xmpp/client/parser'
2
+ require 'agent_xmpp/client/connection'
3
+ require 'agent_xmpp/client/client'
@@ -0,0 +1,40 @@
1
+ ##############################################################################################################
2
+ module AgentXmpp
3
+ module StandardLibrary
4
+ module ArrayPatches
5
+
6
+ ####----------------------------------------------------------------------------------------------------
7
+ module InstanceMethods
8
+
9
+ #......................................................................................................
10
+ def to_x_data(type = 'result')
11
+ data = Jabber::Dataforms::XData.new(type)
12
+ reported = Jabber::Dataforms::XDataReported.new
13
+ if first.instance_of?(Hash)
14
+ first.each_key {|var| reported.add_field(var.to_s)}
15
+ data << reported
16
+ each do |fields|
17
+ item = Jabber::Dataforms::XDataItem.new
18
+ fields.each {|var, value| item.add_field_with_value(var.to_s, value.to_s)}
19
+ data << item
20
+ end
21
+ else
22
+ field = Jabber::Dataforms::XDataField.new
23
+ field.values = map {|v| v.to_s}
24
+ data << field
25
+ end
26
+ data
27
+ end
28
+
29
+ #### InstanceMethods
30
+ end
31
+
32
+ #### ArrayPatches
33
+ end
34
+ ##### StandardLibrary
35
+ end
36
+ #### AgentXmpp
37
+ end
38
+
39
+ ##############################################################################################################
40
+ Array.send(:include, AgentXmpp::StandardLibrary::ArrayPatches::InstanceMethods)
@@ -0,0 +1,25 @@
1
+ ##############################################################################################################
2
+ module AgentXmpp
3
+ module StandardLibrary
4
+ module FloatPatches
5
+
6
+ ####----------------------------------------------------------------------------------------------------
7
+ module InstanceMethods
8
+
9
+ #......................................................................................................
10
+ def precision(p = 3)
11
+ (10.0**p*self).round.to_f/10.0**p
12
+ end
13
+
14
+ #### InstanceMethods
15
+ end
16
+
17
+ #### ArrayPatches
18
+ end
19
+ ##### StandardLibrary
20
+ end
21
+ #### AgentXmpp
22
+ end
23
+
24
+ ##############################################################################################################
25
+ Float.send(:include, AgentXmpp::StandardLibrary::FloatPatches::InstanceMethods)
@@ -0,0 +1,28 @@
1
+ ##############################################################################################################
2
+ module AgentXmpp
3
+ module StandardLibrary
4
+ module HashPatches
5
+
6
+ ####----------------------------------------------------------------------------------------------------
7
+ module InstanceMethods
8
+
9
+ #.......................................................................................................
10
+ def to_x_data(type = 'result')
11
+ inject(Jabber::Dataforms::XData.new(type)) do |data, field|
12
+ data.add_field_with_value(field.first.to_s, field.last.to_s)
13
+ end
14
+ end
15
+
16
+
17
+ #### InstanceMethods
18
+ end
19
+
20
+ #### HashPatches
21
+ end
22
+ ##### StandardLibrary
23
+ end
24
+ #### AgentXmpp
25
+ end
26
+
27
+ ##############################################################################################################
28
+ Hash.send(:include, AgentXmpp::StandardLibrary::HashPatches::InstanceMethods)
@@ -0,0 +1,30 @@
1
+ ##############################################################################################################
2
+ module AgentXmpp
3
+ module StandardLibrary
4
+ module ObjectPatches
5
+
6
+ ####----------------------------------------------------------------------------------------------------
7
+ module InstanceMethods
8
+
9
+ #.......................................................................................................
10
+ def to_x_data(type = 'result')
11
+ Jabber::Dataforms::XData.new(type).add_field_with_value(nil, to_s)
12
+ end
13
+
14
+ #.......................................................................................................
15
+ def define_meta_class_method(name, &blk)
16
+ (class << self; self; end).instance_eval {define_method(name, &blk)}
17
+ end
18
+
19
+ #### InstanceMethods
20
+ end
21
+
22
+ #### ObjectPatches
23
+ end
24
+ ##### StandardLibrary
25
+ end
26
+ #### AgentXmpp
27
+ end
28
+
29
+ ##############################################################################################################
30
+ Object.send(:include, AgentXmpp::StandardLibrary::ObjectPatches::InstanceMethods)
@@ -0,0 +1,25 @@
1
+ ##############################################################################################################
2
+ module AgentXmpp
3
+ module StandardLibrary
4
+ module StringPatches
5
+
6
+ ####----------------------------------------------------------------------------------------------------
7
+ module InstanceMethods
8
+
9
+ #......................................................................................................
10
+ def classify
11
+ split('_').collect{|s| s.capitalize}.join
12
+ end
13
+
14
+ #### InstanceMethods
15
+ end
16
+
17
+ #### ArrayPatches
18
+ end
19
+ ##### StandardLibrary
20
+ end
21
+ #### AgentXmpp
22
+ end
23
+
24
+ ##############################################################################################################
25
+ String.send(:include, AgentXmpp::StandardLibrary::StringPatches::InstanceMethods)
@@ -0,0 +1,5 @@
1
+ require 'agent_xmpp/patches/standard_library_patches/object'
2
+ require 'agent_xmpp/patches/standard_library_patches/array'
3
+ require 'agent_xmpp/patches/standard_library_patches/hash'
4
+ require 'agent_xmpp/patches/standard_library_patches/string'
5
+ require 'agent_xmpp/patches/standard_library_patches/float'
@@ -0,0 +1,26 @@
1
+ ##############################################################################################################
2
+ module AgentXmpp
3
+ module XMPP4RPatches
4
+ module Command
5
+
6
+ ####----------------------------------------------------------------------------------------------------
7
+ module InstanceMethods
8
+
9
+ #.....................................................................................................
10
+ def <<(child)
11
+ add(child)
12
+ end
13
+
14
+ #### InstanceMethods
15
+ end
16
+
17
+ ##### Command
18
+ end
19
+ ##### XMPP4RPatches
20
+ end
21
+ #### AgentXmpp
22
+ end
23
+
24
+ ##############################################################################################################
25
+ Jabber::Command::IqCommand.send(:include, Jabber::XParent)
26
+ Jabber::Command::IqCommand.send(:include, AgentXmpp::XMPP4RPatches::Command::InstanceMethods)
@@ -0,0 +1,26 @@
1
+ ##############################################################################################################
2
+ module AgentXmpp
3
+ module XMPP4RPatches
4
+ module Iq
5
+
6
+ ####----------------------------------------------------------------------------------------------------
7
+ module InstanceMethods
8
+
9
+ #.....................................................................................................
10
+ def command=(newcommand)
11
+ delete_elements(newcommand.name)
12
+ add(newcommand)
13
+ end
14
+
15
+ #### InstanceMethods
16
+ end
17
+
18
+ ##### Iq
19
+ end
20
+ ##### XMPP4RPatches
21
+ end
22
+ #### AgentXmpp
23
+ end
24
+
25
+ ##############################################################################################################
26
+ Jabber::Iq.send(:include, AgentXmpp::XMPP4RPatches::Iq::InstanceMethods)
@@ -0,0 +1,116 @@
1
+ ##############################################################################################################
2
+ module AgentXmpp
3
+ module XMPP4RPatches
4
+ module XData
5
+
6
+ ####----------------------------------------------------------------------------------------------------
7
+ module InstanceMethods
8
+
9
+ #.....................................................................................................
10
+ def <<(child)
11
+ add(child)
12
+ self
13
+ end
14
+
15
+ #.....................................................................................................
16
+ def add_field_with_value(var, value)
17
+ field = Jabber::Dataforms::XDataField.new(var)
18
+ field.value = value
19
+ self << field
20
+ end
21
+
22
+ #### InstanceMethods
23
+ end
24
+
25
+ ##### XData
26
+ end
27
+ ##### XMPP4RPatches
28
+ end
29
+ #### AgentXmpp
30
+ end
31
+
32
+ ##############################################################################################################
33
+ Jabber::Dataforms::XData.send(:include, AgentXmpp::XMPP4RPatches::XData::InstanceMethods)
34
+
35
+ ##############################################################################################################
36
+ module AgentXmpp
37
+ module XMPP4RPatches
38
+ module XDataReported
39
+
40
+ ####----------------------------------------------------------------------------------------------------
41
+ module InstanceMethods
42
+
43
+ #.....................................................................................................
44
+ def fields(including_hidden=false)
45
+ fields = []
46
+ each_element do |xe|
47
+ if xe.kind_of?(Jabber::Dataforms::XDataField) and (including_hidden or (xe.type != :hidden and xe.type != :fixed))
48
+ fields << xe
49
+ end
50
+ end
51
+ fields
52
+ end
53
+
54
+ #.....................................................................................................
55
+ def <<(child)
56
+ add(child)
57
+ self
58
+ end
59
+
60
+ #.....................................................................................................
61
+ def add_field(var)
62
+ self << Jabber::Dataforms::XDataField.new(var)
63
+ end
64
+
65
+ #### InstanceMethods
66
+ end
67
+
68
+ ##### XDataReported
69
+ end
70
+ ##### XMPP4RPatches
71
+ end
72
+ #### AgentXmpp
73
+ end
74
+
75
+ ##############################################################################################################
76
+ Jabber::Dataforms::XDataReported.send(:include, AgentXmpp::XMPP4RPatches::XDataReported::InstanceMethods)
77
+
78
+ ##############################################################################################################
79
+ ##############################################################################################################
80
+ module Jabber
81
+ module Dataforms
82
+ class XDataItem < XMPPElement
83
+
84
+ #.....................................................................................................
85
+ name_xmlns 'item', 'jabber:x:data'
86
+
87
+ #.....................................................................................................
88
+ def fields(including_hidden=false)
89
+ fields = []
90
+ each_element do |xe|
91
+ if xe.kind_of?(Jabber::Dataforms::XDataField) and (including_hidden or (xe.type != :hidden and xe.type != :fixed))
92
+ fields << xe
93
+ end
94
+ end
95
+ fields
96
+ end
97
+
98
+ #.....................................................................................................
99
+ def <<(child)
100
+ add(child)
101
+ self
102
+ end
103
+
104
+ #.....................................................................................................
105
+ def add_field_with_value(var, value)
106
+ field = Jabber::Dataforms::XDataField.new(var)
107
+ field.value = value
108
+ self << field
109
+ end
110
+
111
+ #### XDataItem
112
+ end
113
+ #### Dataforms
114
+ end
115
+ #### Jabber
116
+ end
@@ -0,0 +1,3 @@
1
+ require 'agent_xmpp/patches/xmpp4r_patches/command'
2
+ require 'agent_xmpp/patches/xmpp4r_patches/x_data'
3
+ require 'agent_xmpp/patches/xmpp4r_patches/iq'
@@ -0,0 +1,3 @@
1
+ require 'agent_xmpp/patches/xmpp4r_patches'
2
+ require 'agent_xmpp/patches/standard_library_patches'
3
+
@@ -0,0 +1,24 @@
1
+ ##############################################################################################################
2
+ module AgentXmpp
3
+
4
+ ####......................................................................................................
5
+ class << self
6
+
7
+ #.........................................................................................................
8
+ attr_accessor :log_file
9
+ #.........................................................................................................
10
+
11
+ #.........................................................................................................
12
+ def logger
13
+ @logger ||= Logger.new(STDOUT)
14
+ end
15
+
16
+ #.........................................................................................................
17
+ def logger=(logger)
18
+ @logger = logger
19
+ end
20
+
21
+ end
22
+
23
+ #### AgentXmpp
24
+ end