lita-flowdock 0.2.2 → 0.2.3

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: ccd12e5bf38319575f355c6e0ad78bb8afa72543
4
- data.tar.gz: 83c89df5b4d672704f5f93369537aafa56216055
3
+ metadata.gz: 4e7c5b59bef6c79b46baabff5bb13104fd702d9a
4
+ data.tar.gz: 09e2d9d829cdcfc726c759b499b88c850ffc4904
5
5
  SHA512:
6
- metadata.gz: 50a8b0aec49a210daa05b30c2bf2f2e03676d498ea94a66d5fb96be538387516cc039d026b4b6fa37449a6aec3dafb922547a984e7cde85e21d445722714978d
7
- data.tar.gz: 22fcfa3b0e637a3f75225b027d3f8cf326c288d2ff0569821c78be14bac52299db8f1b908c99cb15f017d62f8484768dad27e5c2f85ca369149812cccfbf7d6d
6
+ metadata.gz: a5f12b386be541e133c554c5fb70cb894bebe50997b262d3622b5811ff35acd9b384f8f3389821198b806ca9cc91f2ff3c0a2c76fce2660053569d7eca34726e
7
+ data.tar.gz: bc3da50050ee8c6d0b4d168874ca0df07aa6c5f120a870cfe9366cc75450082fa3aee95f19d59f694de44b9ad59c40683f8ebcb80d53f6d77510508c08274a01
data/.travis.yml CHANGED
@@ -1,10 +1,6 @@
1
- cache:
2
- - bundler
3
1
  language: ruby
4
2
  rvm:
5
3
  - 2.2.0
6
4
  script: bundle exec rake
7
- before_install:
8
- - gem update --system
9
5
  services:
10
6
  - redis-server
@@ -9,24 +9,26 @@ module Lita
9
9
  class Flowdock < Adapter
10
10
  class Connector
11
11
 
12
- def initialize(robot, api_token, organization, flows, flowdock_client=nil)
12
+ def initialize(robot, api_token, organization, flows, flowdock_client=nil, query_params=Hash.new)
13
13
  @robot = robot
14
14
  @api_token = api_token
15
15
  @organization = organization
16
16
  @flows = flows
17
17
  @client =
18
18
  flowdock_client || ::Flowdock::Client.new(api_token: api_token)
19
+ @query_params = query_params
19
20
  @stream_url =
20
21
  "https://#{api_token}@stream.flowdock.com/flows?filter=#{request_flows}"
21
22
 
22
23
  UsersCreator.create_users(client.get('/users'))
24
+ store_flows
23
25
  end
24
26
 
25
27
  def run(url=stream_url, queue=nil)
26
28
  EM.run do
27
29
  @source = EventMachine::EventSource.new(
28
30
  url,
29
- {query: 'text/event-stream'},
31
+ @query_params,
30
32
  {'Accept' => 'text/event-stream'}
31
33
  )
32
34
 
@@ -51,13 +53,20 @@ module Lita
51
53
  end
52
54
  end
53
55
 
54
- def send_messages(target, messages, message_id = nil)
56
+ def send_messages(target, messages, thread)
57
+ params = {
58
+ flow: target.room
59
+ }
60
+ params.merge!(message_id: target.message_id) if thread
55
61
  messages.each do |message|
56
- client.chat_message(
57
- flow: target,
58
- content: message,
59
- message: message_id
60
- )
62
+ params.merge!(content: message)
63
+ if target.private_message
64
+ params.merge!(user_id: target.user.id)
65
+ client.private_message(params)
66
+ else
67
+ puts params.inspect
68
+ client.chat_message(params)
69
+ end
61
70
  end
62
71
  end
63
72
 
@@ -86,6 +95,12 @@ module Lita
86
95
  def robot_id
87
96
  @robot_id ||= client.get('/user')['id']
88
97
  end
