slack-ruby-block-kit 0.6.0 → 0.10.0

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
  SHA256:
3
- metadata.gz: 98d7b9d263e5a169d46a97f64512f013580d455ef0c928a095e417bbccc77d52
4
- data.tar.gz: ee8488ad4d4bb36317f93a556bc0728d07dc16e38da892fb8067ba9efe5fa661
3
+ metadata.gz: db8635d968932366f6665d3d14a9481c1d98473f07091721dda012d8bb372397
4
+ data.tar.gz: '0398e6c98ac507fa9b29de814fd003a27032c60b59e58901091346727027ce60'
5
5
  SHA512:
6
- metadata.gz: f0e114f5f7e4455a9773e16cd8bf906cc94d1052601d85d0ea5af83d8597cc40c3b462912a6174832ff22ae54c91a9d9f8f79dab864963ec907f8da47e7e0107
7
- data.tar.gz: eddb7b032cd53b0c5974204c518d279311a76ba5f9a88455882ff691f6984ca0f94e6acbfc37b143315519c19fc79a4800c8cdaf581bf962948303d376ee6b6f
6
+ metadata.gz: d5cb493959983cd2fe0db8a23d6a88709819f515652db1a6fb262be708e6b47dcea8e39f9c2be8b95d7b2d8135eb10f2e63186ed68973454cf988712544c2165
7
+ data.tar.gz: ad3e5412c2924f4b4ff49df0fc337b56875227f1ffe5b70455a6537694677dd2e10421562fefe0b4635ea01a0a94926514487f4b3b38c5446e2ca72a3a24d6a5
@@ -2,7 +2,7 @@ version: 2
2
2
  jobs:
3
3
  build:
4
4
  docker:
5
- - image: circleci/ruby:2.5.3
5
+ - image: circleci/ruby:2.7
6
6
 
7
7
  working_directory: ~/repo
8
8
 
@@ -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
@@ -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,7 @@ 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'
27
34
 
28
35
  # Offense count: 4
29
36
  Style/Documentation:
@@ -0,0 +1,45 @@
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
+
14
+ - N/A
15
+
16
+ ### Deprecated
17
+ - N/A
18
+
19
+ ### Removed
20
+ - N/A
21
+
22
+ ### Fixed
23
+ - N/A
24
+
25
+ ### Security
26
+ - N/A
27
+
28
+
29
+ ## [0.10.0] - 2020-09-11
30
+
31
+ ### Added
32
+ - Add `Slack::BlockKit::Element::Checkboxes` (#44 by @caalberts)
33
+
34
+ ### Fixed
35
+ - Fixed initial options in multi select blocks (#46 by @caalberts)
36
+
37
+
38
+ See [releases] for previous changes.
39
+
40
+
41
+
42
+ [Unreleased]: https://github.com/CGA1123/slack-ruby-block-kit/compare/v0.10.0...HEAD
43
+ [0.10.0]: https://github.com/CGA1123/slack-ruby-block-kit/compare/v0.9.0...v0.10.0
44
+
45
+ [releases]: https://github.com/CGA1123/slack-ruby-block-kit/releases
@@ -1,62 +1,65 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- slack-ruby-block-kit (0.6.0)
4
+ slack-ruby-block-kit (0.10.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.4)
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.7.1)
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.90.0)
44
43
  parallel (~> 1.10)
45
- parser (>= 2.5, != 2.5.1.1)
46
- powerpack (~> 0.1)
44
+ parser (>= 2.7.1.1)
47
45
  rainbow (>= 2.2.2, < 4.0)
46
+ regexp_parser (>= 1.7)
47
+ rexml
48
+ rubocop-ast (>= 0.3.0, < 1.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.3.0)
52
+ parser (>= 2.7.1.4)
53
+ rubocop-rspec (1.43.2)
54
+ rubocop (~> 0.87)
55
+ ruby-progressbar (1.10.1)
56
+ unicode-display_width (1.7.0)
54
57
 
55
58
  PLATFORMS
56
59
  ruby
57
60
 
58
61
  DEPENDENCIES
59
- bundler (< 2.0)
62
+ bundler
60
63
  dotenv
61
64
  faraday
62
65
  pry
@@ -68,4 +71,4 @@ DEPENDENCIES
68
71
  slack-ruby-block-kit!
69
72
 
70
73
  BUNDLED WITH
71
- 1.17.3
74
+ 2.1.4
@@ -6,12 +6,13 @@ module Slack
6
6
  module Element; end
7
7
  module Layout; end
8
8
 
9
- VERSION = '0.6.0'
9
+ VERSION = '0.10.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,10 @@ module Slack
9
9
  #
10
10
  # https://api.slack.com/reference/messaging/composition-objects#confirm
11
11
  class ConfirmationDialog
12
+ def initialize
13
+ @title, @confirm, @text, @style = nil
14
+ end
15
+
12
16
  def title(text:, emoji: nil)
13
17
  @title = PlainText.new(text: text, emoji: emoji)
14
18
 
@@ -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
 
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Slack
4
+ module BlockKit
5
+ module Element
6
+ # A checkbox group that allows a user to choose multiple items from
7
+ # a list of possible options.
8
+ #
9
+ # https://api.slack.com/reference/messaging/block-elements#checkboxes
10
+ class Checkboxes
11
+ TYPE = 'checkboxes'
12
+
13
+ attr_accessor :confirm
14
+
15
+ def initialize(action_id:)
16
+ @action_id = action_id
17
+ @options = []
18
+ @initial_options = []
19
+ @confirm = nil
20
+
21
+ yield(self) if block_given?
22
+ end
23
+
24
+ def option(value:, text:, description: nil)
25
+ @options << Composition::Option.new(
26
+ value: value,
27
+ text: text,
28
+ description: description
29
+ )
30
+
31
+ self
32
+ end
33
+
34
+ def initial(value:, text:, description: nil)
35
+ @initial_options << Composition::Option.new(
36
+ value: value,
37
+ text: text,
38
+ description: description
39
+ )
40
+
41
+ self
42
+ end
43
+
44
+ def confirmation_dialog
45
+ @confirm = Composition::ConfirmationDialog.new
46
+
47
+ yield(@confirm) if block_given?
48
+
49
+ @confirm
50
+ end
51
+
52
+ def as_json(*)
53
+ {
54
+ type: TYPE,
55
+ action_id: @action_id,
56
+ options: @options.map(&:as_json),
57
+ initial_options: @initial_options.any? ? @initial_options.map(&:as_json) : nil,
58
+ confirm: @confirm&.as_json
59
+ }.compact
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -22,6 +22,7 @@ module Slack
22
22
  @placeholder = Composition::PlainText.new(text: placeholder, emoji: emoji)
23
23
  @action_id = action_id
24
24
  @initial_conversation = initial
25
+ @filter = nil
25
26
 
26
27
  yield(self) if block_given?
27
28
  end
@@ -34,13 +35,26 @@ module Slack
34
35
  self
35
36
  end
36
37
 
38
+ def filter(only: nil,
39
+ exclude_external_shared_channels: nil,
40
+ exclude_bot_users: nil)
41
+ @filter = Composition::ConversationFilter.new(
42
+ only: only,
43
+ exclude_external_shared_channels: exclude_external_shared_channels,
44
+ exclude_bot_users: exclude_bot_users
45
+ )
46
+
47
+ self
48
+ end
49
+
37
50
  def as_json(*)
38
51
  {
39
52
  type: TYPE,
40
53
  placeholder: @placeholder.as_json,
41
54
  action_id: @action_id,
42
55
  initial_conversation: @initial_conversation,
43
- confirm: @confirm&.as_json
56
+ confirm: @confirm&.as_json,
57
+ filter: @filter&.as_json
44
58
  }.compact
45
59
  end
46
60
  end
@@ -28,6 +28,7 @@ module Slack
28
28
  @action_id = action_id
29
29
  @initial_option = initial
30
30
  @min_query_length = min_query_length
31
+ @confirm = nil
31
32
 
32
33
  yield(self) if block_given?
33
34
  end
@@ -46,7 +47,7 @@ module Slack
46
47
  placeholder: @placeholder.as_json,
