teams_connector 0.1.0 → 0.1.1

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: 1637a8989e80ccddbd794e906543c29845f701ae2aa2241728cfc27c42eb4005
4
- data.tar.gz: 4396ee9a4a861078e29a84b7e4f372505ad397d71ab4b93082476c40d9e984d5
3
+ metadata.gz: c6a72ee260e0976efb58e9871414f88ea25090fef32d9786a9d0b2b5dad252be
4
+ data.tar.gz: 8a17c4cf19aa3313bd2361a2a2ca5524ba354d6be8079f594ef065209fd60c44
5
5
  SHA512:
6
- metadata.gz: 074b2bb7966fd01e514c8c089335e67ab8cdb643a64cef413d744307f441b6acd4523beba610caf5345383a6043b8ab80166d20f66e7bdec6762d21b8c1a8c3c
7
- data.tar.gz: 010c32f3c62b14102603b3196124a671630d38c9d18d9a661dfb10324f9b1ebf47190d9e8098fa925ba013d29705fe9f80b2d25178a0a13149308c1d2b46d26b
6
+ metadata.gz: 51b2a71c1d50f252f1804a037e546d9e240707553f7052128b31191e1c28316177a95afb598eadfff11d1a7dd414eaa7d53294dd64da859fc9d3c6f73112af74
7
+ data.tar.gz: 9f39957ce3655246af7404d99b1f7281c0cc200257faf3ccf4c64ec02d45cd83ef08264e47f8769c0fc2affab1a7cfedf9ce10e60a876a8b9cff21aed2fd6a89
@@ -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,21 @@
1
1
  # Teams Connector Changelog
2
2
 
3
+ 0.1.1
4
+ ---
5
+ - Adaptive Card Notification
6
+ - Send a more complex Adaptive Card instead of the basic Message Card
7
+ - Builder
8
+ - Introduce Builder for [Adaptive Cards](https://docs.microsoft.com/en-us/outlook/actionable-messages/adaptive-card) generation
9
+ - Directly create messages with TeamsConnector::Notification::AdaptiveCard and the adaptive_card default template
10
+ - Output as JSON for creation of custom templates
11
+ - Supports
12
+ - Text
13
+ - Container
14
+ - Facts
15
+ - Notification
16
+ - Change constructor from numbered to named parameters
17
+ - Pretty print JSON to STDOUT with #pretty_print
18
+
3
19
  0.1.0
4
20
  ---
5
21
  - Initial commit of the Teams Connector gem
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Teams Connector
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/teams_connector.svg)](https://badge.fury.io/rb/teams_connector)
4
+ ![RSpec](https://github.com/qurasoft/teams_connector/actions/workflows/ruby.yml/badge.svg)
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
 
@@ -49,13 +52,38 @@ This gem provides some basic templates in its default template path. You can als
49
52
 
50
53
  Template name | Description
51
54
  -----|-------
52
- :test_card | A simple text message without any configurable content for testing
55
+ :adaptive_card | A card with the body of an adaptive card for more complex scenarios
53
56
  :facts_card | A card with title, subtitle and a list of facts
57
+ :test_card | A simple text message without any configurable content for testing
58
+
59
+ ### Custom Templates
60
+
61
+ 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.
62
+
63
+ Templates are json files with the extension `.json.erb`. The file is parsed and populated by the ruby ERB module.
64
+
65
+ ### Builder
66
+
67
+ 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`.
68
+
69
+ ```ruby
70
+ builder = TeamsConnector::Builder.container do |content|
71
+ content << TeamsConnector::Builder.text("This is an introductory text for the following facts")
72
+ content << TeamsConnector::Builder.facts { |facts|
73
+ facts["Usage"] = "Testing the adaptive card builder"
74
+ facts["Quokka fact"] = "They are funny little creatures"
75
+ }
76
+ end
77
+
78
+ TeamsConnector::Notification::AdaptiveCard.new(content: builder).deliver_later
79
+ ```
54
80
 
55
81
  ## Development
56
82
 
57
83
  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
84
 
85
+ You can define the channels you use for testing in the file `bin/channels.yml` or directly in the `bin/console` script.
86
+
59
87
  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
88
 
61
89
  ## 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
- config.channel :default, "<INSERT YOUR WEBHOOK URL HERE>"
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
@@ -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, channel: channel)
7
7
  @summary = summary
8
8
  @content = content
9
9
  end
@@ -1,4 +1,5 @@
1
1
  require 'erb'
2
+ require 'json'
2
3
  require 'net/http'
3
4
  require 'teams_connector/post_worker' if defined? Sidekiq
4
5
 
@@ -6,7 +7,7 @@ module TeamsConnector
6
7
  class Notification
7
8
  attr_accessor :template, :channel
8
9
 
9
- def initialize(template, channel)
10
+ def initialize(template: nil, channel: TeamsConnector.configuration.default)
10
11
  @template = template
11
12
  @channel = channel
12
13
  end
@@ -31,6 +32,16 @@ module TeamsConnector
31
32
  end
32
33
  end
33
34
 
35
+ def pretty_print
36
+ template_path = find_template
37
+
38
+ renderer = ERB.new(File.read(template_path))
39
+ renderer.location = [template_path.to_s, 0]
40
+ content = renderer.result(binding)
41
+
42
+ puts JSON.pretty_generate(JSON.parse(content))
43
+ end
44
+
34
45
  private
35
46
 
36
47
  def find_template
@@ -1,3 +1,3 @@
1
1
  module TeamsConnector
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -2,6 +2,8 @@ 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
@@ -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", "~> 1.17"
37
- spec.add_development_dependency "rake", "~> 10.0"
38
- spec.add_development_dependency "rspec", "~> 3.0"
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.0
4
+ version: 0.1.1
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-11 00:00:00.000000000 Z
11
+ date: 2021-11-15 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,19 @@ 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
119
124
  - lib/teams_connector/version.rb
120
125
  - teams_connector.gemspec
126
+ - templates/teams_connector/adaptive_card.json.erb
121
127
  - templates/teams_connector/facts_card.json.erb
122
128
  - templates/teams_connector/test_card.json.erb
123
129
  homepage: https://github.com/Qurasoft/teams_connector