slkecho 1.2.1 → 1.4.0

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: b531f04eb873f7fa6e28b2bc17560e49b0f0a2cd87885cc00e7bcc566f637fbd
4
- data.tar.gz: 6203249d51a01d0280ddced3801263f0f78efd92206f01a7bd5d4f82e0974f23
3
+ metadata.gz: 60840e25954d5f27219da1751cc8afd0659d8fad0011d9801f392d73eff0fbdd
4
+ data.tar.gz: 01146cb293d39c8e1d7b01ff6748dbca25c3f6a35316b24ec5ef2ddb951d5f62
5
5
  SHA512:
6
- metadata.gz: 2f2ad0611bb599758005d228228396326649a6fb625d42880dc1c375a2a5bea487c88f30ea203677de215a362273711129e06cb3329911b0cdc5f58f28d254b7
7
- data.tar.gz: ad3c3eac4b13c6f7585f88f86c3f81476a6892e433d2a0433368fe23598860de3caa86be00b7cb0f9371febab40e8ada5775f27eb9b32add219847f9bb0c8e20
6
+ metadata.gz: 6a61dc7880593a6cd2f4b53be89f5db6ec22431d086640e770092925751e6cb049f4fe852e061cc8524e69ee99c765134de4a178b31a343cb922aa6d5fcb9be1
7
+ data.tar.gz: fc30c5af4a5fca0defd1a3e87651ff4389e1a19767a5ab16915864d95341caa47abaa34a28d3afdfceb113fcc44f8767e24978565b9859934a41c2040b0221c1
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [v1.4.0] - 2024-01-09
4
+
5
+ - feat: Add --icon-emoji option
6
+
7
+ ## [v1.3.0] - 2024-01-08
8
+
9
+ - chore: Improved description of username option
10
+ - feat: Add --icon-url option
11
+ - refactor: Remove `Slkecho::Options` initialize method
12
+ - refactor: Summarize arguments of `Slkecho::SlackRequest::PostMessage#request` to params
13
+ - refactor: Summarize arguments of `Slkecho::SlackClient#post_message` to params
14
+
3
15
  ## [v1.2.1] - 2024-01-08
4
16
 
5
17
  - fix: Not implemented to username specified
data/README.md CHANGED
@@ -50,6 +50,10 @@ Specify mention to post message. user email or user id (starts `U`).
50
50
 
51
51
  Specify the username for the published message.
52
52
 
53
+ #### --icon-emoji <emoji> (optional)
54
+
55
+ Specify an emoji for the speaker's icon. e.g.) `:smile:`
56
+
53
57
  ## Contributing
54
58
 
55
59
  Bug reports and pull requests are welcome on GitHub at https://github.com/okonomi/slkecho.
data/lib/slkecho/cli.rb CHANGED
@@ -16,13 +16,7 @@ module Slkecho
16
16
 
17
17
  user_id = mention_to_user_id(options.mention)
18
18
 
19
- @slack_client.post_message(
20
- channel: options.channel,
21
- message: options.message,
22
- subject: options.subject,
23
- user_id: user_id,
24
- username: options.username
25
- )
19
+ @slack_client.post_message(post_message_params_from(options, user_id))
26
20
  end
27
21
 
28
22
  def mention_to_user_id(mention)
@@ -35,6 +29,18 @@ module Slkecho
35
29
  user["id"]
36
30
  end
37
31
 
32
+ def post_message_params_from(options, user_id)
33
+ Slkecho::SlackClient::PostMessageParams.new(
34
+ channel: options.channel,
35
+ message: options.message,
36
+ subject: options.subject,
37
+ user_id: user_id,
38
+ username: options.username,
39
+ icon_url: options.icon_url,
40
+ icon_emoji: options.icon_emoji
41
+ )
42
+ end
43
+
38
44
  def self.run(argv)