98
+
99
+ def store_flows
100
+ client.get("/flows").each do |flow|
101
+ Lita.redis.set("flows/#{flow['parameterized_name']}", flow['id'])
102
+ end
103
+ end
89
104
  end
90
105
  end
91
106
  end
@@ -1,5 +1,6 @@
1
1
  require 'lita/adapters/flowdock/users_creator'
2
2
  require 'lita/source/flowdock_source'
3
+ require 'lita/message/flowdock_message'
3
4
 
4
5
  module Lita
5
6
  module Adapters
@@ -23,6 +24,8 @@ module Lita
23
24
  handle_user_activity
24
25
  when "action"
25
26
  handle_action
27
+ when "tag-change"
28
+ handle_tag_change
26
29
  else
27
30
  handle_unknown
28
31
  end
@@ -40,22 +43,18 @@ module Lita
40
43
  data['tags']
41
44
  end
42
45
 
43
- def parent_id
44
- influx_tag = tags.select { |t| t =~ /influx:(\d+)/ }.first
45
- influx_tag.split(':')[-1].to_i
46
- end
47
-
48
- def message_id
49
- type == 'comment' ? parent_id : id
46
+ def thread_id
47
+ data['thread_id']
50
48
  end
51
49
 
52
50
  def dispatch_message(user)
53
51
  source = FlowdockSource.new(
54
52
  user: user,
55
53
  room: flow,
56
- message_id: message_id
54
+ private_message: private_message?,
55
+ message_id: private_message? ? data['id'] : data['thread']['initial_message']
57
56
  )
58
- message = Message.new(robot, body, source)
57
+ message = FlowdockMessage.new(robot, body, source, tags, thread_id)
59
58
  robot.receive(message)
60
59
  end
61
60
 
@@ -63,10 +62,6 @@ module Lita
63
62
  data['flow']
64
63
  end
65
64
 
66
- def id
67
- data['id']
68
- end
69
-
70
65
  def from_self?(user)
71
66
  user.id.to_i == robot_id
72
67
  end
@@ -94,6 +89,10 @@ module Lita
94
89
  end
95
90
  end
96
91
 
92
+ def handle_tag_change
93
+ robot.trigger(:tag_change, added: data['content']['add'], removed: data['content']['remove'], message: data['content']['message'])
94
+ end
95
+
97
96
  def handle_unknown
98
97
  log.debug("Unknown message type: #{data.inspect}")
99
98
  end
@@ -102,6 +101,10 @@ module Lita
102
101
  user = flowdock_client.get("/user/#{id}")
103
102
  UsersCreator.create_user(user)
104
103
  end
104
+
105
+ def private_message?
106
+ data.has_key?('to')
107
+ end
105
108
  end
106
109
  end
107
110
  end
@@ -10,6 +10,8 @@ module Lita
10
10
  config :organization, type: String, required: true
11
11
  config :flows, type: Array, required: true
12
12
  config :thread_responses, type: Symbol, required: false, default: :enabled
13
+ config :private_messages, type: Symbol, required: false, default: :enabled
14
+ config :active_user, type: Symbol, required: false, default: :enabled
13
15
 
14
16
 
15
17
  def mention_format(name)
@@ -22,7 +24,9 @@ module Lita
22
24
  robot,
23
25
  config.api_token,
24
26
  config.organization,
25
- config.flows
27
+ config.flows,
28
+ nil,
29
+ query_params
26
30
  )
27
31
 
28
32
  connector.run
@@ -34,15 +38,30 @@ module Lita
34
38
  end
35
39
 
36
40
  def send_messages(target, messages)
37
- if config.thread_responses.eql?(:enabled)
38
- connector.send_messages(target.room, messages, target.message_id)
39
- else
40
- connector.send_messages(target.room, messages)
41
- end
41
+ connector.send_messages(
42
+ target,
43
+ messages,
44
+ config.thread_responses.eql?(:enabled)
45
+ )
42
46
  end
43
47
 
44
48
  private
45
49
  attr_reader :connector
