slack_message 1.6.0 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -3
- data/README.md +1 -1
- data/lib/slack_message/api.rb +10 -1
- data/lib/slack_message/dsl.rb +10 -2
- data/lib/slack_message.rb +3 -3
- data/slack_message.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a2cd232d81a66a48c9543a5b910c335bca7a82474a60472d03f7cffab3fce0d0
|
4
|
+
data.tar.gz: c27312311ff02ee414f2882461fe5ea9b5c07d9d8e99847ae7af33faf4a31283
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69352d5eb8d4f6837f66ba042817bfe0a51c3483356bbc64ded0cbc60fc7e72c084ea39df542a93bf79a6c0a8c4ad860cdb9791f28d807edb5b1c859b13f129f
|
7
|
+
data.tar.gz: 740af84829c6b258b4788b5f83901f242a5732e98737781efb288ee426ed232726823d9fdde453da6c7d83eb55607733e1d4b55757580676921b37abba1c70ad
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,11 @@
|
|
2
2
|
|
3
3
|
## [Unreleased]
|
4
4
|
|
5
|
+
## [1.7.0] - 2021-10-06
|
6
|
+
- Added new error messages when API configuration is wrong / missing.
|
7
|
+
- Fixed issue with `instance_eval` and using methods within block.
|
8
|
+
- Fixed issue with sectionless `list_item`.
|
9
|
+
|
5
10
|
## [1.6.0] - 2021-10-04
|
6
11
|
- Added `:default_channel` and `post_as` to deal with repetitive channel usage.
|
7
12
|
|
@@ -9,7 +14,7 @@
|
|
9
14
|
- Added `ol` and `ul` to sections w/ some formatting.
|
10
15
|
|
11
16
|
## [1.4.0] - 2021-09-27
|
12
|
-
-
|
17
|
+
- Changed `image` to `accessory_image` to differentiate between the image block
|
13
18
|
and the accessory image within a block.
|
14
19
|
|
15
20
|
## [1.3.0] - 2021-09-27
|
@@ -18,13 +23,12 @@
|
|
18
23
|
- Added warnings for potentially invalid URLs.
|
19
24
|
|
20
25
|
## [1.2.0] - 2021-09-26
|
21
|
-
-
|
26
|
+
- Fixed gemspec, which was entirely broken.
|
22
27
|
|
23
28
|
## [1.1.0] - 2021-09-26
|
24
29
|
- Expanded the README significantly w/ usage instructions.
|
25
30
|
- Added lots of error handling to requests.
|
26
31
|
|
27
32
|
## [1.0.0] - 2021-09-25
|
28
|
-
|
29
33
|
- Added the base gem w/ a DSL for constructing blocks using sections.
|
30
34
|
- Added a changelog, apparently.
|
data/README.md
CHANGED
@@ -240,11 +240,11 @@ DSL to include more of the block API itself.
|
|
240
240
|
|
241
241
|
Also, some behaviors that are still planned but not yet added:
|
242
242
|
|
243
|
+
* some API documentation amirite?
|
243
244
|
* allow custom http_options in configuration
|
244
245
|
* more of BlockKit's options
|
245
246
|
* any interactive elements at all (I don't understand them yet)
|
246
247
|
* more interesting return types for your message
|
247
|
-
* some way to specify default channel for a given profile (and omit param to post_to)
|
248
248
|
* richer text formatting (ul is currently a hack)
|
249
249
|
|
250
250
|
Contributing
|
data/lib/slack_message/api.rb
CHANGED
@@ -17,9 +17,16 @@ class SlackMessage::Api
|
|
17
17
|
|
18
18
|
if response.code != "200"
|
19
19
|
raise "Got an error back from the Slack API (HTTP #{response.code}):\n#{response.body}"
|
20
|
+
elsif response.body == ""
|
21
|
+
raise "Received empty 200 response from Slack when looking up user info. Check your API key."
|
22
|
+
end
|
23
|
+
|
24
|
+
begin
|
25
|
+
payload = JSON.parse(response.body)
|
26
|
+
rescue
|
27
|
+
raise "Unable to parse JSON response from Slack API\n#{response.body}"
|
20
28
|
end
|
21
29
|
|
22
|
-
payload = JSON.parse(response.body)
|
23
30
|
if payload.include?("error") && payload["error"] == "invalid_auth"
|
24
31
|
raise "Received an error because your authentication token isn't properly configured:\n#{response.body}"
|
25
32
|
elsif payload.include?("error")
|
@@ -48,6 +55,8 @@ class SlackMessage::Api
|
|
48
55
|
raise "Tried to send Slack message to non-existent channel or user '#{target}'"
|
49
56
|
elsif response.body == "missing_text_or_fallback_or_attachments"
|
50
57
|
raise "Tried to send Slack message with invalid payload."
|
58
|
+
elsif response.code == "302"
|
59
|
+
raise "Got 302 response while posting to Slack. Check your webhook URL for '#{profile[:handle]}'."
|
51
60
|
elsif response.code != "200"
|
52
61
|
raise "Got an error back from the Slack API (HTTP #{response.code}):\n#{response.body}"
|
53
62
|
end
|
data/lib/slack_message/dsl.rb
CHANGED
@@ -3,7 +3,11 @@ class SlackMessage::Dsl
|
|
3
3
|
|
4
4
|
EMSPACE = " " # unicode emspace
|
5
5
|
|
6
|
-
def initialize
|
6
|
+
def initialize(block)
|
7
|
+
# Delegate missing methods to caller scope. Thanks 2008:
|
8
|
+
# https://www.dan-manges.com/blog/ruby-dsls-instance-eval-with-delegation
|
9
|
+
@caller_self = eval("self", block.binding
|
10
|
+
|
7
11
|
@body = []
|
8
12
|
@default_section = Section.new
|
9
13
|
@custom_bot_name = nil
|
@@ -81,13 +85,17 @@ class SlackMessage::Dsl
|
|
81
85
|
@body
|
82
86
|
end
|
83
87
|
|
88
|
+
def method_missing(meth, *args, &blk)
|
89
|
+
@caller_self.send meth, *args, &blk
|
90
|
+
end
|
91
|
+
|
84
92
|
private
|
85
93
|
|
86
94
|
# when doing things that would generate new top-levels, first try
|
87
95
|
# to finish the implicit section.
|
88
96
|
def finalize_default_section
|
89
97
|
if default_section.has_content?
|
90
|
-
@body.push(default_section.
|
98
|
+
@body.push(default_section.render)
|
91
99
|
end
|
92
100
|
|
93
101
|
@default_section = Section.new
|
data/lib/slack_message.rb
CHANGED
@@ -16,7 +16,7 @@ module SlackMessage
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def self.post_to(target, as: :default, &block)
|
19
|
-
payload = Dsl.new.tap do |instance|
|
19
|
+
payload = Dsl.new(block).tap do |instance|
|
20
20
|
instance.instance_eval(&block)
|
21
21
|
end
|
22
22
|
|
@@ -27,7 +27,7 @@ module SlackMessage
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def self.post_as(profile_name, &block)
|
30
|
-
payload = Dsl.new.tap do |instance|
|
30
|
+
payload = Dsl.new(block).tap do |instance|
|
31
31
|
instance.instance_eval(&block)
|
32
32
|
end
|
33
33
|
|
@@ -43,7 +43,7 @@ module SlackMessage
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def self.build(&block)
|
46
|
-
Dsl.new.tap do |instance|
|
46
|
+
Dsl.new(block).tap do |instance|
|
47
47
|
instance.instance_eval(&block)
|
48
48
|
end.send(:render)
|
49
49
|
end
|
data/slack_message.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slack_message
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe Mastey
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-10-
|
11
|
+
date: 2021-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|