actionslack 0.1.0 → 0.1.2

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: 7d806e62f1769081a642b1bc493bb2bff9385e12a42695c0efd50ee40a6c8d05
4
- data.tar.gz: 8bb05daac3e625e206c7ba47141fe88272831b531513c732916a4acaeb8e1635
3
+ metadata.gz: 21fc855745a83c67aefd2391434f8dede96aff1b45ae677c2abdaec2047933fa
4
+ data.tar.gz: b09236edbb043bf9bbd6cbc1f50472c1dd1eef5fc11821174fd9bd160400c467
5
5
  SHA512:
6
- metadata.gz: ee9728f120912769b9eccf32bd4a77c8b63d1cd5a888a7f0ea25a2019216e31aeb528c461cb3a6fd10dc193405999cde8ab8f336be507de6f8cf95d564a9c4f1
7
- data.tar.gz: 030caa0c7a13a46b7bdaadc5607bce2c8114b89c78a40785b21e02d721ba68c561e50235b33278e012ea4457336854c11bc82c6c921c15f78e145fb75cbeb457
6
+ metadata.gz: 7b194b4a378398b8b8ff13b5d6b2fd906288b565ac33f392fb72467356f30d63f0e7e6e144621be04adaf95e713182277ec49521fa8b5298900c6d9d0f82acd8
7
+ data.tar.gz: e46830da21df1ad7ce58863e6e09a6113b7e4d847af2ec44f3592f80a4e8a77b2617cf6b471796edbf69e357941e7cc1edf28624c6c2e07a3a4f1e308bf2d69c
data/LICENSE.txt ADDED
@@ -0,0 +1,19 @@
1
+ Copyright © 2022 Akito Hikasa
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the "Software"),
5
+ to deal in the Software without restriction, including without limitation
6
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
7
+ and/or sell copies of the Software, and to permit persons to whom the
8
+ Software is furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included
11
+ in all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
15
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
17
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
18
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
19
+ OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -4,13 +4,11 @@ ActionSlack is a framework that supports your implementation of slack notificati
4
4
 
5
5
  ## Installation
6
6
 
7
- Install the gem and add to the application's Gemfile by executing:
8
-
9
- $ bundle add actionslack
10
-
11
- If bundler is not being used to manage dependencies, install the gem by executing:
7
+ ```ruby
8
+ gem 'actionslack', require: 'action_slack'
9
+ ```
12
10
 
13
- $ gem install actionslack
11
+ That's all
14
12
 
15
13
  ## Usage
16
14
 
@@ -55,12 +53,27 @@ person = Person.new('John')
55
53
  WelcomingNewCommer.notify(new_person: person)
56
54
  ```
57
55
 
58
- ## Development
56
+ Optionally, three configuration items are available.
57
+
58
+ Especially, there are three options for type: local, testflight, and production.
59
+
60
+ In `local`, ActionSlack does not post to Slack, only writes logs.
61
+ In `testflight`, ActionSlack will post to Slack, but adds an obvious prefix to the message to tell you that it is not a notice from a production environment.
62
+ So, I recommend to use it for checking connections.
59
63
 
60
- I will not release this to rubygems until becomes stable.
61
- Until then, I develop this privately.
64
+ I know you understand about `production` mode.
65
+
66
+ ```ruby
67
+ ActionSlack.configure do |config|
68
+ config.filepath = "#{PROJECT_ROOT}/webhooks.yml"
69
+ config.async = false # then, we don't use ActiveJob for posting
70
+ config.type = :production
71
+ end
72
+ ```
73
+
74
+ ## Development
62
75
 
63
- I'm also planning providing rspec tools. Stay tuned.
76
+ I'm planning provide rspec tools.
64
77
 
65
78
  ## Contributing
66
79
 
@@ -12,11 +12,7 @@ module ActionSlack
12
12
  def notify(**kargs)
13
13
  instance = create(**kargs)
14
14
 
15
- if ActionSlack.configuration.async
16
- SendJob.perform_later(url: instance.url, message: instance.message)
17
- else
18
- Notifier.notify(url: instance.url, message: instance.message)
19
- end
15
+ Notifier.notify(url: instance.url, message: instance.message)
20
16
  end
21
17
 
22
18
  def attributes=(attrs)
@@ -24,8 +24,18 @@ module ActionSlack
24
24
  @configuration = self.class.default_configuration.dup
25
25
  end
26
26
 
27
+ def async?
28
+ async
29
+ end
30
+
31
+ %i[local testflight production].each do |type_name|
32
+ define_method :"#{type_name}?" do
33
+ type_name == type
34
+ end
35
+ end
36
+
27
37
  set_default(:filepath, 'config/slack_webhooks.yml')
28
38
  set_default(:async, true)
29
- set_default(:env, :development)
39
+ set_default(:type, :local) # production, testflight, local
30
40
  end
31
41
  end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionSlack
4
+ class Logger < ::Logger; end
5
+ end
@@ -1,9 +1,31 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActionSlack
4
- class Notifier
5
- def self.notify(url:, message:)
6
- Slack::Notifier.new(url).post(text: message)
4
+ module Notifier
5
+ module_function
6
+
7
+ def notify(url:, message:)
8
+ message = ActionSlack.configuration.testflight? ? "[ActionSlack Test Posting]\n#{message}\n" : message
9
+
10
+ if ActionSlack.configuration.async?
11
+ notify_later(url, message)
12
+ else
13
+ notify_now(url, message)
14
+ end
15
+ end
16
+
17
+ def notify_now(url, message)
18
+ if ActionSlack.configuration.local?
19
+ ActionSlack.logger.debug { "Post to Slack webhook url: #{url}, message: \"#{message}\"" }
20
+ else
21
+ ActionSlack.logger.info { "Start posting to Slack webhook url: #{url}, message: \"#{message}\"" }
22
+ Slack::Notifier.new(url).post(text: message)
23
+ ActionSlack.logger.info 'Posted to Slack'
24
+ end
25
+ end
26
+
27
+ def notify_later(url, message)
28
+ SendJob.perform_later(url: url, message: message)
7
29
  end
8
30
  end
9
31
  end
@@ -2,8 +2,8 @@
2
2
 
3
3
  module ActionSlack
4
4
  class SendJob < ActiveJob::Base
5
- def perform(url:, message:)
6
- Notifier.notify(url: url, message: message)
5
+ def perform(url, message)
6
+ Notifier.__send__(:notify_now, url, message)
7
7
  end
8
8
  end
9
9
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActionSlack
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.2'
5
5
  end
@@ -26,9 +26,9 @@ module ActionSlack
26
26
 
27
27
  def load_yaml(src)
28
28
  if Psych::VERSION > '4.0'
29
- YAML.load(src, symbolize_names: true, aliases: true, freeze: true)
29
+ YAML.safe_load(src, symbolize_names: true, freeze: true)
30
30
  else
31
- YAML.safe_load(src)
31
+ YAML.safe_load(src, symbolize_names: true)
32
32
  end
33
33
  end
34
34
  end
data/lib/action_slack.rb CHANGED
@@ -4,6 +4,7 @@ require 'active_support'
4
4
  require 'active_support/core_ext'
5
5
  require 'yaml'
6
6
  require 'erb'
7
+ require 'logger'
7
8
  require 'slack-notifier'
8
9
 
9
10
  module ActionSlack
@@ -13,6 +14,7 @@ module ActionSlack
13
14
  autoload :Webhook
14
15
  autoload :Notifier
15
16
  autoload :Base
17
+ autoload :Logger
16
18
 
17
19
  autoload :SendJob if const_defined?(:ActiveJob)
18
20
 
@@ -24,5 +26,18 @@ module ActionSlack
24
26
  def configuration
25
27
  @configuration ||= Configuration.new
26
28
  end
29
+
30
+ def logger
31
+ @logger ||= ActionSlack::Logger.new($stdout, level: :info)
32
+ end
33
+
34
+ def logger=(logger)
35
+ if logger.nil?
36
+ self.logger.level = Logger::FATAL
37
+ return
38
+ end
39
+
40
+ @logger = logger
41
+ end
27
42
  end
28
43
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: actionslack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - kakubin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-11-03 00:00:00.000000000 Z
11
+ date: 2022-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  description: actionslack
56
70
  email:
57
71
  - wetsand.wfs@gmail.com
@@ -65,11 +79,13 @@ files:
65
79
  - CHANGELOG.md
66
80
  - CODE_OF_CONDUCT.md
67
81
  - Gemfile
82
+ - LICENSE.txt
68
83
  - README.md
69
84
  - Rakefile
70
85
  - lib/action_slack.rb
71
86
  - lib/action_slack/base.rb
72
87
  - lib/action_slack/configuration.rb
88
+ - lib/action_slack/logger.rb
73
89
  - lib/action_slack/notifier.rb
74
90
  - lib/action_slack/send_job.rb
75
91
  - lib/action_slack/version.rb
@@ -97,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
113
  - !ruby/object:Gem::Version
98
114
  version: '0'
99
115
  requirements: []
100
- rubygems_version: 3.3.7
116
+ rubygems_version: 3.0.3.1
101
117
  signing_key:
102
118
  specification_version: 4
103
119
  summary: actionslack