slkecho 1.2.0 → 1.3.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: 6d32f248314a8ecc59325cf6cb2092a53ef4bfed9e9866ad46c0ad09076e79d2
4
- data.tar.gz: 377be48a2826d3a0df573127cb06add79bb25a0a31fb4c152a7eb709faee127c
3
+ metadata.gz: '06487abc9f5c53432e2d6e93f0db427338c44d34c51e766b4bb9aa4b45c20e07'
4
+ data.tar.gz: f6e04c8fd4433d136d5d8262862d213a3aa8a1181d7fc03c8744cd20fe9b34cf
5
5
  SHA512:
6
- metadata.gz: 3aa071ad29e150bcb983f3c674ba6aaccda853fc8ff65fe93395a92e86e7e4190e39f5dcfcad9f88019b74986ccd2bba41556ee5a5b5f8a3d720686e072f12bb
7
- data.tar.gz: 6293abc9ec4d005d50fa5fdc1672e6e981713957ee3a9548ef86d9c2c0a4d2a9c4c8a1f2da06d19738ddad31613f9345159321df5dd59088cd65c3d17eb056cf
6
+ metadata.gz: 96d474087c4760de85be2bd90a6d3f144a24505396b7a6a5eaedc357fd1f010ec4164234202d620ccd3f5f30d75be3f4d69c8a907df578950919f1fa2f48d386
7
+ data.tar.gz: 8a27c49d64315fa4652c12a1736a350c3a31e68c305309ef6e4d4ebec8cdb6edf343dd32a75af5ae6e63fac6ef76d528a44bd5549fa83d310a62c21486c1cb1f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [v1.3.0] - 2024-01-08
4
+
5
+ - chore: Improved description of username option
6
+ - feat: Add --icon-url option
7
+ - refactor: Remove `Slkecho::Options` initialize method
8
+ - refactor: Summarize arguments of `Slkecho::SlackRequest::PostMessage#request` to params
9
+ - refactor: Summarize arguments of `Slkecho::SlackClient#post_message` to params
10
+
11
+ ## [v1.2.1] - 2024-01-08
12
+
13
+ - fix: Not implemented to username specified
14
+
3
15
  ## [v1.2.0] - 2024-01-08
4
16
 
5
17
  - feat: Add --username option
data/lib/slkecho/cli.rb CHANGED
@@ -16,12 +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
- )
19
+ @slack_client.post_message(post_message_params_from(options, user_id))
25
20
  end
26
21
 
27
22
  def mention_to_user_id(mention)
@@ -34,6 +29,17 @@ module Slkecho
34
29
  user["id"]
35
30
  end
36
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
+ )
41
+ end
42
+
37
43
  def self.run(argv)
38
44
  cli = new(
39
45
  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
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,8 @@ 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 }
14
15
  end
15
16
  end
16
17
 
@@ -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
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,9 +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)
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)
33
+ .request(params)
32
34
  end
33
35
  end
34
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, keyword_init: true)
7
+
6
8
  def initialize(slack_api_token:)
7
9
  @slack_api_token = slack_api_token
8
10
 
@@ -15,10 +17,10 @@ module Slkecho
15
17
  }
16
18
  end
17
19
 
18
- def request(channel:, message:, subject: nil, user_id: 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).to_json,
23
+ request_body(params).to_json,
22
24
  @headers
23
25
  )
24
26
  raise Slkecho::SlackRequestError, response.body unless response.is_a?(Net::HTTPSuccess)
@@ -29,14 +31,15 @@ module Slkecho
29
31
  true
30
32
  end
31
33
 
32
- def request_body(channel:, message:, subject: nil, user_id: nil, username: nil)
34
+ def request_body(params)
33
35
  body = {
34
- "channel" => channel,
36
+ "channel" => params.channel,
35
37
  "blocks" => [],
36
- "username" => username
38
+ "username" => params.username,
39
+ "icon_url" => params.icon_url
37
40
  }
38
- body["blocks"] << header_block(subject) unless subject.nil?
39
- body["blocks"] << section_block(message, user_id: user_id)
41
+ body["blocks"] << header_block(params.subject) unless params.subject.nil?
42
+ body["blocks"] << section_block(params.message, user_id: params.user_id)
40
43
 
41
44
  body
42
45
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Slkecho
4
- VERSION = "1.2.0"
4
+ VERSION = "1.3.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slkecho
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - okonomi