slackened 0.0.2 → 0.0.4

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: 131cd9af2cc7798da89323458bdb71d379009074849eaa1afc2d1497aa73491d
4
- data.tar.gz: 1ef60c6aa2368e38b41f555f64bd49804f87832d2ba9cf58a58569045485c744
3
+ metadata.gz: 1bad9043ef7f4e72714275b03a7fb6fe42614d832c7140518db72606cbe2f923
4
+ data.tar.gz: bd67503ad085cd0a662ea3bfc08eb6263a2022f137fd01e0a6c06771a6548fc7
5
5
  SHA512:
6
- metadata.gz: 6350be07eb3211b1d01035c657213df54d33ab1a8729749faf8aa7dbd3a66f075e336959d35fc538dba78de5f63ccbd1452b40d47c4a14cc5f58723c25c1f293
7
- data.tar.gz: bfce28774bab1611467e07016506b7694e4372fab927286e9158d6a05e4e6dbdafed48e9f905ff144aa31ab2b87d4bdf71a409ff0aee92e731fdeaa78eef2183
6
+ metadata.gz: d546b2be2252060e8d8345a5ae56c5aa3cbdc1856f7c22bc28fb1586f04e561685cfa1763d94eabba73cd3fc6b76db1dbff2e6a8e4ba03f250938c4f40286e1f
7
+ data.tar.gz: 97727c761a96d7f0f16a7c351e13f68880e86c50e15621e9c23655ae9706d69388c024fb3aa4bd234f80962bbfadf9925b1ad07152071a452a28a0c10af51b00
checksums.yaml.gz.sig CHANGED
Binary file
@@ -8,6 +8,7 @@ module Slackened
8
8
  module Blocks
9
9
  class Actions < Slackened::BlockKit::Blocks::Base
10
10
  MAX_LENGTH = 25
11
+ ELEMENTS = %i(button checkboxes datepicker datetimepicker email_text_input file_input image multi_static_select multi_external_select multi_users_select multi_conversations_select multi_channels_select number_input overflow plain_text_input radio_buttons rich_text_input option_groups external_select users_select conversations_select channels_select timepicker url_text_input workflow_button)
11
12
 
12
13
  def initialize(*elements)
13
14
  raise MinimumElementsError if elements.length.zero?
@@ -15,7 +16,11 @@ module Slackened
15
16
 
16
17
  set({
17
18
  type: :actions,
18
- elements:
19
+ elements: elements.map do |element|
20
+ raise InvalidElement unless ELEMENTS.include? element.block[:type]
21
+
22
+ element
23
+ end
19
24
  })
20
25
 
21
26
  self
@@ -14,6 +14,9 @@ module Slackened
14
14
  class MaximumElementsError < StandardError; end
15
15
 
16
16
  class MustBeString < StandardError; end
17
+ class MustBeHash < StandardError; end
18
+
19
+ class InvalidElement < StandardError; end
17
20
 
18
21
  class Base
19
22
  attr_accessor :block
@@ -10,7 +10,7 @@ module Slackened
10
10
  MAX_LENGTH = 10
11
11
 
12
12
  def initialize(*elements)
13
- raise TooManyElementsError, "#{elements.count} can't be greater than #{MAX_LENGTH}" if elements.length > MAX_LENGTH
13
+ raise MaximumElementsError, "#{elements.count} can't be greater than #{MAX_LENGTH}" if elements.length > MAX_LENGTH
14
14
 
15
15
  # TODO: need to allow for image
16
16
  # https://api.slack.com/reference/block-kit/blocks#context
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'base'
4
+
5
+ module Slackened
6
+ module BlockKit
7
+ # proof of concept
8
+ module Blocks
9
+ class Custom < Slackened::BlockKit::Blocks::Base
10
+ def initialize(block)
11
+ raise MustBeHash unless block.is_a? Hash
12
+
13
+ set(block)
14
+
15
+ self
16
+ end
17
+
18
+ def to_h
19
+ @block.to_h
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -10,7 +10,7 @@ module Slackened
10
10
  MAX_LENGTH = 150
11
11
 
12
12
  def initialize(plain_text)
13
- raise TooManyCharactersError, "#{plain_text} can't be greater than #{MAX_LENGTH}" if plain_text.length > MAX_LENGTH
13
+ raise MaximumCharactersError, "#{plain_text} can't be greater than #{MAX_LENGTH}" if plain_text.length > MAX_LENGTH
14
14
  raise MustBeString unless plain_text.is_a? String
15
15
 
16
16
  set({
@@ -10,7 +10,7 @@ module Slackened
10
10
  MAX_LENGTH = 10
11
11
 
12
12
  def initialize(*fields) # rubocop:disable Metrics/MethodLength
13
- raise TooManyFieldsError, "#{fields.count} can't be greater than #{MAX_LENGTH}" if fields.length > MAX_LENGTH
13
+ raise MaximumFieldsError, "#{fields.count} can't be greater than #{MAX_LENGTH}" if fields.length > MAX_LENGTH
14
14
  raise MustBeString unless fields.all? { |f| f.is_a? String }
15
15
 
16
16
  if fields.one?
@@ -10,7 +10,7 @@ module Slackened
10
10
  MAX_LENGTH = 3000
11
11
 
12
12
  def initialize(markdown)
13
- raise TooManyCharactersError, "#{markdown.length} can't be greater than #{MAX_LENGTH}" if markdown.length > MAX_LENGTH
13
+ raise MaximumCharactersError, "#{markdown.length} can't be greater than #{MAX_LENGTH}" if markdown.length > MAX_LENGTH
14
14
 
15
15
  set({
16
16
  type: :mrkdwn,
@@ -8,9 +8,6 @@ module Slackened
8
8
  module Blocks
9
9
  extend Forwardable
10
10
 
11
- # alphabetical
12
- def_delegators self, :actions, :button, :context, :divider, :header, :section, :text
13
-
14
11
  # alphabetical
15
12
  class << self
16
13
  def actions(*elements)
@@ -25,6 +22,10 @@ module Slackened
25
22
  Context.new(*elements)
26
23
  end
27
24
 
25
+ def custom(block)
26
+ Custom.new(block)
27
+ end
28
+
28
29
  def divider
29
30
  Divider.new
30
31
  end
@@ -41,6 +42,10 @@ module Slackened
41
42
  Text.new(*args)
42
43
  end
43
44
  end
45
+
46
+ # alphabetical
47
+ def_delegators self, :actions, :button, :context, :custom, :divider, :header, :section, :text
48
+
44
49
  end
45
50
  end
46
51
  end
@@ -7,12 +7,16 @@ module Slackened
7
7
  attr_accessor :blocks
8
8
 
9
9
  def initialize
10
- @blocks = []
10
+ setup!
11
11
  end
12
12
 
13
13
  def row(row)
14
14
  blocks.push(row)
15
15
  end
16
+
17
+ def setup!
18
+ @blocks = []
19
+ end
16
20
  end
17
21
  end
18
22
  end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Slackened
4
+ class Error < StandardError
5
+ attr_reader :response
6
+
7
+ def initialize(http_response)
8
+ @response = http_response
9
+
10
+ super("#{@response.code} #{@response.message}: #{@response.body}")
11
+ end
12
+ end
13
+ end