grape-slack-bot 1.5.8 → 1.6.0

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: 2b60e4e6431b476b397857caf09be7d11d1f2215e4ab5ab912e77c1289ab5285
4
- data.tar.gz: 5a11a97b7ed08470a83163f4c77fa52eb895bdbe260159c87c2fbae1c302fe58
3
+ metadata.gz: 6d1e2ef3d6febf5115a2d8276cb673f6ed5559ee9a3db93116bd7171bade5bf0
4
+ data.tar.gz: ec20059fae8d6c3198ac5d989d8a61913a780f3b45c4345c7b744d46a31e50f7
5
5
  SHA512:
6
- metadata.gz: 669f0d6b4b8b5475b5fdcfe58d281d9b3b0f3f49fa6b083469708789cbf2fa2202d2cb427a78148a9502154325680a4c6d3f254e10367a25b17441c9b91fcfcf
7
- data.tar.gz: 8c0e1357083e27ec6477c7cfd9a9f029178bfc38ad68af451af1cee21e16261744b6268782cdd9aada62aae83bfcae328182647f7157f4385ff5ca3de6701a9b
6
+ metadata.gz: 2be7aab3a38801d1b8e8f1581badb224a9e3767f638805c69d1a7efcf59ad8e8be75589a49c636c2fe0793591f431063ea824688fbf8cce1647020151bc970c1
7
+ data.tar.gz: 36821a7bc17bf1641c3d0a8da65497ec46a35713b7b71abed8a95c38c7cff276d501483c8d378c56105bd60669b421d31ae879f0de15f09c4d42143de2d2f6dc
@@ -1,12 +1,10 @@
1
+ require 'slack_bot/concerns/interaction_klass'
2
+ require 'slack_bot/concerns/view_klass'
3
+
1
4
  module SlackBot
2
5
  class Command
3
- def self.interaction(klass)
4
- define_singleton_method(:interaction_klass) { klass }
5
- end
6
-
7
- def self.view(klass)
8
- define_singleton_method(:view_klass) { klass }
9
- end
6
+ include SlackBot::Concerns::InteractionKlass
7
+ include SlackBot::Concerns::ViewKlass
10
8
 
11
9
  attr_reader :current_user, :params, :args, :config
12
10
  def initialize(current_user:, params:, args:, config: nil)
@@ -0,0 +1,17 @@
1
+ module SlackBot::Concerns
2
+ module InteractionKlass
3
+ def self.included(base)
4
+ base.extend(ClassMethods)
5
+ end
6
+
7
+ module ClassMethods
8
+ def interaction_klass
9
+ raise SlackBot::Errors::InteractionClassNotImplemented.new(name)
10
+ end
11
+
12
+ def interaction(klass)
13
+ define_singleton_method(:interaction_klass) { klass }
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module SlackBot::Concerns
2
+ module PagerKlass
3
+ def self.included(base)
4
+ base.extend(ClassMethods)
5
+ end
6
+
7
+ module ClassMethods
8
+ def pager_klass
9
+ SlackBot::Pager
10
+ end
11
+
12
+ def pager(klass)
13
+ define_singleton_method(:pager_klass) { klass }
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module SlackBot::Concerns
2
+ module ViewKlass
3
+ def self.included(base)
4
+ base.extend(ClassMethods)
5
+ end
6
+
7
+ module ClassMethods
8
+ def view_klass
9
+ raise SlackBot::Errors::ViewClassNotImplemented.new(name)
10
+ end
11
+
12
+ def view(klass)
13
+ define_singleton_method(:view_klass) { klass }
14
+ end
15
+ end
16
+ end
17
+ end
@@ -31,6 +31,20 @@ module SlackBot
31
31
  end
32
32
  end
33
33
 
34
+ class InteractionClassNotImplemented < SlackBot::Error
35
+ attr_reader :class_name
36
+ def initialize(class_name)
37
+ @class_name = class_name
38
+ end
39
+ end
40
+
41
+ class ViewClassNotImplemented < SlackBot::Error
42
+ attr_reader :class_name
43
+ def initialize(class_name)
44
+ @class_name = class_name
45
+ end
46
+ end
47
+
34
48
  class SlackResponseError < SlackBot::Error
35
49
  attr_reader :error, :data, :payload
36
50
  def initialize(error, data: nil, payload: nil)
@@ -1,12 +1,10 @@
1
+ require 'slack_bot/concerns/interaction_klass'
2
+ require 'slack_bot/concerns/view_klass'
3
+
1
4
  module SlackBot
2
5
  class Event
3
- def self.interaction(klass)
4
- define_singleton_method(:interaction_klass) { klass }
5
- end
6
-
7
- def self.view(klass)
8
- define_singleton_method(:view_klass) { klass }
9
- end
6
+ include SlackBot::Concerns::InteractionKlass
7
+ include SlackBot::Concerns::ViewKlass
10
8
 
11
9
  attr_reader :current_user, :params, :config, :callback, :metadata
12
10
  def initialize(current_user: nil, params: nil, callback: nil, config: nil)
@@ -1,12 +1,12 @@
1
1
  require 'active_support/core_ext/object'
2
2
 
3
+ require 'slack_bot/concerns/view_klass'
4
+
3
5
  module SlackBot
4
6
  class Interaction
5
- SlackViewsReply = Data.define(:callback_id, :view_id)
7
+ SlackViewsReply = Struct.new(:callback_id, :view_id)
6
8
 
7
- def self.view(klass)
8
- define_singleton_method(:view_klass) { klass }
9
- end
9
+ include SlackBot::Concerns::ViewKlass
10
10
 
11
11
  def self.open_modal(
12
12
  trigger_id:,
@@ -1,14 +1,9 @@
1
1
  require 'active_support/core_ext/hash/indifferent_access'
2
+ require 'slack_bot/concerns/pager_klass'
2
3
 
3
4
  module SlackBot
4
5
  class View
5
- def self.pager_klass
6
- SlackBot::Pager
7
- end
8
-
9
- def self.pager(klass)
10
- define_singleton_method(:pager_klass) { klass }
11
- end
6
+ include SlackBot::Concerns::PagerKlass
12
7
 
13
8
  attr_reader :args, :current_user, :params, :context, :config
14
9
  def initialize(current_user:, params:, args: nil, context: nil, config: nil)
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.8'.freeze
25
+ VERSION = '1.6.0'.freeze
26
26
  end
@@ -1,5 +1,74 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe SlackBot::Event do
4
+ let(:current_user) { double(:current_user) }
5
+ let(:params) { double(:params) }
6
+ let(:callback) { double(:callback) }
7
+ let(:config) { double(:config) }
4
8
 
9
+ subject do
10
+ described_class.new(
11
+ current_user: current_user,
12
+ params: params,
13
+ callback: callback,
14
+ config: config
15
+ )
16
+ end
17
+
18
+ describe '.view_klass' do
19
+ it 'raises exception' do
20
+ expect { subject.class.view_klass }.to raise_error(SlackBot::Errors::ViewClassNotImplemented)
21
+ end
22
+
23
+ context "when view is called" do
24
+ before do
25
+ subject.class.view :view_name
26
+ end
27
+ it 'returns view_name' do
28
+ expect(subject.class.view_klass).to eq(:view_name)
29
+ end
30
+ end
31
+ end
32
+
33
+ describe '.interaction_klass' do
34
+ it 'raises exception' do
35
+ expect { subject.class.interaction_klass }.to raise_error(SlackBot::Errors::InteractionClassNotImplemented)
36
+ end
37
+ context "when interaction is called" do
38
+ before do
39
+ subject.class.interaction :interaction_name
40
+ end
41
+ it 'returns interaction_name' do
42
+ expect(subject.class.interaction_klass).to eq(:interaction_name)
43
+ end
44
+ end
45
+ end
46
+
47
+ describe '#initialize' do
48
+ it 'sets current_user' do
49
+ expect(subject.current_user).to eq(current_user)
50
+ end
51
+
52
+ it 'sets params' do
53
+ expect(subject.params).to eq(params)
54
+ end
55
+
56
+ it 'sets callback' do
57
+ expect(subject.callback).to eq(callback)
58
+ end
59
+
60
+ it 'sets config' do
61
+ expect(subject.config).to eq(config)
62
+ end
63
+ end
64
+
65
+ describe '#call' do
66
+ it 'returns nil' do
67
+ expect(subject.call).to eq(nil)
68
+ end
69
+ end
70
+
71
+ describe '#publish_view' do
72
+
73
+ end
5
74
  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.8
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrei Makarov
@@ -167,6 +167,9 @@ files:
167
167
  - lib/slack_bot/callback.rb
168
168
  - lib/slack_bot/callback_storage.rb
169
169
  - lib/slack_bot/command.rb
170
+ - lib/slack_bot/concerns/interaction_klass.rb
171
+ - lib/slack_bot/concerns/pager_klass.rb
172
+ - lib/slack_bot/concerns/view_klass.rb
170
173
  - lib/slack_bot/config.rb
171
174
  - lib/slack_bot/dev_console.rb
172
175
  - lib/slack_bot/error.rb