47
48
  action_id: @action_id,
48
49
  initial_option: @initial_option&.as_json,
49
- min_query_length: min_query_length,
50
+ min_query_length: @min_query_length,
50
51
  confirm: @confirm&.as_json
51
52
  }.compact
52
53
  end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Slack
4
+ module BlockKit
5
+ module Element
6
+ # A select menu, just as with a standard HTML <select> tag, creates a drop
7
+ # down menu with a list of options for a user to choose. The select menu
8
+ # also includes type-ahead functionality, where a user can type a part or
9
+ # all of an option string to filter the list.
10
+ #
11
+ # This multi-select menu will populate its options with a list of public
12
+ # channels visible to the current user in the active workspace.
13
+ #
14
+ # https://api.slack.com/reference/block-kit/block-elements#channel_multi_select
15
+ class MultiChannelsSelect
16
+ TYPE = 'multi_channels_select'
17
+
18
+ attr_accessor :confirm
19
+
20
+ def initialize(placeholder:, action_id:, initial: nil, emoji: nil, max_selected_items: nil)
21
+ @placeholder = Composition::PlainText.new(text: placeholder, emoji: emoji)
22
+ @action_id = action_id
23
+ @initial_channels = initial
24
+ @confirm = nil
25
+ @max_selected_items = max_selected_items
26
+
27
+ yield(self) if block_given?
28
+ end
29
+
30
+ def confirmation_dialog
31
+ @confirm = Composition::ConfirmationDialog.new
32
+
33
+ yield(@confirm) if block_given?
34
+
35
+ self
36
+ end
37
+
38
+ def as_json(*)
39
+ {
40
+ type: TYPE,
41
+ placeholder: @placeholder.as_json,
42
+ action_id: @action_id,
43
+ initial_channels: @initial_channels,
44
+ confirm: @confirm&.as_json,
45
+ max_selected_items: @max_selected_items
46
+ }.compact
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Slack
4
+ module BlockKit
5
+ module Element
6
+ # A select menu, just as with a standard HTML <select> tag, creates a drop
7
+ # down menu with a list of options for a user to choose. The select menu
8
+ # also includes type-ahead functionality, where a user can type a part or
9
+ # all of an option string to filter the list.
10
+ #
11
+ # This multi-select menu will populate its options with a list of public and
12
+ # private channels, DMs, and MPIMs visible to the current user in the
13
+ # active workspace.
14
+ #
15
+ # https://api.slack.com/reference/block-kit/block-elements#conversation_multi_select
16
+ class MultiConversationsSelect
17
+ TYPE = 'multi_conversations_select'
18
+
19
+ attr_accessor :confirm
20
+
21
+ def initialize(placeholder:, action_id:, initial: nil, emoji: nil, max_selected_items: nil)
22
+ @placeholder = Composition::PlainText.new(text: placeholder, emoji: emoji)
23
+ @action_id = action_id
24
+ @initial_conversations = initial
25
+ @confirm = nil
26
+ @max_selected_items = max_selected_items
27
+ @filter = nil
28
+
29
+ yield(self) if block_given?
30
+ end
31
+
32
+ def confirmation_dialog
33
+ @confirm = Composition::ConfirmationDialog.new
34
+
35
+ yield(@confirm) if block_given?
36
+
37
+ self
38
+ end
39
+
40
+ def filter(only: nil,
41
+ exclude_external_shared_channels: nil,
42
+ exclude_bot_users: nil)
43
+ @filter = Composition::ConversationFilter.new(
44
+ only: only,
45
+ exclude_external_shared_channels: exclude_external_shared_channels,
46
+ exclude_bot_users: exclude_bot_users
47
+ )
48
+
49
+ self
50
+ end
51
+
52
+ def as_json(*)
53
+ {
54
+ type: TYPE,
55
+ placeholder: @placeholder.as_json,
56
+ action_id: @action_id,
57
+ initial_conversations: @initial_conversations,
58
+ confirm: @confirm&.as_json,
59
+ max_selected_items: @max_selected_items,
60
+ filter: @filter&.as_json
61
+ }.compact
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Slack
4
+ module BlockKit
5
+ module Element
6
+ # A select menu, just as with a standard HTML <select> tag, creates a drop
7
+ # down menu with a list of options for a user to choose. The select menu
8
+ # also includes type-ahead functionality, where a user can type a part or
9
+ # all of an option string to filter the list.
10
+ #
11
+ # This select menu will load its options from an external data source,
12
+ # allowing for a dynamic list of options.
13
+ #
14
+ # Each time a select menu of this type is opened or the user starts typing
15
+ # in the typeahead field, we'll send a request to your specified URL. Your
16
+ # app should return an HTTP 200 OK response, along with an
17
+ # application/json post body with an object containing either an options
18
+ # array, or an option_groups array.
19
+ #
20
+ # https://api.slack.com/reference/block-kit/block-elements#external_multi_select
21
+ class MultiExternalSelect
22
+ TYPE = 'multi_external_select'
23
+
24
+ attr_accessor :confirm
25
+
26
+ def initialize(placeholder:, action_id:,
27
+ initial: nil, min_query_length: nil, emoji: nil, max_selected_items: nil)
28
+
29
+ @placeholder = Composition::PlainText.new(text: placeholder, emoji: emoji)
30
+ @action_id = action_id
31
+ @initial_options = initial
32
+ @min_query_length = min_query_length
33
+ @confirm = nil
34
+ @max_selected_items = max_selected_items
35
+
36
+ yield(self) if block_given?
37
+ end
38
+
39
+ def confirmation_dialog
40
+ @confirm = Composition::ConfirmationDialog.new
41
+
42
+ yield(@confirm) if block_given?
43
+
44
+ self
45
+ end
46
+
47
+ def as_json(*)
48
+ {
49
+ type: TYPE,
50
+ placeholder: @placeholder.as_json,
51
+ action_id: @action_id,
52
+ initial_options: @initial_options&.map(&:as_json),
53
+ min_query_length: @min_query_length,
54
+ confirm: @confirm&.as_json,
55
+ max_selected_items: @max_selected_items
56
+ }.compact
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Slack
4
+ module BlockKit
5
+ module Element
6
+ # A select menu, just as with a standard HTML <select> tag, creates a drop
7
+ # down menu with a list of options for a user to choose. The select menu
8
+ # also includes type-ahead functionality, where a user can type a part or
9
+ # all of an option string to filter the list.
10
+ #
11
+ # This is the simplest form of select menu, with a static list of options
12
+ # passed in when defining the element.
13
+ #
14
+ # https://api.slack.com/reference/block-kit/block-elements#static_multi_select
15
+ class MultiStaticSelect
16
+ TYPE = 'multi_static_select'
17
+
18
+ attr_accessor :confirm, :options, :option_groups, :initial_options
19
+
20
+ def initialize(placeholder:, action_id:, emoji: nil, max_selected_items: nil)
21
+ @placeholder = Composition::PlainText.new(text: placeholder, emoji: emoji)
22
+ @action_id = action_id
23
+ @confirm = nil
24
+ @max_selected_items = max_selected_items
25
+
26
+ @options = nil
27
+ @option_groups = nil
28
+ @initial_options = nil
29
+
30
+ yield(self) if block_given?
31
+ end
32
+
33
+ def confirmation_dialog
34
+ @confirm = Composition::ConfirmationDialog.new
35
+
36
+ yield(@confirm) if block_given?
37
+
38
+ self
39
+ end
40
+
41
+ def option(value:, text:, emoji: nil)
42
+ @options ||= []
43
+ @options << Composition::Option.new(
44
+ value: value,
45
+ text: text,
46
+ emoji: emoji
47
+ )
48
+
49
+ self
50
+ end
51
+
52
+ def option_group(label:, emoji: nil)
53
+ option_group = Composition::OptionGroup.new(label: label, emoji: emoji)
54
+
55
+ yield(option_group) if block_given?
56
+
57
+ @option_groups ||= []
58
+ @option_groups << option_group
59
+
60
+ self
61
+ end
62
+
63
+ def initial(value:, text:, emoji: nil)
64
+ @initial_options ||= []
65
+ @initial_options << Composition::Option.new(
66
+ value: value,
67
+ text: text,
68
+ emoji: emoji
69
+ )
70
+
71
+ self
72
+ end
73
+
74
+ def as_json(*)
75
+ {
76
+ type: TYPE,
77
+ placeholder: @placeholder.as_json,
78
+ action_id: @action_id,
79
+ options: @options&.map(&:as_json),
80
+ option_groups: @option_groups&.map(&:as_json),
81
+ initial_options: @initial_options&.map(&:as_json),
82
+ confirm: @confirm&.as_json,
83
+ max_selected_items: @max_selected_items
84
+ }.compact
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Slack
4
+ module BlockKit
5
+ module Element
6
+ # A select menu, just as with a standard HTML <select> tag, creates a drop
7
+ # down menu with a list of options for a user to choose. The select menu
8
+ # also includes type-ahead functionality, where a user can type a part or
9
+ # all of an option string to filter the list.
10
+ #
11
+ # This multi-select menu will populate its options with a list of Slack users
12
+ # visible to the current user in the active workspace.
13
+ #
14
+ # https://api.slack.com/reference/block-kit/block-elements#users_multi_select
15
+ class MultiUsersSelect
16
+ TYPE = 'multi_users_select'
17
+
18
+ attr_accessor :confirm
19
+
20
+ def initialize(placeholder:, action_id:, initial: nil, emoji: nil, max_selected_items: nil)
21
+ @placeholder = Composition::PlainText.new(text: placeholder, emoji: emoji)
22
+ @action_id = action_id
23
+ @initial_users = initial
24
+ @confirm = nil
25
+ @max_selected_items = max_selected_items
26
+
27
+ yield(self) if block_given?
28
+ end
29
+
30
+ def confirmation_dialog
31
+ @confirm = Composition::ConfirmationDialog.new
32
+
33
+ yield(@confirm) if block_given?
34
+
35
+ self
36
+ end
37
+
38
+ def as_json(*)
39
+ {
40
+ type: TYPE,
41
+ placeholder: @placeholder.as_json,
42
+ action_id: @action_id,
43
+ initial_users: @initial_users,
44
+ confirm: @confirm&.as_json,
45
+ max_selected_items: @max_selected_items
46
+ }.compact
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -22,6 +22,7 @@ module Slack
22
22
  def initialize(action_id:)
23
23
  @action_id = action_id
24
24
  @options = []
25
+ @confirm = nil
25
26
 
26
27
  yield(self) if block_given?
27
28
  end
@@ -22,7 +22,7 @@ module Slack
22
22
  min_length: nil,
23
23
  max_length: nil
24
24
  )
25
- @placeholder = Composition::PlainText.new(text: placeholder, emoji: emoji) if placeholder
25
+ @placeholder = placeholder && Composition::PlainText.new(text: placeholder, emoji: emoji)
26
26
  @initial_value = initial_value
27
27
  @action_id = action_id
28
28
  @multiline = multiline
@@ -10,6 +10,7 @@ module Slack
10
10
  TYPE = 'context'
11
11
 
12
12
  attr_accessor :elements
13
+
13
14
  def initialize(block_id: nil)
14
15
  @block_id = block_id
15
16
  @elements = []
@@ -13,10 +13,7 @@ module Slack
13
13
  @image_url = url
14
14
  @alt_text = alt_text
15
15
  @block_id = block_id
16
-
17
- return unless title
18
-
19
- @title = Composition::PlainText.new(
16
+ @title = title && Composition::PlainText.new(
20
17
  text: title,
21
18
  emoji: emoji
22
19
  )
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative './section/multi_select_elements'
4
+
3
5
  module Slack
4
6
  module BlockKit
5
7
  module Layout
@@ -8,13 +10,19 @@ module Slack
8
10
  # with any of the available block elements.
9
11
  #
10
12
  # https://api.slack.com/reference/messaging/blocks#section
13
+ # rubocop:disable Metrics/ClassLength
11
14
  class Section
15
+ # rubocop:enable Metrics/ClassLength
16
+
17
+ include Section::MultiSelectElements
12
18
  TYPE = 'section'
13
19
 
14
20
  attr_accessor :fields, :text, :accessory
15
21
 
16
22
  def initialize(block_id: nil)
17
23
  @block_id = block_id
24
+ @fields = nil
25
+ @accessory = nil
18
26
 
19
27
  yield(self) if block_given?
20
28
  end
@@ -148,8 +156,18 @@ module Slack
148
156
  accessorise(element)
149
157
  end
150
158
 
159
+ def checkboxes(action_id:)
160
+ element = Element::Checkboxes.new(
161
+ action_id: action_id
162
+ )
163
+
164
+ yield(element) if block_given?
165
+
166
+ accessorise(element)
167
+ end
168
+
151
169
  def image(url:, alt_text:)
152
- accessorize(Element::Image.new(image_url: url, alt_text: alt_text))
170
+ accessorise(Element::Image.new(image_url: url, alt_text: alt_text))
153
171
  end
154
172
 
155
173
  def accessorise(element)
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Slack
4
+ module BlockKit
5
+ module Layout
6
+ class Section
7
+ # Helper methods for Multi Select to inject to section
8
+ module MultiSelectElements
9
+ def multi_channels_select(placeholder:, action_id:,
10
+ initial: nil, emoji: nil, max_selected_items: nil)
11
+ element = Element::MultiChannelsSelect.new(
12
+ placeholder: placeholder,
13
+ action_id: action_id,
14
+ initial: initial,
15
+ emoji: emoji,
16
+ max_selected_items: max_selected_items
17
+ )
18
+
19
+ yield(element) if block_given?
20
+
21
+ accessorise(element)
22
+ end
23
+
24
+ def multi_conversations_select(placeholder:, action_id:,
25
+ initial: nil, emoji: nil, max_selected_items: nil)
26
+ element = Element::MultiConversationsSelect.new(
27
+ placeholder: placeholder,
28
+ action_id: action_id,
29
+ initial: initial,
30
+ emoji: emoji,
31
+ max_selected_items: max_selected_items
32
+ )
33
+
34
+ yield(element) if block_given?
35
+
36
+ accessorise(element)
37
+ end
38
+
39
+ def multi_external_select(placeholder:, action_id:,
40
+ initial: nil,
41
+ min_query_length: nil,
42
+ emoji: nil,
43
+ max_selected_items: nil)
44
+ element = Element::MultiExternalSelect.new(
45
+ placeholder: placeholder,
46
+ action_id: action_id,
47
+ initial: initial,
48
+ min_query_length: min_query_length,
49
+ emoji: emoji,
50
+ max_selected_items: max_selected_items
51
+ )
52
+
53
+ yield(element) if block_given?
54
+
55
+ accessorise(element)
56
+ end
57
+
58
+ def multi_static_select(placeholder:, action_id:,
59
+ emoji: nil, max_selected_items: nil)
60
+ element = Element::MultiStaticSelect.new(
61
+ placeholder: placeholder,
62
+ action_id: action_id,
63
+ emoji: emoji,
64
+ max_selected_items: max_selected_items
65
+ )
66
+
67
+ yield(element) if block_given?
68
+
69
+ accessorise(element)
70
+ end
71
+
72
+ def multi_users_select(placeholder:, action_id:,
73
+ initial: nil,
74
+ emoji: nil,
75
+ max_selected_items: nil)
76
+ element = Element::MultiUsersSelect.new(
77
+ placeholder: placeholder,
78
+ action_id: action_id,
79
+ emoji: emoji,
80
+ initial: initial,
81
+ max_selected_items: max_selected_items
82
+ )
83
+
84
+ yield(element) if block_given?
85
+
86
+ accessorise(element)
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Slack
4
+ module Surfaces
5
+ # The Home tab is a persistent, yet dynamic interface
6
+ # for apps that lives within the App Home.
7
+ #
8
+ # https://api.slack.com/surfaces#tabs
9
+ # https://api.slack.com/reference/surfaces/views
10
+ class Home
11
+ TYPE = 'home'
12
+
13
+ def initialize(blocks: nil,
14
+ private_metadata: nil, callback_id: nil, external_id: nil)
15
+ @blocks = blocks || Slack::BlockKit::Blocks.new
16
+
17
+ @private_metadata = private_metadata
18
+ @callback_id = callback_id
19
+ @external_id = external_id
20
+ end
21
+
22
+ attr_reader :blocks
23
+
24
+ def as_json(*)
25
+ {
26
+ type: TYPE,
27
+ blocks: @blocks.as_json,
28
+ private_metadata: @private_metadata,
29
+ callback_id: @callback_id,
30
+ external_id: @external_id
31
+ }.compact
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Slack
4
+ module Surfaces
5
+ # App-published messages are dynamic yet transient spaces.
6
+ # They allow users to complete workflows among their Slack conversations.
7
+ #
8
+ # https://api.slack.com/surfaces#messages
9
+ # https://api.slack.com/messaging/composing#complex_layouts
10
+ class Message
11
+ TYPE = 'message'
12
+
13
+ def initialize(blocks: nil, text: nil, channel: nil, thread_ts: nil, as_user: nil)
14
+ @blocks = blocks || Slack::BlockKit::Blocks.new
15
+ @channel = channel
16
+ @thread_ts = thread_ts
17
+ @as_user = as_user
18
+ @text = text
19
+ end
20
+
21
+ attr_reader :blocks
22
+
23
+ def as_json(*)
24
+ {
25
+ channel: @channel,
26
+ thread_ts: @thread_ts,
27
+ as_user: @as_user,
28
+ text: @text,
29
+ blocks: @blocks.as_json
30
+ }.compact
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Slack
4
+ module Surfaces
5
+ # Modals provide focused spaces ideal for requesting and collecting data from users,
6
+ # or temporarily displaying dynamic and interactive information.
7
+ #
8
+ # https://api.slack.com/surfaces#modals
9
+ # https://api.slack.com/reference/surfaces/views
10
+ #
11
+ # @param title [String] title is required. Must be set as an initial argument
12
+ # or using #title for detail setup
13
+ #
14
+ class Modal
15
+ TYPE = 'modal'
16
+
17
+ def initialize(
18
+ title: nil,
19
+ blocks: nil,
20
+ private_metadata: nil,
21
+ callback_id: nil,
22
+ external_id: nil,
23
+ clear_on_close: nil,
24
+ notify_on_close: nil
25
+ )
26
+ @blocks = blocks || Slack::BlockKit::Blocks.new
27
+
28
+ @private_metadata = private_metadata
29
+ @callback_id = callback_id
30
+ @external_id = external_id
31
+
32
+ @clear_on_close = clear_on_close
33
+ @notify_on_close = notify_on_close
34
+
35
+ @title = Slack::BlockKit::Composition::PlainText.new(text: title) if title
36
+
37
+ @close, @submit = nil
38
+ end
39
+
40
+ attr_reader :blocks
41
+
42
+ def title(text:, emoji: nil)
43
+ @title = Slack::BlockKit::Composition::PlainText.new(text: text, emoji: emoji)
44
+
45
+ self
46
+ end
47
+
48
+ def close(text:, emoji: nil)
49
+ @close = Slack::BlockKit::Composition::PlainText.new(text: text, emoji: emoji)
50
+
51
+ self
52
+ end
53
+
54
+ def submit(text:, emoji: nil)
55
+ @submit = Slack::BlockKit::Composition::PlainText.new(text: text, emoji: emoji)
56
+
57
+ self
58
+ end
59
+
60
+ def as_json(*) # rubocop:disable Metrics/MethodLength
61
+ {
62
+ type: TYPE,
63
+ blocks: @blocks.as_json,
64
+ title: @title&.as_json,
65
+ close: @close&.as_json,
66
+ submit: @submit&.as_json,
67
+ clear_on_close: @clear_on_close,
68
+ notify_on_close: @notify_on_close,
69
+ private_metadata: @private_metadata,
70
+ callback_id: @callback_id,
71
+ external_id: @external_id
72
+ }.compact
73
+ end
74
+ end
75
+ end
76
+ end
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
28
28
  spec.require_paths = ['lib']
29
29
  spec.required_ruby_version = '>= 2.5'
30
30
 
31
- spec.add_development_dependency 'bundler', '< 2.0'
31
+ spec.add_development_dependency 'bundler'
32
32
  spec.add_development_dependency 'dotenv'
33
33
  spec.add_development_dependency 'faraday'
34
34
  spec.add_development_dependency 'pry'
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slack-ruby-block-kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Gregg
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-29 00:00:00.000000000 Z
11
+ date: 2020-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "<"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '2.0'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "<"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '2.0'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: dotenv
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -136,7 +136,7 @@ dependencies:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
- description:
139
+ description:
140
140
  email:
141
141
  - c_arlt@hotmail.com
142
142
  executables: []
@@ -144,10 +144,12 @@ extensions: []
144
144
  extra_rdoc_files: []
145
145
  files:
146
146
  - ".circleci/config.yml"
147
+ - ".github/dependabot.yml"
147
148
  - ".gitignore"
148
149
  - ".rspec"
149
150
  - ".rubocop.yml"
150
151
  - ".rubocop_todo.yml"
152
+ - CHANGELOG.md
151
153
  - Gemfile
152
154
  - Gemfile.lock
153
155
  - LICENSE.txt
@@ -158,16 +160,23 @@ files:
158
160
  - lib/slack/block_kit.rb
159
161
  - lib/slack/block_kit/blocks.rb
160
162
  - lib/slack/block_kit/composition/confirmation_dialog.rb
163
+ - lib/slack/block_kit/composition/conversation_filter.rb
161
164
  - lib/slack/block_kit/composition/mrkdwn.rb
162
165
  - lib/slack/block_kit/composition/option.rb
163
166
  - lib/slack/block_kit/composition/option_group.rb
164
167
  - lib/slack/block_kit/composition/plain_text.rb
165
168
  - lib/slack/block_kit/element/button.rb
166
169
  - lib/slack/block_kit/element/channels_select.rb
170
+ - lib/slack/block_kit/element/checkboxes.rb
167
171
  - lib/slack/block_kit/element/conversations_select.rb
168
172
  - lib/slack/block_kit/element/date_picker.rb
169
173
  - lib/slack/block_kit/element/external_select.rb
170
174
  - lib/slack/block_kit/element/image.rb
175
+ - lib/slack/block_kit/element/multi_channels_select.rb
176
+ - lib/slack/block_kit/element/multi_conversations_select.rb
177
+ - lib/slack/block_kit/element/multi_external_select.rb
178
+ - lib/slack/block_kit/element/multi_static_select.rb
179
+ - lib/slack/block_kit/element/multi_users_select.rb
171
180
  - lib/slack/block_kit/element/overflow_menu.rb
172
181
  - lib/slack/block_kit/element/plain_text_input.rb
173
182
  - lib/slack/block_kit/element/static_select.rb
@@ -178,13 +187,17 @@ files:
178
187
  - lib/slack/block_kit/layout/image.rb
179
188
  - lib/slack/block_kit/layout/input.rb
180
189
  - lib/slack/block_kit/layout/section.rb
190
+ - lib/slack/block_kit/layout/section/multi_select_elements.rb
191
+ - lib/slack/surfaces/home.rb
192
+ - lib/slack/surfaces/message.rb
193
+ - lib/slack/surfaces/modal.rb
181
194
  - slack-ruby-block-kit.gemspec
182
195
  homepage: https://github.com/CGA1123/slack-ruby-block-kit
183
196
  licenses:
184
197
  - MIT
185
198
  metadata:
186
199
  allowed_push_host: https://rubygems.org
187
- post_install_message:
200
+ post_install_message:
188
201
  rdoc_options: []
189
202
  require_paths:
190
203
  - lib
@@ -200,7 +213,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
200
213
  version: '0'
201
214
  requirements: []
202
215
  rubygems_version: 3.0.3
203
- signing_key:
216
+ signing_key:
204
217
  specification_version: 4
205
218
  summary: A ruby wrapper for Slack's Block Kit
206
219
  test_files: []