lita-hipchat 1.5.0 → 1.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3afeeed54c6b3093fd68a764bdda47a6d925ce4e
4
- data.tar.gz: 4bc84ba99ea9bf19751559e8532e8d2d2816da21
3
+ metadata.gz: 80be126d9118aac2e700c31b23559fbed60ae90e
4
+ data.tar.gz: 115d3081432b9077665381f9b02e2141f5935dec
5
5
  SHA512:
6
- metadata.gz: af847c34127057fe05a209e1f3131887f18b7b04da82472f15af56dbb4c893106fc77abc10650fd72530a8cb0cf680795de6a9b3dfd8dfea07458488e31389dd
7
- data.tar.gz: 80c197bae7c7b5d1740b82b16e45bacd9115481892dd498acff094a3214e25a14468331f533b131da0a8b8554c1105c7a7dc42fae3e52dfb31ba333193630af8
6
+ metadata.gz: 5d375ca0fac539d04a6aae0863ec92b3253af71be27fdf91bf8ecd789095d77a875b6b4b4ebed4b9728eaa0af1763d844df70c451bf42659c080d47fd71941cb
7
+ data.tar.gz: 8e68828a8465e119e0a8d342f15b3361461bc604f147d11e4c1814de2dc50f0322cbe7d8b2d24fbc8c78fee09251d79fd9a707014b1a3346346240880b194049
data/README.md CHANGED
@@ -50,7 +50,10 @@ end
50
50
 
51
51
  ## Events
52
52
 
53
- The HipChat adapter will trigger the `:connected` and `:disconnected` events when the robot has connected and disconnected from HipChat, respectively. There is no payload data for either event.
53
+ `:connected` - When the robot has connected to HipChat. No payload.
54
+ `:disconnected` - When the robot has disconnected from HipChat. No payload.
55
+ `:joined` - When the robot joins a room. Payload: `:room`: The String room ID that was joined.
56
+ `:parted` - When the robot parts from a room. Payload: `:room`: The String room ID that was parted from.
54
57
 
55
58
  ## License
56
59
 
@@ -10,12 +10,12 @@ module Lita
10
10
 
11
11
  def initialize(robot)
12
12
  super
13
-
14
13
  @connector = Connector.new(robot, config.jid, config.password, debug: debug)
15
14
  end
16
15
 
17
16
  def join(room_id)
18
17
  connector.join(muc_domain, room_id)
18
+ robot.trigger(:joined, room: room_id)
19
19
  end
20
20
 
21
21
  def mention_format(name)
@@ -23,13 +23,14 @@ module Lita
23
23
  end
24
24
 
25
25
  def part(room_id)
26
+ robot.trigger(:parted, room: room_id)
26
27
  connector.part(muc_domain, room_id)
27
28
  end
28
29
 
29
30
  def run
30
31
  connector.connect
31
32
  robot.trigger(:connected)
32
- connector.join_rooms(muc_domain, rooms)
33
+ rooms.each { |r| join(r) }
33
34
  sleep
34
35
  rescue Interrupt
35
36
  shut_down
@@ -48,12 +49,21 @@ module Lita
48
49
  end
49
50
 
50
51
  def shut_down
52
+ rooms.each { |r| part(r) }
51
53
  connector.shut_down
52
54
  robot.trigger(:disconnected)
53
55
  end
54
56
 
55
57
  private
56
58
 
59
+ def rooms
60
+ if config.rooms == :all
61
+ connector.list_rooms(muc_domain)
62
+ else
63
+ Array(config.rooms)
64
+ end
65
+ end
66
+
57
67
  def config
58
68
  Lita.config.adapter
59
69
  end
@@ -66,13 +76,6 @@ module Lita
66
76
  config.muc_domain.nil? ? "conf.hipchat.com" : config.muc_domain.dup
67
77
  end
68
78
 
69
- def rooms
70
- if config.rooms == :all
71
- connector.list_rooms(muc_domain)
72
- else
73
- Array(config.rooms)
74
- end
75
- end
76
79
  end
77
80
 
78
81
  Lita.register_adapter(:hipchat, HipChat)
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-hipchat"
3
- spec.version = "1.5.0"
3
+ spec.version = "1.6.0"
4
4
  spec.authors = ["Jimmy Cuadra"]
5
5
  spec.email = ["jimmy@jimmycuadra.com"]
6
6
  spec.description = %q{A HipChat adapter for Lita.}
@@ -5,6 +5,7 @@ describe Lita::Adapters::HipChat::Connector, lita: true do
5
5
 
6
6
  let(:client) do
7
7
  client = instance_double("Jabber::Client")
8
+ allow(robot).to receive(:trigger)
8
9
  allow(client).to receive(:auth)
9
10
  allow(client).to receive(:connect)
10
11
  allow(client).to receive(:send)
@@ -16,6 +16,7 @@ describe Lita::Adapters::HipChat do
16
16
 
17
17
  let(:robot) { instance_double("Lita::Robot") }
18
18
  let(:connector) { instance_double("Lita::Adapters::HipChat::Connector") }
19
+ let(:domain) { "conf.hipchat.com" }
19
20
 
20
21
  it "registers with Lita" do
21
22
  expect(Lita.adapters[:hipchat]).to eql(described_class)
@@ -28,9 +29,13 @@ describe Lita::Adapters::HipChat do
28
29
  end
29
30
 
30
31
  describe "#join" do
32
+ let(:room) { "#foo" }
33
+ before do
34
+ allow(robot).to receive(:trigger).with(:joined, room: room)
35
+ end
31
36
  it "joins a room" do
32
- expect(subject.connector).to receive(:join).with("conf.hipchat.com", "#foo")
33
- subject.join("#foo")
37
+ expect(subject.connector).to receive(:join).with(domain, room)
38
+ subject.join(room)
34
39
  end
35
40
  end
36
41
 
@@ -41,17 +46,23 @@ describe Lita::Adapters::HipChat do
41
46
  end
42
47
 
43
48
  describe "#part" do
49
+ let(:room) { "#foo" }
50
+ before do
51
+ allow(robot).to receive(:trigger).with(:parted, room: room)
52
+ end
44
53
  it "parts from a room" do
45
- expect(subject.connector).to receive(:part).with("conf.hipchat.com", "#foo")
46
- subject.part("#foo")
54
+ expect(subject.connector).to receive(:part).with(domain, room)
55
+ subject.part(room)
47
56
  end
48
57
  end
49
58
 
50
59
  describe "#run" do
60
+ let(:rooms) { ["room_1_id", "room_2_id"] }
61
+
51
62
  before do
52
63
  allow(subject.connector).to receive(:connect)
53
64
  allow(robot).to receive(:trigger)
54
- allow(subject.connector).to receive(:join_rooms)
65
+ allow(subject.connector).to receive(:join)
55
66
  allow(subject).to receive(:sleep)
56
67
  end
57
68
 
@@ -61,24 +72,31 @@ describe Lita::Adapters::HipChat do
61
72
  subject.run
62
73
  end
63
74
 
64
- it "joins rooms with a custom muc_domain" do
65
- Lita.config.adapter.muc_domain = "foo.bar.com"
66
- expect(subject.connector).to receive(:join_rooms).with("foo.bar.com", anything)
67
- subject.run
75
+ context "with a custom domain" do
76
+ let(:domain) { "foo.bar.com" }
77
+ it "joins rooms with a custom muc_domain" do
78
+ Lita.config.adapter.muc_domain = domain
79
+ allow(subject).to receive(:rooms).and_return(rooms)
80
+ expect(subject.connector).to receive(:join).with(domain, anything)
81
+ subject.run
82
+ end
68
83
  end
69
84
 
70
85
  it "joins all rooms when config.rooms is :all" do
71
- rooms = ["room_1_id", "room_2_id"]
72
86
  Lita.config.adapter.rooms = :all
73
- allow(subject.connector).to receive(:list_rooms).with("conf.hipchat.com").and_return(rooms)
74
- expect(subject.connector).to receive(:join_rooms).with("conf.hipchat.com", rooms)
87
+ allow(subject.connector).to receive(:list_rooms).with(domain).and_return(rooms)
88
+ rooms.each do |room|
89
+ expect(subject).to receive(:join).with(room)
90
+ end
75
91
  subject.run
76
92
  end
77
93
 
78
94
  it "joins rooms specified by config.rooms" do
79
- custom_rooms = ["my_room_1_id", "my_room_2_id"]
95
+ custom_rooms = rooms
80
96
  Lita.config.adapter.rooms = custom_rooms
81
- expect(subject.connector).to receive(:join_rooms).with("conf.hipchat.com",custom_rooms)
97
+ rooms.each do |room|
98
+ expect(subject).to receive(:join).with(room)
99
+ end
82
100
  subject.run
83
101
  end
84
102
 
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.5.0
4
+ version: 1.6.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-04-26 00:00:00.000000000 Z
11
+ date: 2014-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita