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.
Files changed (3) hide show
  1. data/lib/actionjabber.rb +20 -10
  2. data/lib/activejabber.rb +3 -2
  3. metadata +3 -2
@@ -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
- #begin
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
- #rescue
48
- # respond_to request, :status => 500
49
- # puts "Error responding to #{message.from.to_s.strip}:"
50
- # puts $!
51
- #else
52
- # puts "Responded to '#{from}' in #{(Time.now - start).to_s} seconds."
53
- #end
54
- puts "Responded to '#{from}' in #{(Time.now - start).to_s} seconds.\n"
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
@@ -82,7 +82,7 @@ module ActiveJabber
82
82
  :args => '',
83
83
  :timeout => 5.0
84
84
  }
85
- if args.length > 1
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
- elsif args.first.is_a? Hash
93
+ end
94
+ if args.first.is_a? Hash
94
95
  opts.merge! args.first
95
96
  end
96
97
  # TODO: Support more formats.
metadata CHANGED
@@ -4,8 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 3
8
- version: "0.3"
7
+ - 4
8
+ - 1
9
+ version: 0.4.1
9
10
  platform: ruby
10
11
  authors:
11
12
  - Dirk Gadsden