grape-slack-bot 1.5.6 → 1.5.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 20631471a50c1063efab2b44ebf94f2ccb3d4d8836eb52e0ec99d709e6e2e221
4
- data.tar.gz: 4a956eb022a301cbcf0988a5b8fde6ff21c0fbbc30f94c6f966b4d0ca2febbb6
3
+ metadata.gz: 2b60e4e6431b476b397857caf09be7d11d1f2215e4ab5ab912e77c1289ab5285
4
+ data.tar.gz: 5a11a97b7ed08470a83163f4c77fa52eb895bdbe260159c87c2fbae1c302fe58
5
5
  SHA512:
6
- metadata.gz: e30000e0c25fd8722fb53d3da386a3e78dd9f8cc490f49e434390c4b256b2450eb5f0542d7f21a30037856d9b197e538cb51f384866b52bd4ea3bcc633e623dc
7
- data.tar.gz: 1718485fcfabf43fff9a81fac46fe3b68c285a10e2b7b35b2babfceac5a14a110cacfae9accb81d57f49578c7cab3dd5dfeb5b5ef127bea91fcfcc197e8a2592
6
+ metadata.gz: 669f0d6b4b8b5475b5fdcfe58d281d9b3b0f3f49fa6b083469708789cbf2fa2202d2cb427a78148a9502154325680a4c6d3f254e10367a25b17441c9b91fcfcf
7
+ data.tar.gz: 8c0e1357083e27ec6477c7cfd9a9f029178bfc38ad68af451af1cee21e16261744b6268782cdd9aada62aae83bfcae328182647f7157f4385ff5ca3de6701a9b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # 1.5.7
2
+
3
+ * Raise error if handler class not resolved
4
+ * App home interaction example added
5
+ * Callback logic and usage fixed
6
+ * Views improvements
7
+
1
8
  # 1.5.0
2
9
 
3
10
  * Complete upgrade of callback storage logic
data/README.md CHANGED
@@ -292,6 +292,30 @@ module MySlackBot::Game
292
292
  end
293
293
  ```
294
294
 
295
+ App home interaction example:
296
+
297
+ ```ruby
298
+ module MySlackBot
299
+ class AppHomeInteraction < SlackBot::Event
300
+ view MySlackBot::AppHomeView
301
+
302
+ def call
303
+ action_id = payload.dig("actions", 0, "action_id")
304
+ case action_id
305
+ when "add_game"
306
+ add_game
307
+ end
308
+ end
309
+
310
+ private
311
+
312
+ def add_game
313
+ open_modal :add_game_modal
314
+ end
315
+ end
316
+ end
317
+ ```
318
+
295
319
  ## View example
296
320
 
297
321
  Modal view example:
@@ -456,7 +480,7 @@ module MySlackBot
456
480
  self.callback = SlackBot::Callback.find_or_create(
457
481
  id: "app_home_opened",
458
482
  user: current_user,
459
- class_name: VacationsBot::AppHomeInteraction.name
483
+ class_name: self.class.name
460
484
  )
461
485
 
462
486
  publish_view :index_view
@@ -107,7 +107,7 @@ module SlackBot
107
107
 
108
108
  def handler_class=(handler_class)
109
109
  new_class_name = handler_class&.name
110
- raise "Callback handler class not found" if !config.find_handler_class(class_name)
110
+ config.find_handler_class(class_name)
111
111
 
112
112
  self.class_name = new_class_name
113
113
  end
@@ -26,6 +26,7 @@ module SlackBot
26
26
  end
27
27
 
28
28
  def event(event_type, event_klass)
29
+ handler_class(event_klass.name, event_klass)
29
30
  event_handlers[event_type.to_sym] = event_klass
30
31
  end
31
32
 
@@ -72,7 +73,9 @@ module SlackBot
72
73
 
73
74
  def find_handler_class(class_name)
74
75
  @handler_classes ||= {}
75
- @handler_classes[class_name.to_sym]
76
+ @handler_classes.fetch(class_name.to_sym)
77
+ rescue KeyError
78
+ raise SlackBot::Errors::HandlerClassNotFound.new(class_name, handler_classes: @handler_classes)
76
79
  end
77
80
  end
78
81
 
@@ -21,6 +21,16 @@ module SlackBot
21
21
  class CallbackNotFound < SlackBot::Error
22
22
  end
23
23
 
24
+ class HandlerClassNotFound < SlackBot::Error
25
+ attr_reader :class_name, :handler_classes
26
+ def initialize(class_name, handler_classes:)
27
+ @class_name = class_name
28
+ @handler_classes = handler_classes
29
+
30
+ super("Handler class not found for #{class_name}")
31
+ end
32
+ end
33
+
24
34
  class SlackResponseError < SlackBot::Error
25
35
  attr_reader :error, :data, :payload
26
36
  def initialize(error, data: nil, payload: nil)
@@ -1,5 +1,9 @@
1
1
  module SlackBot
2
2
  class Event
3
+ def self.interaction(klass)
4
+ define_singleton_method(:interaction_klass) { klass }
5
+ end
6
+
3
7
  def self.view(klass)
4
8
  define_singleton_method(:view_klass) { klass }
5
9
  end
data/lib/slack_bot.rb CHANGED
@@ -22,5 +22,5 @@ require 'slack_bot/pager'
22
22
  require 'slack_bot/grape_extension'
23
23
 
24
24
  module SlackBot
25
- VERSION = '1.5.6'.freeze
25
+ VERSION = '1.5.8'.freeze
26
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grape-slack-bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.6
4
+ version: 1.5.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrei Makarov