grape-slack-bot 1.6.12 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/slack_bot.rb CHANGED
@@ -1,26 +1,26 @@
1
- require 'slack_bot/logger'
2
- require 'slack_bot/dev_console'
1
+ require "slack_bot/logger"
2
+ require "slack_bot/dev_console"
3
3
 
4
- require 'slack_bot/config'
5
- require 'slack_bot/error'
6
- require 'slack_bot/errors'
4
+ require "slack_bot/config"
5
+ require "slack_bot/error"
6
+ require "slack_bot/errors"
7
7
 
8
- require 'slack_bot/args'
9
- require 'slack_bot/api_client'
8
+ require "slack_bot/args"
9
+ require "slack_bot/api_client"
10
10
 
11
- require 'slack_bot/callback_storage'
12
- require 'slack_bot/callback'
11
+ require "slack_bot/callback_storage"
12
+ require "slack_bot/callback"
13
13
 
14
- require 'slack_bot/command'
15
- require 'slack_bot/interaction'
16
- require 'slack_bot/event'
17
- require 'slack_bot/menu_options'
18
- require 'slack_bot/view'
14
+ require "slack_bot/command"
15
+ require "slack_bot/interaction"
16
+ require "slack_bot/event"
17
+ require "slack_bot/menu_options"
18
+ require "slack_bot/view"
19
19
 
20
- require 'slack_bot/pager'
20
+ require "slack_bot/pager"
21
21
 
22
- require 'slack_bot/grape_extension'
22
+ require "slack_bot/grape_extension"
23
23
 
24
24
  module SlackBot
25
- VERSION = '1.6.12'.freeze
25
+ VERSION = "1.7.0".freeze
26
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grape-slack-bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.12
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrei Makarov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-06 00:00:00.000000000 Z
11
+ date: 2024-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -150,6 +150,48 @@ dependencies:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
152
  version: '2'
153
+ - !ruby/object:Gem::Dependency
154
+ name: standard
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '1'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '1'
167
+ - !ruby/object:Gem::Dependency
168
+ name: standard-performance
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '1'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: '1'
181
+ - !ruby/object:Gem::Dependency
182
+ name: standard-rspec
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: '0.2'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
193
+ - !ruby/object:Gem::Version
194
+ version: '0.2'
153
195
  description: Slack bot implementation for ruby-grape
154
196
  email:
155
197
  - andrei@kiskolabs.com
@@ -181,20 +223,6 @@ files:
181
223
  - lib/slack_bot/menu_options.rb
182
224
  - lib/slack_bot/pager.rb
183
225
  - lib/slack_bot/view.rb
184
- - spec/slack_bot/api_client_spec.rb
185
- - spec/slack_bot/args_spec.rb
186
- - spec/slack_bot/callback_spec.rb
187
- - spec/slack_bot/command_spec.rb
188
- - spec/slack_bot/config_spec.rb
189
- - spec/slack_bot/dev_console_spec.rb
190
- - spec/slack_bot/event_spec.rb
191
- - spec/slack_bot/grape_extension_spec.rb
192
- - spec/slack_bot/interaction_spec.rb
193
- - spec/slack_bot/logger_spec.rb
194
- - spec/slack_bot/menu_options_spec.rb
195
- - spec/slack_bot/pager_spec.rb
196
- - spec/slack_bot/view_spec.rb
197
- - spec/slack_bot_spec.rb
198
226
  homepage: https://github.com/amkisko/grape-slack-bot.rb
199
227
  licenses:
200
228
  - MIT
@@ -212,29 +240,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
212
240
  requirements:
213
241
  - - ">="
214
242
  - !ruby/object:Gem::Version
215
- version: 2.5.0
243
+ version: '3'
216
244
  required_rubygems_version: !ruby/object:Gem::Requirement
217
245
  requirements:
218
246
  - - ">="
219
247
  - !ruby/object:Gem::Version
220
248
  version: '0'
221
249
  requirements: []
222
- rubygems_version: 3.4.19
250
+ rubygems_version: 3.5.9
223
251
  signing_key:
224
252
  specification_version: 4
225
253
  summary: Slack bot implementation for ruby-grape
226
- test_files:
227
- - spec/slack_bot/api_client_spec.rb
228
- - spec/slack_bot/args_spec.rb
229
- - spec/slack_bot/callback_spec.rb
230
- - spec/slack_bot/command_spec.rb
231
- - spec/slack_bot/config_spec.rb
232
- - spec/slack_bot/dev_console_spec.rb
233
- - spec/slack_bot/event_spec.rb
234
- - spec/slack_bot/grape_extension_spec.rb
235
- - spec/slack_bot/interaction_spec.rb
236
- - spec/slack_bot/logger_spec.rb
237
- - spec/slack_bot/menu_options_spec.rb
238
- - spec/slack_bot/pager_spec.rb
239
- - spec/slack_bot/view_spec.rb
240
- - spec/slack_bot_spec.rb
254
+ test_files: []
@@ -1,479 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe SlackBot::ApiClient do
4
- subject(:client) { described_class.new(authorization_token: authorization_token) }
5
- let(:authorization_token) { "test_authorization_token" }
6
-
7
- it "does not raise errors" do
8
- expect { client }.not_to raise_error
9
- end
10
-
11
- context "when the authorization token is not set" do
12
- let(:authorization_token) { nil }
13
- it "raises an error" do
14
- expect { client }.to raise_error("Slack bot API token is not set")
15
- end
16
- end
17
-
18
- describe "#users_info" do
19
- before do
20
- stub_request(:post, "https://slack.com/api/users.info").to_return(response)
21
- end
22
- subject(:users_info) { client.users_info(user_id: user_id) }
23
- let(:user_id) { "U0R7JM" }
24
- let(:response) {
25
- {
26
- status: 200,
27
- body: {
28
- "ok" => true,
29
- "user" => {
30
- "id" => "W012A3CDE",
31
- "team_id" => "T012AB3C4",
32
- "name" => "spengler",
33
- "deleted" => false,
34
- "color" => "9f69e7",
35
- "real_name" => "Egon Spengler",
36
- "tz" => "America/Los_Angeles",
37
- "tz_label" => "Pacific Daylight Time",
38
- "tz_offset" => -25200,
39
- "profile" => {
40
- "avatar_hash" => "ge3b51ca72de",
41
- "status_text" => "Print is dead",
42
- "status_emoji" => ":books:",
43
- "real_name" => "Egon Spengler",
44
- "display_name" => "spengler",
45
- "real_name_normalized" => "Egon Spengler",
46
- "display_name_normalized" => "spengler",
47
- "email" => "spengler@ghostbusters.example.com",
48
- "image_original" => "https://.../avatar/e3b51ca72dee4ef87916ae2b9240df50.jpg",
49
- "image_24" => "https://.../avatar/e3b51ca72dee4ef87916ae2b9240df50.jpg",
50
- "image_32" => "https://.../avatar/e3b51ca72dee4ef87916ae2b9240df50.jpg",
51
- "image_48" => "https://.../avatar/e3b51ca72dee4ef87916ae2b9240df50.jpg",
52
- "image_72" => "https://.../avatar/e3b51ca72dee4ef87916ae2b9240df50.jpg",
53
- "image_192" => "https://.../avatar/e3b51ca72dee4ef87916ae2b9240df50.jpg",
54
- "image_512" => "https://.../avatar/e3b51ca72dee4ef87916ae2b9240df50.jpg",
55
- "team" => "T012AB3C4"
56
- },
57
- "is_admin" => true,
58
- "is_owner" => false,
59
- "is_primary_owner" => false,
60
- "is_restricted" => false,
61
- "is_ultra_restricted" => false,
62
- "is_bot" => false,
63
- "updated" => 1502138686,
64
- "is_app_user" => false,
65
- "has_2fa" => false
66
- }
67
- }.to_json
68
- }
69
- }
70
- it "sends authorization token" do
71
- expect(users_info.response.env.request_headers["Authorization"]).to eq("Bearer #{authorization_token}")
72
- end
73
- it "returns a successful response" do
74
- expect(users_info.ok?).to eq(true)
75
- end
76
- context "when the response is not successful" do
77
- let(:response) {
78
- {
79
- status: 200,
80
- body: {
81
- "ok" => false,
82
- "error" => "user_not_found"
83
- }.to_json
84
- }
85
- }
86
- it "returns an unsuccessful response" do
87
- expect(users_info.ok?).to eq(false)
88
- end
89
- end
90
- end
91
-
92
- describe "#views_open" do
93
- before do
94
- stub_request(:post, "https://slack.com/api/views.open").to_return(response)
95
- end
96
- subject(:views_open) {
97
- client.views_open(
98
- trigger_id: "trigger_id",
99
- view: {
100
- "type" => "modal",
101
- "title" => {
102
- "type" => "plain_text",
103
- "text" => "Quite a plain modal"
104
- },
105
- "submit" => {
106
- "type" => "plain_text",
107
- "text" => "Create"
108
- },
109
- "blocks" => [
110
- {
111
- "type" => "input",
112
- "block_id" => "a_block_id",
113
- "label" => [
114
- "type" => "plain_text",
115
- "text" => "A simple label",
116
- "emoji" => true
117
- ],
118
- "optional" => false,
119
- "element" => {
120
- "type" => "plain_text_input",
121
- "action_id" => "an_action_id"
122
- }
123
- }
124
- ],
125
- }
126
- )
127
- }
128
- let(:response) {
129
- {
130
- status: 200,
131
- body: {
132
- "ok" => true,
133
- "view" => {
134
- "id" => "VMHU10V25",
135
- "team_id" => "T8N4K1JN",
136
- "type" => "modal",
137
- "title" => {
138
- "type" => "plain_text",
139
- "text" => "Quite a plain modal"
140
- },
141
- "submit" => {
142
- "type" => "plain_text",
143
- "text" => "Create"
144
- },
145
- "blocks" => [
146
- {
147
- "type" => "input",
148
- "block_id" => "a_block_id",
149
- "label" => {
150
- "type" => "plain_text",
151
- "text" => "A simple label",
152
- "emoji" => true
153
- },
154
- "optional" => false,
155
- "element" => {
156
- "type" => "plain_text_input",
157
- "action_id" => "an_action_id"
158
- }
159
- }
160
- ],
161
- "private_metadata" => "Shh it is a secret",
162
- "callback_id" => "identify_your_modals",
163
- "external_id" => "",
164
- "state" => {
165
- "values" => {}
166
- },
167
- "hash" => "156772938.1827394",
168
- "clear_on_close" => false,
169
- "notify_on_close" => false,
170
- "root_view_id" => "VMHU10V25",
171
- "app_id" => "AA4928AQ",
172
- "bot_id" => "BA13894H"
173
- }
174
- }.to_json
175
- }
176
- }
177
- it "returns a successful response" do
178
- expect(views_open.ok?).to eq(true)
179
- end
180
-
181
- context "when the response is unsuccessful" do
182
- let(:response) {
183
- {
184
- status: 200,
185
- body: {
186
- "ok" => false,
187
- "error" => "invalid_arguments",
188
- "response_metadata" => {
189
- "messages" => [
190
- "invalid `trigger_id`"
191
- ]
192
- }
193
- }.to_json
194
- }
195
- }
196
- it "returns an unsuccessful response" do
197
- expect(views_open.ok?).to eq(false)
198
- end
199
- end
200
- end
201
-
202
- describe "#views_update" do
203
- before do
204
- stub_request(:post, "https://slack.com/api/views.update").to_return(response)
205
- end
206
- subject(:views_update) {
207
- client.views_update(
208
- view_id: "VMHU10V25",
209
- view: {
210
- "type" => "modal",
211
- "title" => {
212
- "type" => "plain_text",
213
- "text" => "Quite a plain modal"
214
- },
215
- "submit" => {
216
- "type" => "plain_text",
217
- "text" => "Create"
218
- },
219
- "blocks" => [
220
- {
221
- "type" => "input",
222
- "block_id" => "a_block_id",
223
- "label" => [
224
- "type" => "plain_text",
225
- "text" => "A simple label",
226
- "emoji" => true
227
- ],
228
- "optional" => false,
229
- "element" => {
230
- "type" => "plain_text_input",
231
- "action_id" => "an_action_id"
232
- }
233
- }
234
- ],
235
- }
236
- )
237
- }
238
- let(:response) {
239
- {
240
- status: 200,
241
- body: {
242
- "ok" => true,
243
- "view" => {
244
- "id" => "VMHU10V25",
245
- "team_id" => "T8N4K1JN",
246
- "type" => "modal",
247
- "title" => {
248
- "type" => "plain_text",
249
- "text" => "Quite a plain modal"
250
- },
251
- "submit" => {
252
- "type" => "plain_text",
253
- "text" => "Create"
254
- },
255
- "blocks" => [
256
- {
257
- "type" => "input",
258
- "block_id" => "a_block_id",
259
- "label" => {
260
- "type" => "plain_text",
261
- "text" => "A simple label",
262
- "emoji" => true
263
- },
264
- "optional" => false,
265
- "element" => {
266
- "type" => "plain_text_input",
267
- "action_id" => "an_action_id"
268
- }
269
- }
270
- ],
271
- "private_metadata" => "Shh it is a secret",
272
- "callback_id" => "identify_your_modals",
273
- "external_id" => "",
274
- "state" => {
275
- "values" => {}
276
- },
277
- "hash" => "156772938.1827394",
278
- "clear_on_close" => false,
279
- "notify_on_close" => false,
280
- "root_view_id" => "VMHU10V25",
281
- "app_id" => "AA4928AQ",
282
- "bot_id" => "BA13894H"
283
- }
284
- }.to_json
285
- }
286
- }
287
- it "returns a successful response" do
288
- expect(views_update.ok?).to eq(true)
289
- end
290
- context "when the response is unsuccessful" do
291
- let(:response) {
292
- {
293
- status: 200,
294
- body: {
295
- "ok" => false,
296
- "error" => "invalid_arguments",
297
- "response_metadata" => {
298
- "messages" => [
299
- "invalid `trigger_id`"
300
- ]
301
- }
302
- }.to_json
303
- }
304
- }
305
- it "returns an unsuccessful response" do
306
- expect(views_update.ok?).to eq(false)
307
- end
308
- end
309
- end
310
-
311
- describe "#chat_post_message" do
312
- before do
313
- stub_request(:post, "https://slack.com/api/chat.postMessage").to_return(response)
314
- end
315
- subject(:chat_post_message) {
316
- client.chat_post_message(
317
- channel: "C1234567890",
318
- text: "Hello world",
319
- blocks: [
320
- {
321
- "type" => "section",
322
- "text" => {
323
- "type" => "mrkdwn",
324
- "text" => "Hello world"
325
- }
326
- }
327
- ]
328
- )
329
- }
330
- let(:response) {
331
- {
332
- status: 200,
333
- body: {
334
- "ok" => true,
335
- "channel" => "C1234567890",
336
- "ts" => "1503435956.000247",
337
- "message" => {
338
- "text" => "Hello world",
339
- "username" => "ecto1",
340
- "bot_id" => "B19LU7CSY",
341
- "attachments" => [
342
- {
343
- "text" => "This is an attachment",
344
- "id" => 1,
345
- "fallback" => "This is an attachment's fallback"
346
- }
347
- ],
348
- "type" => "message",
349
- "subtype" => "bot_message",
350
- "ts" => "1503435956.000247"
351
- }
352
- }.to_json
353
- }
354
- }
355
- it "returns a successful response" do
356
- expect(chat_post_message.ok?).to eq(true)
357
- end
358
- context "when the response is unsuccessful" do
359
- let(:response) {
360
- {
361
- status: 200,
362
- body: {
363
- "ok" => false,
364
- "error" => "too_many_attachments"
365
- }.to_json
366
- }
367
- }
368
- it "returns an unsuccessful response" do
369
- expect(chat_post_message.ok?).to eq(false)
370
- end
371
- end
372
- end
373
-
374
- describe "#chat_update" do
375
- before do
376
- stub_request(:post, "https://slack.com/api/chat.update").to_return(response)
377
- end
378
- subject(:chat_update) {
379
- client.chat_update(
380
- channel: "C1234567890",
381
- ts: "1503435956.000247",
382
- text: "Hello world",
383
- blocks: [
384
- {
385
- "type" => "section",
386
- "text" => {
387
- "type" => "mrkdwn",
388
- "text" => "Hello world"
389
- }
390
- }
391
- ]
392
- )
393
- }
394
- let(:response) {
395
- {
396
- status: 200,
397
- body: {
398
- "ok" => true,
399
- "channel" => "C1234567890",
400
- "ts" => "1503435956.000247",
401
- "message" => {
402
- "text" => "Hello world",
403
- "username" => "ecto1",
404
- "bot_id" => "B19LU7CSY",
405
- "attachments" => [
406
- {
407
- "text" => "This is an attachment",
408
- "id" => 1,
409
- "fallback" => "This is an attachment's fallback"
410
- }
411
- ],
412
- "type" => "message",
413
- "subtype" => "bot_message",
414
- "ts" => "1503435956.000247"
415
- }
416
- }.to_json
417
- }
418
- }
419
- it "returns a successful response" do
420
- expect(chat_update.ok?).to eq(true)
421
- end
422
- context "when the response is unsuccessful" do
423
- let(:response) {
424
- {
425
- status: 200,
426
- body: {
427
- "ok" => false,
428
- "error" => "too_many_attachments"
429
- }.to_json
430
- }
431
- }
432
- it "returns an unsuccessful response" do
433
- expect(chat_update.ok?).to eq(false)
434
- end
435
- end
436
- end
437
-
438
- describe "#views_publish" do
439
- before do
440
- stub_request(:post, "https://slack.com/api/views.publish").to_return(response)
441
- end
442
- subject(:views_publish) {
443
- client.views_publish(
444
- user_id: "U0R7JM",
445
- view: {
446
- "type" => "home",
447
- "blocks" => [
448
- {
449
- "type" => "section",
450
- "text" => {
451
- "type" => "mrkdwn",
452
- "text" => "Welcome to your _App's Home_* :tada:"
453
- }
454
- },
455
- {
456
- "type" => "divider"
457
- },
458
- {
459
- "type" => "section",
460
- "text" => {
461
- "type" => "mrkdwn",
462
- "text" => "This is a section block with a button."
463
- },
464
- "accessory" => {
465
- "type" => "button",
466
- "text" => {
467
- "type" => "plain_text",
468
- "text" => "Click Me"
469
- },
470
- "action_id" => "button_click"
471
- }
472
- }
473
- ]
474
- }
475
- )
476
- }
477
- # TODO: Add a test for the response
478
- end
479
- end
@@ -1,34 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe SlackBot::Args do
4
- let(:args) { SlackBot::Args.new }
5
- let(:raw_args) { "foo=bar&baz=qux" }
6
-
7
- describe "#raw_args=" do
8
- it "parses raw args" do
9
- args.raw_args = raw_args
10
- expect(args.args).to eq({ "foo" => "bar", "baz" => "qux" }.with_indifferent_access)
11
- end
12
- end
13
-
14
- describe "#to_s" do
15
- it "builds args" do
16
- args.raw_args = raw_args
17
- expect(args.to_s).to eq(raw_args)
18
- end
19
- end
20
-
21
- describe "#merge" do
22
- it "merges args" do
23
- args.raw_args = raw_args
24
- expect(args.merge(foo: "baz").args).to eq({ "foo" => "baz", "baz" => "qux" }.with_indifferent_access)
25
- end
26
- end
27
-
28
- describe "#except" do
29
- it "removes args" do
30
- args.raw_args = raw_args
31
- expect(args.except(:foo).args).to eq({ "baz" => "qux" }.with_indifferent_access)
32
- end
33
- end
34
- end