50
+
51
+ def query_params
52
+ {
53
+ user: respond_to_private_messages?,
54
+ active: show_user_as_active?
55
+ }
56
+ end
57
+
58
+ def respond_to_private_messages?
59
+ [:enabled, :help].include?(config.private_messages) ? 1 : 0
60
+ end
61
+
62
+ def show_user_as_active?
63
+ config.active_user.eql?(:enabled) ? 'true' : 'idle'
64
+ end
46
65
  end
47
66
 
48
67
  Lita.register_adapter(:flowdock, Flowdock)
@@ -0,0 +1,10 @@
1
+ module Lita
2
+ class FlowdockMessage < Message
3
+ attr_reader :tags, :thread_id
4
+ def initialize(robot, body, source, tags, thread_id)
5
+ @tags = tags
6
+ @thread_id = thread_id
7
+ super(robot, body, source)
8
+ end
9
+ end
10
+ end
@@ -3,6 +3,7 @@ module Lita
3
3
  attr_reader :message_id
4
4
 
5
5
  def initialize(user: nil, room: nil, private_message: false, message_id: nil)
6
+ room = Lita.redis.get("flows/#{room}") || room unless room.nil?
6
7
  super(user: user, room: room, private_message: private_message)
7
8
  @message_id = message_id
8
9
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-flowdock"
3
- spec.version = "0.2.2"
3
+ spec.version = "0.2.3"
4
4
  spec.authors = ["Ben House"]
5
5
  spec.email = ["ben@benhouse.io"]
6
6
  spec.description = %q{flowdock adapter for lita.io}
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
16
16
 
17
17
  spec.add_runtime_dependency "lita", "~> 4.2"
18
18
  spec.add_runtime_dependency "em-eventsource"
19
- spec.add_runtime_dependency "flowdock"
19
+ spec.add_runtime_dependency "flowdock", ">= 0.6"
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake"
@@ -26,4 +26,6 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency "coveralls"
27
27
  spec.add_development_dependency "rubocop"
28
28
  spec.add_development_dependency "bump"
29
+ spec.add_development_dependency "pry"
30
+ spec.add_development_dependency "pry-byebug"
29
31
  end
@@ -14,12 +14,14 @@ describe Lita::Adapters::Flowdock::Connector, lita: true do
14
14
  }
15
15
 
16
16
  let(:registry) { Lita::Registry.new }
17
+ let(:source) { instance_double('Lita::FlowdockSource', private_message?: false, message_id: message_id) }
17
18
  let(:robot) { Lita::Robot.new(registry) }
18
19
  let(:api_token) { 'a8f828cfe7efc65b53b3de06761e83e9' }
19
20
  let(:organization) { 'lita-test' }
20
21
  let(:flows) { ['testing'] }
21
22
  let(:fd_client) { instance_double('Flowdock::Client') }
22
23
  let(:users) { [ user_hash(1), user_hash(2) ] }
24
+ let(:flows) { [ flow_hash(1) ] }
23
25
  let(:queue) { Queue.new }
24
26
  let(:url) { "http://example.com" }
25
27
 
@@ -28,16 +30,25 @@ describe Lita::Adapters::Flowdock::Connector, lita: true do
28
30
 
29
31
  it "creates users" do
30
32
  expect(fd_client).to receive(:get).with('/users').and_return(users)
33
+ allow(fd_client).to receive(:get).with('/flows').and_return([])
31
34
  expect(Lita::Adapters::Flowdock::UsersCreator).to receive(
32
35
  :create_users
33
36
  ).with(users)
34
37
  subject.new(robot, api_token, organization, flows, fd_client)
35
38
  end
39
+
40
+ it "stores flows" do
41
+ allow(fd_client).to receive(:get).with('/users').and_return([])
42
+ allow(fd_client).to receive(:get).with("/flows").and_return(flows)
43
+ expect(Lita.redis).to receive(:set).with("flows/#{flows[0]['parameterized_name']}", flows[0]['id'])
44
+ subject.new(robot, api_token, organization, flows, fd_client)
45
+ end
36
46
  end
37
47
 
38
48
  describe "#run" do
39
49
  before do
40
50
  allow(fd_client).to receive(:get).with('/users').and_return([])
51
+ allow(fd_client).to receive(:get).with('/flows').and_return([])
41
52
  end
42
53
 
43
54
  it "starts the reactor" do
@@ -54,17 +65,20 @@ describe Lita::Adapters::Flowdock::Connector, lita: true do
54
65
  end
55
66
 
56
67
  describe "#send_messages" do
57
- let(:target) { 'testing:lita-test' }
68
+ let(:target) { source }
58
69
  let(:message) { 'foo' }
59
70
  let(:message_id) { 1234 }
60
71
 
61
72
  before do
62
73
  allow(fd_client).to receive(:get).with('/users').and_return(users)
74
+ allow(fd_client).to receive(:get).with('/flows').and_return(flows)
75
+ allow(source).to receive(:room).and_return('testing:lita-test')
76
+ allow(source).to receive(:private_message).and_return(false)
63
77
  end
64
78
 
65
79
  it "sends messages" do
66
- expect(fd_client).to receive(:chat_message).with(flow: target, content: message, message: message_id)
67
- subject.send_messages(target, [message], message_id)
80
+ expect(fd_client).to receive(:chat_message).with(flow: target.room, message_id: message_id, content: message)
81
+ subject.send_messages(target, [message], true)
68
82
  end
69
83
  end
70
84
  end
@@ -28,14 +28,18 @@ describe Lita::Adapters::Flowdock::MessageHandler, lita: true do
28
28
  let(:id) { 2345 }
29
29
  let(:data) do
30
30
  {
31
- 'content' => 'Hello World!',
32
- 'event' => 'message',
33
- 'flow' => test_flow,
34
- 'id' => id,
35
- 'user' => test_user_id
31
+ 'content' => 'Hello World!',
32
+ 'event' => 'message',
33
+ 'flow' => test_flow,
34
+ 'id' => id,
35
+ 'thread' => {
36
+ 'initial_message' => id
37
+ },
38
+ 'tags' => [],
39
+ 'user' => test_user_id
36
40
  }
37
41
  end
38
- let(:message) { instance_double('Lita::Message', command!: false) }
42
+ let(:message) { instance_double('Lita::FlowdockMessage', command!: false) }
39
43
  let(:source) { instance_double('Lita::FlowdockSource', private_message?: false, message_id: id) }
40
44
  let(:user) { user_double(test_user_id) }
41
45
 
@@ -44,10 +48,11 @@ describe Lita::Adapters::Flowdock::MessageHandler, lita: true do
44
48
  allow(Lita::FlowdockSource).to receive(:new).with(
45
49
  user: user,
46
50
  room: test_flow,
51
+ private_message: false,
47
52
  message_id: id
48
53
  ).and_return(source)
49
- allow(Lita::Message).to receive(:new).with(
50
- robot, 'Hello World!', source).and_return(message)
54
+ allow(Lita::FlowdockMessage).to receive(:new).with(
55
+ robot, 'Hello World!', source, [], nil).and_return(message)
51
56
  allow(robot).to receive(:receive).with(message)
52
57
  end
53
58
 
@@ -60,18 +65,24 @@ describe Lita::Adapters::Flowdock::MessageHandler, lita: true do
60
65
  context "when the message is nil" do
61
66
  let(:data) do
62
67
  {
63
- 'event' => 'message',
64
- 'flow' => test_flow,
65
- 'user' => test_user_id,
66
- 'id' => id
68
+ 'event' => 'message',
69
+ 'flow' => test_flow,
70
+ 'user' => test_user_id,
71
+ 'tags' => [],
72
+ 'id' => id,
73
+ 'thread' => {
74
+ 'initial_message' => id
75
+ }
67
76
  }
68
77
  end
69
78
 
70
79
  it "dispatches an empty message to Lita" do
71
- expect(Lita::Message).to receive(:new).with(
80
+ expect(Lita::FlowdockMessage).to receive(:new).with(
72
81
  robot,
73
82
  "",
74
- source
83
+ source,
84
+ [],
85
+ nil
75
86
  ).and_return(message)
76
87
 
77
88
  subject.handle
@@ -79,12 +90,35 @@ describe Lita::Adapters::Flowdock::MessageHandler, lita: true do
79
90
  end
80
91
  end
81
92
 
93
+ context "a tag-change event" do
94
+ let(:data) do
95
+ {
96
+ 'content' => {
97
+ 'add' => ['foo'],
98
+ 'remove' => ['bar'],
99
+ 'message' => ['I have #foo']
100
+ },
101
+ 'event' => 'tag-change',
102
+ 'flow' => test_flow,
103
+ 'tags' => [],
104
+ 'user' => test_user_id
105
+ }
106
+ end
107
+
108
+ it 'triggers tag-change trigger' do
109
+ expect(robot).to receive(:trigger).with(:tag_change, added: ['foo'], removed: ['bar'], message: ['I have #foo'])
110
+
111
+ subject.handle
112
+ end
113
+ end
114
+
82
115
  context "a message with an unsupported type" do
83
116
  let(:data) do
84
117
  {
85
118
  'content' => 'this type is not supported',
86
119
  'event' => 'unsupported',
87
120
  'flow' => test_flow,
121
+ 'tags' => [],
88
122
  'user' => test_user_id
89
123
  }
90
124
  end
@@ -102,6 +136,7 @@ describe Lita::Adapters::Flowdock::MessageHandler, lita: true do
102
136
  'content' => 'reply from lita',
103
137
  'event' => 'message',
104
138
  'flow' => test_flow,
139
+ 'tags' => [],
105
140
  'user' => robot_id
106
141
  }
107
142
  end
@@ -128,6 +163,10 @@ describe Lita::Adapters::Flowdock::MessageHandler, lita: true do
128
163
  'content' => "hi i'm new here",
129
164
  'event' => 'message',
130
165
  'flow' => test_flow,
166
+ 'tags' => [],
167
+ 'thread' => {
168
+ 'initial_message' => 5678
169
+ },
131
170
  'user' => new_user_id
132
171
  }
133
172
  end
@@ -160,6 +199,7 @@ describe Lita::Adapters::Flowdock::MessageHandler, lita: true do
160
199
  'content' => { 'last_activity' => 1317715364447 },
161
200
  'event' => 'activity.user',
162
201
  'flow' => test_flow,
202
+ 'tags' => [],
163
203
  'user' => test_user_id
164
204
  }
165
205
  end
@@ -174,17 +214,21 @@ describe Lita::Adapters::Flowdock::MessageHandler, lita: true do
174
214
  context "receives a comment message" do
175
215
  let(:id) { 4321 }
176
216
  let(:parent_id) { 123456 }
217
+ let(:tags) { [] }
177
218
  let(:data) do
178
219
  {
179
220
  'content' => {
180
- 'title' => 'Thread title',
181
- 'text' => 'Lita: help'
221
+ 'title' => 'Thread title',
222
+ 'text' => 'Lita: help'
182
223
  },
183
- 'event' => 'comment',
184
- 'flow' => test_flow,
185
- 'id' => id,
186
- 'tags' => ["influx:#{parent_id}"],
187
- 'user' => test_user_id
224
+ 'event' => 'comment',
225
+ 'flow' => test_flow,
226
+ 'id' => id,
227
+ 'thread' => {
228
+ 'initial_message' => parent_id
229
+ },
230
+ 'tags' => tags,
231
+ 'user' => test_user_id
188
232
  }
189
233
  end
190
234
  let(:message) { instance_double('Lita::Message', command!: true) }
@@ -196,10 +240,11 @@ describe Lita::Adapters::Flowdock::MessageHandler, lita: true do
196
240
  allow(Lita::FlowdockSource).to receive(:new).with(
197
241
  user: user,
198
242
  room: test_flow,
243
+ private_message: false,
199
244
  message_id: parent_id
200
245
  ).and_return(source)
201
- allow(Lita::Message).to receive(:new).with(
202
- robot, 'Lita: help', source).and_return(message)
246
+ allow(Lita::FlowdockMessage).to receive(:new).with(
247
+ robot, 'Lita: help', source, tags, nil).and_return(message)
203
248
  allow(robot).to receive(:receive).with(message)
204
249
  end
205
250
 
@@ -216,6 +261,7 @@ describe Lita::Adapters::Flowdock::MessageHandler, lita: true do
216
261
  'content' => {'type' => 'add_people', 'description' => 'user5'},
217
262
  'event' => 'action',
218
263
  'flow' => test_flow,
264
+ 'tags' => [],
219
265
  'user' => test_user_id
220
266
  }
221
267
  end
@@ -246,6 +292,7 @@ describe Lita::Adapters::Flowdock::MessageHandler, lita: true do
246
292
  'content' => {'type' => 'join', 'description' => 'tbd'},
247
293
  'event' => 'action',
248
294
  'flow' => test_flow,
295
+ 'tags' => [],
249
296
  'user' => joining_user_id
250
297
  }
251
298
  end
@@ -275,6 +322,7 @@ describe Lita::Adapters::Flowdock::MessageHandler, lita: true do
275
322
  },
276
323
  'event' => 'action',
277
324
  'flow' => test_flow,
325
+ 'tags' => [],
278
326
  'user' => test_user_id
279
327
  }
280
328
  end
@@ -21,9 +21,12 @@ describe Lita::Adapters::Flowdock, lita: true do
21
21
  robot,
22
22
  api_token,
23
23
  organization,
24
- flows
24
+ flows,
25
+ nil,
26
+ {:user => 1, :active => 'true'}
25
27
  ).and_return(connector)
26
28
  allow(connector).to receive(:run)
29
+ allow(Lita.redis).to receive(:get).with("flows/1234abcd").and_return("dcba4321")
27
30
  end
28
31
 
29
32
  it "registers with Lita" do
@@ -51,7 +54,7 @@ describe Lita::Adapters::Flowdock, lita: true do
51
54
  let(:user_source) { Lita::Source.new(user: user) }
52
55
 
53
56
  it "sends messages to flows" do
54
- expect(connector).to receive(:send_messages).with(room_source.room, ['foo'], room_source.message_id)
57
+ expect(connector).to receive(:send_messages).with(room_source, ['foo'], true)
55
58
 
56
59
  subject.run
57
60
 
@@ -64,7 +67,17 @@ describe Lita::Adapters::Flowdock, lita: true do
64
67
  end
65
68
 
66
69
  it "sends messages to flow without the original message id" do
67
- expect(connector).to receive(:send_messages).with(room_source.room, ['foo'])
70
+ expect(connector).to receive(:send_messages).with(room_source, ['foo'], false)
71
+ subject.run
72
+ subject.send_messages(room_source, ['foo'])
73
+ end
74
+ end
75
+
76
+ context "from a private message source" do
77
+ let(:room_source) { Lita::FlowdockSource.new(room: '1234abcd', message_id: id, private_message: true) }
78
+
79
+ it "responds via a private message to flowdock" do
80
+ expect(connector).to receive(:send_messages).with(room_source, ['foo'], false)
68
81
  subject.run
69
82
  subject.send_messages(room_source, ['foo'])
70
83
  end
@@ -0,0 +1,129 @@
1
+ require 'spec_helper'
2
+
3
+ describe Lita::FlowdockMessage, lita: true do
4
+ let(:message_handler) do
5
+ Lita::Adapters::Flowdock::MessageHandler.new(
6
+ robot,
7
+ 123456,
8
+ data,
9
+ fd_client
10
+ )
11
+ end
12
+
13
+ let(:source) { instance_double('Lita::FlowdockSource', private_message?: false, message_id: 1234) }
14
+
15
+ let(:robot) { Lita::Robot.new(registry) }
16
+ let(:fd_client) { instance_double('Flowdock::Client') }
17
+ let(:test_flow) { 'testing:lita-test' }
18
+ let(:test_user_id) { 3 }
19
+ let(:test_fd_user) { user_hash(test_user_id) }
20
+ let(:user) { user_double(test_user_id) }
21
+
22
+ before do
23
+ allow(fd_client).to receive(:get).with("/user/3").and_return(test_fd_user)
24
+ allow(Lita::FlowdockSource).to receive(:new).with(
25
+ user: user,
26
+ room: test_flow,
27
+ private_message: false,
28
+ message_id: 1234
29
+ ).and_return(source)
30
+ allow(Lita::User).to receive(:find_by_id).and_return(user)
31
+ end
32
+
33
+ context "a message in a thread has a tag" do
34
+ let(:tags) { ['down'] }
35
+ let(:body) { 'the system is #down' }
36
+ let(:data) do
37
+ {
38
+ 'content' => {
39
+ 'title' => 'Thread title',
40
+ 'text' => body
41
+ },
42
+ 'event' => 'comment',
43
+ 'flow' => test_flow,
44
+ 'id' => 2345,
45
+ 'thread' => {
46
+ 'initial_message' => 1234
47
+ },
48
+ 'tags' => tags,
49
+ 'user' => 3
50
+ }
51
+ end
52
+
53
+ it 'creates a message with tags' do
54
+ expect(Lita::FlowdockMessage).to receive(:new).with(
55
+ robot,
56
+ body,
57
+ source,
58
+ tags,
59
+ nil
60
+ )
61
+
62
+ message_handler.handle
63
+ end
64
+ end
65
+
66
+ context "a message in a thread" do
67
+ let(:tags) { ['down'] }
68
+ let(:body) { 'the system is #down' }
69
+ let(:data) do
70
+ {
71
+ 'content' => {
72
+ 'title' => 'Thread title',
73
+ 'text' => body
74
+ },
75
+ 'event' => 'comment',
76
+ 'flow' => test_flow,
77
+ 'id' => 2345,
78
+ 'thread_id' => 'deadbeef',
79
+ 'thread' => {
80
+ 'initial_message' => 1234
81
+ },
82
+ 'tags' => tags,
83
+ 'user' => 3
84
+ }
85
+ end
86
+
87
+ it 'stores the message_id on the flowdock_message' do
88
+ expect(Lita::FlowdockMessage).to receive(:new).with(
89
+ robot,
90
+ body,
91
+ source,
92
+ tags,
93
+ 'deadbeef'
94
+ )
95
+
96
+ message_handler.handle
97
+ end
98
+ end
99
+
100
+ context 'a regular message with a tag' do
101
+ let(:tags) { ['world'] }
102
+ let(:body) { 'Hello #world' }
103
+ let(:data) do
104
+ {
105
+ 'content' => body,
106
+ 'event' => 'message',
107
+ 'flow' => test_flow,
108
+ 'id' => 1234,
109
+ 'thread' => {
110
+ 'initial_message' => 1234
111
+ },
112
+ 'tags' => tags,
113
+ 'user' => 3
114
+ }
115
+ end
116
+
117
+ it 'creates a message with tags' do
118
+ expect(Lita::FlowdockMessage).to receive(:new).with(
119
+ robot,
120
+ body,
121
+ source,
122
+ tags,
123
+ nil
124
+ )
125
+
126
+ message_handler.handle
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe Lita::FlowdockSource do
4
+ let(:room){ "Main" }
5
+ let(:room_id) { "123123123" }
6
+
7
+ subject{ Lita::FlowdockSource.new(room: room) }
8
+
9
+ describe "with a room" do
10
+ it "looks up rooms" do
11
+ expect(Lita.redis).to receive(:get).with("flows/#{room}").and_return(room_id)
12
+ expect(subject.room).to eql(room_id)
13
+ end
14
+
15
+ describe "if the room doesn't exist" do
16
+ it "defaults to the passed in room" do
17
+ expect(Lita.redis).to receive(:get).with("flows/#{room}").and_return(nil)
18
+ expect(subject.room).to eql(room)
19
+ end
20
+ end
21
+ end
22
+
23
+ describe "without a room" do
24
+ subject{ Lita::FlowdockSource.new(user: "Bob") }
25
+
26
+ it "skips the room lookup if no room is given" do
27
+ expect(Lita.redis).not_to receive(:get).with("flows/#{room}")
28
+ expect(subject.room).to be_nil
29
+ expect(subject.user).to eql("Bob")
30
+ end
31
+ end
32
+
33
+
34
+ describe "with a message id" do
35
+ subject{ Lita::FlowdockSource.new(room: room, message_id: 123) }
36
+
37
+ it "saves the message id" do
38
+ allow(Lita.redis).to receive(:get).with("flows/#{room}").and_return(room_id)
39
+ expect(subject.message_id).to eql(123)
40
+ end
41
+ end
42
+ end
data/spec/spec_helper.rb CHANGED
@@ -27,3 +27,7 @@ end
27
27
  def user_hash(id)
28
28
  { 'id' => id, 'name' => "Test User#{id}", "nick" => "user#{id}" }
29
29
  end
30
+
31
+ def flow_hash(id)
32
+ { 'id' => id, 'name' => "Test Flow#{id}", 'parameterized_name' => "test_flow#{id}"}
33
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-flowdock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben House
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-11 00:00:00.000000000 Z
11
+ date: 2015-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '0.6'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '0.6'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -164,6 +164,34 @@ dependencies:
164
164
  - - ">="
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: pry
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: pry-byebug
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
167
195
  description: flowdock adapter for lita.io
168
196
  email:
169
197
  - ben@benhouse.io
@@ -184,6 +212,7 @@ files:
184
212
  - lib/lita/adapters/flowdock/connector.rb
185
213
  - lib/lita/adapters/flowdock/message_handler.rb
186
214
  - lib/lita/adapters/flowdock/users_creator.rb
215
+ - lib/lita/message/flowdock_message.rb
187
216
  - lib/lita/source/flowdock_source.rb
188
217
  - lita-flowdock.gemspec
189
218
  - locales/en.yml
@@ -191,6 +220,8 @@ files:
191
220
  - spec/lita/adapters/flowdock/message_handler_spec.rb
192
221
  - spec/lita/adapters/flowdock/users_creator_spec.rb
193
222
  - spec/lita/adapters/flowdock_spec.rb
223
+ - spec/lita/message/flowdock_message_spec.rb
224
+ - spec/lita/source/flowdock_source_spec.rb
194
225
  - spec/spec_helper.rb
195
226
  homepage: https://github.com/bhouse/lita-flowdock
196
227
  licenses:
@@ -213,7 +244,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
213
244
  version: '0'
214
245
  requirements: []
215
246
  rubyforge_project:
216
- rubygems_version: 2.2.2
247
+ rubygems_version: 2.4.5
217
248
  signing_key:
218
249
  specification_version: 4
219
250
  summary: connects lita.io to flowdock chat service
@@ -222,4 +253,6 @@ test_files:
222
253
  - spec/lita/adapters/flowdock/message_handler_spec.rb
223
254
  - spec/lita/adapters/flowdock/users_creator_spec.rb
224
255
  - spec/lita/adapters/flowdock_spec.rb
256
+ - spec/lita/message/flowdock_message_spec.rb
257
+ - spec/lita/source/flowdock_source_spec.rb
225
258
  - spec/spec_helper.rb