ms_teams_notification 1.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: bfb249a3e91d820836863718c53f9e86c2a454de8619faefb25e1b9720cf7640
4
+ data.tar.gz: c988cb1572833486317fde003f0cb9a8c54d36f9feb3bc6204408e5a3a416276
5
+ SHA512:
6
+ metadata.gz: 70f0fb885391cb86803aba55c243dbe51cd5a898ee943d068fdbcbcab8713bb1da6dd44d704521260cd98cb4c86e8198ca5a937a9c154d761d796f5948f43b8e
7
+ data.tar.gz: '0859660f2eae0ef259a3509151acfd7e54673da2d2e2b71b970071b5c487e1f6ac94a6c781a7e6c0baecaadbfee4f9bc220ac2d57db9ea9e89958885177b8934'
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ ms_teams_notification
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.3.1
data/.standard.yml ADDED
@@ -0,0 +1,3 @@
1
+ # For available configuration options, see:
2
+ # https://github.com/standardrb/standard
3
+ ruby_version: 3.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Abdullah Barrak
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # MS Teams Notifier
2
+
3
+ A ruby library from simple notification capablities for Microsoft Teams.
4
+
5
+ > Extracted from [volume sweeper](https://github.com/abarrak/volume_sweeper/blob/main/lib/volume_sweeper) tool.
6
+
7
+ ## Installation
8
+
9
+ Install the gem and add to the application's Gemfile by executing:
10
+
11
+ ```bash
12
+ bundle add ms_teams_notification
13
+ ```
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ ```bash
18
+ gem install ms_teams_notification
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ You can build your notifer per configuration:
24
+
25
+ ```ruby
26
+ opts = { ms_teams_webhook: "", notification_subject: "Notice: for service maintenance" }
27
+ notifier = MsTeamsNotification::Base.new **options
28
+ ```
29
+
30
+ **Optionally** you can formlate a rich message with formatter.
31
+ THe formatter accepts a hash of additional fields that will be appended as list after the message.
32
+
33
+ ```ruby
34
+ text = "The system will undergo maintenace today."
35
+ text_opts = { time: Time.now, support_phone: "9304-1343"}
36
+
37
+ message = MsTeamsNotification::Formatter.formlate_meessage text, text_opts
38
+ ```
39
+
40
+ Then, fire it:
41
+
42
+ ```ruby
43
+ notifier.send_ms_teams_notice message
44
+ ```
45
+
46
+
47
+ ## API Docs
48
+
49
+ The gem specs can [be found at RubyDocs.](https://www.rubydoc.info/gems/ms_teams_notification)
50
+
51
+ ## Contributing
52
+
53
+ Bug reports and pull requests are welcome [on GitHub](https://github.com/abarrak/ms_teams_notification).
54
+
55
+ ## License
56
+
57
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "minitest/test_task"
5
+
6
+ Minitest::TestTask.create
7
+
8
+ require "standard/rake"
9
+
10
+ task default: %i[test standard]
@@ -0,0 +1,62 @@
1
+ require 'uri'
2
+ require 'active_support/core_ext/object/blank'
3
+ require_relative 'logger'
4
+
5
+ module MsTeamsNotification
6
+ class Base
7
+
8
+ attr_reader :default_subject
9
+
10
+ def initialize **kwargs
11
+ @log = MsTeamsNotification::Logger.instance
12
+
13
+ setup_configuration **kwargs
14
+ configure_ms_teams
15
+ end
16
+
17
+ def send_ms_teams_notice text
18
+ return unless @webhook_url.present?
19
+
20
+ @log.msg "#{self_name}: sending ms teams notification."
21
+
22
+ request = Net::HTTP::Post.new @webhook_url.request_uri
23
+ request['Content-Type'] = 'application/json'
24
+ request.body = { title: message_subject, text: text }.to_json
25
+
26
+ http = Net::HTTP.new @webhook_url.host, @webhook_url.port
27
+ http.use_ssl = true
28
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
29
+
30
+ body = http.request(request)&.body
31
+ @log.msg "#{self_name}: ms teams notification is sent."
32
+ body
33
+ rescue StandardError => e
34
+ @log.msg "#{self_name}: ms teams notification failed.", level: :error
35
+ @log.msg "#{self_name}: #{e.message}.", level: :error
36
+ end
37
+
38
+ private
39
+
40
+ def self_name
41
+ @klass ||= self.class.name.downcase.split(":").last
42
+ end
43
+
44
+ def setup_configuration **opts
45
+ %i[notification_subject ms_teams_webhook].each do |sym|
46
+ @log.msg "#{self_name}: argument #{sym} is empty.", level: :warn if opts[sym].blank?
47
+ instance_variable_set "@#{sym.to_s}", opts[sym]
48
+ end
49
+
50
+ @default_subject = "Automated Notification."
51
+ end
52
+
53
+ def configure_ms_teams
54
+ return unless @ms_teams_webhook.present?
55
+ @webhook_url = URI.parse @ms_teams_webhook
56
+ end
57
+
58
+ def message_subject
59
+ @notification_subject || default_subject
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,27 @@
1
+ require 'erb'
2
+ require 'active_support/core_ext/object/blank'
3
+
4
+ module MsTeamsNotification
5
+ class Formatter
6
+
7
+ def initialize fields
8
+ @fields = fields
9
+ end
10
+
11
+ def formlate_meessage message, fields_values: nil
12
+ ERB.new(
13
+ <<~HTML
14
+ <%= message %>
15
+ <u>More Details:</u>
16
+ <br>
17
+ <ul style="color: #400707">
18
+ <% @fields.each do |f| %>
19
+ <li><%= f #>: <%= fields_values[f] %>.</li>
20
+ <% end %>
21
+ </ul>
22
+ HTML
23
+ ).result(binding)
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,17 @@
1
+ require 'logger'
2
+ require 'singleton'
3
+
4
+ module MsTeamsNotification
5
+ class Logger
6
+ include Singleton
7
+
8
+ def initialize
9
+ @logger = ::Logger.new STDOUT
10
+ @logger.level = ::Logger::DEBUG
11
+ end
12
+
13
+ def msg *message, level: :info
14
+ @logger.send level.to_s, message.join('').to_s if @logger.respond_to?(level)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MsTeamsNotification
4
+ VERSION = "1.0.0"
5
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "ms_teams_notification/version"
4
+ require_relative "ms_teams_notification/base"
5
+ require_relative "ms_teams_notification/formatter"
6
+
7
+ module MsTeamsNotification
8
+ end
metadata ADDED
@@ -0,0 +1,153 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ms_teams_notification
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Abdullah Barrak
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: activesupport
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '7.1'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '7.1'
26
+ - !ruby/object:Gem::Dependency
27
+ name: rake
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '13.0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '13.0'
40
+ - !ruby/object:Gem::Dependency
41
+ name: minitest
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '5.16'
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '5.16'
54
+ - !ruby/object:Gem::Dependency
55
+ name: standard
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.3'
61
+ type: :development
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '1.3'
68
+ - !ruby/object:Gem::Dependency
69
+ name: simplecov
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '='
73
+ - !ruby/object:Gem::Version
74
+ version: 0.22.0
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - '='
80
+ - !ruby/object:Gem::Version
81
+ version: 0.22.0
82
+ - !ruby/object:Gem::Dependency
83
+ name: simplecov-cobertura
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: 2.1.0
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: 2.1.0
96
+ - !ruby/object:Gem::Dependency
97
+ name: codeclimate-test-reporter
98
+ requirement: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '1.0'
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '1.0'
110
+ description: A ruby library that offers simple notification capablities for Microsoft
111
+ Teams.
112
+ email:
113
+ - abdullah@abarrak.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".ruby-gemset"
119
+ - ".ruby-version"
120
+ - ".standard.yml"
121
+ - LICENSE.txt
122
+ - README.md
123
+ - Rakefile
124
+ - lib/ms_teams_notification.rb
125
+ - lib/ms_teams_notification/base.rb
126
+ - lib/ms_teams_notification/formatter.rb
127
+ - lib/ms_teams_notification/logger.rb
128
+ - lib/ms_teams_notification/version.rb
129
+ homepage: https://rubygems.org/gems/ms_teams_notification
130
+ licenses:
131
+ - MIT
132
+ metadata:
133
+ homepage_uri: https://rubygems.org/gems/ms_teams_notification
134
+ source_code_uri: https://github.com/abarrak/ms_teams_notification/blob/main/lib/ms_teams_notification
135
+ changelog_uri: https://github.com/abarrak/ms_teams_notification/releases
136
+ rdoc_options: []
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: 3.1.0
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ requirements: []
150
+ rubygems_version: 3.6.7
151
+ specification_version: 4
152
+ summary: A simple ms teams noftifier gem.
153
+ test_files: []