slkecho 2.1.0 → 2.1.1
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 +4 -4
- data/CHANGELOG.md +9 -0
- data/lib/slkecho/blocks_builder.rb +4 -4
- data/lib/slkecho/slack_request/lookup_user_by_email.rb +11 -9
- data/lib/slkecho/slack_request/post_message.rb +15 -13
- data/lib/slkecho/slack_request.rb +19 -0
- data/lib/slkecho/version.rb +1 -1
- data/lib/slkecho.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4316f376c8717965ab2c3518c054be6d983bc005d343803305bdb90f2bc0b963
|
4
|
+
data.tar.gz: 11cf2ec4be6b49b6a4d4d566ac9c767036ae91871c3ebe39e4a760198f13e367
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25a8acf5fd4f84c7d76b91ac9a44e99e780e398c0b878dac33352e621e5139dc09d9d13b041eaec04227b20c7996596799656b5cf367195d65aeb10b959507e2
|
7
|
+
data.tar.gz: da7a9a3a06f06910e7660f5408c0a9c9a3b1d0f057c02ad88b5c9bc10ba96f559141b956659a6993b6b04c611a6fde5f0b26a06998c39ad9651270ad21d877f0
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [v2.1.1] - 2024-02-12
|
4
|
+
|
5
|
+
- chore: Add ruby-lsp gem
|
6
|
+
- refactor: Parse JSON with symbolize names
|
7
|
+
- refactor: Make request body with symbolize keys
|
8
|
+
- refactor: Make blocks with symbolize keys
|
9
|
+
- refactor: Extract http response checking
|
10
|
+
- test: Introduce saharspec gem
|
11
|
+
|
3
12
|
## [v2.1.0] - 2024-01-19
|
4
13
|
|
5
14
|
- feat: Add --message-as-blocks option
|
@@ -7,10 +7,10 @@ module Slkecho
|
|
7
7
|
def build_from_message(message, user_id = nil)
|
8
8
|
[
|
9
9
|
{
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
type: "section",
|
11
|
+
text: {
|
12
|
+
type: "mrkdwn",
|
13
|
+
text: user_id.nil? ? message : "<@#{user_id}> #{message}"
|
14
14
|
}
|
15
15
|
}
|
16
16
|
]
|
@@ -4,6 +4,8 @@ require "net/http"
|
|
4
4
|
require "uri"
|
5
5
|
require "json"
|
6
6
|
|
7
|
+
require_relative "../slack_request"
|
8
|
+
|
7
9
|
module Slkecho
|
8
10
|
module SlackRequest
|
9
11
|
class LookupUserByEmail
|
@@ -20,18 +22,18 @@ module Slkecho
|
|
20
22
|
end
|
21
23
|
|
22
24
|
def request(email:)
|
23
|
-
|
24
|
-
|
25
|
-
rescue StandardError => e
|
26
|
-
raise Slkecho::SlackApiHttpError, e.message
|
25
|
+
user_info = Slkecho::SlackRequest.send_request do
|
26
|
+
@http.get(uri_with_query(@uri, { email: email }), @headers)
|
27
27
|
end
|
28
|
-
raise Slkecho::SlackApiHttpError, response.body unless response.is_a?(Net::HTTPSuccess)
|
29
28
|
|
30
|
-
user_info
|
31
|
-
|
32
|
-
|
29
|
+
case user_info
|
30
|
+
in { ok: true, user: user }
|
31
|
+
user
|
32
|
+
in { ok: false, error: error }
|
33
|
+
raise Slkecho::SlackApiResultError, "user not found. (#{email})" if error == "users_not_found"
|
33
34
|
|
34
|
-
|
35
|
+
raise Slkecho::SlackApiResultError, error
|
36
|
+
end
|
35
37
|
end
|
36
38
|
|
37
39
|
def uri_with_query(uri, params)
|
@@ -4,6 +4,8 @@ require "net/http"
|
|
4
4
|
require "uri"
|
5
5
|
require "json"
|
6
6
|
|
7
|
+
require_relative "../slack_request"
|
8
|
+
|
7
9
|
module Slkecho
|
8
10
|
module SlackRequest
|
9
11
|
class PostMessage
|
@@ -22,26 +24,26 @@ module Slkecho
|
|
22
24
|
end
|
23
25
|
|
24
26
|
def request(params)
|
25
|
-
|
26
|
-
@
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
result = Slkecho::SlackRequest.send_request do
|
28
|
+
@http.post(
|
29
|
+
@uri.path,
|
30
|
+
request_body(params).to_json,
|
31
|
+
@headers
|
32
|
+
)
|
33
|
+
end
|
31
34
|
|
32
|
-
result
|
33
|
-
raise Slkecho::SlackApiResultError, result["error"] unless result["ok"]
|
35
|
+
raise Slkecho::SlackApiResultError, result[:error] unless result[:ok]
|
34
36
|
|
35
37
|
true
|
36
38
|
end
|
37
39
|
|
38
40
|
def request_body(params)
|
39
41
|
{
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
42
|
+
channel: params.channel,
|
43
|
+
blocks: params.blocks,
|
44
|
+
username: params.username,
|
45
|
+
icon_url: params.icon_url,
|
46
|
+
icon_emoji: params.icon_emoji
|
45
47
|
}
|
46
48
|
end
|
47
49
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Slkecho
|
4
|
+
module SlackRequest
|
5
|
+
def self.send_request
|
6
|
+
return unless block_given?
|
7
|
+
|
8
|
+
response = yield
|
9
|
+
raise Slkecho::SlackApiError, "API Response could not be retrieved." unless response.is_a?(Net::HTTPResponse)
|
10
|
+
raise Slkecho::SlackApiHttpError, "#{response.code} #{response.message}" unless response.is_a?(Net::HTTPSuccess)
|
11
|
+
|
12
|
+
begin
|
13
|
+
JSON.parse(response.body, symbolize_names: true)
|
14
|
+
rescue JSON::ParserError
|
15
|
+
raise Slkecho::SlackApiError, "API Response is not JSON."
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/slkecho/version.rb
CHANGED
data/lib/slkecho.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slkecho
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- okonomi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-02-12 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Post message to Slack like echo command.
|
14
14
|
email:
|
@@ -29,6 +29,7 @@ files:
|
|
29
29
|
- lib/slkecho/option_parser.rb
|
30
30
|
- lib/slkecho/options.rb
|
31
31
|
- lib/slkecho/slack_client.rb
|
32
|
+
- lib/slkecho/slack_request.rb
|
32
33
|
- lib/slkecho/slack_request/lookup_user_by_email.rb
|
33
34
|
- lib/slkecho/slack_request/post_message.rb
|
34
35
|
- lib/slkecho/version.rb
|