slack-ruby-block-kit 0.6.1 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +9 -0
  3. data/.github/workflows/ci.yml +31 -0
  4. data/.rubocop.yml +46 -1
  5. data/.rubocop_todo.yml +8 -0
  6. data/CHANGELOG.md +56 -0
  7. data/Gemfile +0 -1
  8. data/Gemfile.lock +33 -28
  9. data/lib/slack/block_kit.rb +49 -5
  10. data/lib/slack/block_kit/composition/confirmation_dialog.rb +20 -0
  11. data/lib/slack/block_kit/composition/conversation_filter.rb +33 -0
  12. data/lib/slack/block_kit/composition/option.rb +1 -1
  13. data/lib/slack/block_kit/element/button.rb +3 -11
  14. data/lib/slack/block_kit/element/channels_select.rb +3 -11
  15. data/lib/slack/block_kit/element/checkboxes.rb +55 -0
  16. data/lib/slack/block_kit/element/conversations_select.rb +13 -7
  17. data/lib/slack/block_kit/element/date_picker.rb +3 -9
  18. data/lib/slack/block_kit/element/external_select.rb +3 -11
  19. data/lib/slack/block_kit/element/multi_channels_select.rb +42 -0
  20. data/lib/slack/block_kit/element/multi_conversations_select.rb +57 -0
  21. data/lib/slack/block_kit/element/multi_external_select.rb +52 -0
  22. data/lib/slack/block_kit/element/multi_static_select.rb +82 -0
  23. data/lib/slack/block_kit/element/multi_users_select.rb +42 -0
  24. data/lib/slack/block_kit/element/overflow_menu.rb +4 -10
  25. data/lib/slack/block_kit/element/plain_text_input.rb +1 -1
  26. data/lib/slack/block_kit/element/radio_buttons.rb +48 -0
  27. data/lib/slack/block_kit/element/static_select.rb +4 -10
  28. data/lib/slack/block_kit/element/users_select.rb +3 -11
  29. data/lib/slack/block_kit/layout/context.rb +1 -0
  30. data/lib/slack/block_kit/layout/image.rb +1 -4
  31. data/lib/slack/block_kit/layout/section.rb +29 -1
  32. data/lib/slack/block_kit/layout/section/multi_select_elements.rb +92 -0
  33. data/lib/slack/surfaces/home.rb +35 -0
  34. data/lib/slack/surfaces/message.rb +34 -0
  35. data/lib/slack/surfaces/modal.rb +76 -0
  36. metadata +21 -7
  37. data/.circleci/config.yml +0 -49
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a1ce18c84f51fac5942313852cb7f12420a4aa77440e3c360ea05b69da6bfa8c
4
- data.tar.gz: b01973fff58d82c84652e9238285463d2b59052ffa4ada98bbf99f45eb789739
3
+ metadata.gz: ba759b665f6bc72dfb41ad6f501de3ddd00e7047673ac805dddbae20bc6c69fb
4
+ data.tar.gz: e30ecec2128b9f94f4f5f1d55b1b86b035555d49ef6b27f1abeae22e5b0e63b4
5
5
  SHA512:
6
- metadata.gz: db52491fa1c4402c393daf83ad402f7f173f243b42ecc06567e33a69a90056f13547836b5dd6c32ef0774310be8f86190aa96e27bddaa243f4545444d5525583
7
- data.tar.gz: 3b8644c48e2dcacce01d10a8c9b34eb181096bcb94159194169cc618ac233819cacbd78f58afce0baf03c63c233b98b6e686e0af4403b4dfddd81655e2ac60b1
6
+ metadata.gz: e7784041e0d6e9b42bbfd8dc02dac3bbff8872ba268571c3b1f022a59b390e59fb637dedefb38894f8ee98234db5fa3fd3c1e03e99a8f4f1cd3befc9130ce368
7
+ data.tar.gz: 2fd57d0ad2722e86e03e130799af76ec58828b9d701fd9726a68b5bbf6e1ce6da780ea93553d34a4f7423ade363c13463cbc28e02e4b65348ec389901c05420c
@@ -0,0 +1,9 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: bundler
4
+ directory: "/"
5
+ schedule:
6
+ interval: daily
7
+ open-pull-requests-limit: 99
8
+ reviewers:
9
+ - CGA1123
@@ -0,0 +1,31 @@
1
+ name: Test & Lint
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+
9
+ jobs:
10
+ build:
11
+ runs-on: ubuntu-latest
12
+ continue-on-error: ${{ matrix.experimental }}
13
+ strategy:
14
+ fail-fast: false
15
+ matrix:
16
+ ruby: [ '2.6', '2.7' ]
17
+ experimental: [ false ]
18
+ include:
19
+ - ruby: 'head'
20
+ experimental: true
21
+
22
+ name: Ruby ${{ matrix.ruby }}
23
+ steps:
24
+ - uses: actions/checkout@v2
25
+ - uses: ruby/setup-ruby@v1
26
+ with:
27
+ ruby-version: ${{ matrix.ruby }}
28
+ - run: gem install bundler:2.1.4
29
+ - run: bundle install
30
+ - run: bundle exec rubocop
31
+ - run: bundle exec rspec --format progress
@@ -4,7 +4,7 @@ inherit_from: .rubocop_todo.yml
4
4
  AllCops:
5
5
  TargetRubyVersion: 2.5.3
6
6
 
7
- Metrics/LineLength:
7
+ Layout/LineLength:
8
8
  Max: 120
9
9
 
10
10
  Style/AsciiComments:
@@ -23,3 +23,48 @@ Metrics/BlockLength:
23
23
  - '**/*.rake'
24
24
  - 'spec/**/*.rb'
25
25
  - '**/*.gemspec'
26
+
27
+ Layout/EmptyLinesAroundAttributeAccessor:
28
+ Enabled: true
29
+
30
+ Layout/SpaceAroundMethodCallOperator:
31
+ Enabled: true
32
+
33
+ Lint/DeprecatedOpenSSLConstant:
34
+ Enabled: true
35
+
36
+ Lint/RaiseException:
37
+ Enabled: true
38
+
39
+ Lint/StructNewOverride:
40
+ Enabled: true
41
+
42
+ Style/ExponentialNotation:
43
+ Enabled: true
44
+
45
+ Style/HashEachMethods:
46
+ Enabled: true
47
+
48
+ Style/HashTransformKeys:
49
+ Enabled: true
50
+
51
+ Style/HashTransformValues:
52
+ Enabled: true
53
+
54
+ Style/SlicingWithRange:
55
+ Enabled: true
56
+
57
+ Lint/MixedRegexpCaptureTypes:
58
+ Enabled: true
59
+
60
+ Style/RedundantFetchBlock:
61
+ Enabled: true
62
+
63
+ Style/RedundantRegexpCharacterClass:
64
+ Enabled: true
65
+
66
+ Style/RedundantRegexpEscape:
67
+ Enabled: true
68
+
69
+ RSpec/MultipleMemoizedHelpers:
70
+ Max: 10
@@ -17,6 +17,12 @@ Metrics/BlockLength:
17
17
  Metrics/ClassLength:
18
18
  Max: 117
19
19
 
20
+ # Offense count: 1
21
+ # Configuration parameters: IgnoredMethods.
22
+ Metrics/CyclomaticComplexity:
23
+ Exclude:
24
+ - 'lib/slack/block_kit/element/multi_static_select.rb'
25
+
20
26
  # Offense count: 5
21
27
  # Configuration parameters: Max.
22
28
  RSpec/ExampleLength:
@@ -24,6 +30,8 @@ RSpec/ExampleLength:
24
30
  - 'spec/lib/slack/block_kit/composition/confirmation_dialog_spec.rb'
25
31
  - 'spec/lib/slack/block_kit/composition/option_group_spec.rb'
26
32
  - 'spec/lib/slack/block_kit/composition/option_spec.rb'
33
+ - 'spec/lib/slack/block_kit/element/checkboxes_spec.rb'
34
+ - 'spec/lib/slack/block_kit/element/radio_buttons_spec.rb'
27
35
 
28
36
  # Offense count: 4
29
37
  Style/Documentation:
@@ -0,0 +1,56 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ ### Added
10
+ - N/A
11
+
12
+ ### Changed
13
+ - N/A
14
+
15
+ ### Deprecated
16
+ - N/A
17
+
18
+ ### Removed
19
+ - N/A
20
+
21
+ ### Fixed
22
+ - N/A
23
+
24
+ ### Security
25
+ - N/A
26
+
27
+
28
+ ## [0.11.0] - 2020-10-03
29
+
30
+ ### Added
31
+ - Add `Slack::BlockKit::Element::RadioButtons` (#52 by @caalberts)
32
+
33
+ ### Changed
34
+ - Internal refactoring of `#confirmation_dialog` methods into a shared `Confirmable` module. (#48)
35
+
36
+ ### Fixed
37
+ - Ruby2.7 kwarg deprecation warnings
38
+
39
+
40
+ ## [0.10.0] - 2020-09-11
41
+
42
+ ### Added
43
+ - Add `Slack::BlockKit::Element::Checkboxes` (#44 by @caalberts)
44
+
45
+ ### Fixed
46
+ - Fixed initial options in multi select blocks (#46 by @caalberts)
47
+
48
+
49
+ See [releases] for previous changes.
50
+
51
+
52
+ [Unreleased]: https://github.com/CGA1123/slack-ruby-block-kit/compare/v0.11.0...HEAD
53
+ [0.11.0]: https://github.com/CGA1123/slack-ruby-block-kit/compare/v0.10.0...v0.11.0
54
+ [0.10.0]: https://github.com/CGA1123/slack-ruby-block-kit/compare/v0.9.0...v0.10.0
55
+
56
+ [releases]: https://github.com/CGA1123/slack-ruby-block-kit/releases
data/Gemfile CHANGED
@@ -2,5 +2,4 @@
2
2
 
3
3
  source 'https://rubygems.org'
4
4
 
5
- # Specify your gem's dependencies in tenios-rb.gemspec
6
5
  gemspec
@@ -1,56 +1,61 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- slack-ruby-block-kit (0.6.1)
4
+ slack-ruby-block-kit (0.11.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- ast (2.4.0)
9
+ ast (2.4.1)
10
10
  coderay (1.1.2)
11
11
  diff-lcs (1.3)
12
- dotenv (2.7.5)
12
+ dotenv (2.7.6)
13
13
  faraday (1.0.1)
14
14
  multipart-post (>= 1.2, < 3)
15
- jaro_winkler (1.5.2)
16
15
  method_source (1.0.0)
17
16
  multipart-post (2.1.1)
18
- parallel (1.13.0)
19
- parser (2.6.0.0)
20
- ast (~> 2.4.0)
21
- powerpack (0.1.2)
17
+ parallel (1.19.2)
18
+ parser (2.7.1.5)
19
+ ast (~> 2.4.1)
22
20
  pry (0.13.1)
23
21
  coderay (~> 1.1)
24
22
  method_source (~> 1.0)
25
23
  rainbow (3.0.0)
26
24
  rake (13.0.1)
27
- rspec (3.8.0)
28
- rspec-core (~> 3.8.0)
29
- rspec-expectations (~> 3.8.0)
30
- rspec-mocks (~> 3.8.0)
31
- rspec-core (3.8.0)
32
- rspec-support (~> 3.8.0)
33
- rspec-expectations (3.8.2)
25
+ regexp_parser (1.8.0)
26
+ rexml (3.2.4)
27
+ rspec (3.9.0)
28
+ rspec-core (~> 3.9.0)
29
+ rspec-expectations (~> 3.9.0)
30
+ rspec-mocks (~> 3.9.0)
31
+ rspec-core (3.9.2)
32
+ rspec-support (~> 3.9.3)
33
+ rspec-expectations (3.9.2)
34
34
  diff-lcs (>= 1.2.0, < 2.0)
35
- rspec-support (~> 3.8.0)
36
- rspec-mocks (3.8.0)
35
+ rspec-support (~> 3.9.0)
36
+ rspec-mocks (3.9.1)
37
37
  diff-lcs (>= 1.2.0, < 2.0)
38
- rspec-support (~> 3.8.0)
39
- rspec-support (3.8.0)
38
+ rspec-support (~> 3.9.0)
39
+ rspec-support (3.9.3)
40
40
  rspec_junit_formatter (0.4.1)
41
41
  rspec-core (>= 2, < 4, != 2.12.0)
42
- rubocop (0.63.1)
43
- jaro_winkler (~> 1.5.1)
42
+ rubocop (0.92.0)
44
43
  parallel (~> 1.10)
45
- parser (>= 2.5, != 2.5.1.1)
46
- powerpack (~> 0.1)
44
+ parser (>= 2.7.1.5)
47
45
  rainbow (>= 2.2.2, < 4.0)
46
+ regexp_parser (>= 1.7)
47
+ rexml
48
+ rubocop-ast (>= 0.5.0)
48
49
  ruby-progressbar (~> 1.7)
49
- unicode-display_width (~> 1.4.0)
50
- rubocop-rspec (1.32.0)
51
- rubocop (>= 0.60.0)
52
- ruby-progressbar (1.10.0)
53
- unicode-display_width (1.4.1)
50
+ unicode-display_width (>= 1.4.0, < 2.0)
51
+ rubocop-ast (0.7.0)
52
+ parser (>= 2.7.1.5)
53
+ strscan (>= 1.0.0)
54
+ rubocop-rspec (1.43.2)
55
+ rubocop (~> 0.87)
56
+ ruby-progressbar (1.10.1)
57
+ strscan (1.0.3)
58
+ unicode-display_width (1.7.0)
54
59
 
55
60
  PLATFORMS
56
61
  ruby
@@ -6,12 +6,13 @@ module Slack
6
6
  module Element; end
7
7
  module Layout; end
8
8
 
9
- VERSION = '0.6.1'
9
+ VERSION = '0.11.0'
10
10
 
11
- Dir[File.join(__dir__, 'block_kit', 'composition', '*.rb')].each { |file| require file }
12
- Dir[File.join(__dir__, 'block_kit', 'element', '*.rb')].each { |file| require file }
13
- Dir[File.join(__dir__, 'block_kit', 'layout', '*.rb')].each { |file| require file }
14
- Dir[File.join(__dir__, 'block_kit', '*.rb')].each { |file| require file }
11
+ Dir[File.join(__dir__, 'block_kit', 'composition', '*.rb')].sort.each { |file| require file }
12
+ Dir[File.join(__dir__, 'block_kit', 'element', '*.rb')].sort.each { |file| require file }
13
+ Dir[File.join(__dir__, 'block_kit', 'layout', '*.rb')].sort.each { |file| require file }
14
+ Dir[File.join(__dir__, 'block_kit', '*.rb')].sort.each { |file| require file }
15
+ Dir[File.join(__dir__, 'surfaces', '*.rb')].sort.each { |file| require file }
15
16
 
16
17
  module_function
17
18
 
@@ -22,5 +23,48 @@ module Slack
22
23
 
23
24
  blocks
24
25
  end
26
+
27
+ def home(blocks: nil,
28
+ private_metadata: nil, callback_id: nil, external_id: nil)
29
+ home_surface = Slack::Surfaces::Home.new(blocks: blocks,
30
+ private_metadata: private_metadata,
31
+ callback_id: callback_id,
32
+ external_id: external_id)
33
+
34
+ yield(home_surface) if block_given?
35
+
36
+ home_surface
37
+ end
38
+
39
+ def modal(title: nil,
40
+ blocks: nil,
41
+ private_metadata: nil, callback_id: nil, external_id: nil,
42
+ clear_on_close: nil, notify_on_close: nil)
43
+ modal_surface = Slack::Surfaces::Modal.new(title: title,
44
+ blocks: blocks,
45
+ private_metadata: private_metadata,
46
+ callback_id: callback_id,
47
+ external_id: external_id,
48
+ clear_on_close: clear_on_close,
49
+ notify_on_close: notify_on_close)
50
+
51
+ yield(modal_surface) if block_given?
52
+
53
+ modal_surface
54
+ end
55
+
56
+ def message(blocks: nil, channel: nil, thread_ts: nil, as_user: nil, text: nil)
57
+ message_surface = Slack::Surfaces::Message.new(
58
+ blocks: blocks,
59
+ channel: channel,
60
+ thread_ts: thread_ts,
61
+ text: text,
62
+ as_user: as_user
63
+ )
64
+
65
+ yield(message_surface) if block_given?
66
+
67
+ message_surface
68
+ end
25
69
  end
26
70
  end
@@ -9,6 +9,26 @@ module Slack
9
9
  #
10
10
  # https://api.slack.com/reference/messaging/composition-objects#confirm
11
11
  class ConfirmationDialog
12
+ # {Confirmable} contains the common behaviour for configuring a
13
+ # {ConfirmationDialog}
14
+ module Confirmable
15
+ def self.included(klass)
16
+ klass.attr_accessor :confirm
17
+ end
18
+
19
+ def confirmation_dialog
20
+ self.confirm = Composition::ConfirmationDialog.new
21
+
22
+ yield(confirm) if block_given?
23
+
24
+ self
25
+ end
26
+ end
27
+
28
+ def initialize
29
+ @title, @confirm, @text, @style = nil
30
+ end
31
+
12
32
  def title(text:, emoji: nil)
13
33
  @title = PlainText.new(text: text, emoji: emoji)
14
34
 
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Slack
4
+ module BlockKit
5
+ module Composition
6
+ # Provides a way to filter the list of options in a conversations select menu
7
+ # or conversations multi-select menu.
8
+ #
9
+ # @param [Array] only - "include" field
10
+ #
11
+ # https://api.slack.com/reference/block-kit/composition-objects#filter_conversations
12
+ # https://api.slack.com/reference/block-kit/block-elements#conversation_multi_select
13
+ # https://api.slack.com/reference/block-kit/block-elements#conversation_select
14
+ class ConversationFilter
15
+ def initialize(only: nil,
16
+ exclude_external_shared_channels: nil,
17
+ exclude_bot_users: nil)
18
+ @only = only
19
+ @exclude_external_shared_channels = exclude_external_shared_channels
20
+ @exclude_bot_users = exclude_bot_users
21
+ end
22
+
23
+ def as_json(*)
24
+ {
25
+ include: @only,
26
+ exclude_external_shared_channels: @exclude_external_shared_channels,
27
+ exclude_bot_users: @exclude_bot_users
28
+ }.compact
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -11,7 +11,7 @@ module Slack
11
11
  def initialize(value:, text:, emoji: nil, description: nil, url: nil)
12
12
  @text = PlainText.new(text: text, emoji: emoji)
13
13
  @value = value
14
- @description = PlainText.new(text: description, emoji: emoji) if description
14
+ @description = description && PlainText.new(text: description, emoji: emoji)
15
15
  @url = url
16
16
  end
17
17
 
@@ -9,9 +9,9 @@ module Slack
9
9
  #
10
10
  # https://api.slack.com/reference/messaging/block-elements#button
11
11
  class Button
12
- TYPE = 'button'
12
+ include Composition::ConfirmationDialog::Confirmable
13
13
 
14
- attr_accessor :confirm
14
+ TYPE = 'button'
15
15
 
16
16
  def initialize(text:, action_id:, style: nil, emoji: nil, url: nil, value: nil)
17
17
  @text = Composition::PlainText.new(text: text, emoji: emoji)
@@ -23,14 +23,6 @@ module Slack
23
23
  yield(self) if block_given?
24
24
  end
25
25
 
26
- def confirmation_dialog
27
- @confirm = Composition::ConfirmationDialog.new
28
-
29
- yield(@confirm) if block_given?
30
-
31
- @confirm
32
- end
33
-
34
26
  def as_json(*)
35
27
  {
36
28
  type: TYPE,
@@ -39,7 +31,7 @@ module Slack
39
31
  url: @url,
40
32
  value: @value,
41
33
  style: @style,
42
- confirm: @confirm&.as_json
34
+ confirm: confirm&.as_json
43
35
  }.compact
44
36
  end
45
37
  end