jacs 0.3 → 0.4.1
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/lib/actionjabber.rb +20 -10
- data/lib/activejabber.rb +3 -2
- metadata +3 -2
data/lib/actionjabber.rb
CHANGED
@@ -25,9 +25,10 @@ module ActionJabber
|
|
25
25
|
end
|
26
26
|
class Server
|
27
27
|
# Sets up the server. The @controller@ argument is expected to be a class, not an instance.
|
28
|
-
def initialize(username, password, controller)
|
28
|
+
def initialize(username, password, controller, debug = false)
|
29
29
|
@jabber = Jabber::Simple.new(username, password)
|
30
30
|
@controller = controller # Should be a class.
|
31
|
+
@debug = debug
|
31
32
|
end
|
32
33
|
# Initiates the loop to check for new messages.
|
33
34
|
def run!
|
@@ -40,18 +41,27 @@ module ActionJabber
|
|
40
41
|
hash = parts.first
|
41
42
|
path_parts = parts.last.split('?', 2)
|
42
43
|
request = Request.new(hash, from, path_parts.first, ((path_parts.length == 2) ? path_parts.last : ''))
|
43
|
-
#
|
44
|
+
# TODO: DRY this portion up.
|
45
|
+
if @debug
|
46
|
+
# Allow errors to fall through and kill the process.
|
44
47
|
controller_response = @controller.route!(request)
|
45
48
|
response = {:status => 200, :data => ''}.merge(controller_response)
|
46
49
|
respond_to request, :status => response[:status], :data => response[:data]
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
50
|
+
puts "Responded to '#{from}' in #{(Time.now - start).to_s} seconds."
|
51
|
+
else
|
52
|
+
# Capture the errors so that the server keeps on running.
|
53
|
+
begin
|
54
|
+
controller_response = @controller.route!(request)
|
55
|
+
response = {:status => 200, :data => ''}.merge(controller_response)
|
56
|
+
respond_to request, :status => response[:status], :data => response[:data]
|
57
|
+
rescue
|
58
|
+
respond_to request, :status => 500
|
59
|
+
puts "Error responding to #{message.from.to_s.strip}:"
|
60
|
+
puts $!
|
61
|
+
else
|
62
|
+
puts "Responded to '#{from}' in #{(Time.now - start).to_s} seconds."
|
63
|
+
end
|
64
|
+
end
|
55
65
|
#puts "\n"
|
56
66
|
end
|
57
67
|
end
|
data/lib/activejabber.rb
CHANGED
@@ -82,7 +82,7 @@ module ActiveJabber
|
|
82
82
|
:args => '',
|
83
83
|
:timeout => 5.0
|
84
84
|
}
|
85
|
-
if args.length
|
85
|
+
if args.length >= 1
|
86
86
|
# TODO: Logic to handle other ways of transforming data into a sendable format.
|
87
87
|
if args.first.respond_to? :to_s
|
88
88
|
opts[:args] = args.first.to_s
|
@@ -90,7 +90,8 @@ module ActiveJabber
|
|
90
90
|
if args.second.is_a? Hash
|
91
91
|
opts.merge! args.second
|
92
92
|
end
|
93
|
-
|
93
|
+
end
|
94
|
+
if args.first.is_a? Hash
|
94
95
|
opts.merge! args.first
|
95
96
|
end
|
96
97
|
# TODO: Support more formats.
|