mrw-uppercut 0.0.1.pre1
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/README.textile +151 -0
- data/VERSION.yml +4 -0
- data/examples/basic_agent.rb +28 -0
- data/examples/personal.rb +42 -0
- data/lib/uppercut.rb +8 -0
- data/lib/uppercut/agent.rb +229 -0
- data/lib/uppercut/base.rb +90 -0
- data/lib/uppercut/conversation.rb +28 -0
- data/lib/uppercut/message.rb +18 -0
- data/lib/uppercut/notifier.rb +64 -0
- data/spec/agent_spec.rb +381 -0
- data/spec/conversation_spec.rb +14 -0
- data/spec/jabber_stub.rb +121 -0
- data/spec/notifier_spec.rb +85 -0
- data/spec/spec_helper.rb +59 -0
- metadata +100 -0
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
|
4
|
+
describe Uppercut::Conversation do
|
5
|
+
before(:each) do
|
6
|
+
@conv = Uppercut::Conversation.new('test@foo.com', nil)
|
7
|
+
end
|
8
|
+
|
9
|
+
describe :contact do
|
10
|
+
it "should have a contact method" do
|
11
|
+
@conv.should.respond_to?(:contact)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/spec/jabber_stub.rb
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
Object.send(:remove_const, :Jabber)
|
2
|
+
class Jabber
|
3
|
+
class Client
|
4
|
+
def initialize(user)
|
5
|
+
@user = user
|
6
|
+
end
|
7
|
+
|
8
|
+
def connect
|
9
|
+
@connected = true
|
10
|
+
end
|
11
|
+
|
12
|
+
def auth(pw)
|
13
|
+
@pw = pw
|
14
|
+
end
|
15
|
+
|
16
|
+
def is_connected?
|
17
|
+
@connected
|
18
|
+
end
|
19
|
+
|
20
|
+
def close
|
21
|
+
@connected = nil
|
22
|
+
end
|
23
|
+
|
24
|
+
attr_reader :sent
|
25
|
+
def send(msg)
|
26
|
+
@sent ||= []
|
27
|
+
@sent << msg
|
28
|
+
end
|
29
|
+
|
30
|
+
attr_reader :on_message
|
31
|
+
def add_message_callback(&block)
|
32
|
+
@on_message = block
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
# TESTING HELPER METHODS
|
38
|
+
|
39
|
+
def receive_message(from, body, type=:chat)
|
40
|
+
msg = Message.new(nil)
|
41
|
+
msg.type = type
|
42
|
+
msg.body = body
|
43
|
+
msg.from = from
|
44
|
+
@on_message[msg]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class Presence
|
49
|
+
attr_accessor :from, :type, :show, :status
|
50
|
+
|
51
|
+
def initialize(a, b)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class Message
|
56
|
+
attr_accessor :type, :body, :from
|
57
|
+
def initialize(to)
|
58
|
+
@to = to
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
class Roster
|
63
|
+
class Helper
|
64
|
+
class RosterItem
|
65
|
+
attr_accessor :subscription
|
66
|
+
end
|
67
|
+
|
68
|
+
def initialize(client)
|
69
|
+
@client = client
|
70
|
+
end
|
71
|
+
|
72
|
+
def accept_subscription(a)
|
73
|
+
end
|
74
|
+
|
75
|
+
def add(a)
|
76
|
+
end
|
77
|
+
|
78
|
+
attr_reader :on_subscription_request
|
79
|
+
def add_subscription_request_callback(&block)
|
80
|
+
@on_subscription_request = block
|
81
|
+
end
|
82
|
+
|
83
|
+
def add_presence_callback(&block)
|
84
|
+
@on_presence = block
|
85
|
+
end
|
86
|
+
|
87
|
+
def add_subscription_callback(&block)
|
88
|
+
@on_subscription = block
|
89
|
+
end
|
90
|
+
|
91
|
+
# TESTING HELPER METHODS
|
92
|
+
|
93
|
+
def receive_presence(item, old_presence, new_presence)
|
94
|
+
@on_presence[item, old_presence, new_presence]
|
95
|
+
end
|
96
|
+
|
97
|
+
def receive_subscription(item, presence)
|
98
|
+
@on_subscription[item, presence]
|
99
|
+
end
|
100
|
+
|
101
|
+
def receive_subscription_request(item, presence)
|
102
|
+
@on_subscription_request[item, presence]
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
class JID
|
108
|
+
def self.fake_jid
|
109
|
+
new 'foo', 'bar.com', 'baz'
|
110
|
+
end
|
111
|
+
|
112
|
+
def initialize(node, domain, res)
|
113
|
+
@node, @domain, @res = node, domain, res
|
114
|
+
end
|
115
|
+
|
116
|
+
def bare
|
117
|
+
self.class.new @node, @domain, nil
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
describe Uppercut::Notifier do
|
4
|
+
before :each do
|
5
|
+
@notifier = TestNotifier.new('test@foo.com', 'pw', :connect => false)
|
6
|
+
end
|
7
|
+
|
8
|
+
describe :new do
|
9
|
+
it "connects by default" do
|
10
|
+
notifier = Uppercut::Notifier.new('test@foo', 'pw')
|
11
|
+
notifier.should be_connected
|
12
|
+
end
|
13
|
+
|
14
|
+
it "does not connect by default with :connect = false" do
|
15
|
+
notifier = Uppercut::Notifier.new('test@foo', 'pw', :connect => false)
|
16
|
+
notifier.should_not be_connected
|
17
|
+
end
|
18
|
+
|
19
|
+
it "populates @pw and @user" do
|
20
|
+
notifier = Uppercut::Notifier.new('test@foo', 'pw')
|
21
|
+
notifier.instance_eval { @pw }.should == 'pw'
|
22
|
+
notifier.instance_eval { @user }.should == 'test@foo'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe :connect do
|
27
|
+
it "does not try to connect if already connected" do
|
28
|
+
@notifier.connect
|
29
|
+
old_client = @notifier.client
|
30
|
+
|
31
|
+
@notifier.connect
|
32
|
+
(@notifier.client == old_client).should == true
|
33
|
+
end
|
34
|
+
|
35
|
+
it "connects if disconnected" do
|
36
|
+
@notifier.should_not be_connected
|
37
|
+
|
38
|
+
old_client = @notifier.client
|
39
|
+
|
40
|
+
@notifier.connect
|
41
|
+
(@notifier.client == old_client).should_not == true
|
42
|
+
end
|
43
|
+
|
44
|
+
it "sends a Presence notification" do
|
45
|
+
@notifier.connect
|
46
|
+
@notifier.client.sent.first.class.should == Jabber::Presence
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe :disconnect do
|
51
|
+
it "does not try to disconnect if not connected" do
|
52
|
+
@notifier.client.should be_nil
|
53
|
+
@notifier.instance_eval { @client = :foo }
|
54
|
+
|
55
|
+
@notifier.disconnect
|
56
|
+
@notifier.client.should == :foo
|
57
|
+
end
|
58
|
+
|
59
|
+
it "sets @client to nil" do
|
60
|
+
@notifier.connect
|
61
|
+
@notifier.client.should_not be_nil
|
62
|
+
|
63
|
+
@notifier.disconnect
|
64
|
+
@notifier.client.should be_nil
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe :reconnect do
|
69
|
+
it "calls disconnect then connect" do
|
70
|
+
@notifier.should_receive(:disconnect).once.ordered
|
71
|
+
@notifier.should_receive(:connect).once.ordered
|
72
|
+
|
73
|
+
@notifier.reconnect
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe :connected? do
|
78
|
+
it "returns true if client#is_connected? is true" do
|
79
|
+
@notifier.connect
|
80
|
+
@notifier.client.instance_eval { @connected = true }
|
81
|
+
@notifier.should be_connected
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'spec'
|
3
|
+
require 'set'
|
4
|
+
|
5
|
+
$: << File.dirname(__FILE__)
|
6
|
+
$: << File.join(File.dirname(__FILE__), '../lib')
|
7
|
+
|
8
|
+
# Loads uppercut and jabber
|
9
|
+
require 'uppercut'
|
10
|
+
|
11
|
+
# Unloads jabber, replacing it with a stub
|
12
|
+
require 'jabber_stub'
|
13
|
+
|
14
|
+
class TestAgent < Uppercut::Agent
|
15
|
+
command 'hi' do |c, args|
|
16
|
+
c.instance_eval { @base.instance_eval { @called_hi = true } }
|
17
|
+
c.send 'called hi'
|
18
|
+
end
|
19
|
+
|
20
|
+
command /^hi/ do |c, args|
|
21
|
+
c.instance_eval { @base.instance_eval { @called_hi_regex = true } }
|
22
|
+
c.send 'called hi regex'
|
23
|
+
end
|
24
|
+
|
25
|
+
command 'hello' do |c|
|
26
|
+
c.instance_eval { @base.instance_eval { @called_hello = true } }
|
27
|
+
c.send 'called hello'
|
28
|
+
end
|
29
|
+
|
30
|
+
command /^hello i am (.*), your (.*)/ do |c, name, relation|
|
31
|
+
c.instance_eval { @base.instance_eval { @called_hello_regex = "#{name} is a my #{relation}" } }
|
32
|
+
c.send 'called hello regex'
|
33
|
+
end
|
34
|
+
|
35
|
+
Uppercut::Agent::VALID_CALLBACKS.each do |cb|
|
36
|
+
on(cb) do |c, presence|
|
37
|
+
c.instance_eval { @base.instance_eval { @last_callback = cb.to_sym } }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
command 'salve' do
|
42
|
+
instance_eval { @base.instance_eval { @called_salve = true } }
|
43
|
+
send 'called salve'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
class FrenchTestAgent < Uppercut::Agent
|
48
|
+
command 'salut' do |c, args|
|
49
|
+
c.instance_eval { @base.instance_eval { @called_salut = true } }
|
50
|
+
c.send 'called salut'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class TestNotifier < Uppercut::Notifier
|
55
|
+
notifier :foo do |m, data|
|
56
|
+
m.to = 'foo@bar.com'
|
57
|
+
m.send 'Foo happened!'
|
58
|
+
end
|
59
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mrw-uppercut
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: -1876988188
|
5
|
+
prerelease: true
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
- pre1
|
11
|
+
version: 0.0.1.pre1
|
12
|
+
platform: ruby
|
13
|
+
authors:
|
14
|
+
- Tyler McMullen
|
15
|
+
- Others
|
16
|
+
autorequire:
|
17
|
+
bindir: bin
|
18
|
+
cert_chain: []
|
19
|
+
|
20
|
+
date: 2008-12-27 00:00:00 +00:00
|
21
|
+
default_executable:
|
22
|
+
dependencies:
|
23
|
+
- !ruby/object:Gem::Dependency
|
24
|
+
name: xmpp4r
|
25
|
+
prerelease: false
|
26
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
27
|
+
none: false
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
hash: 3
|
32
|
+
segments:
|
33
|
+
- 0
|
34
|
+
version: "0"
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
description: |
|
38
|
+
A DSL for writing agents and notifiers for Jabber.
|
39
|
+
This is a modified version incorporating changes from
|
40
|
+
https://github.com/yolk/uppercut.
|
41
|
+
|
42
|
+
email:
|
43
|
+
executables: []
|
44
|
+
|
45
|
+
extensions: []
|
46
|
+
|
47
|
+
extra_rdoc_files: []
|
48
|
+
|
49
|
+
files:
|
50
|
+
- README.textile
|
51
|
+
- VERSION.yml
|
52
|
+
- lib/uppercut/agent.rb
|
53
|
+
- lib/uppercut/base.rb
|
54
|
+
- lib/uppercut/conversation.rb
|
55
|
+
- lib/uppercut/message.rb
|
56
|
+
- lib/uppercut/notifier.rb
|
57
|
+
- lib/uppercut.rb
|
58
|
+
- spec/agent_spec.rb
|
59
|
+
- spec/conversation_spec.rb
|
60
|
+
- spec/jabber_stub.rb
|
61
|
+
- spec/notifier_spec.rb
|
62
|
+
- spec/spec_helper.rb
|
63
|
+
- examples/basic_agent.rb
|
64
|
+
- examples/personal.rb
|
65
|
+
has_rdoc: true
|
66
|
+
homepage: http://github.com/tyler/uppercut
|
67
|
+
licenses: []
|
68
|
+
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
hash: 3
|
80
|
+
segments:
|
81
|
+
- 0
|
82
|
+
version: "0"
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
hash: 3
|
89
|
+
segments:
|
90
|
+
- 0
|
91
|
+
version: "0"
|
92
|
+
requirements: []
|
93
|
+
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 1.3.7
|
96
|
+
signing_key:
|
97
|
+
specification_version: 2
|
98
|
+
summary: A DSL for writing agents and notifiers for Jabber.
|
99
|
+
test_files: []
|
100
|
+
|