slack_block_kit 0.1.0 → 0.2.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: e5d96c457901f958a818423822d263731b973700608553814c22121d5250bc64
4
- data.tar.gz: 74f88c477c0611c4396234ccab674ba608d868db9cb2dfdfd9fdd15e96b4166a
3
+ metadata.gz: 067c0037a8fd2f3bff99855b8879b6dedb658ac2006b458022d3053b9bca46ca
4
+ data.tar.gz: 879d0649e57afa5815c1b16be7c87b41b28d934832eebfdc6d3b36352ad005f1
5
5
  SHA512:
6
- metadata.gz: de53fe305167a4d8039b30faf18c4f8ea029631a79e8f7571fb913eb6453dc2040e79d0edcd62cfa65f7be7453d1d1f9f32243d9d7ee573c200f96803dc0e637
7
- data.tar.gz: '018baa8a2ab4b6f046ec8582e22614fce06b88934690c5eaee85bd0d96c706dc582e4cc4079bcb761ee5ba649b9e5f6f15afdc732836c935c34ab9210ac12032'
6
+ metadata.gz: ae170ecd8b12fad81fdf955fc36840295bdef4e1ca4c4b454022571713e610c60c5e6880a0a260bc9b002adbe4423a74f6d871503fe213730f49c04ec04bd4c7
7
+ data.tar.gz: 4042f3ab1ac4efa2de8f108a065caea0d6f1334cd19bc24aab6dee4c55d5267e50517c99bbcafc8e8c281eed815697018c04e148ab88ab5729f5d623576cc888
@@ -0,0 +1,49 @@
1
+ version: 2
2
+ jobs:
3
+ build:
4
+ docker:
5
+ - image: circleci/ruby:2.5.3
6
+
7
+ working_directory: ~/repo
8
+
9
+ steps:
10
+ - checkout
11
+ - restore_cache:
12
+ keys:
13
+ - v1-dependencies-{{ checksum "Gemfile.lock" }}
14
+ - v1-dependencies-
15
+
16
+ - run:
17
+ name: bundle
18
+ command: |
19
+ bundle install --jobs=4 --retry=3 --path vendor/bundle
20
+
21
+ - save_cache:
22
+ paths:
23
+ - ./vendor/bundle
24
+ key: v1-dependencies-{{ checksum "Gemfile.lock" }}
25
+
26
+ - run:
27
+ name: rspec
28
+ command: |
29
+ mkdir /tmp/test-results
30
+ TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | \
31
+ circleci tests split --split-by=timings)"
32
+
33
+ bundle exec rspec \
34
+ --format progress \
35
+ --format RspecJunitFormatter \
36
+ --out /tmp/test-results/rspec.xml \
37
+ --format progress \
38
+ $TEST_FILES
39
+
40
+ # collect reports
41
+ - store_test_results:
42
+ path: /tmp/test-results
43
+ - store_artifacts:
44
+ path: /tmp/test-results
45
+ destination: test-results
46
+
47
+ - run:
48
+ name: rubocop
49
+ command: bundle exec rubocop -p
data/.gitignore CHANGED
@@ -5,7 +5,9 @@
5
5
  /doc/
6
6
  /pkg/
7
7
  /spec/reports/
8
+ /spec/examples.txt
8
9
  /tmp/
9
10
 
10
11
  # rspec failure tracking
11
12
  .rspec_status
13
+ *.gem
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.rubocop.yml CHANGED
@@ -1,3 +1,4 @@
1
+ require: rubocop-rspec
1
2
  inherit_from: .rubocop_todo.yml
2
3
 
3
4
  AllCops:
@@ -5,3 +6,6 @@ AllCops:
5
6
 
6
7
  Metrics/LineLength:
7
8
  Max: 120
