teams_connector 0.1.0 → 0.1.4
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 +4 -4
- data/.github/workflows/codeql-analysis.yml +70 -0
- data/.github/workflows/ruby.yml +35 -0
- data/CHANGES.md +28 -0
- data/README.md +80 -6
- data/bin/.gitignore +1 -0
- data/bin/console +16 -1
- data/lib/teams_connector/builder.rb +60 -0
- data/lib/teams_connector/configuration.rb +12 -1
- data/lib/teams_connector/notification/adaptive_card.rb +16 -0
- data/lib/teams_connector/notification/message.rb +1 -1
- data/lib/teams_connector/notification.rb +27 -12
- data/lib/teams_connector/testing.rb +13 -0
- data/lib/teams_connector/version.rb +1 -1
- data/lib/teams_connector.rb +13 -1
- data/teams_connector.gemspec +3 -3
- data/templates/teams_connector/adaptive_card.json.erb +18 -0
- metadata +15 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46a69bacfa1eb6a6b46616d436ff4b8c7890db602ce30c7f082e004e53e161c3
|
4
|
+
data.tar.gz: e98ac0f36a4fc64a1ec41f100ce6b062dc4b1ff4579a2094e2b6d49530b2b5f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5183b39ff855da474a6417861020f44b2933a4e93fbc497207eab427802e88a33d41511ca30c90390741baf85f39a72b30804ddf78a302f1247e49bfb3edd69
|
7
|
+
data.tar.gz: b68b7311f4ba4f7fd2b37c99bdc960fef80d0c7528fdad6a06002820df60131c0f4b5ae1eb2f5f08a9d57e54c5a7673ee96add2d9aca7219c76301ccc5d27f14
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# For most projects, this workflow file will not need changing; you simply need
|
2
|
+
# to commit it to your repository.
|
3
|
+
#
|
4
|
+
# You may wish to alter this file to override the set of languages analyzed,
|
5
|
+
# or to provide custom queries or build logic.
|
6
|
+
#
|
7
|
+
# ******** NOTE ********
|
8
|
+
# We have attempted to detect the languages in your repository. Please check
|
9
|
+
# the `language` matrix defined below to confirm you have the correct set of
|
10
|
+
# supported CodeQL languages.
|
11
|
+
#
|
12
|
+
name: "CodeQL"
|
13
|
+
|
14
|
+
on:
|
15
|
+
push:
|
16
|
+
branches: [ main ]
|
17
|
+
pull_request:
|
18
|
+
# The branches below must be a subset of the branches above
|
19
|
+
branches: [ main ]
|
20
|
+
schedule:
|
21
|
+
- cron: '20 21 * * 1'
|
22
|
+
|
23
|
+
jobs:
|
24
|
+
analyze:
|
25
|
+
name: Analyze
|
26
|
+
runs-on: ubuntu-latest
|
27
|
+
permissions:
|
28
|
+
actions: read
|
29
|
+
contents: read
|
30
|
+
security-events: write
|
31
|
+
|
32
|
+
strategy:
|
33
|
+
fail-fast: false
|
34
|
+
matrix:
|
35
|
+
language: [ 'ruby' ]
|
36
|
+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
|
37
|
+
# Learn more about CodeQL language support at https://git.io/codeql-language-support
|
38
|
+
|
39
|
+
steps:
|
40
|
+
- name: Checkout repository
|
41
|
+
uses: actions/checkout@v2
|
42
|
+
|
43
|
+
# Initializes the CodeQL tools for scanning.
|
44
|
+
- name: Initialize CodeQL
|
45
|
+
uses: github/codeql-action/init@v1
|
46
|
+
with:
|
47
|
+
languages: ${{ matrix.language }}
|
48
|
+
# If you wish to specify custom queries, you can do so here or in a config file.
|
49
|
+
# By default, queries listed here will override any specified in a config file.
|
50
|
+
# Prefix the list here with "+" to use these queries and those in the config file.
|
51
|
+
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
52
|
+
|
53
|
+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
54
|
+
# If this step fails, then you should remove it and run the build manually (see below)
|
55
|
+
- name: Autobuild
|
56
|
+
uses: github/codeql-action/autobuild@v1
|
57
|
+
|
58
|
+
# ℹ️ Command-line programs to run using the OS shell.
|
59
|
+
# 📚 https://git.io/JvXDl
|
60
|
+
|
61
|
+
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
62
|
+
# and modify them (or add more) to build your code if your project
|
63
|
+
# uses a compiled language
|
64
|
+
|
65
|
+
#- run: |
|
66
|
+
# make bootstrap
|
67
|
+
# make release
|
68
|
+
|
69
|
+
- name: Perform CodeQL Analysis
|
70
|
+
uses: github/codeql-action/analyze@v1
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: Ruby
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: [ main ]
|
13
|
+
pull_request:
|
14
|
+
branches: [ main ]
|
15
|
+
|
16
|
+
jobs:
|
17
|
+
test:
|
18
|
+
|
19
|
+
runs-on: ubuntu-latest
|
20
|
+
strategy:
|
21
|
+
matrix:
|
22
|
+
ruby-version: ['2.6', '2.7', '3.0']
|
23
|
+
|
24
|
+
steps:
|
25
|
+
- uses: actions/checkout@v2
|
26
|
+
- name: Set up Ruby
|
27
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
28
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
29
|
+
# uses: ruby/setup-ruby@v1
|
30
|
+
uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
|
31
|
+
with:
|
32
|
+
ruby-version: ${{ matrix.ruby-version }}
|
33
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
34
|
+
- name: Run tests
|
35
|
+
run: bundle exec rake
|
data/CHANGES.md
CHANGED
@@ -1,5 +1,33 @@
|
|
1
1
|
# Teams Connector Changelog
|
2
2
|
|
3
|
+
0.1.4
|
4
|
+
---
|
5
|
+
- Add rudimentary testing method
|
6
|
+
|
7
|
+
0.1.3
|
8
|
+
---
|
9
|
+
- Allow sending a notification to multiple channels at the same time
|
10
|
+
|
11
|
+
0.1.2
|
12
|
+
---
|
13
|
+
- Use `TeamsConnector::Configuration#load_from_rails_credentials` to load encrypted channel URLs in your Rails environment
|
14
|
+
|
15
|
+
0.1.1
|
16
|
+
---
|
17
|
+
- Adaptive Card Notification
|
18
|
+
- Send a more complex Adaptive Card instead of the basic Message Card
|
19
|
+
- Builder
|
20
|
+
- Introduce Builder for [Adaptive Cards](https://docs.microsoft.com/en-us/outlook/actionable-messages/adaptive-card) generation
|
21
|
+
- Directly create messages with TeamsConnector::Notification::AdaptiveCard and the adaptive_card default template
|
22
|
+
- Output as JSON for creation of custom templates
|
23
|
+
- Supports
|
24
|
+
- Text
|
25
|
+
- Container
|
26
|
+
- Facts
|
27
|
+
- Notification
|
28
|
+
- Change constructor from numbered to named parameters
|
29
|
+
- Pretty print JSON to STDOUT with #pretty_print
|
30
|
+
|
3
31
|
0.1.0
|
4
32
|
---
|
5
33
|
- Initial commit of the Teams Connector gem
|
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# Teams Connector
|
2
2
|
|
3
|
+
[](https://badge.fury.io/rb/teams_connector)
|
4
|
+

|
5
|
+
|
3
6
|
Welcome to Teams Connector. This gem allows you to easily send messages from your ruby project to Microsoft Teams channels.
|
4
7
|
It integrates in your rails project, when you are using bundler or even in plain ruby projects.
|
5
8
|
|
@@ -22,16 +25,18 @@ Or install it yourself as:
|
|
22
25
|
$ gem install teams_connector
|
23
26
|
|
24
27
|
## Usage
|
25
|
-
After setting up the Incoming Webhook Connector
|
28
|
+
After setting up the Incoming Webhook Connector for your Microsoft Teams channel, it is as simple as configuring the channel and creating a new `TeamsConnector::Notification`.
|
29
|
+
|
30
|
+
The `channels` parameter can either be a single channel identifier or an array of multiple channel identifiers, that each will receive the notification.
|
26
31
|
|
27
32
|
```ruby
|
28
|
-
#
|
33
|
+
# TeamsConnector initializer
|
29
34
|
TeamsConnector.configure do |config|
|
30
35
|
config.channel :channel_id, "https://<YOUR COMPLETE WEBHOOK URL GOES HERE>"
|
31
36
|
end
|
32
37
|
|
33
38
|
# Send a test card to your channel
|
34
|
-
TeamsConnector::Notification.new(:test_card, :channel_id).deliver_later
|
39
|
+
TeamsConnector::Notification.new(template: :test_card, channels: :channel_id).deliver_later
|
35
40
|
|
36
41
|
# Send a card with a list of facts
|
37
42
|
content = {
|
@@ -43,19 +48,88 @@ content = {
|
|
43
48
|
}
|
44
49
|
TeamsConnector::Notification::Message.new(:facts_card, "This is a summary", content).deliver_later
|
45
50
|
```
|
46
|
-
This gem provides some basic templates in its default template path. You can also define your own templates in your own path. The default templates will be still available so you can mix and match.
|
47
51
|
|
48
|
-
###
|
52
|
+
### Secure Channel Configuration
|
53
|
+
Since the Incoming Webhook Connector does not allow any authentication at the endpoint it is crucial that you keep your channel urls secret.
|
54
|
+
At best nobody finds the url but it can also lead to spam or even faking of critical messages.
|
55
|
+
|
56
|
+
In Rails provides the credentials functionality for [environmental security](https://edgeguides.rubyonrails.org/security.html#environmental-security). This mechanism can be used by TeamsConnector to load channels from an encrypted file. This also allows easy separation of production and development channel URLs.
|
57
|
+
All channels are defined under the top-level entry `teams_connector` and will be identified by their key.
|
58
|
+
```yaml
|
59
|
+
# $ bin/rails credentials:edit
|
60
|
+
teams_connector:
|
61
|
+
default: "<INSERT DEFAULT URL HERE>"
|
62
|
+
sales: "<INSERT URL FOR THE :sales CHANNEL HERE>"
|
63
|
+
```
|
64
|
+
|
65
|
+
After configuration of the credentials you can load the channels in your initializer.
|
66
|
+
Since `#load_from_rails_configuration` is a wrapper around `#channel` both methods can be used together.
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
# TeamsConnector initializer
|
70
|
+
TeamsConnector.configure do |config|
|
71
|
+
config.load_from_rails_credentials
|
72
|
+
# After loading the :default channel is available and can be set as the default
|
73
|
+
config.default = :default
|
74
|
+
config.channel :another_channel, "<URL>"
|
75
|
+
end
|
76
|
+
```
|
77
|
+
|
78
|
+
### Templates
|
79
|
+
This gem provides some basic templates in its default template path. You can also define your own templates in your own path.
|
80
|
+
The default templates will be still available so you can mix and match.
|
81
|
+
|
82
|
+
#### Default templates
|
49
83
|
|
50
84
|
Template name | Description
|
51
85
|
-----|-------
|
52
|
-
:
|
86
|
+
:adaptive_card | A card with the body of an adaptive card for more complex scenarios
|
53
87
|
:facts_card | A card with title, subtitle and a list of facts
|
88
|
+
:test_card | A simple text message without any configurable content for testing
|
89
|
+
|
90
|
+
#### Custom Templates
|
91
|
+
|
92
|
+
Custom templates are stored in the directory specified by the configuration option `template_dir`. As an array of strings, describing the path relative to the project root. When using Rails or Bundler their root is used, otherwise it is the current working directory.
|
93
|
+
|
94
|
+
Templates are json files with the extension `.json.erb`. The file is parsed and populated by the ruby ERB module.
|
95
|
+
|
96
|
+
#### Builder
|
97
|
+
|
98
|
+
You can use TeamsConnector::Builder to create Adaptive Cards directly in ruby. YOu can output the result of the builder as JSON for future use with `TeamsController::Notification::AdaptiveCard#pretty_print`.
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
builder = TeamsConnector::Builder.container do |content|
|
102
|
+
content << TeamsConnector::Builder.text("This is an introductory text for the following facts")
|
103
|
+
content << TeamsConnector::Builder.facts { |facts|
|
104
|
+
facts["Usage"] = "Testing the adaptive card builder"
|
105
|
+
facts["Quokka fact"] = "They are funny little creatures"
|
106
|
+
}
|
107
|
+
end
|
108
|
+
|
109
|
+
TeamsConnector::Notification::AdaptiveCard.new(content: builder).deliver_later
|
110
|
+
```
|
111
|
+
|
112
|
+
## Testing
|
113
|
+
|
114
|
+
To test TeamsConnector integration in your application you can use the `:testing` method.
|
115
|
+
Instead of performing real HTTP requests, an array in `TeamsConnector.testing.requests` is filled in chronological order.
|
116
|
+
|
117
|
+
The request elements have the following structure:
|
118
|
+
```ruby
|
119
|
+
{
|
120
|
+
channel: :default,
|
121
|
+
template: :facts_card,
|
122
|
+
content: "rendered content",
|
123
|
+
time: Time.now
|
124
|
+
}
|
125
|
+
```
|
54
126
|
|
55
127
|
## Development
|
56
128
|
|
57
129
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
58
130
|
|
131
|
+
You can define the channels you use for testing in the file `bin/channels.yml` or directly in the `bin/console` script.
|
132
|
+
|
59
133
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
60
134
|
|
61
135
|
## Contributing
|
data/bin/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
channels.yml
|
data/bin/console
CHANGED
@@ -11,7 +11,22 @@ require "teams_connector"
|
|
11
11
|
# Pry.start
|
12
12
|
|
13
13
|
TeamsConnector.configure do |config|
|
14
|
-
|
14
|
+
if File.exist?("channels.yml")
|
15
|
+
# NOTE(Keune): The channels available in the console can be set in the file channels.yml. It contains a simple
|
16
|
+
# mapping of channel identifiers to webhook URLs. The channel identifier is loaded as a symbol.
|
17
|
+
#
|
18
|
+
# Example: default: "<INSERT YOUR WEBHOOK URL HERE>"
|
19
|
+
puts "Load channels specified by file"
|
20
|
+
|
21
|
+
require "yaml"
|
22
|
+
channels = YAML.load_file "channels.yml"
|
23
|
+
channels.each do |k, v|
|
24
|
+
config.channel k.to_sym, v
|
25
|
+
end
|
26
|
+
else
|
27
|
+
# NOTE(Keune): Specify the channels you want to have available in the console
|
28
|
+
config.channel :default, "<INSERT YOUR WEBHOOK URL HERE>"
|
29
|
+
end
|
15
30
|
config.default = :default
|
16
31
|
config.always_use_default = true
|
17
32
|
config.method = :direct
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module TeamsConnector
|
2
|
+
class Builder
|
3
|
+
attr_accessor :type, :content
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
yield self
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.text(text)
|
10
|
+
TeamsConnector::Builder.new { |entry| entry.text text }
|
11
|
+
end
|
12
|
+
|
13
|
+
def text(text)
|
14
|
+
@type = :text
|
15
|
+
@content = text
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.container
|
19
|
+
TeamsConnector::Builder.new { |entry| entry.container { |items| yield items } }
|
20
|
+
end
|
21
|
+
|
22
|
+
def container
|
23
|
+
@type = :container
|
24
|
+
@content = []
|
25
|
+
yield @content
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.facts
|
29
|
+
TeamsConnector::Builder.new { |entry| entry.facts { |facts| yield facts } }
|
30
|
+
end
|
31
|
+
|
32
|
+
def facts
|
33
|
+
@type = :facts
|
34
|
+
@content = {}
|
35
|
+
yield @content
|
36
|
+
end
|
37
|
+
|
38
|
+
def result
|
39
|
+
case @type
|
40
|
+
when :container
|
41
|
+
{
|
42
|
+
type: "Container",
|
43
|
+
items: @content.map { |element| element.result }
|
44
|
+
}
|
45
|
+
when :facts
|
46
|
+
{
|
47
|
+
type: "FactSet",
|
48
|
+
facts: @content.map { |fact| { title: fact[0], value: fact[1] } }
|
49
|
+
}
|
50
|
+
when :text
|
51
|
+
{
|
52
|
+
type: "TextBlock",
|
53
|
+
text: @content
|
54
|
+
}
|
55
|
+
else
|
56
|
+
raise TypeError, "The type #{@type} is not supported by the TeamsConnector::Builder"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -19,7 +19,7 @@ module TeamsConnector
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def method=(method)
|
22
|
-
raise ArgumentError, "Method '#{method.to_s}' is not supported" unless [:direct, :sidekiq].include? method
|
22
|
+
raise ArgumentError, "Method '#{method.to_s}' is not supported" unless [:direct, :sidekiq, :testing].include? method
|
23
23
|
raise ArgumentError, "Sidekiq is not available" if method == :sidekiq && !defined? Sidekiq
|
24
24
|
@method = method
|
25
25
|
end
|
@@ -27,5 +27,16 @@ module TeamsConnector
|
|
27
27
|
def channel(name, url)
|
28
28
|
@channels[name] = url;
|
29
29
|
end
|
30
|
+
|
31
|
+
def load_from_rails_credentials
|
32
|
+
unless defined? Rails
|
33
|
+
raise RuntimeError, "This method is only available in Ruby on Rails."
|
34
|
+
end
|
35
|
+
|
36
|
+
webhook_urls = Rails.application.credentials.teams_connector!
|
37
|
+
webhook_urls.each do |entry|
|
38
|
+
channel(entry[0], entry[1])
|
39
|
+
end
|
40
|
+
end
|
30
41
|
end
|
31
42
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module TeamsConnector
|
2
|
+
class Notification::AdaptiveCard < Notification
|
3
|
+
attr_accessor :content
|
4
|
+
|
5
|
+
def initialize(template: :adaptive_card, content: {}, channel: TeamsConnector.configuration.default)
|
6
|
+
super(template: template, channel: channel)
|
7
|
+
if content.instance_of? TeamsConnector::Builder
|
8
|
+
@content = {
|
9
|
+
card: [content.result]
|
10
|
+
}
|
11
|
+
else
|
12
|
+
@content = content
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -3,7 +3,7 @@ module TeamsConnector
|
|
3
3
|
attr_accessor :summary, :content
|
4
4
|
|
5
5
|
def initialize(template, summary, content = {}, channel = TeamsConnector.configuration.default)
|
6
|
-
super(template, channel)
|
6
|
+
super(template: template, channels: channel)
|
7
7
|
@summary = summary
|
8
8
|
@content = content
|
9
9
|
end
|
@@ -1,14 +1,15 @@
|
|
1
1
|
require 'erb'
|
2
|
+
require 'json'
|
2
3
|
require 'net/http'
|
3
4
|
require 'teams_connector/post_worker' if defined? Sidekiq
|
4
5
|
|
5
6
|
module TeamsConnector
|
6
7
|
class Notification
|
7
|
-
attr_accessor :template, :
|
8
|
+
attr_accessor :template, :channels
|
8
9
|
|
9
|
-
def initialize(template,
|
10
|
+
def initialize(template: nil, channels: TeamsConnector.configuration.default)
|
10
11
|
@template = template
|
11
|
-
@
|
12
|
+
@channels = channels.instance_of?(Array) ? channels : [channels]
|
12
13
|
end
|
13
14
|
|
14
15
|
def deliver_later
|
@@ -17,20 +18,34 @@ module TeamsConnector
|
|
17
18
|
renderer = ERB.new(File.read(template_path))
|
18
19
|
renderer.location = [template_path.to_s, 0]
|
19
20
|
|
20
|
-
url = TeamsConnector.configuration.channels[@channel]
|
21
|
-
url = TeamsConnector.configuration.channels[TeamsConnector.configuration.default] if TeamsConnector.configuration.always_use_default
|
22
|
-
raise ArgumentError, "The Teams channel '#{@channel}' is not available in the configuration." if url.nil?
|
23
|
-
|
24
21
|
content = renderer.result(binding)
|
25
22
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
23
|
+
channels = TeamsConnector.configuration.always_use_default ? [TeamsConnector.configuration.default] : @channels
|
24
|
+
channels.each do |channel|
|
25
|
+
url = TeamsConnector.configuration.channels[channel]
|
26
|
+
raise ArgumentError, "The Teams channel '#{channel}' is not available in the configuration." if url.nil?
|
27
|
+
|
28
|
+
if TeamsConnector.configuration.method == :sidekiq
|
29
|
+
TeamsConnector::PostWorker.perform_async(url, content)
|
30
|
+
elsif TeamsConnector.configuration.method == :testing
|
31
|
+
TeamsConnector.testing.perform_request channel, @template, content
|
32
|
+
else
|
33
|
+
response = Net::HTTP.post(URI(url), content, { "Content-Type": "application/json" })
|
34
|
+
response.value
|
35
|
+
end
|
31
36
|
end
|
32
37
|
end
|
33
38
|
|
39
|
+
def pretty_print
|
40
|
+
template_path = find_template
|
41
|
+
|
42
|
+
renderer = ERB.new(File.read(template_path))
|
43
|
+
renderer.location = [template_path.to_s, 0]
|
44
|
+
content = renderer.result(binding)
|
45
|
+
|
46
|
+
puts JSON.pretty_generate(JSON.parse(content))
|
47
|
+
end
|
48
|
+
|
34
49
|
private
|
35
50
|
|
36
51
|
def find_template
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module TeamsConnector
|
2
|
+
class Testing
|
3
|
+
attr_reader :requests
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@requests = []
|
7
|
+
end
|
8
|
+
|
9
|
+
def perform_request(channel, template, content)
|
10
|
+
@requests.push({channel: channel, content: content, template: template, time: Time.now})
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/teams_connector.rb
CHANGED
@@ -2,10 +2,12 @@ require 'teams_connector/configuration'
|
|
2
2
|
require 'teams_connector/version'
|
3
3
|
require 'teams_connector/notification'
|
4
4
|
require 'teams_connector/notification/message'
|
5
|
+
require 'teams_connector/notification/adaptive_card'
|
6
|
+
require 'teams_connector/builder'
|
5
7
|
|
6
8
|
module TeamsConnector
|
7
9
|
class << self
|
8
|
-
attr_accessor :configuration
|
10
|
+
attr_accessor :configuration, :testing
|
9
11
|
end
|
10
12
|
|
11
13
|
def self.configuration
|
@@ -20,6 +22,16 @@ module TeamsConnector
|
|
20
22
|
yield configuration
|
21
23
|
end
|
22
24
|
|
25
|
+
def self.testing
|
26
|
+
require 'teams_connector/testing'
|
27
|
+
@testing ||= Testing.new
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.reset_testing
|
31
|
+
require 'teams_connector/testing'
|
32
|
+
@testing = Testing.new
|
33
|
+
end
|
34
|
+
|
23
35
|
def self.project_root
|
24
36
|
if defined?(Rails)
|
25
37
|
return Rails.root
|
data/teams_connector.gemspec
CHANGED
@@ -33,9 +33,9 @@ Gem::Specification.new do |spec|
|
|
33
33
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
34
34
|
spec.require_paths = ["lib"]
|
35
35
|
|
36
|
-
spec.add_development_dependency "bundler", "
|
37
|
-
spec.add_development_dependency "rake", "
|
38
|
-
spec.add_development_dependency "rspec", "
|
36
|
+
spec.add_development_dependency "bundler", ">= 1.17"
|
37
|
+
spec.add_development_dependency "rake", ">= 10.0"
|
38
|
+
spec.add_development_dependency "rspec", ">= 3.0"
|
39
39
|
spec.add_development_dependency "webmock"
|
40
40
|
spec.add_development_dependency "sidekiq"
|
41
41
|
spec.add_development_dependency "simplecov"
|
@@ -0,0 +1,18 @@
|
|
1
|
+
{
|
2
|
+
"type": "message",
|
3
|
+
"attachments": [
|
4
|
+
{
|
5
|
+
"contentType": "application/vnd.microsoft.card.adaptive",
|
6
|
+
"contentUrl": null,
|
7
|
+
"padding": "None",
|
8
|
+
"content": {
|
9
|
+
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
|
10
|
+
"type": "AdaptiveCard",
|
11
|
+
"version": "1.2",
|
12
|
+
"body": [
|
13
|
+
<%= @content[:card].map {|k| k.to_json}.join(", ") %>
|
14
|
+
]
|
15
|
+
}
|
16
|
+
}
|
17
|
+
]
|
18
|
+
}
|
metadata
CHANGED
@@ -1,55 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: teams_connector
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lucas Keune
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.17'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.17'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '10.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '3.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
@@ -101,6 +101,8 @@ executables: []
|
|
101
101
|
extensions: []
|
102
102
|
extra_rdoc_files: []
|
103
103
|
files:
|
104
|
+
- ".github/workflows/codeql-analysis.yml"
|
105
|
+
- ".github/workflows/ruby.yml"
|
104
106
|
- ".gitignore"
|
105
107
|
- ".rspec"
|
106
108
|
- ".travis.yml"
|
@@ -109,15 +111,20 @@ files:
|
|
109
111
|
- LICENSE.txt
|
110
112
|
- README.md
|
111
113
|
- Rakefile
|
114
|
+
- bin/.gitignore
|
112
115
|
- bin/console
|
113
116
|
- bin/setup
|
114
117
|
- lib/teams_connector.rb
|
118
|
+
- lib/teams_connector/builder.rb
|
115
119
|
- lib/teams_connector/configuration.rb
|
116
120
|
- lib/teams_connector/notification.rb
|
121
|
+
- lib/teams_connector/notification/adaptive_card.rb
|
117
122
|
- lib/teams_connector/notification/message.rb
|
118
123
|
- lib/teams_connector/post_worker.rb
|
124
|
+
- lib/teams_connector/testing.rb
|
119
125
|
- lib/teams_connector/version.rb
|
120
126
|
- teams_connector.gemspec
|
127
|
+
- templates/teams_connector/adaptive_card.json.erb
|
121
128
|
- templates/teams_connector/facts_card.json.erb
|
122
129
|
- templates/teams_connector/test_card.json.erb
|
123
130
|
homepage: https://github.com/Qurasoft/teams_connector
|