mattermost-messenger 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.env.template +1 -0
- data/.rspec +3 -0
- data/.rubocop.yml +24 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +89 -0
- data/README.md +3 -0
- data/Rakefile +12 -0
- data/lib/mattermost/messenger/all.rb +11 -0
- data/lib/mattermost/messenger/client.rb +82 -0
- data/lib/mattermost/messenger/version.rb +7 -0
- data/lib/mattermost/messenger.rb +9 -0
- data/mattermost-messenger.gemspec +37 -0
- metadata +59 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5ce8bcc8110fb6d871489ac57aa76c8b125dd777d44df7614697c112a6c8debf
|
4
|
+
data.tar.gz: 2d8fe8e053938721dfd7c6039102b268c4e2f13c613186097029b91993f8877a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 54fd0d53d15de460f27ed54ae12c1a9d42cf427cc41c226a001cd7f0736637cd91937bf40fc9a2785469502f7b91485ceac2a258167daedea1c69a40148dcdc8
|
7
|
+
data.tar.gz: f73d047bd0c038d2b58376542d98a89b0e8cd22e4fd3824ed6da9787c49a885318f40f556b21f5b666b3b7bac633ef86a61b8e9b31c46c6cc9cb8901429145f4
|
data/.env.template
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
MATTERMOST_WEBHOOK_URL=https://your-mattermost-webhook.url.com
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
AllCops:
|
2
|
+
NewCops: enable
|
3
|
+
SuggestExtensions: false
|
4
|
+
TargetRubyVersion: 2.6
|
5
|
+
|
6
|
+
Style/StringLiterals:
|
7
|
+
Enabled: true
|
8
|
+
EnforcedStyle: double_quotes
|
9
|
+
|
10
|
+
Style/Documentation:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
Style/StringLiteralsInInterpolation:
|
14
|
+
Enabled: true
|
15
|
+
EnforcedStyle: double_quotes
|
16
|
+
|
17
|
+
Layout/LineLength:
|
18
|
+
Max: 120
|
19
|
+
|
20
|
+
Metrics/BlockLength:
|
21
|
+
Enabled: false
|
22
|
+
|
23
|
+
Metrics/MethodLength:
|
24
|
+
Enabled: false
|
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in mattermost-messenger.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem "dotenv", "~> 2.8"
|
9
|
+
gem "factory_bot", "~> 6.2"
|
10
|
+
gem "faker", "~> 3.0"
|
11
|
+
gem "rake", "~> 13.0"
|
12
|
+
gem "rspec", "~> 3.12"
|
13
|
+
gem "rubocop", "~> 1.39"
|
14
|
+
gem "vcr", "~> 6.1"
|
15
|
+
gem "webmock", "~> 3.18"
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
mattermost-messenger (0.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
activesupport (7.0.4)
|
10
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
11
|
+
i18n (>= 1.6, < 2)
|
12
|
+
minitest (>= 5.1)
|
13
|
+
tzinfo (~> 2.0)
|
14
|
+
addressable (2.8.1)
|
15
|
+
public_suffix (>= 2.0.2, < 6.0)
|
16
|
+
ast (2.4.2)
|
17
|
+
concurrent-ruby (1.1.10)
|
18
|
+
crack (0.4.5)
|
19
|
+
rexml
|
20
|
+
diff-lcs (1.5.0)
|
21
|
+
dotenv (2.8.1)
|
22
|
+
factory_bot (6.2.1)
|
23
|
+
activesupport (>= 5.0.0)
|
24
|
+
faker (3.0.0)
|
25
|
+
i18n (>= 1.8.11, < 2)
|
26
|
+
hashdiff (1.0.1)
|
27
|
+
i18n (1.12.0)
|
28
|
+
concurrent-ruby (~> 1.0)
|
29
|
+
json (2.6.3)
|
30
|
+
minitest (5.16.3)
|
31
|
+
parallel (1.22.1)
|
32
|
+
parser (3.1.3.0)
|
33
|
+
ast (~> 2.4.1)
|
34
|
+
public_suffix (5.0.0)
|
35
|
+
rainbow (3.1.1)
|
36
|
+
rake (13.0.6)
|
37
|
+
regexp_parser (2.6.1)
|
38
|
+
rexml (3.2.5)
|
39
|
+
rspec (3.12.0)
|
40
|
+
rspec-core (~> 3.12.0)
|
41
|
+
rspec-expectations (~> 3.12.0)
|
42
|
+
rspec-mocks (~> 3.12.0)
|
43
|
+
rspec-core (3.12.0)
|
44
|
+
rspec-support (~> 3.12.0)
|
45
|
+
rspec-expectations (3.12.0)
|
46
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
47
|
+
rspec-support (~> 3.12.0)
|
48
|
+
rspec-mocks (3.12.0)
|
49
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
50
|
+
rspec-support (~> 3.12.0)
|
51
|
+
rspec-support (3.12.0)
|
52
|
+
rubocop (1.39.0)
|
53
|
+
json (~> 2.3)
|
54
|
+
parallel (~> 1.10)
|
55
|
+
parser (>= 3.1.2.1)
|
56
|
+
rainbow (>= 2.2.2, < 4.0)
|
57
|
+
regexp_parser (>= 1.8, < 3.0)
|
58
|
+
rexml (>= 3.2.5, < 4.0)
|
59
|
+
rubocop-ast (>= 1.23.0, < 2.0)
|
60
|
+
ruby-progressbar (~> 1.7)
|
61
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
62
|
+
rubocop-ast (1.24.0)
|
63
|
+
parser (>= 3.1.1.0)
|
64
|
+
ruby-progressbar (1.11.0)
|
65
|
+
tzinfo (2.0.5)
|
66
|
+
concurrent-ruby (~> 1.0)
|
67
|
+
unicode-display_width (2.3.0)
|
68
|
+
vcr (6.1.0)
|
69
|
+
webmock (3.18.1)
|
70
|
+
addressable (>= 2.8.0)
|
71
|
+
crack (>= 0.3.2)
|
72
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
73
|
+
|
74
|
+
PLATFORMS
|
75
|
+
arm64-darwin-21
|
76
|
+
|
77
|
+
DEPENDENCIES
|
78
|
+
dotenv (~> 2.8)
|
79
|
+
factory_bot (~> 6.2)
|
80
|
+
faker (~> 3.0)
|
81
|
+
mattermost-messenger!
|
82
|
+
rake (~> 13.0)
|
83
|
+
rspec (~> 3.12)
|
84
|
+
rubocop (~> 1.39)
|
85
|
+
vcr (~> 6.1)
|
86
|
+
webmock (~> 3.18)
|
87
|
+
|
88
|
+
BUNDLED WITH
|
89
|
+
2.3.26
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "uri"
|
4
|
+
require "net/http"
|
5
|
+
|
6
|
+
module Mattermost
|
7
|
+
module Messenger
|
8
|
+
class Client
|
9
|
+
attr_reader :webhook_url
|
10
|
+
|
11
|
+
MESSAGE_COLOR = { success: "#4DD200", alert: "#E31B16" }.freeze
|
12
|
+
|
13
|
+
def initialize(options: {})
|
14
|
+
@options = options
|
15
|
+
parse_options!
|
16
|
+
end
|
17
|
+
|
18
|
+
def send_messages!(options = {})
|
19
|
+
if options.any?
|
20
|
+
@options.merge!(options)
|
21
|
+
parse_options!
|
22
|
+
end
|
23
|
+
|
24
|
+
uri = URI.parse(@webhook_url)
|
25
|
+
|
26
|
+
client = Net::HTTP.new(uri.host, uri.port)
|
27
|
+
client.use_ssl = true
|
28
|
+
|
29
|
+
request = Net::HTTP::Post.new(uri.request_uri, { "Content-Type": "application/json" })
|
30
|
+
request.body = message_body
|
31
|
+
|
32
|
+
client.request(request)
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def parse_options!
|
38
|
+
@webhook_url = @options[:webhook_url] || ENV.fetch("MATTERMOST_WEBHOOK_URL", nil)
|
39
|
+
@title = @options.dig(:title, :text)
|
40
|
+
@title_link = @options.dig(:title, :link)
|
41
|
+
@type = @options[:type]
|
42
|
+
@messages = @options[:messages]
|
43
|
+
end
|
44
|
+
|
45
|
+
def message_fields
|
46
|
+
msg = [
|
47
|
+
{
|
48
|
+
short: false,
|
49
|
+
title: @messages.first[:title],
|
50
|
+
value: @messages.first[:content]
|
51
|
+
}
|
52
|
+
]
|
53
|
+
|
54
|
+
if @messages.count > 1
|
55
|
+
msg = @messages.map do |message|
|
56
|
+
{
|
57
|
+
short: true,
|
58
|
+
title: message[:title],
|
59
|
+
value: message[:content]
|
60
|
+
}
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
msg
|
65
|
+
end
|
66
|
+
|
67
|
+
def message_body
|
68
|
+
{
|
69
|
+
attachments: [
|
70
|
+
{
|
71
|
+
fallback: @title,
|
72
|
+
color: MESSAGE_COLOR[@type.to_sym],
|
73
|
+
title: @title,
|
74
|
+
title_link: @title_link,
|
75
|
+
fields: message_fields
|
76
|
+
}
|
77
|
+
]
|
78
|
+
}.to_json
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/mattermost/messenger/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "mattermost-messenger"
|
7
|
+
spec.version = Mattermost::Messenger::VERSION
|
8
|
+
spec.authors = ["Kao Chien Long"]
|
9
|
+
spec.email = ["eddie@5xcampus.com"]
|
10
|
+
|
11
|
+
spec.summary = "Simpel Mattermost message helper"
|
12
|
+
spec.description = "Simpel Mattermost message helper"
|
13
|
+
spec.homepage = "https://github.com/5xTraining/mattermost-messenger"
|
14
|
+
spec.required_ruby_version = ">= 2.6.0"
|
15
|
+
|
16
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
19
|
+
spec.metadata["changelog_uri"] = spec.homepage
|
20
|
+
|
21
|
+
spec.files = Dir.chdir(__dir__) do
|
22
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
23
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
# Uncomment to register a new dependency of your gem
|
32
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
33
|
+
|
34
|
+
# For more information and examples about making a new gem, check out our
|
35
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
36
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mattermost-messenger
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kao Chien Long
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-12-07 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Simpel Mattermost message helper
|
14
|
+
email:
|
15
|
+
- eddie@5xcampus.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".env.template"
|
21
|
+
- ".rspec"
|
22
|
+
- ".rubocop.yml"
|
23
|
+
- Gemfile
|
24
|
+
- Gemfile.lock
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- lib/mattermost/messenger.rb
|
28
|
+
- lib/mattermost/messenger/all.rb
|
29
|
+
- lib/mattermost/messenger/client.rb
|
30
|
+
- lib/mattermost/messenger/version.rb
|
31
|
+
- mattermost-messenger.gemspec
|
32
|
+
homepage: https://github.com/5xTraining/mattermost-messenger
|
33
|
+
licenses: []
|
34
|
+
metadata:
|
35
|
+
allowed_push_host: https://rubygems.org
|
36
|
+
homepage_uri: https://github.com/5xTraining/mattermost-messenger
|
37
|
+
source_code_uri: https://github.com/5xTraining/mattermost-messenger
|
38
|
+
changelog_uri: https://github.com/5xTraining/mattermost-messenger
|
39
|
+
rubygems_mfa_required: 'true'
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 2.6.0
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
requirements: []
|
55
|
+
rubygems_version: 3.3.26
|
56
|
+
signing_key:
|
57
|
+
specification_version: 4
|
58
|
+
summary: Simpel Mattermost message helper
|
59
|
+
test_files: []
|