9
+
10
+ Style/AsciiComments:
11
+ Enabled: false
data/.rubocop_todo.yml CHANGED
@@ -1,16 +1,33 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2019-03-02 15:46:18 +0000 using RuboCop version 0.63.1.
3
+ # on 2019-03-05 20:45:28 +0000 using RuboCop version 0.63.1.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
+ # Offense count: 5
10
+ # Configuration parameters: CountComments, ExcludedMethods.
11
+ # ExcludedMethods: refine
12
+ Metrics/BlockLength:
13
+ Max: 63
14
+
9
15
  # Offense count: 1
10
- # Configuration parameters: CountKeywordArgs.
11
- Metrics/ParameterLists:
12
- Max: 6
16
+ # Configuration parameters: CountComments.
17
+ Metrics/ClassLength:
18
+ Max: 116
19
+
20
+ # Offense count: 5
21
+ # Configuration parameters: Max.
22
+ RSpec/ExampleLength:
23
+ Exclude:
24
+ - 'spec/lib/slack/block_kit/composition/confirmation_dialog_spec.rb'
25
+ - 'spec/lib/slack/block_kit/composition/option_group_spec.rb'
26
+ - 'spec/lib/slack/block_kit/composition/option_spec.rb'
13
27
 
14
- # Offense count: 19
28
+ # Offense count: 4
15
29
  Style/Documentation:
16
- Enabled: false
30
+ Exclude:
31
+ - 'spec/**/*'
32
+ - 'test/**/*'
33
+ - 'lib/slack/block_kit.rb'
data/Gemfile.lock CHANGED
@@ -28,6 +28,8 @@ GEM
28
28
  diff-lcs (>= 1.2.0, < 2.0)
29
29
  rspec-support (~> 3.8.0)
30
30
  rspec-support (3.8.0)
31
+ rspec_junit_formatter (0.4.1)
32
+ rspec-core (>= 2, < 4, != 2.12.0)
31
33
  rubocop (0.63.1)
32
34
  jaro_winkler (~> 1.5.1)
33
35
  parallel (~> 1.10)
@@ -36,6 +38,8 @@ GEM
36
38
  rainbow (>= 2.2.2, < 4.0)
37
39
  ruby-progressbar (~> 1.7)
38
40
  unicode-display_width (~> 1.4.0)
41
+ rubocop-rspec (1.32.0)
42
+ rubocop (>= 0.60.0)
39
43
  ruby-progressbar (1.10.0)
40
44
  unicode-display_width (1.4.1)
41
45
 
@@ -46,7 +50,9 @@ DEPENDENCIES
46
50
  bundler (< 2.0)
47
51
  rake
48
52
  rspec
53
+ rspec_junit_formatter
49
54
  rubocop
55
+ rubocop-rspec
50
56
  slack_block_kit!
51
57
 
52
58
  BUNDLED WITH
data/README.md CHANGED
@@ -1,6 +1,17 @@
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)
3
+
1
4
  # Slack::BlockKit
2
5
 
3
- TODO
6
+ A collection of ruby objects that represent Slack's block kit.
7
+
8
+ You can play around with the block kit using [Slack's block kit builder!](https://api.slack.com/tools/block-kit-builder)
9
+
10
+ The 'blocks' availables are split in line with how Slack documents them, that is:
11
+
12
+ - `Slack::BlockKit::Layout` contains the [Layout blocks](https://api.slack.com/reference/messaging/blocks)
13
+ - `Slack::BlockKit::Element` contains the [Block elements](https://api.slack.com/reference/messaging/block-elements)
14
+ - `Slack::BlockKit::Composition` contains the [Message composition objects](https://api.slack.com/reference/messaging/composition-objects)
4
15
 
5
16
  ## Installation
6
17
 
@@ -30,6 +41,8 @@ require 'slack/block_kit'
30
41
 
31
42
  Bug reports and pull requests are welcome on GitHub at https://github.com/CGA1123/slack_block_kit-ruby
32
43
 
44
+ See [issues](https://github.com/CGA1123/slack_block_kit-ruby/issues) if you want any inspiration as to what to help with!
45
+
33
46
  ## License
34
47
 
35
48
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -4,12 +4,23 @@ module Slack
4
4
  module BlockKit
5
5
  module Composition; end
6
6
  module Element; end
7
- module Layout;end
7
+ module Layout; end
8
8
 
9
- VERSION = '0.1.0'
9
+ VERSION = '0.2.0'
10
10
 
11
11
  Dir[File.join(__dir__, 'block_kit', 'composition', '*.rb')].each { |file| require file }
12
12
  Dir[File.join(__dir__, 'block_kit', 'element', '*.rb')].each { |file| require file }
13
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 }
15
+
16
+ module_function
17
+
18
+ def blocks
19
+ blocks = Blocks.new
20
+
21
+ yield(blocks) if block_given?
22
+
23
+ blocks
24
+ end
14
25
  end
15
26
  end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Slack
4
+ module BlockKit
5
+ # Blocks are a series of components that can be combined to create visually
6
+ # rich and compellingly interactive messages.
7
+ #
8
+ # https://api.slack.com/reference/messaging/blocks
9
+ class Blocks
10
+ attr_accessor :blocks
11
+
12
+ def initialize
13
+ @blocks = []
14
+
15
+ yield(self) if block_given?
16
+ end
17
+
18
+ def actions(block_id: nil)
19
+ block = Layout::Actions.new(block_id: block_id)
20
+
21
+ yield(block) if block_given?
22
+
23
+ append(block)
24
+ end
25
+
26
+ def context(block_id: nil)
27
+ block = Layout::Context.new(block_id: block_id)
28
+
29
+ yield(block) if block_given?
30
+
31
+ append(block)
32
+ end
33
+
34
+ def divider(block_id: nil)
35
+ block = Layout::Divider.new(block_id: block_id)
36
+
37
+ append(block)
38
+ end
39
+
40
+ def image(url:, alt_text:, title: nil, block_id: nil, emoji: nil)
41
+ block = Layout::Image.new(
42
+ url: url,
43
+ alt_text: alt_text,
44
+ title: title,
45
+ block_id: block_id,
46
+ emoji: emoji
47
+ )
48
+
49
+ append(block)
50
+ end
51
+
52
+ def section(block_id: nil)
53
+ block = Layout::Section.new(block_id: block_id)
54
+
55
+ yield(block) if block_given?
56
+
57
+ append(block)
58
+ end
59
+
60
+ def append(block)
61
+ @blocks << block
62
+
63
+ self
64
+ end
65
+
66
+ def as_json(*)
67
+ @blocks.map(&:as_json)
68
+ end
69
+ end
70
+ end
71
+ end
@@ -3,12 +3,40 @@
3
3
  module Slack
4
4
  module BlockKit
5
5
  module Composition
6
+ # An object that defines a dialog that provides a confirmation step to any
7
+ # interactive element. This dialog will ask the user to confirm their
8
+ # action by offering confirm and deny buttons.
9
+ #
10
+ # https://api.slack.com/reference/messaging/composition-objects#confirm
6
11
  class ConfirmationDialog
7
- def initialize(title:, text:, confirm:, deny:)
8
- @title = title
9
- @text = text
10
- @confirm = confirm
11
- @deny = deny
12
+ def title(text:, emoji: nil)
13
+ @title = PlainText.new(text: text, emoji: emoji)
14
+
15
+ self
16
+ end
17
+
18
+ def confirm(text:, emoji: nil)
19
+ @confirm = PlainText.new(text: text, emoji: emoji)
20
+
21
+ self
22
+ end
23
+
24
+ def deny(text:, emoji: nil)
25
+ @deny = PlainText.new(text: text, emoji: emoji)
26
+
27
+ self
28
+ end
29
+
30
+ def plain_text(text:, emoji: nil)
31
+ @text = PlainText.new(text: text, emoji: emoji)
32
+
33
+ self
34
+ end
35
+
36
+ def mrkdwn(text:, verbatim: nil)
37
+ @text = Mrkdwn.new(text: text, verbatim: verbatim)
38
+
39
+ self
12
40
  end
13
41
 
14
42
  def as_json(*)
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Slack
4
+ module BlockKit
5
+ module Composition
6
+ # An object containing some text, formatted using Slack's "mrkdwn".
7
+ #
8
+ # https://api.slack.com/reference/messaging/composition-objects#text
9
+ # https://api.slack.com/messaging/composing/formatting
10
+ class Mrkdwn
11
+ TYPE = 'mrkdwn'
12
+
13
+ def initialize(text:, verbatim: nil)
14
+ @text = text
15
+ @verbatim = verbatim
16
+ end
17
+
18
+ def as_json(*)
19
+ {
20
+ type: TYPE,
21
+ text: @text,
22
+ verbatim: @verbatim
23
+ }.compact
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -3,9 +3,13 @@
3
3
  module Slack
4
4
  module BlockKit
5
5
  module Composition
6
+ # An object that represents a single selectable item in a select menu.
7
+ #
8
+ # https://api.slack.com/reference/messaging/composition-objects#option
9
+ # https://api.slack.com/reference/messaging/block-elements#select
6
10
  class Option
7
- def initialize(text:, value:)
8
- @text = text
11
+ def initialize(value:, text:, emoji: nil)
12
+ @text = PlainText.new(text: text, emoji: emoji)
9
13
  @value = value
10
14
  end
11
15
 
@@ -3,16 +3,30 @@
3
3
  module Slack
4
4
  module BlockKit
5
5
  module Composition
6
+ # Provides a way to group options in a select menu.
7
+ #
8
+ # https://api.slack.com/reference/messaging/composition-objects#option-group
9
+ # https://api.slack.com/reference/messaging/block-elements#select
6
10
  class OptionGroup
7
- def initialize(label:, options:)
8
- @label = label
9
- @options = options
11
+ attr_accessor :options
12
+
13
+ def initialize(label:, emoji: nil)
14
+ @label = PlainText.new(text: label, emoji: emoji)
15
+ @options = []
16
+
17
+ yield(self) if block_given?
18
+ end
19
+
20
+ def option(text:, value:, emoji: nil)
21
+ @options << Option.new(text: text, value: value, emoji: emoji)
22
+
23
+ self
10
24
  end
11
25
 
12
26
  def as_json(*)
13
27
  {
14
28
  label: @label.as_json,
15
- options: options.map(&:as_json)
29
+ options: @options.map(&:as_json)
16
30
  }
17
31
  end
18
32
  end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Slack
4
+ module BlockKit
5
+ module Composition
6
+ # An object containing some text, formatted using plain text.
7
+ #
8
+ # https://api.slack.com/reference/messaging/composition-objects#text
9
+ class PlainText
10
+ TYPE = 'plain_text'
11
+
12
+ def initialize(text:, emoji: nil)
13
+ @text = text
14
+ @emoji = emoji
15
+ end
16
+
17
+ def as_json(*)
18
+ {
19
+ type: TYPE,
20
+ text: @text,
21
+ emoji: @emoji
22
+ }.compact
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -3,15 +3,31 @@
3
3
  module Slack
4
4
  module BlockKit
5
5
  module Element
6
+ # An interactive element that inserts a button.
7
+ # The button can be a trigger for anything from opening a simple link
8
+ # to starting a complex workflow.
9
+ #
10
+ # https://api.slack.com/reference/messaging/block-elements#button
6
11
  class Button
7
12
  TYPE = 'button'
8
13
 
9
- def initialize(text:, action_id:, url: nil, value: nil, confirm: nil)
10
- @text = text
14
+ attr_accessor :confirm
15
+
16
+ def initialize(text:, action_id:, emoji: nil, url: nil, value: nil)
17
+ @text = Composition::PlainText.new(text: text, emoji: emoji)
11
18
  @action_id = action_id
12
19
  @url = url
13
20
  @value = value
14
- @confirm = confirm
21
+
22
+ yield(self) if block_given?
23
+ end
24
+
25
+ def confirmation_dialog
26
+ @confirm = Composition::ConfirmationDialog.new
27
+
28
+ yield(@confirm) if block_given?
29
+
30
+ @confirm
15
31
  end
16
32
 
17
33
  def as_json(*)