slack-ruby-block-kit 0.4.0 → 0.8.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: 40f294a5c8ef52820a0db8fd474a4cba423dad298f14092217f6213b47ba45ad
4
- data.tar.gz: e22e8b941d6d3c765c6f40735bd97ecd11f94ac4560e3ba038e0cef073a72241
3
+ metadata.gz: ba4b59b1f8d591f6560563d913833ea5193d3c0ad1ff46e30b4484949d8cfeda
4
+ data.tar.gz: 90c8576e1fadb6b9a17d8e6c76f9c871e073fa0cab1e9178a26959b80e62b1fa
5
5
  SHA512:
6
- metadata.gz: d7d952242309b0906da8e5ae6072f618a200e3604ad304ceeb323e2387ec5185cadee7e1554729f9beaf004431f0c97053d30c462d40c0c9bee6aaaa1cd91b88
7
- data.tar.gz: 639e9d8b9b57c99022e0080233a0ecae95f958e04732a0f2bd0fc41cc1b704918fa0eb04a28d6e451a2d373f823c1fb8e40c1890d24ebe5d60af58150e6c27cb
6
+ metadata.gz: 37e969657c3cd6f54fd0f4d9a77292b4740917463823b84af9325a87455b6b686af353d98769a09d6e36e2ddd503e62fc1d460f981c359326deb87232349d89c
7
+ data.tar.gz: af06784a17f10737b24c85b3ee2b59dd34f0bd61da21e19234d1cca04e213a195ca5698ec8ddbb876dd3a8fdf5894814b2c39da65305747f78a907401fbf5ccb
@@ -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
data/.gitignore CHANGED
@@ -11,3 +11,4 @@
11
11
  # rspec failure tracking
12
12
  .rspec_status
13
13
  *.gem
14
+ .env
@@ -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:
@@ -13,3 +13,43 @@ Style/AsciiComments:
13
13
  Naming/FileName:
14
14
  Exclude:
15
15
  - lib/slack-ruby-block-kit.rb
16
+
17
+ Metrics/ParameterLists:
18
+ Max: 8
19
+
20
+ Metrics/BlockLength:
21
+ Exclude:
22
+ - 'Rakefile'
23
+ - '**/*.rake'
24
+ - 'spec/**/*.rb'
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
@@ -17,11 +17,6 @@ Metrics/BlockLength:
17
17
  Metrics/ClassLength:
18
18
  Max: 117
19
19
 
20
- # Offense count: 3
21
- # Configuration parameters: CountKeywordArgs.
22
- Metrics/ParameterLists:
23
- Max: 6
24
-
25
20
  # Offense count: 5
26
21
  # Configuration parameters: Max.
27
22
  RSpec/ExampleLength:
@@ -1,53 +1,68 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- slack-ruby-block-kit (0.4.0)
4
+ slack-ruby-block-kit (0.8.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
+ coderay (1.1.2)
10
11
  diff-lcs (1.3)
11
- jaro_winkler (1.5.2)
12
- parallel (1.13.0)
13
- parser (2.6.0.0)
14
- ast (~> 2.4.0)
15
- powerpack (0.1.2)
12
+ dotenv (2.7.5)
13
+ faraday (1.0.1)
14
+ multipart-post (>= 1.2, < 3)
15
+ method_source (1.0.0)
16
+ multipart-post (2.1.1)
17
+ parallel (1.19.2)
18
+ parser (2.7.1.4)
19
+ ast (~> 2.4.1)
20
+ pry (0.13.1)
21
+ coderay (~> 1.1)
22
+ method_source (~> 1.0)
16
23
  rainbow (3.0.0)
17
24
  rake (13.0.1)
18
- rspec (3.8.0)
19
- rspec-core (~> 3.8.0)
20
- rspec-expectations (~> 3.8.0)
21
- rspec-mocks (~> 3.8.0)
22
- rspec-core (3.8.0)
23
- rspec-support (~> 3.8.0)
24
- 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)
25
34
  diff-lcs (>= 1.2.0, < 2.0)
26
- rspec-support (~> 3.8.0)
27
- rspec-mocks (3.8.0)
35
+ rspec-support (~> 3.9.0)
36
+ rspec-mocks (3.9.1)
28
37
  diff-lcs (>= 1.2.0, < 2.0)
29
- rspec-support (~> 3.8.0)
30
- rspec-support (3.8.0)
38
+ rspec-support (~> 3.9.0)
39
+ rspec-support (3.9.3)
31
40
  rspec_junit_formatter (0.4.1)
32
41
  rspec-core (>= 2, < 4, != 2.12.0)
33
- rubocop (0.63.1)
34
- jaro_winkler (~> 1.5.1)
42
+ rubocop (0.86.0)
35
43
  parallel (~> 1.10)
36
- parser (>= 2.5, != 2.5.1.1)
37
- powerpack (~> 0.1)
44
+ parser (>= 2.7.0.1)
38
45
  rainbow (>= 2.2.2, < 4.0)
46
+ regexp_parser (>= 1.7)
47
+ rexml
48
+ rubocop-ast (>= 0.0.3, < 1.0)
39
49
  ruby-progressbar (~> 1.7)
40
- unicode-display_width (~> 1.4.0)
41
- rubocop-rspec (1.32.0)
42
- rubocop (>= 0.60.0)
43
- ruby-progressbar (1.10.0)
44
- unicode-display_width (1.4.1)
50
+ unicode-display_width (>= 1.4.0, < 2.0)
51
+ rubocop-ast (0.0.3)
52
+ parser (>= 2.7.0.1)
53
+ rubocop-rspec (1.40.0)
54
+ rubocop (>= 0.68.1)
55
+ ruby-progressbar (1.10.1)
56
+ unicode-display_width (1.7.0)
45
57
 
46
58
  PLATFORMS
47
59
  ruby
48
60
 
49
61
  DEPENDENCIES
50
- bundler (< 2.0)
62
+ bundler
63
+ dotenv
64
+ faraday
65
+ pry
51
66
  rake
52
67
  rspec
53
68
  rspec_junit_formatter
@@ -56,4 +71,4 @@ DEPENDENCIES
56
71
  slack-ruby-block-kit!
57
72
 
58
73
  BUNDLED WITH
59
- 1.17.3
74
+ 2.1.4
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
- [![CircleCI](https://circleci.com/gh/CGA1123/slack_block_kit-ruby/tree/master.svg?style=svg)](https://circleci.com/gh/CGA1123/slack_block_kit-ruby/tree/master)
2
- [![Gem Version](https://badge.fury.io/rb/slack_block_kit.svg)](https://badge.fury.io/rb/slack_block_kit)
1
+ [![CircleCI](https://circleci.com/gh/CGA1123/slack-ruby-block-kit/tree/master.svg?style=svg)](https://circleci.com/gh/CGA1123/slack-ruby-block-kit/tree/master)
2
+ [![Gem Version](https://badge.fury.io/rb/slack-ruby-block-kit.svg)](https://badge.fury.io/rb/slack-ruby-block-kit)
3
3
 
4
4
  # Slack::BlockKit
5
5
 
@@ -18,7 +18,7 @@ The 'blocks' availables are split in line with how Slack documents them, that is
18
18
  Add this line to your application's Gemfile:
19
19
 
20
20
  ```ruby
21
- gem 'slack_block_kit'
21
+ gem 'slack-ruby-block-kit'
22
22
  ```
23
23
 
24
24
 
@@ -29,12 +29,12 @@ And then execute:
29
29
 
30
30
  Or install it yourself as:
31
31
 
32
- $ gem install slack_block_kit
32
+ $ gem install slack-ruby-block-kit
33
33
 
34
34
  Finally, require this:
35
35
 
36
36
  ```ruby
37
- require 'slack/block_kit'
37
+ require 'slack-ruby-block-kit'
38
38
  ```
39
39
 
40
40
  ## Examples
@@ -43,7 +43,7 @@ Here are a few examples that might help you get started!
43
43
 
44
44
  ```ruby
45
45
  require 'faraday'
46
- require 'slack/block_kit'
46
+ require 'slack-ruby-block-kit'
47
47
  require 'json'
48
48
 
49
49
  a_prebuilt_block = Slack::BlockKit::Layout::Section.new
@@ -86,9 +86,9 @@ You can also check out the [`slackerduty`](https://github.com/CGA1123/slackerdut
86
86
 
87
87
  ## Contributing
88
88
 
89
- Bug reports and pull requests are welcome on GitHub at https://github.com/CGA1123/slack_block_kit-ruby
89
+ Bug reports and pull requests are welcome on GitHub at https://github.com/CGA1123/slack-ruby-block-kit
90
90
 
91
- See [issues](https://github.com/CGA1123/slack_block_kit-ruby/issues) if you want any inspiration as to what to help with!
91
+ See [issues](https://github.com/CGA1123/slack-ruby-block-kit/issues) if you want any inspiration as to what to help with!
92
92
 
93
93
  ## License
94
94
 
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ lib = File.expand_path('../lib', __dir__)
5
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
+
7
+ require 'bundler/setup'
8
+ require 'dotenv/load'
9
+ require 'slack-ruby-block-kit'
10
+ require 'faraday'
11
+ require 'pry'
12
+
13
+ Pry.start
@@ -6,12 +6,12 @@ module Slack
6
6
  module Element; end
7
7
  module Layout; end
8
8
 
9
- VERSION = '0.4.0'
9
+ VERSION = '0.8.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
15
 
16
16
  module_function
17
17
 
@@ -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
 
@@ -33,6 +37,12 @@ module Slack
33
37
  self
34
38
  end
35
39
 
40
+ def style(value)
41
+ @style = value
42
+
43
+ self
44
+ end
45
+
36
46
  def mrkdwn(text:, verbatim: nil)
37
47
  @text = Mrkdwn.new(text: text, verbatim: verbatim)
38
48
 
@@ -44,8 +54,9 @@ module Slack
44
54
  title: @title.as_json,
45
55
  text: @text.as_json,
46
56
  confirm: @confirm.as_json,
47
- deny: @deny.as_json
48
- }
57
+ deny: @deny.as_json,
58
+ style: @style
59
+ }.compact
49
60
  end
50
61
  end
51
62
  end
@@ -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
@@ -8,16 +8,20 @@ module Slack
8
8
  # https://api.slack.com/reference/messaging/composition-objects#option
9
9
  # https://api.slack.com/reference/messaging/block-elements#select
10
10
  class Option
11
- def initialize(value:, text:, emoji: nil)
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 = description && PlainText.new(text: description, emoji: emoji)
15
+ @url = url
14
16
  end
15
17
 
16
18
  def as_json(*)
17
19
  {
18
20
  text: @text.as_json,
19
- value: @value
20
- }
21
+ value: @value,
22
+ description: @description&.as_json,
23
+ url: @url
24
+ }.compact
21
25
  end
22
26
  end
23
27
  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_channel = 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_channel: @initial_channel,
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_conversation = 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_conversation: @initial_conversation,
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_option = 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_option: @initial_option&.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,88 @@
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_option
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_option = 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_option = Composition::Option.new(
65
+ value: value,
66
+ text: text,
67
+ emoji: emoji
68
+ )
69
+
70
+ self
71
+ end
72
+
73
+ def as_json(*)
74
+ {
75
+ type: TYPE,
76
+ placeholder: @placeholder.as_json,
77
+ action_id: @action_id,
78
+ options: @options&.map(&:as_json),
79
+ option_groups: @option_groups&.map(&:as_json),
80
+ initial_option: @initial_option&.as_json,
81
+ confirm: @confirm&.as_json,
82
+ max_selected_items: @max_selected_items
83
+ }.compact
84
+ end
85
+ end
86
+ end
87
+ end
88
+ 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_user = 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_user: @initial_user,
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,15 +22,17 @@ 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
28
29
 
29
- def option(value:, text:, emoji: nil)
30
+ def option(value:, text:, emoji: nil, url: nil)
30
31
  @options << Composition::Option.new(
31
32
  value: value,
32
33
  text: text,
33
- emoji: emoji
34
+ emoji: emoji,
35
+ url: url
34
36
  )
35
37
 
36
38
  self
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Slack
4
+ module BlockKit
5
+ module Element
6
+ # A plain-text input, similar to the HTML <input> tag, creates a field
7
+ # where a user can enter freeform data. It can appear as a single-line
8
+ # field or a larger textarea using the multiline flag.
9
+ #
10
+ # Plain-text input elements are currently only available in modals
11
+ #
12
+ # https://api.slack.com/reference/block-kit/block-elements#input
13
+ class PlainTextInput
14
+ TYPE = 'plain_text_input'
15
+
16
+ def initialize(
17
+ action_id:,
18
+ placeholder: nil,
19
+ emoji: nil,
20
+ initial_value: nil,
21
+ multiline: nil,
22
+ min_length: nil,
23
+ max_length: nil
24
+ )
25
+ @placeholder = placeholder && Composition::PlainText.new(text: placeholder, emoji: emoji)
26
+ @initial_value = initial_value
27
+ @action_id = action_id
28
+ @multiline = multiline
29
+ @min_length = min_length
30
+ @max_length = max_length
31
+ end
32
+
33
+ def as_json(*)
34
+ {
35
+ type: TYPE,
36
+ action_id: @action_id,
37
+ placeholder: @placeholder&.as_json,
38
+ multiline: @multiline,
39
+ min_length: @min_length,
40
+ max_length: @max_length,
41
+ initial_value: @initial_value
42
+ }.compact
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -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 = []
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Slack
4
+ module BlockKit
5
+ module Layout
6
+ # A block that collects information from users - it can hold a plain-text
7
+ # input element, a select menu element, a multi-select menu element, or a
8
+ # datepicker.
9
+ #
10
+ # https://api.slack.com/reference/block-kit/blocks#input
11
+ class Input
12
+ TYPE = 'input'
13
+
14
+ attr_accessor :label, :element, :block_id, :hint, :optional, :emoji
15
+
16
+ def initialize(
17
+ label:,
18
+ element:,
19
+ block_id: nil,
20
+ hint: nil,
21
+ optional: nil,
22
+ emoji: nil
23
+ )
24
+ @label = Composition::PlainText.new(text: label, emoji: emoji) if label
25
+ @hint = Composition::PlainText.new(text: hint, emoji: emoji) if hint
26
+ @block_id = block_id
27
+ @optional = optional
28
+ @element = element
29
+ end
30
+
31
+ def as_json(*)
32
+ {
33
+ type: TYPE,
34
+ element: @element.as_json,
35
+ label: @label&.as_json,
36
+ hint: @hint&.as_json,
37
+ block_id: @block_id,
38
+ optional: optional
39
+ }.compact
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -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
@@ -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
@@ -28,7 +28,10 @@ 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
+ spec.add_development_dependency 'dotenv'
33
+ spec.add_development_dependency 'faraday'
34
+ spec.add_development_dependency 'pry'
32
35
  spec.add_development_dependency 'rake'
33
36
  spec.add_development_dependency 'rspec'
34
37
  spec.add_development_dependency 'rspec_junit_formatter'
metadata CHANGED
@@ -1,29 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slack-ruby-block-kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Gregg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-29 00:00:00.000000000 Z
11
+ date: 2020-06-26 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
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: dotenv
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
18
32
  - !ruby/object:Gem::Version
19
- version: '2.0'
33
+ version: '0'
20
34
  type: :development
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
- - - "<"
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
25
46
  - !ruby/object:Gem::Version
26
- version: '2.0'
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
27
69
  - !ruby/object:Gem::Dependency
28
70
  name: rake
29
71
  requirement: !ruby/object:Gem::Requirement
@@ -102,6 +144,7 @@ extensions: []
102
144
  extra_rdoc_files: []
103
145
  files:
104
146
  - ".circleci/config.yml"
147
+ - ".github/dependabot.yml"
105
148
  - ".gitignore"
106
149
  - ".rspec"
107
150
  - ".rubocop.yml"
@@ -111,10 +154,12 @@ files:
111
154
  - LICENSE.txt
112
155
  - README.md
113
156
  - Rakefile
157
+ - bin/console
114
158
  - lib/slack-ruby-block-kit.rb
115
159
  - lib/slack/block_kit.rb
116
160
  - lib/slack/block_kit/blocks.rb
117
161
  - lib/slack/block_kit/composition/confirmation_dialog.rb
162
+ - lib/slack/block_kit/composition/conversation_filter.rb
118
163
  - lib/slack/block_kit/composition/mrkdwn.rb
119
164
  - lib/slack/block_kit/composition/option.rb
120
165
  - lib/slack/block_kit/composition/option_group.rb
@@ -125,14 +170,22 @@ files:
125
170
  - lib/slack/block_kit/element/date_picker.rb
126
171
  - lib/slack/block_kit/element/external_select.rb
127
172
  - lib/slack/block_kit/element/image.rb
173
+ - lib/slack/block_kit/element/multi_channels_select.rb
174
+ - lib/slack/block_kit/element/multi_conversations_select.rb
175
+ - lib/slack/block_kit/element/multi_external_select.rb
176
+ - lib/slack/block_kit/element/multi_static_select.rb
177
+ - lib/slack/block_kit/element/multi_users_select.rb
128
178
  - lib/slack/block_kit/element/overflow_menu.rb
179
+ - lib/slack/block_kit/element/plain_text_input.rb
129
180
  - lib/slack/block_kit/element/static_select.rb
130
181
  - lib/slack/block_kit/element/users_select.rb
131
182
  - lib/slack/block_kit/layout/actions.rb
132
183
  - lib/slack/block_kit/layout/context.rb
133
184
  - lib/slack/block_kit/layout/divider.rb
134
185
  - lib/slack/block_kit/layout/image.rb
186
+ - lib/slack/block_kit/layout/input.rb
135
187
  - lib/slack/block_kit/layout/section.rb
188
+ - lib/slack/block_kit/layout/section/multi_select_elements.rb
136
189
  - slack-ruby-block-kit.gemspec
137
190
  homepage: https://github.com/CGA1123/slack-ruby-block-kit
138
191
  licenses:
@@ -154,7 +207,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
207
  - !ruby/object:Gem::Version
155
208
  version: '0'
156
209
  requirements: []
157
- rubygems_version: 3.0.3
210
+ rubygems_version: 3.1.2
158
211
  signing_key:
159
212
  specification_version: 4
160
213
  summary: A ruby wrapper for Slack's Block Kit