circus-deployment 0.0.1 → 0.2

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.
@@ -1,59 +0,0 @@
1
- require 'blather/client/dsl'
2
- require 'circus/agents/params'
3
- require 'circus/agents/logger'
4
- require 'circus/agents/connection'
5
-
6
- module Circus
7
- module Agents
8
- class Agent
9
- include Blather::DSL
10
-
11
- class <<self
12
- def commands
13
- @commands ||= []
14
- end
15
-
16
- def command(name, &body)
17
- commands << name
18
-
19
- define_method("command_#{name}", &body)
20
- end
21
- end
22
-
23
- def initialize(connection = nil)
24
- @client = (connection || Connection.new)
25
-
26
- # Approve all subscription requests
27
- subscription :request? do |s|
28
- write_to_stream s.approve!
29
- end
30
-
31
- # Add a handler for each chat command
32
- self.class.commands.each do |name|
33
- message :chat?, :body => /^#{name}( .*)?$/ do |m|
34
- # begin
35
- params = CommandParams.new(m.body[(name.length + 1)..-1])
36
- logger = XMPPLogger.new(m.from, m.thread || m.id, lambda { |msg| write_to_stream(msg) })
37
-
38
- send("command_#{name}", params, logger)
39
- # rescue
40
- # puts $!, $@
41
- # end
42
- end
43
- end
44
-
45
- disconnected do
46
- puts "Disconnected"
47
- end
48
- end
49
-
50
- def configure!(config)
51
- client.configure!(config)
52
- end
53
-
54
- def run
55
- client.run
56
- end
57
- end
58
- end
59
- end
@@ -1,52 +0,0 @@
1
- require 'circus/agents/encoding'
2
- require 'circus/agents/conversation'
3
-
4
- module Circus
5
- module Agents
6
- class XMPPLogger
7
- def initialize(to, thread, writer)
8
- @to = to
9
- @thread = thread || "thread#{Blather::Stanza.next_id}"
10
- @writer = writer
11
- end
12
-
13
- def info(content)
14
- write("#{content}")
15
- end
16
-
17
-
18
- def error(content)
19
- write("ERROR: #{content}")
20
- end
21
-
22
- def failed(msg)
23
- write("failed #{msg}")
24
- gone
25
- end
26
-
27
- def complete(res = nil)
28
- if res
29
- write("ok #{Encoding.encode(res)}")
30
- else
31
- write('ok')
32
- end
33
- gone
34
- end
35
-
36
- private
37
- def write(content)
38
- msg = Blather::Stanza::Message.new @to, content
39
- msg.thread = @thread
40
- @writer.call(msg)
41
- end
42
-
43
- def gone
44
- msg = Blather::Stanza::Message.new @to, nil
45
- msg.thread = @thread
46
-
47
- Conversation.end(msg)
48
- @writer.call(msg)
49
- end
50
- end
51
- end
52
- end