lita-hipchat 1.2.4 → 1.3.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.
- checksums.yaml +4 -4
- data/lib/lita/adapters/hipchat.rb +19 -15
- data/lib/lita/adapters/hipchat/connector.rb +20 -9
- data/lita-hipchat.gemspec +3 -3
- data/spec/lita/adapters/hipchat/callback_spec.rb +16 -35
- data/spec/lita/adapters/hipchat/connector_spec.rb +72 -62
- data/spec/lita/adapters/hipchat_spec.rb +28 -31
- metadata +6 -7
- data/lib/lita/encoding_patches.rb +0 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4eafe0fed02771e3620e3c24e787e5ac93bd6161
|
4
|
+
data.tar.gz: d3ce7410e3b5ac946ca7b8647faf3fd11606f511
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 766865e1b4d6179bec66e66a7c5ad22d1da935eb541e96822619ed3cd4bb1eb74fd5aaacb297beff1d448dea5d3dd491795f3ca0d0c11e8901c7f40fa228a08b
|
7
|
+
data.tar.gz: 0cf3c6890479743a5193272ad6070034d1b936cdabf434331f4ff98606a013eeebc1e6573451ca37ceaf7de0bf22454f58e6658c79203ac3ebf19a04812af0d0
|
@@ -11,20 +11,21 @@ module Lita
|
|
11
11
|
def initialize(robot)
|
12
12
|
super
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
14
|
+
@connector = Connector.new(robot, config.jid, config.password, debug: debug)
|
15
|
+
end
|
16
|
+
|
17
|
+
def join(room_id)
|
18
|
+
connector.join(muc_domain, room_id)
|
19
|
+
end
|
20
|
+
|
21
|
+
def part(room_id)
|
22
|
+
connector.part(muc_domain, room_id)
|
22
23
|
end
|
23
24
|
|
24
25
|
def run
|
25
26
|
connector.connect
|
26
27
|
robot.trigger(:connected)
|
27
|
-
connector.join_rooms(
|
28
|
+
connector.join_rooms(muc_domain, rooms)
|
28
29
|
sleep
|
29
30
|
rescue Interrupt
|
30
31
|
shut_down
|
@@ -53,18 +54,21 @@ module Lita
|
|
53
54
|
Lita.config.adapter
|
54
55
|
end
|
55
56
|
|
57
|
+
def debug
|
58
|
+
config.debug || false
|
59
|
+
end
|
60
|
+
|
61
|
+
def muc_domain
|
62
|
+
config.muc_domain || "conf.hipchat.com"
|
63
|
+
end
|
64
|
+
|
56
65
|
def rooms
|
57
66
|
if config.rooms == :all
|
58
|
-
connector.list_rooms(
|
67
|
+
connector.list_rooms(muc_domain)
|
59
68
|
else
|
60
69
|
Array(config.rooms)
|
61
70
|
end
|
62
71
|
end
|
63
|
-
|
64
|
-
def set_default_config_values
|
65
|
-
config.debug = false if config.debug.nil?
|
66
|
-
config.muc_domain = "conf.hipchat.com" if config.muc_domain.nil?
|
67
|
-
end
|
68
72
|
end
|
69
73
|
|
70
74
|
Lita.register_adapter(:hipchat, HipChat)
|
@@ -1,4 +1,3 @@
|
|
1
|
-
require "lita/encoding_patches"
|
2
1
|
require "lita/adapters/hipchat/callback"
|
3
2
|
|
4
3
|
require "xmpp4r"
|
@@ -34,15 +33,21 @@ module Lita
|
|
34
33
|
send_presence
|
35
34
|
end
|
36
35
|
|
36
|
+
def join(muc_domain, room)
|
37
|
+
room_jid = normalized_jid(room, muc_domain, robot.name)
|
38
|
+
return if mucs[room_jid.bare.to_s]
|
39
|
+
|
40
|
+
muc = Jabber::MUC::SimpleMUCClient.new(client)
|
41
|
+
mucs[room_jid.bare.to_s] = muc
|
42
|
+
|
43
|
+
register_muc_message_callback(muc)
|
44
|
+
|
45
|
+
Lita.logger.info("Joining room: #{room_jid}.")
|
46
|
+
muc.join(room_jid)
|
47
|
+
end
|
48
|
+
|
37
49
|
def join_rooms(muc_domain, rooms)
|
38
|
-
rooms.each
|
39
|
-
muc = Jabber::MUC::SimpleMUCClient.new(client)
|
40
|
-
room_jid = normalized_jid(room_name, muc_domain, robot.name)
|
41
|
-
mucs[room_jid.bare.to_s] = muc
|
42
|
-
register_muc_message_callback(muc)
|
43
|
-
Lita.logger.info("Joining room: #{room_jid}.")
|
44
|
-
muc.join(room_jid)
|
45
|
-
end
|
50
|
+
rooms.each { |room| join(muc_domain, room) }
|
46
51
|
end
|
47
52
|
|
48
53
|
def list_rooms(muc_domain)
|
@@ -72,6 +77,12 @@ module Lita
|
|
72
77
|
@mucs ||= {}
|
73
78
|
end
|
74
79
|
|
80
|
+
def part(muc_domain, room)
|
81
|
+
room_jid = normalized_jid(room, muc_domain, robot.name)
|
82
|
+
muc = mucs[room_jid.bare.to_s]
|
83
|
+
muc.exit if muc
|
84
|
+
end
|
85
|
+
|
75
86
|
def set_topic(room_jid, topic)
|
76
87
|
muc = mucs[room_jid]
|
77
88
|
if muc
|
data/lita-hipchat.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "lita-hipchat"
|
3
|
-
spec.version = "1.
|
3
|
+
spec.version = "1.3.0"
|
4
4
|
spec.authors = ["Jimmy Cuadra"]
|
5
5
|
spec.email = ["jimmy@jimmycuadra.com"]
|
6
6
|
spec.description = %q{A HipChat adapter for Lita.}
|
@@ -15,11 +15,11 @@ Gem::Specification.new do |spec|
|
|
15
15
|
spec.require_paths = ["lib"]
|
16
16
|
|
17
17
|
spec.add_runtime_dependency "lita", ">= 2.5"
|
18
|
-
spec.add_runtime_dependency "xmpp4r", ">= 0.5"
|
18
|
+
spec.add_runtime_dependency "xmpp4r", ">= 0.5.6"
|
19
19
|
|
20
20
|
spec.add_development_dependency "bundler", "~> 1.3"
|
21
21
|
spec.add_development_dependency "rake"
|
22
|
-
spec.add_development_dependency "rspec", ">=
|
22
|
+
spec.add_development_dependency "rspec", ">= 3.0.0.beta2"
|
23
23
|
spec.add_development_dependency "simplecov"
|
24
24
|
spec.add_development_dependency "coveralls"
|
25
25
|
end
|
@@ -3,15 +3,15 @@ require "spec_helper"
|
|
3
3
|
describe Lita::Adapters::HipChat::Callback, lita: true do
|
4
4
|
subject { described_class.new(robot, roster) }
|
5
5
|
|
6
|
-
let(:robot) {
|
6
|
+
let(:robot) { instance_double("Lita::Robot") }
|
7
7
|
let(:roster) do
|
8
|
-
|
8
|
+
instance_double("Jabber::Roster::Helper", items: { "user_id" => roster_item })
|
9
9
|
end
|
10
|
-
let(:user) {
|
11
|
-
let(:source) {
|
12
|
-
let(:message) {
|
10
|
+
let(:user) { instance_double("Lita::User", id: "user_id") }
|
11
|
+
let(:source) { instance_double("Lita::Source") }
|
12
|
+
let(:message) { instance_double("Lita::Message") }
|
13
13
|
let(:roster_item) do
|
14
|
-
|
14
|
+
instance_double("Jabber::Roster::RosterItem", attributes: {
|
15
15
|
"jid" => "user_id",
|
16
16
|
"name" => "Carl",
|
17
17
|
"mention_name" => "@Carl"
|
@@ -36,9 +36,9 @@ describe Lita::Adapters::HipChat::Callback, lita: true do
|
|
36
36
|
end
|
37
37
|
|
38
38
|
describe "#private_message" do
|
39
|
-
let(:client) {
|
39
|
+
let(:client) { instance_double("Jabber::Client") }
|
40
40
|
let(:jabber_message) do
|
41
|
-
|
41
|
+
instance_double("Jabber::Message", type: :chat, from: "user_id", body: "foo")
|
42
42
|
end
|
43
43
|
|
44
44
|
before do
|
@@ -47,11 +47,7 @@ describe Lita::Adapters::HipChat::Callback, lita: true do
|
|
47
47
|
|
48
48
|
it "sends the message to the robot with the proper source and body" do
|
49
49
|
allow(Lita::Source).to receive(:new).with(user: user).and_return(source)
|
50
|
-
allow(Lita::Message).to receive(:new).with(
|
51
|
-
robot,
|
52
|
-
"foo",
|
53
|
-
source
|
54
|
-
).and_return(message)
|
50
|
+
allow(Lita::Message).to receive(:new).with(robot, "foo", source).and_return(message)
|
55
51
|
expect(message).to receive(:command!)
|
56
52
|
expect(robot).to receive(:receive).with(message)
|
57
53
|
subject.private_message(client)
|
@@ -71,39 +67,28 @@ describe Lita::Adapters::HipChat::Callback, lita: true do
|
|
71
67
|
end
|
72
68
|
|
73
69
|
describe "#muc_message" do
|
74
|
-
let(:jid) {
|
75
|
-
let(:muc) {
|
70
|
+
let(:jid) { instance_double("Jabber::JID", bare: "room_id") }
|
71
|
+
let(:muc) { instance_double("Jabber::MUC::SimpleMUCClient", jid: jid) }
|
76
72
|
|
77
73
|
before do
|
78
74
|
allow(muc).to receive(:on_message).and_yield(nil, "Carl", "foo")
|
79
75
|
end
|
80
76
|
|
81
77
|
it "sends the message to the robot with the proper source and body" do
|
82
|
-
allow(Lita::Source).to receive(:new).with(
|
83
|
-
|
84
|
-
room: "room_id"
|
85
|
-
).and_return(source)
|
86
|
-
allow(Lita::Message).to receive(:new).with(
|
87
|
-
robot,
|
88
|
-
"foo",
|
89
|
-
source
|
90
|
-
).and_return(message)
|
78
|
+
allow(Lita::Source).to receive(:new).with(user: user, room: "room_id").and_return(source)
|
79
|
+
allow(Lita::Message).to receive(:new).with(robot, "foo", source).and_return(message)
|
91
80
|
expect(robot).to receive(:receive).with(message)
|
92
81
|
subject.muc_message(muc)
|
93
82
|
end
|
94
83
|
|
95
84
|
it "creates a temporary source user if the JID isn't in the roster" do
|
96
|
-
roster =
|
85
|
+
roster = instance_double("Jabber::Roster::Helper", items: {})
|
97
86
|
allow(muc).to receive(:on_message).and_yield(nil, "Unknown", "foo")
|
98
87
|
allow(Lita::Source).to receive(:new).with(
|
99
88
|
user: an_instance_of(Lita::User),
|
100
89
|
room: "room_id"
|
101
90
|
).and_return(source)
|
102
|
-
allow(Lita::Message).to receive(:new).with(
|
103
|
-
robot,
|
104
|
-
"foo",
|
105
|
-
source
|
106
|
-
).and_return(message)
|
91
|
+
allow(Lita::Message).to receive(:new).with(robot, "foo", source).and_return(message)
|
107
92
|
expect(robot).to receive(:receive).with(message)
|
108
93
|
subject.muc_message(muc)
|
109
94
|
end
|
@@ -112,11 +97,7 @@ describe Lita::Adapters::HipChat::Callback, lita: true do
|
|
112
97
|
describe "#roster_update" do
|
113
98
|
it "finds/creates a user object for the roster item" do
|
114
99
|
allow(roster).to receive(:add_update_callback).and_yield(nil, roster_item)
|
115
|
-
expect(Lita::User).to receive(:create).with(
|
116
|
-
"user_id",
|
117
|
-
name: "Carl",
|
118
|
-
mention_name: "@Carl"
|
119
|
-
)
|
100
|
+
expect(Lita::User).to receive(:create).with("user_id", name: "Carl", mention_name: "@Carl")
|
120
101
|
subject.roster_update
|
121
102
|
end
|
122
103
|
|
@@ -3,8 +3,15 @@ require "spec_helper"
|
|
3
3
|
describe Lita::Adapters::HipChat::Connector, lita: true do
|
4
4
|
subject { described_class.new(robot, "user", "secret") }
|
5
5
|
|
6
|
-
let(:client)
|
7
|
-
|
6
|
+
let(:client) do
|
7
|
+
client = instance_double("Jabber::Client")
|
8
|
+
allow(client).to receive(:auth)
|
9
|
+
allow(client).to receive(:connect)
|
10
|
+
allow(client).to receive(:send)
|
11
|
+
client
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:robot) { instance_double("Lita::Robot", name: "Lita" ) }
|
8
15
|
|
9
16
|
before { allow(subject).to receive(:client).and_return(client) }
|
10
17
|
|
@@ -29,22 +36,23 @@ describe Lita::Adapters::HipChat::Connector, lita: true do
|
|
29
36
|
end
|
30
37
|
|
31
38
|
describe "#connect" do
|
32
|
-
let(:presence) {
|
33
|
-
let(:
|
34
|
-
let(:
|
39
|
+
let(:presence) { instance_double("Jabber::Presence") }
|
40
|
+
let(:callback) { instance_double("Lita::Adapters::HipChat::Callback") }
|
41
|
+
let(:roster) { instance_double("Jabber::Roster::Helper") }
|
42
|
+
let(:roster_item) do
|
43
|
+
instance_double("Jabber::Roster::RosterItem", attributes: { "mention_name" => "LitaBot"})
|
44
|
+
end
|
35
45
|
|
36
46
|
before do
|
37
47
|
allow(Jabber::Presence).to receive(:new).and_return(presence)
|
38
|
-
allow(Jabber::Roster::Helper).to receive(:new).with(
|
39
|
-
|
40
|
-
false
|
41
|
-
).and_return(roster)
|
42
|
-
allow(Lita::Adapters::HipChat::Callback).to receive(:new).and_return(
|
43
|
-
callback
|
44
|
-
)
|
48
|
+
allow(Jabber::Roster::Helper).to receive(:new).with(client, false).and_return(roster)
|
49
|
+
allow(Lita::Adapters::HipChat::Callback).to receive(:new).and_return(callback)
|
45
50
|
allow(callback).to receive(:private_message)
|
46
51
|
allow(callback).to receive(:roster_update)
|
47
52
|
allow(robot).to receive(:mention_name=)
|
53
|
+
allow(roster).to receive(:get_roster)
|
54
|
+
allow(roster).to receive(:wait_for_roster)
|
55
|
+
allow(roster).to receive(:[]).with(subject.jid).and_return(roster_item)
|
48
56
|
end
|
49
57
|
|
50
58
|
it "connects to HipChat" do
|
@@ -78,67 +86,58 @@ describe Lita::Adapters::HipChat::Connector, lita: true do
|
|
78
86
|
end
|
79
87
|
|
80
88
|
it "assigns the robot's mention_name with info from the roster" do
|
81
|
-
allow(roster).to receive(:[]).with(subject.jid).and_return(
|
82
|
-
double("Jabber::Roster::RosterItem", attributes: {
|
83
|
-
"mention_name" => "LitaBot"
|
84
|
-
})
|
85
|
-
)
|
86
89
|
expect(robot).to receive(:mention_name=).with("LitaBot")
|
87
90
|
subject.connect
|
88
91
|
end
|
89
92
|
end
|
90
93
|
|
91
|
-
describe "#join
|
92
|
-
let(:
|
93
|
-
let(:
|
94
|
-
let(:muc_1) { double("Jabber::MUC::SimpleMUCClient").as_null_object }
|
95
|
-
let(:muc_2) { double("Jabber::MUC::SimpleMUCClient").as_null_object }
|
96
|
-
let(:callback) { double("Lita::Adapters::HipChat::Callback") }
|
97
|
-
let(:roster) { double("Jabber::Roster::Helper") }
|
94
|
+
describe "#join" do
|
95
|
+
let(:muc) { instance_double("Jabber::MUC::SimpleMUCClient") }
|
96
|
+
let(:callback) { instance_double("Lita::Adapters::HipChat::Callback") }
|
98
97
|
|
99
98
|
before do
|
100
|
-
allow(Jabber::MUC::SimpleMUCClient).to receive(:new).with(
|
101
|
-
|
102
|
-
).and_return(muc_1, muc_2)
|
103
|
-
allow(Lita::Adapters::HipChat::Callback).to receive(:new).and_return(
|
104
|
-
callback
|
105
|
-
)
|
99
|
+
allow(Jabber::MUC::SimpleMUCClient).to receive(:new).with(client).and_return(muc)
|
100
|
+
allow(Lita::Adapters::HipChat::Callback).to receive(:new).and_return(callback)
|
106
101
|
allow(callback).to receive(:muc_message)
|
107
|
-
allow(
|
102
|
+
allow(muc).to receive(:join)
|
108
103
|
end
|
109
104
|
|
110
|
-
it "
|
111
|
-
subject.
|
112
|
-
expect(subject.mucs).to eq(
|
113
|
-
"muc_1@conf.hipchat.com" => muc_1,
|
114
|
-
"muc_2@conf.hipchat.com" => muc_2,
|
115
|
-
)
|
105
|
+
it "stores a SimpleMUCClient for the room" do
|
106
|
+
subject.join("conf.hipchat.com", "foo")
|
107
|
+
expect(subject.mucs["foo@conf.hipchat.com"]).to eq(muc)
|
116
108
|
end
|
117
109
|
|
118
|
-
it "registers a message callback
|
119
|
-
expect(
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
expect(
|
125
|
-
subject.
|
110
|
+
it "registers a message callback" do
|
111
|
+
expect(callback).to receive(:muc_message).with(muc)
|
112
|
+
subject.join("conf.hipchat.com", "foo")
|
113
|
+
end
|
114
|
+
|
115
|
+
it "joins the room" do
|
116
|
+
expect(muc).to receive(:join)
|
117
|
+
subject.join("conf.hipchat.com", "foo")
|
126
118
|
end
|
127
119
|
|
120
|
+
it "doesn't attempt to join a room it's already in" do
|
121
|
+
expect(callback).to receive(:muc_message).with(muc).once
|
122
|
+
expect(muc).to receive(:join).once
|
123
|
+
2.times { subject.join("conf.hipchat.com", "foo") }
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
describe "#join rooms" do
|
128
|
+
let(:rooms) { %w(foo bar) }
|
129
|
+
|
128
130
|
it "joins each room" do
|
129
|
-
expect(
|
130
|
-
|
131
|
-
subject.join_rooms(muc_domain, rooms)
|
131
|
+
rooms.each { |room| expect(subject).to receive(:join).with("conf.hipchat.com", room) }
|
132
|
+
subject.join_rooms("conf.hipchat.com", rooms)
|
132
133
|
end
|
133
134
|
end
|
134
135
|
|
135
136
|
describe "#list_rooms" do
|
136
|
-
let(:browser) {
|
137
|
+
let(:browser) { instance_double("Jabber::MUC::MUCBrowser") }
|
137
138
|
|
138
139
|
before do
|
139
|
-
allow(Jabber::MUC::MUCBrowser).to receive(:new).with(client).and_return(
|
140
|
-
browser
|
141
|
-
)
|
140
|
+
allow(Jabber::MUC::MUCBrowser).to receive(:new).with(client).and_return(browser)
|
142
141
|
end
|
143
142
|
|
144
143
|
it "returns an array of room JIDs for the MUC domain" do
|
@@ -154,16 +153,12 @@ describe Lita::Adapters::HipChat::Connector, lita: true do
|
|
154
153
|
end
|
155
154
|
|
156
155
|
describe "#message_jid" do
|
157
|
-
let(:message_1) {
|
158
|
-
let(:message_2) {
|
156
|
+
let(:message_1) { instance_double("Jabber::Message") }
|
157
|
+
let(:message_2) { instance_double("Jabber::Message") }
|
159
158
|
|
160
159
|
it "sends the messages to the user" do
|
161
|
-
allow(Jabber::Message).to receive(:new).with("jid", "foo").and_return(
|
162
|
-
|
163
|
-
)
|
164
|
-
allow(Jabber::Message).to receive(:new).with("jid", "bar").and_return(
|
165
|
-
message_2
|
166
|
-
)
|
160
|
+
allow(Jabber::Message).to receive(:new).with("jid", "foo").and_return(message_1)
|
161
|
+
allow(Jabber::Message).to receive(:new).with("jid", "bar").and_return(message_2)
|
167
162
|
expect(message_1).to receive(:type=).with(:chat)
|
168
163
|
expect(message_2).to receive(:type=).with(:chat)
|
169
164
|
expect(client).to receive(:send).with(message_1)
|
@@ -174,7 +169,7 @@ describe Lita::Adapters::HipChat::Connector, lita: true do
|
|
174
169
|
|
175
170
|
describe "#message_muc" do
|
176
171
|
it "sends the messages to the room" do
|
177
|
-
muc =
|
172
|
+
muc = instance_double("Jabber::MUC::SimpleMUCClient")
|
178
173
|
allow(subject).to receive(:mucs).and_return("jid" => muc)
|
179
174
|
expect(muc).to receive(:say).with("foo")
|
180
175
|
expect(muc).to receive(:say).with("bar")
|
@@ -182,9 +177,24 @@ describe Lita::Adapters::HipChat::Connector, lita: true do
|
|
182
177
|
end
|
183
178
|
end
|
184
179
|
|
180
|
+
describe "#part" do
|
181
|
+
let(:muc) { instance_double("Jabber::MUC::SimpleMUCClient") }
|
182
|
+
|
183
|
+
it "parts from a room" do
|
184
|
+
subject.mucs["#foo@conf.hipchat.com"] = muc
|
185
|
+
expect(muc).to receive(:exit)
|
186
|
+
subject.part("conf.hipchat.com", "#foo")
|
187
|
+
end
|
188
|
+
|
189
|
+
it "doesn't attempt to part from a room it's not in" do
|
190
|
+
expect(muc).not_to receive(:exit)
|
191
|
+
subject.part("conf.hipchat.com", "#foo")
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
185
195
|
describe "#set_topic" do
|
186
196
|
it "sets the room's topic to the supplied message" do
|
187
|
-
muc =
|
197
|
+
muc = instance_double("Jabber::MUC::SimpleMUCClient")
|
188
198
|
allow(subject).to receive(:mucs).and_return("jid" => muc)
|
189
199
|
expect(muc).to receive(:subject=).with("New topic")
|
190
200
|
subject.set_topic("jid", "New topic")
|
@@ -14,19 +14,33 @@ describe Lita::Adapters::HipChat do
|
|
14
14
|
|
15
15
|
subject { described_class.new(robot) }
|
16
16
|
|
17
|
-
let(:robot) {
|
18
|
-
let(:connector) {
|
17
|
+
let(:robot) { instance_double("Lita::Robot") }
|
18
|
+
let(:connector) { instance_double("Lita::Adapters::HipChat::Connector") }
|
19
19
|
|
20
20
|
it "registers with Lita" do
|
21
21
|
expect(Lita.adapters[:hipchat]).to eql(described_class)
|
22
22
|
end
|
23
23
|
|
24
24
|
it "requires config.jid and config.password" do
|
25
|
-
Lita.
|
25
|
+
Lita.config.adapter.jid = Lita.config.adapter.password = nil
|
26
26
|
expect(Lita.logger).to receive(:fatal).with(/jid, password/)
|
27
27
|
expect { subject }.to raise_error(SystemExit)
|
28
28
|
end
|
29
29
|
|
30
|
+
describe "#join" do
|
31
|
+
it "joins a room" do
|
32
|
+
expect(subject.connector).to receive(:join).with("conf.hipchat.com", "#foo")
|
33
|
+
subject.join("#foo")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "#part" do
|
38
|
+
it "parts from a room" do
|
39
|
+
expect(subject.connector).to receive(:part).with("conf.hipchat.com", "#foo")
|
40
|
+
subject.part("#foo")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
30
44
|
describe "#run" do
|
31
45
|
before do
|
32
46
|
allow(subject.connector).to receive(:connect)
|
@@ -43,33 +57,22 @@ describe Lita::Adapters::HipChat do
|
|
43
57
|
|
44
58
|
it "joins rooms with a custom muc_domain" do
|
45
59
|
Lita.config.adapter.muc_domain = "foo.bar.com"
|
46
|
-
expect(subject.connector).to receive(:join_rooms).with(
|
47
|
-
"foo.bar.com",
|
48
|
-
anything
|
49
|
-
)
|
60
|
+
expect(subject.connector).to receive(:join_rooms).with("foo.bar.com", anything)
|
50
61
|
subject.run
|
51
62
|
end
|
52
63
|
|
53
64
|
it "joins all rooms when config.rooms is :all" do
|
54
|
-
|
65
|
+
rooms = ["room_1_id", "room_2_id"]
|
55
66
|
Lita.config.adapter.rooms = :all
|
56
|
-
allow(subject.connector).to receive(:list_rooms).with(
|
57
|
-
|
58
|
-
).and_return(all_rooms)
|
59
|
-
expect(subject.connector).to receive(:join_rooms).with(
|
60
|
-
"conf.hipchat.com",
|
61
|
-
all_rooms
|
62
|
-
)
|
67
|
+
allow(subject.connector).to receive(:list_rooms).with("conf.hipchat.com").and_return(rooms)
|
68
|
+
expect(subject.connector).to receive(:join_rooms).with("conf.hipchat.com", rooms)
|
63
69
|
subject.run
|
64
70
|
end
|
65
71
|
|
66
72
|
it "joins rooms specified by config.rooms" do
|
67
73
|
custom_rooms = ["my_room_1_id", "my_room_2_id"]
|
68
74
|
Lita.config.adapter.rooms = custom_rooms
|
69
|
-
expect(subject.connector).to receive(:join_rooms).with(
|
70
|
-
"conf.hipchat.com",
|
71
|
-
custom_rooms
|
72
|
-
)
|
75
|
+
expect(subject.connector).to receive(:join_rooms).with("conf.hipchat.com",custom_rooms)
|
73
76
|
subject.run
|
74
77
|
end
|
75
78
|
|
@@ -87,28 +90,22 @@ describe Lita::Adapters::HipChat do
|
|
87
90
|
|
88
91
|
describe "#send_messages" do
|
89
92
|
it "sends messages to rooms" do
|
90
|
-
source =
|
91
|
-
expect(subject.connector).to receive(:message_muc).with(
|
92
|
-
"room_id",
|
93
|
-
["Hello!"]
|
94
|
-
)
|
93
|
+
source = instance_double("Lita::Source", room: "room_id", private_message?: false)
|
94
|
+
expect(subject.connector).to receive(:message_muc).with("room_id", ["Hello!"])
|
95
95
|
subject.send_messages(source, ["Hello!"])
|
96
96
|
end
|
97
97
|
|
98
98
|
it "sends private messages to users" do
|
99
|
-
user =
|
100
|
-
source =
|
101
|
-
expect(subject.connector).to receive(:message_jid).with(
|
102
|
-
"user_id",
|
103
|
-
["Hello!"]
|
104
|
-
)
|
99
|
+
user = instance_double("Lita::User", id: "user_id")
|
100
|
+
source = instance_double("Lita::Source", user: user, private_message?: true)
|
101
|
+
expect(subject.connector).to receive(:message_jid).with("user_id", ["Hello!"])
|
105
102
|
subject.send_messages(source, ["Hello!"])
|
106
103
|
end
|
107
104
|
end
|
108
105
|
|
109
106
|
describe "#set_topic" do
|
110
107
|
it "sets a new topic for a room" do
|
111
|
-
source =
|
108
|
+
source = instance_double("Lita::Source", room: "room_id")
|
112
109
|
expect(subject.connector).to receive(:set_topic).with("room_id", "Topic")
|
113
110
|
subject.set_topic(source, "Topic")
|
114
111
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita-hipchat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jimmy Cuadra
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lita
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 0.5.6
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 0.5.6
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 3.0.0.beta2
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 3.0.0.beta2
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: simplecov
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -125,7 +125,6 @@ files:
|
|
125
125
|
- lib/lita/adapters/hipchat.rb
|
126
126
|
- lib/lita/adapters/hipchat/callback.rb
|
127
127
|
- lib/lita/adapters/hipchat/connector.rb
|
128
|
-
- lib/lita/encoding_patches.rb
|
129
128
|
- lita-hipchat.gemspec
|
130
129
|
- spec/lita/adapters/hipchat/callback_spec.rb
|
131
130
|
- spec/lita/adapters/hipchat/connector_spec.rb
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# xmpp4r and REXML are bad and should feel bad.
|
2
|
-
# https://github.com/ln/xmpp4r/issues/3#issuecomment-1739952
|
3
|
-
require 'socket'
|
4
|
-
class TCPSocket
|
5
|
-
def external_encoding
|
6
|
-
Encoding::BINARY
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
require 'rexml/source'
|
11
|
-
class REXML::IOSource
|
12
|
-
alias_method :encoding_assign, :encoding=
|
13
|
-
def encoding=(value)
|
14
|
-
encoding_assign(value) if value
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
begin
|
19
|
-
# OpenSSL is optional and can be missing
|
20
|
-
require 'openssl'
|
21
|
-
class OpenSSL::SSL::SSLSocket
|
22
|
-
def external_encoding
|
23
|
-
Encoding::BINARY
|
24
|
-
end
|
25
|
-
end
|
26
|
-
rescue
|
27
|
-
end
|