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
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
6
+ *.tmproj
7
+ *.yml
8
+ *.db
9
+ log/*
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Troy Stribling
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,7 @@
1
+ = agent_xmpp
2
+
3
+ Description goes here.
4
+
5
+ == Copyright
6
+
7
+ Copyright (c) 2009 Troy Stribling. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,62 @@
1
+ ############################################################################################################
2
+ require 'rubygems'
3
+ require 'rake'
4
+ require 'lib/agent_xmpp/version'
5
+
6
+ #####-------------------------------------------------------------------------------------------------------
7
+ require 'jeweler'
8
+ Jeweler::Tasks.new do |gem|
9
+ gem.name = "agent_xmpp"
10
+ gem.summary = %Q{Agent XMPP is a ruby XMPP bot framework inspired by MVC web frameworks.}
11
+ gem.email = "troy.stribling@gmail.com"
12
+ gem.homepage = "http://github.com/troystribling/agent_xmpp"
13
+ gem.authors = ["Troy Stribling"]
14
+ gem.files.include %w(lib/jeweler/templates/.gitignore VERSION)
15
+ gem.add_dependency('rake', '>= 0.8.3')
16
+ gem.add_dependency('eventmachine', '= 0.12.6')
17
+ gem.add_dependency('troystribling-evma_xmlpushparser', '= 0.0.1')
18
+ gem.add_dependency('xmpp4r', '= 0.4')
19
+ end
20
+
21
+ #####-------------------------------------------------------------------------------------------------------
22
+ task :install => :build do
23
+ %x[gem install pkg/agent_xmpp-#{AgentXmpp::VERSION}]
24
+ end
25
+
26
+ #####-------------------------------------------------------------------------------------------------------
27
+ task :uninstall do
28
+ %x[gem uninstall agent_xmpp]
29
+ end
30
+
31
+ #####-------------------------------------------------------------------------------------------------------
32
+ require 'rake/testtask'
33
+ Rake::TestTask.new(:test) do |test|
34
+ test.libs << 'lib' << 'test'
35
+ test.pattern = 'test/**/*_test.rb'
36
+ test.verbose = true
37
+ end
38
+
39
+ #####-------------------------------------------------------------------------------------------------------
40
+ begin
41
+ require 'rcov/rcovtask'
42
+ Rcov::RcovTask.new do |test|
43
+ test.libs << 'test'
44
+ test.pattern = 'test/**/*_test.rb'
45
+ test.verbose = true
46
+ end
47
+ rescue LoadError
48
+ task :rcov do
49
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
50
+ end
51
+ end
52
+
53
+ #####-------------------------------------------------------------------------------------------------------
54
+ task :default => :test
55
+ require 'rake/rdoctask'
56
+ Rake::RDocTask.new do |rdoc|
57
+ rdoc.rdoc_dir = 'rdoc'
58
+ rdoc.title = "agent_xmpp #{AgentXmpp::VERSION}"
59
+ rdoc.rdoc_files.include('README*')
60
+ rdoc.rdoc_files.include('lib/**/*.rb')
61
+ end
62
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,89 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{agent_xmpp}
5
+ s.version = "0.0.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Troy Stribling"]
9
+ s.date = %q{2009-06-02}
10
+ s.default_executable = %q{agent_xmpp}
11
+ s.email = %q{troy.stribling@gmail.com}
12
+ s.executables = ["agent_xmpp"]
13
+ s.extra_rdoc_files = [
14
+ "LICENSE",
15
+ "README.rdoc"
16
+ ]
17
+ s.files = [
18
+ ".document",
19
+ ".gitignore",
20
+ "LICENSE",
21
+ "README.rdoc",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "agent_xmpp.gemspec",
25
+ "bin/agent_xmpp",
26
+ "lib/agent_xmpp.rb",
27
+ "lib/agent_xmpp/app.rb",
28
+ "lib/agent_xmpp/app/boot.rb",
29
+ "lib/agent_xmpp/app/chat_message_body_controller.rb",
30
+ "lib/agent_xmpp/app/controller.rb",
31
+ "lib/agent_xmpp/app/format.rb",
32
+ "lib/agent_xmpp/app/map.rb",
33
+ "lib/agent_xmpp/app/routes.rb",
34
+ "lib/agent_xmpp/app/view.rb",
35
+ "lib/agent_xmpp/client.rb",
36
+ "lib/agent_xmpp/client/client.rb",
37
+ "lib/agent_xmpp/client/connection.rb",
38
+ "lib/agent_xmpp/client/parser.rb",
39
+ "lib/agent_xmpp/patches.rb",
40
+ "lib/agent_xmpp/patches/standard_library_patches.rb",
41
+ "lib/agent_xmpp/patches/standard_library_patches/array.rb",
42
+ "lib/agent_xmpp/patches/standard_library_patches/float.rb",
43
+ "lib/agent_xmpp/patches/standard_library_patches/hash.rb",
44
+ "lib/agent_xmpp/patches/standard_library_patches/object.rb",
45
+ "lib/agent_xmpp/patches/standard_library_patches/string.rb",
46
+ "lib/agent_xmpp/patches/xmpp4r_patches.rb",
47
+ "lib/agent_xmpp/patches/xmpp4r_patches/command.rb",
48
+ "lib/agent_xmpp/patches/xmpp4r_patches/iq.rb",
49
+ "lib/agent_xmpp/patches/xmpp4r_patches/x_data.rb",
50
+ "lib/agent_xmpp/utils.rb",
51
+ "lib/agent_xmpp/utils/logger.rb",
52
+ "lib/agent_xmpp/utils/roster.rb",
53
+ "lib/agent_xmpp/version.rb",
54
+ "test/agent_xmpp_test.rb",
55
+ "test/test_helper.rb"
56
+ ]
57
+ s.has_rdoc = true
58
+ s.homepage = %q{http://github.com/troystribling/agent_xmpp}
59
+ s.rdoc_options = ["--charset=UTF-8"]
60
+ s.require_paths = ["lib"]
61
+ s.rubygems_version = %q{1.3.1}
62
+ s.summary = %q{TODO}
63
+ s.test_files = [
64
+ "test/agent_xmpp_test.rb",
65
+ "test/test_helper.rb"
66
+ ]
67
+
68
+ if s.respond_to? :specification_version then
69
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
70
+ s.specification_version = 2
71
+
72
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
73
+ s.add_runtime_dependency(%q<rake>, [">= 0.8.3"])
74
+ s.add_runtime_dependency(%q<eventmachine>, ["= 0.12.6"])
75
+ s.add_runtime_dependency(%q<troystribling-evma_xmlpushparser>, ["= 0.0.1"])
76
+ s.add_runtime_dependency(%q<xmpp4r>, ["= 0.4"])
77
+ else
78
+ s.add_dependency(%q<rake>, [">= 0.8.3"])
79
+ s.add_dependency(%q<eventmachine>, ["= 0.12.6"])
80
+ s.add_dependency(%q<troystribling-evma_xmlpushparser>, ["= 0.0.1"])
81
+ s.add_dependency(%q<xmpp4r>, ["= 0.4"])
82
+ end
83
+ else
84
+ s.add_dependency(%q<rake>, [">= 0.8.3"])
85
+ s.add_dependency(%q<eventmachine>, ["= 0.12.6"])
86
+ s.add_dependency(%q<troystribling-evma_xmlpushparser>, ["= 0.0.1"])
87
+ s.add_dependency(%q<xmpp4r>, ["= 0.4"])
88
+ end
89
+ end
data/bin/agent_xmpp ADDED
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ####------------------------------------------------------------------------------------------------------
4
+ require 'rubygems'
5
+ require 'optparse'
6
+ require 'agent_xmpp'
7
+ begin
8
+ require 'config/boot'
9
+ rescue LoadError
10
+ AgentXmpp.logger.info "config/boot.rb not given"
11
+ end
12
+
13
+
14
+ ####------------------------------------------------------------------------------------------------------
15
+ config_file = 'config/agent.yml'
16
+ AgentXmpp.log_file = STDOUT
17
+ OptionParser.new do |opts|
18
+ opts.banner = 'Usage: agent_xmpp.rb [options]'
19
+ opts.separator ''
20
+ opts.on('-f', '--file config.yml', 'YAML agent configuration file') {|f| config_file = f}
21
+ opts.on('-l', '--logfile file.log', 'name of logfile') {|f| AgentXmpp.log_file = f}
22
+ opts.on_tail('-h', '--help', 'Show this message') {
23
+ puts opts
24
+ exit
25
+ }
26
+ opts.parse!(ARGV)
27
+ end
28
+
29
+ ####------------------------------------------------------------------------------------------------------
30
+ raise Exception, "Configuration file #{config_file} required." unless File.exist?(config_file)
31
+
32
+ ####------------------------------------------------------------------------------------------------------
33
+ AgentXmpp.logger = Logger.new(AgentXmpp.log_file, 10, 1024000)
34
+ AgentXmpp.logger.info "STARTING AgentXmpp"
35
+ AgentXmpp.logger.info "LOG FILE: #{AgentXmpp.log_file.kind_of?(String) ? AgentXmpp.log_file : "STDOUT"}"
36
+ AgentXmpp.logger.info "CONFIGURATION FILE: #{config_file}"
37
+
38
+ ####------------------------------------------------------------------------------------------------------
39
+ AgentXmpp::Boot.call_before_config_load if AgentXmpp::Boot.respond_to?(:call_before_config_load)
40
+
41
+ ####------------------------------------------------------------------------------------------------------
42
+ AgentXmpp::Boot.load('config', {:exclude => ['config/boot'], :ordered_load => AgentXmpp::Boot.config_load_order})
43
+
44
+ ####------------------------------------------------------------------------------------------------------
45
+ AgentXmpp::Boot.call_before_app_load if AgentXmpp::Boot.respond_to?(:call_before_app_load)
46
+
47
+ ####------------------------------------------------------------------------------------------------------
48
+ AgentXmpp::Boot.load('app/models', {:ordered_load => AgentXmpp::Boot.app_load_order})
49
+ AgentXmpp::Boot.load('app/controllers')
50
+
51
+ ####------------------------------------------------------------------------------------------------------
52
+ AgentXmpp::Boot.call_after_app_load if AgentXmpp::Boot.respond_to?(:call_after_app_load)
53
+
54
+ ####------------------------------------------------------------------------------------------------------
55
+ config = File.open(config_file) {|yf| YAML::load(yf)}
56
+ AgentXmpp::Client.new(config).connect
@@ -0,0 +1,64 @@
1
+ ##############################################################################################################
2
+ module AgentXmpp
3
+
4
+ #####-------------------------------------------------------------------------------------------------------
5
+ class Boot
6
+
7
+ #.......................................................................................................
8
+ @config_load_order = []
9
+ @app_load_order = []
10
+
11
+ ####......................................................................................................
12
+ class << self
13
+
14
+ #.......................................................................................................
15
+ attr_accessor :config_load_order, :app_load_order
16
+
17
+ #.......................................................................................................
18
+ def app_dir
19
+ Dir.pwd
20
+ end
21
+
22
+ #.......................................................................................................
23
+ def before_config_load(&blk)
24
+ define_meta_class_method(:call_before_config_load, &blk)
25
+ end
26
+
27
+ #.......................................................................................................
28
+ def after_connection_completed(&blk)
29
+ define_meta_class_method(:call_after_connection_completed, &blk)
30
+ end
31
+
32
+ #.......................................................................................................
33
+ def before_app_load(&blk)
34
+ define_meta_class_method(:call_before_app_load, &blk)
35
+ end
36
+
37
+ #.......................................................................................................
38
+ def after_app_load(&blk)
39
+ define_meta_class_method(:call_after_app_load, &blk)
40
+ end
41
+
42
+ ####------------------------------------------------------------------------------------------------------
43
+ def load(path, options = {})
44
+ exclude_files = options[:exclude] || []
45
+ ordered_files = options[:ordered_load] || []
46
+ ordered_files.each{|f| require f}
47
+ Find.find(path) do |file_path|
48
+ if file_match = /(.*)\.rb$/.match(file_path)
49
+ file = file_match.captures.last
50
+ unless exclude_files.include?(file) and ordered_files.include?(file)
51
+ require file
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ end
58
+ ####......................................................................................................
59
+
60
+ #### Boot
61
+ end
62
+
63
+ #### AgentXmpp
64
+ end
@@ -0,0 +1,16 @@
1
+ ############################################################################################################
2
+ class ChatMessageBodyController < AgentXmpp::Controller
3
+
4
+ #.........................................................................................................
5
+ def body
6
+ result_for do
7
+ params[:body].reverse
8
+ end
9
+ respond_to do |result|
10
+ result.to_s
11
+ end
12
+ AgentXmpp.logger.info "ACTION: ChatMessageBodyController\#body"
13
+ end
14
+
15
+ #### ChatMessageBodyController
16
+ end
@@ -0,0 +1,44 @@
1
+ ##############################################################################################################
2
+ module AgentXmpp
3
+
4
+ #####-------------------------------------------------------------------------------------------------------
5
+ class Controller
6
+
7
+ #---------------------------------------------------------------------------------------------------------
8
+ attr_reader :format, :params, :connection
9
+ #---------------------------------------------------------------------------------------------------------
10
+
11
+ #.........................................................................................................
12
+ def initialize
13
+ end
14
+
15
+ #---------------------------------------------------------------------------------------------------------
16
+ # handle request
17
+ #.........................................................................................................
18
+ def handle_request(connection, action, params)
19
+ @params = params
20
+ @connection = connection
21
+ @format = Format.new(params[:xmlns])
22
+ send(action)
23
+ end
24
+
25
+ #.........................................................................................................
26
+ def result_for(&blk)
27
+ @result_for_blk = blk
28
+ end
29
+
30
+ #.........................................................................................................
31
+ def respond_to(&blk)
32
+ View.send(:define_method, :respond_to, &blk)
33
+ View.send(:define_method, :result_callback) do |*result|
34
+ connection.send(add_payload_to_container(respond_to(result)))
35
+ end
36
+ EventMachine.defer(@result_for_blk, View.new(connection, format, params).method(:result_callback).to_proc)
37
+ end
38
+
39
+ #### Controller
40
+ end
41
+
42
+ #### AgentXmpp
43
+ end
44
+
@@ -0,0 +1,41 @@
1
+ ##############################################################################################################
2
+ module AgentXmpp
3
+
4
+ #####-------------------------------------------------------------------------------------------------------
5
+ class Format
6
+
7
+ #---------------------------------------------------------------------------------------------------------
8
+ attr_accessor :xmlns
9
+ #---------------------------------------------------------------------------------------------------------
10
+
11
+ #.........................................................................................................
12
+ def initialize(xmlns)
13
+ @xmlns = xmlns
14
+ end
15
+
16
+ #.........................................................................................................
17
+ def x_data(&blk)
18
+ call_block_for_xmlns('jabber:x:data', &blk)
19
+ end
20
+
21
+ #.........................................................................................................
22
+ def json(&blk)
23
+ call_block_for_xmlns('jabber:x:json', &blk)
24
+ end
25
+
26
+ private
27
+
28
+ #.........................................................................................................
29
+ def call_block_for_xmlns(check_xmlns, &blk)
30
+ if xmlns.eql?(check_xmlns)
31
+ if blk
32
+ blk.call
33
+ end
34
+ end
35
+ end
36
+
37
+ #### Format
38
+ end
39
+
40
+ #### AgentXmpp
41
+ end
@@ -0,0 +1,45 @@
1
+ ##############################################################################################################
2
+ module AgentXmpp
3
+ module Routing
4
+
5
+ #####-------------------------------------------------------------------------------------------------------
6
+ class RoutingConnection < Exception; end
7
+
8
+ #####-------------------------------------------------------------------------------------------------------
9
+ class Map
10
+
11
+ #.........................................................................................................
12
+ attr_reader :chat_message_body_route
13
+ #.........................................................................................................
14
+
15
+ #.........................................................................................................
16
+ def initialize
17
+ @routes = Hash.new
18
+ @chat_message_body_route = {:controller => 'chat_message_body', :action => 'body'}
19
+ end
20
+
21
+ #.........................................................................................................
22
+ def connect(path, options = {})
23
+ path.strip!; path.gsub!(/^\//,'')
24
+ path_elements = path.split('/')
25
+ raise RoutingConnection, "Inavild route connection: #{path}." if path_elements.count < 2
26
+ @routes[path] = {:controller => options[:controller] || path_elements[0], :action => options[:action] || path_elements[1]}
27
+ end
28
+
29
+ #.........................................................................................................
30
+ def [](path)
31
+ @routes[path]
32
+ end
33
+
34
+ #.........................................................................................................
35
+ def connect_chat_message_body(route)
36
+ @chat_message_body_route = {:controller => route[:controller], :action => route[:action]}
37
+ end
38
+
39
+ #### Map
40
+ end
41
+
42
+ #### Routing
43
+ end
44
+ #### AgentXmpp
45
+ end