39
45
  cli = new(
40
46
  option_parser: Slkecho::OptionParser.new,
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Slkecho
4
4
  class OptionParser
5
- def option_parser
5
+ def option_parser # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
6
6
  @option_parser ||= ::OptionParser.new do |o|
7
7
  o.banner = "Usage: slkecho [options] message"
8
8
  o.program_name = "slkecho"
@@ -10,7 +10,9 @@ module Slkecho
10
10
  o.on("-c", "--channel CHANNEL", "Slack channel to post the message") { @options.channel = _1 }
11
11
  o.on("-s", "--subject SUBJECT", "Subject of message") { @options.subject = _1 }
12
12
  o.on("-m", "--mention EMAIL", "Mention to user by email") { @options.mention = _1 }
13
- o.on("--username USERNAME", "Username to post the message") { @options.username = _1 }
13
+ o.on("--username USERNAME", "Set your bot's user name") { @options.username = _1 }
14
+ o.on("--icon-url ICON_URL", "URL to an image to use as the icon for this message") { @options.icon_url = _1 }
15
+ o.on("--icon-emoji ICON_EMOJI", "Emoji to use as the icon for this message") { @options.icon_emoji = _1 }
14
16
  end
15
17
  end
16
18
 
@@ -2,14 +2,6 @@
2
2
 
3
3
  module Slkecho
4
4
  class Options
5
- attr_accessor :channel, :subject, :mention, :message, :username
6
-
7
- def initialize(channel: nil, subject: nil, mention: nil, message: nil, username: nil)
8
- @channel = channel
9
- @subject = subject
10
- @mention = mention
11
- @message = message
12
- @username = username
13
- end
5
+ attr_accessor :channel, :subject, :mention, :message, :username, :icon_url, :icon_emoji
14
6
  end
15
7
  end
@@ -9,6 +9,8 @@ require_relative "slack_request/post_message"
9
9
 
10
10
  module Slkecho
11
11
  class SlackClient
12
+ PostMessageParams = Slkecho::SlackRequest::PostMessage::Params
13
+
12
14
  def initialize(slack_api_token:)
13
15
  @slack_api_token = slack_api_token
14
16
 
@@ -26,10 +28,9 @@ module Slkecho
26
28
  .request(email: email)
27
29
  end
28
30
 
29
- def post_message(channel:, message:, subject: nil, user_id: nil, username: nil)
31
+ def post_message(params)
30
32
  Slkecho::SlackRequest::PostMessage.new(slack_api_token: @slack_api_token)
31
- .request(channel: channel, message: message, subject: subject, user_id: user_id,
32
- username: username)
33
+ .request(params)
33
34
  end
34
35
  end
35
36
  end
@@ -3,6 +3,8 @@
3
3
  module Slkecho
4
4
  module SlackRequest
5
5
  class PostMessage
6
+ Params = Struct.new(:channel, :message, :subject, :user_id, :username, :icon_url, :icon_emoji, keyword_init: true)
7
+
6
8
  def initialize(slack_api_token:)
7
9
  @slack_api_token = slack_api_token
8
10
 
@@ -15,11 +17,10 @@ module Slkecho
15
17
  }
16
18
  end
17
19
 
18
- def request(channel:, message:, subject: nil, user_id: nil, username: nil)
20
+ def request(params)
19
21
  response = @http.post(
20
22
  @uri.path,
21
- request_body(channel: channel, message: message, subject: subject, user_id: user_id,
22
- username: username).to_json,
23
+ request_body(params).to_json,
23
24
  @headers
24
25
  )
25
26
  raise Slkecho::SlackRequestError, response.body unless response.is_a?(Net::HTTPSuccess)
@@ -30,14 +31,16 @@ module Slkecho
30
31
  true
31
32
  end
32
33
 
33
- def request_body(channel:, message:, subject: nil, user_id: nil, username: nil)
34
+ def request_body(params)
34
35
  body = {
35
- "channel" => channel,
36
+ "channel" => params.channel,
36
37
  "blocks" => [],
37
- "username" => username
38
+ "username" => params.username,
39
+ "icon_url" => params.icon_url,
40
+ "icon_emoji" => params.icon_emoji
38
41
  }
39
- body["blocks"] << header_block(subject) unless subject.nil?
40
- body["blocks"] << section_block(message, user_id: user_id)
42
+ body["blocks"] << header_block(params.subject) unless params.subject.nil?
43
+ body["blocks"] << section_block(params.message, user_id: params.user_id)
41
44
 
42
45
  body
43
46
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Slkecho
4
- VERSION = "1.2.1"
4
+ VERSION = "1.4.0"
5
5
  end
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: 1.2.1
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - okonomi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-01-08 00:00:00.000000000 Z
11
+ date: 2024-01-09 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Post message to Slack like echo command.
14
14
  email: