msteams_hermes 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4cf0e67a3baf8adb2febaabec358bc95bdbb4bd05b22a9cd3f73f2b3438690ab
4
+ data.tar.gz: 28004b92b73f486f1f7a4cdc9a182989bb6b89ee0cb440d88b9cf972e35c82f5
5
+ SHA512:
6
+ metadata.gz: f175e08b3de73132ac2b5893ae66e7f6e2312e76fa1018a0ea5a319f65f3a707ed9e8d01169e71e40eca42d5e1d5bcf52610c522cb905be631536924027b8e9c
7
+ data.tar.gz: 8d41d5c53012d6e3aff9d830283026762e30e81d87b289e559fde21377660090108ae1c14a84fa59d544fced6a8729aab01f1f6b4670668bcd13e3855d9f681c
@@ -0,0 +1,30 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [ "main" ]
6
+ pull_request:
7
+ branches: [ "main" ]
8
+
9
+ jobs:
10
+ build:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ ruby-version: [ "2.7", "3.0", "3.1.2" ]
15
+ steps:
16
+ - uses: actions/checkout@v2
17
+
18
+ - name: Set up Ruby ${{ matrix.ruby-version }}
19
+ uses: ruby/setup-ruby@v1
20
+ with:
21
+ ruby-version: ${{ matrix.ruby-version }}
22
+
23
+ - name: Install dependencies
24
+ run: bundle install
25
+
26
+ - name: Run rubocop
27
+ run: bundle exec rubocop
28
+
29
+ - name: Run rspec
30
+ run: bundle exec rspec spec/
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /.idea/
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
13
+ .DS_Store
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,23 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.7
3
+
4
+ Metrics/BlockLength:
5
+ Exclude:
6
+ - 'spec/**/*'
7
+
8
+ Style/StringLiterals:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Style/StringLiteralsInInterpolation:
13
+ Enabled: true
14
+ EnforcedStyle: double_quotes
15
+
16
+ Layout/LineLength:
17
+ Max: 120
18
+
19
+ Lint/MissingSuper:
20
+ Enabled: false
21
+
22
+ Metrics/ParameterLists:
23
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## Changelog
2
+
3
+ ## [1.0.0] - 2022-09-02
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at rafael.rocha@xing.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in msteams_hermes.gemspec
6
+ gemspec
7
+
8
+ gem "rake"
9
+ gem "rspec"
10
+ gem "rubocop"
data/Gemfile.lock ADDED
@@ -0,0 +1,59 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ msteams_hermes (1.0.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ diff-lcs (1.5.0)
11
+ json (2.6.2)
12
+ parallel (1.22.1)
13
+ parser (3.1.2.1)
14
+ ast (~> 2.4.1)
15
+ rainbow (3.1.1)
16
+ rake (13.0.6)
17
+ regexp_parser (2.5.0)
18
+ rexml (3.2.5)
19
+ rspec (3.11.0)
20
+ rspec-core (~> 3.11.0)
21
+ rspec-expectations (~> 3.11.0)
22
+ rspec-mocks (~> 3.11.0)
23
+ rspec-core (3.11.0)
24
+ rspec-support (~> 3.11.0)
25
+ rspec-expectations (3.11.0)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.11.0)
28
+ rspec-mocks (3.11.1)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.11.0)
31
+ rspec-support (3.11.0)
32
+ rubocop (1.36.0)
33
+ json (~> 2.3)
34
+ parallel (~> 1.10)
35
+ parser (>= 3.1.2.1)
36
+ rainbow (>= 2.2.2, < 4.0)
37
+ regexp_parser (>= 1.8, < 3.0)
38
+ rexml (>= 3.2.5, < 4.0)
39
+ rubocop-ast (>= 1.20.1, < 2.0)
40
+ ruby-progressbar (~> 1.7)
41
+ unicode-display_width (>= 1.4.0, < 3.0)
42
+ rubocop-ast (1.21.0)
43
+ parser (>= 3.1.1.0)
44
+ ruby-progressbar (1.11.0)
45
+ unicode-display_width (2.2.0)
46
+
47
+ PLATFORMS
48
+ ruby
49
+ x86_64-darwin-20
50
+ x86_64-darwin-21
51
+
52
+ DEPENDENCIES
53
+ msteams_hermes!
54
+ rake
55
+ rspec
56
+ rubocop
57
+
58
+ BUNDLED WITH
59
+ 2.2.15
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Rafael Rocha
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,66 @@
1
+ # MsTeamsHermes
2
+
3
+ Like Hermes, the messenger of the greek gods, this gem helps you sending messages to your Microsoft Teams channels. With autonomy to create your own layouts, like UI kits such as React, Flutter, SwiftUI (and some others), you will be able to customize it with the objects representations of [Microsoft's adaptive cards](https://adaptivecards.io/explorer/).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'msteams_hermes'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install msteams_hermes
20
+
21
+ ## Usage
22
+
23
+ First of all, you need a Webhook URL, which is responsible to identify which channel should receive the messages we are about to send. To generate one, follow [Microsoft's instructions](https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook).
24
+
25
+ ### Your first message
26
+
27
+ A default _Hello World!_ message could be sent by simply:
28
+
29
+ ```ruby
30
+ require "msteams_hermes/components/adaptive_card"
31
+ require "msteams_hermes/components/text_block"
32
+ require "msteams_hermes/message"
33
+
34
+ content = MsTeamsHermes::Components::AdaptiveCard.new(
35
+ body: [
36
+ MsTeamsHermes::Components::TextBlock.new(
37
+ text: "Hello World!",
38
+ )
39
+ ]
40
+ )
41
+
42
+ MsTeamsHermes::Message.new(webhook_url: <YOUR_WEBHOOK_URL>, content: content).deliver
43
+ ```
44
+
45
+ - You can provide the `webhook_url` by either sending it as a param or setting it as an environment variable, but it must not be nil.
46
+ - `content` must always be an `AdaptiveCard`, which is the top component for Microsoft's webhook messages.
47
+
48
+ Each component, each style, each action is a 1:1 representation from [Microsoft's adaptive cards](https://adaptivecards.io/explorer/).
49
+
50
+ If you want a more elaborated example on how to create message with complex layouts, check out this [example](https://github.com/xing/msteams_hermes/blob/main/complex_example.rb).
51
+
52
+ ## Contributing
53
+
54
+ Bug reports and pull requests are welcome on GitHub at https://github.com/xing/msteams_hermes. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/xing/msteams_hermes/blob/main/CODE_OF_CONDUCT.md).
55
+
56
+ ### Adding new components, styles and actions
57
+
58
+ Every new component, style or action must implement the `to_hash` method, which serializes the object into a hash object to be sent to the `webhook_url`. When implementing the `to_hash` method, pay attention to the JSON structure of the given object, usually described on the _Example_ section of its documentation on [adaptivecards.io](https://adaptivecards.io/explorer/).
59
+
60
+ ## License
61
+
62
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
63
+
64
+ ## Code of Conduct
65
+
66
+ Everyone interacting in the MsTeamsHermes project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/xing/msteams_hermes/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "msteams_hermes"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "msteams_hermes/actions/open_url"
5
+ require "msteams_hermes/components/adaptive_card"
6
+ require "msteams_hermes/components/text_block"
7
+ require "msteams_hermes/components/container"
8
+ require "msteams_hermes/components/fact_set"
9
+ require "msteams_hermes/message"
10
+
11
+ YOUR_WEBHOOK_URL = "YOUR_WEBHOOK_URL"
12
+
13
+ header = MsTeamsHermes::Components::Container.new(
14
+ style: MsTeamsHermes::Style::ContainerStyle::WARNING,
15
+ items: [
16
+ MsTeamsHermes::Components::TextBlock.new(
17
+ text: "John Cena",
18
+ size: MsTeamsHermes::Style::FontSize::LARGE,
19
+ weight: MsTeamsHermes::Style::FontWeight::BOLDER
20
+ ),
21
+ MsTeamsHermes::Components::TextBlock.new(
22
+ text: "Saturday, 1 January 2022"
23
+ )
24
+ ]
25
+ )
26
+
27
+ description = MsTeamsHermes::Components::TextBlock.new(
28
+ text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et " \
29
+ "dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip " \
30
+ "ex ea commodo consequat.",
31
+ wrap: true
32
+ )
33
+
34
+ facts = MsTeamsHermes::Components::FactSet.new(
35
+ facts: [
36
+ {
37
+ "title": "Board:",
38
+ "value": "Adaptive Card"
39
+ },
40
+ {
41
+ "title": "List:",
42
+ "value": "Backlog"
43
+ },
44
+ {
45
+ "title": "Assigned to:",
46
+ "value": "John Cena"
47
+ },
48
+ {
49
+ "title": "Due date:",
50
+ "value": "Not set"
51
+ }
52
+ ]
53
+ )
54
+
55
+ action = MsTeamsHermes::Actions::OpenUrl.new(
56
+ title: "View Website",
57
+ url: "https://adaptivecards.io"
58
+ )
59
+
60
+ content = MsTeamsHermes::Components::AdaptiveCard.new(
61
+ body: [
62
+ header,
63
+ MsTeamsHermes::Components::Container.new(
64
+ items: [
65
+ description,
66
+ facts
67
+ ]
68
+ )
69
+ ],
70
+ actions: [
71
+ action
72
+ ]
73
+ )
74
+
75
+ MsTeamsHermes::Message.new(webhook_url: YOUR_WEBHOOK_URL, content: content).deliver
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "msteams_hermes/components/base"
4
+
5
+ module MsTeamsHermes
6
+ module Actions
7
+ ##
8
+ # Base class of Actions representations
9
+ ##
10
+ class Base
11
+ def to_hash
12
+ raise "Should be implemented on the subclass"
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "msteams_hermes/actions/base"
4
+
5
+ module MsTeamsHermes
6
+ module Actions
7
+ ##
8
+ # A class representing Microsoft's Action.OpenUrl object
9
+ # https://adaptivecards.io/explorer/Action.OpenUrl.html
10
+ ##
11
+ class OpenUrl < Base
12
+ attr_reader :url, :title, :tooltip
13
+
14
+ def initialize(url:, title: nil, tooltip: nil)
15
+ @url = url
16
+ @title = title
17
+ @tooltip = tooltip
18
+ end
19
+
20
+ def to_hash
21
+ {
22
+ type: "Action.OpenUrl",
23
+ url: url,
24
+ title: title,
25
+ tooltip: tooltip
26
+ }
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "msteams_hermes/components/base"
4
+ require "msteams_hermes/style"
5
+
6
+ module MsTeamsHermes
7
+ ##
8
+ # Module containing Microsoft's components representations
9
+ ##
10
+ module Components
11
+ ##
12
+ # A class representing Microsoft's ActionSet object
13
+ # https://adaptivecards.io/explorer/ActionSet.html
14
+ ##
15
+ class ActionSet < Base
16
+ attr_reader :actions
17
+
18
+ def initialize(actions:)
19
+ @actions = actions
20
+ raise "ActionSet `actions` must be an Array" unless @actions.is_a? Array
21
+ end
22
+
23
+ def to_hash
24
+ {
25
+ type: "ActionSet",
26
+ actions: actions.map(&:to_hash)
27
+ }
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "msteams_hermes/components/base"
4
+
5
+ module MsTeamsHermes
6
+ ##
7
+ # Module containing Microsoft's components representations
8
+ ##
9
+ module Components
10
+ ##
11
+ # A class representing Microsoft's AdaptiveCard object
12
+ # https://adaptivecards.io/explorer/AdaptiveCard.html
13
+ ##
14
+ class AdaptiveCard < Base
15
+ attr_reader :body, :actions
16
+
17
+ def initialize(body:, actions: nil)
18
+ @body = body
19
+ raise "AdaptiveCard `body` must be an Array" unless @body.is_a? Array
20
+
21
+ @actions = actions
22
+ raise "AdaptiveCard `actions` must be an Array" unless @actions.nil? || @actions.is_a?(Array)
23
+ end
24
+
25
+ def to_hash
26
+ {
27
+ type: "AdaptiveCard",
28
+ version: "1.5",
29
+ body: body.map(&:to_hash),
30
+ actions: actions&.map(&:to_hash)
31
+ }
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "msteams_hermes/components/base"
4
+
5
+ module MsTeamsHermes
6
+ ##
7
+ # Module containing Microsoft's components representations
8
+ ##
9
+ module Components
10
+ ##
11
+ # Base class of Components representations
12
+ ##
13
+ class Base
14
+ def to_hash
15
+ raise "Should be implemented on the subclass"
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "msteams_hermes/components/base"
4
+ require "msteams_hermes/style"
5
+
6
+ module MsTeamsHermes
7
+ ##
8
+ # Module containing Microsoft's components representations
9
+ ##
10
+ module Components
11
+ ##
12
+ # A class representing Microsoft's Column object
13
+ # https://adaptivecards.io/explorer/Column.html
14
+ ##
15
+ class Column < Base
16
+ attr_reader :items, :width
17
+
18
+ def initialize(items:, width: "auto")
19
+ @items = items
20
+ raise "Column `items` must be an Array" unless @items.is_a? Array
21
+
22
+ @width = width
23
+ end
24
+
25
+ def to_hash
26
+ {
27
+ type: "Column",
28
+ width: width,
29
+ items: items.map(&:to_hash)
30
+ }
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "msteams_hermes/components/base"
4
+ require "msteams_hermes/style"
5
+
6
+ module MsTeamsHermes
7
+ ##
8
+ # Module containing Microsoft's components representations
9
+ ##
10
+ module Components
11
+ ##
12
+ # A class representing Microsoft's ColumnSet object
13
+ # https://adaptivecards.io/explorer/ColumnSet.html
14
+ ##
15
+ class ColumnSet < Base
16
+ attr_reader :columns
17
+
18
+ def initialize(columns:)
19
+ @columns = columns
20
+ raise "ColumnSet `columns` must be an Array" unless @columns.is_a? Array
21
+ end
22
+
23
+ def to_hash
24
+ {
25
+ type: "ColumnSet",
26
+ columns: columns.map(&:to_hash)
27
+ }
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "msteams_hermes/components/base"
4
+ require "msteams_hermes/style"
5
+
6
+ module MsTeamsHermes
7
+ ##
8
+ # Module containing Microsoft's components representations
9
+ ##
10
+ module Components
11
+ include MsTeamsHermes::Style
12
+ ##
13
+ # A class representing Microsoft's Container object
14
+ # https://adaptivecards.io/explorer/Container.html
15
+ ##
16
+ class Container < Base
17
+ attr_reader :items, :style, :select_action
18
+
19
+ def initialize(items:, style: Style::ContainerStyle::DEFAULT, select_action: nil)
20
+ @items = items
21
+ raise "Container `items` must be an Array" unless @items.is_a? Array
22
+
23
+ @style = style
24
+ @select_action = select_action
25
+ end
26
+
27
+ def to_hash
28
+ {
29
+ type: "Container",
30
+ style: style,
31
+ selectAction: select_action&.to_hash,
32
+ items: items.map(&:to_hash)
33
+ }
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "msteams_hermes/components/base"
4
+ require "msteams_hermes/style"
5
+
6
+ module MsTeamsHermes
7
+ ##
8
+ # Module containing Microsoft's components representations
9
+ ##
10
+ module Components
11
+ ##
12
+ # A class representing Microsoft's FactSet object
13
+ # https://adaptivecards.io/explorer/FactSet.html
14
+ ##
15
+ class FactSet < Base
16
+ attr_reader :facts
17
+
18
+ def initialize(facts:)
19
+ @facts = facts
20
+ raise "FactSet `facts` must be an Array of hashes containing title and value keys" unless valid_facts?
21
+ end
22
+
23
+ def to_hash
24
+ {
25
+ type: "FactSet",
26
+ facts: facts
27
+ }
28
+ end
29
+
30
+ private
31
+
32
+ def valid_facts?
33
+ facts.is_a?(Array) && facts.all? do |fact|
34
+ extra_keys = %i[title value] - fact.keys
35
+ fact.is_a?(Hash) && extra_keys.empty?
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "msteams_hermes/components/base"
4
+ require "msteams_hermes/style"
5
+
6
+ module MsTeamsHermes
7
+ ##
8
+ # Module containing Microsoft's components representations
9
+ ##
10
+ module Components
11
+ include MsTeamsHermes::Style
12
+ ##
13
+ # A class representing Microsoft's TextBlock object
14
+ # https://adaptivecards.io/explorer/TextBlock.html
15
+ ##
16
+ class TextBlock < Base
17
+ attr_reader :text, :wrap, :color, :size, :font_type, :weight, :is_subtle
18
+
19
+ def initialize(text:,
20
+ wrap: false,
21
+ color: Style::Colors::DEFAULT,
22
+ size: Style::FontSize::DEFAULT,
23
+ font_type: Style::FontType::DEFAULT,
24
+ weight: Style::FontWeight::DEFAULT,
25
+ is_subtle: false)
26
+ @text = text
27
+ raise "TextBlock `text` must be a String" unless @text.is_a? String
28
+
29
+ @wrap = wrap
30
+ @color = color
31
+ @size = size
32
+ @font_type = font_type
33
+ @weight = weight
34
+ @is_subtle = is_subtle
35
+ end
36
+
37
+ def to_hash
38
+ {
39
+ type: "TextBlock",
40
+ text: text,
41
+ color: color,
42
+ size: size,
43
+ font_type: font_type,
44
+ weight: weight,
45
+ wrap: wrap,
46
+ is_subtle: is_subtle
47
+ }
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "net/http"
4
+ require "json"
5
+
6
+ module MsTeamsHermes
7
+ ##
8
+ # A class representing Microsoft's webhook message object
9
+ # https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/connectors-using?tabs=cURL#send-adaptive-cards-using-an-incoming-webhook
10
+ ##
11
+ class Message
12
+ attr_reader :webhook_url, :content
13
+
14
+ def initialize(content:, webhook_url: ENV["WEBHOOK_URL"])
15
+ @webhook_url = webhook_url
16
+ @content = content
17
+
18
+ raise "Message `webhook_url` cannot be empty" if @webhook_url.nil?
19
+ raise "Message `content` must be an AdaptiveCard" unless @content.is_a? Components::AdaptiveCard
20
+ end
21
+
22
+ ##
23
+ # Sends a HTTP request to the webhook URL specified via
24
+ # either environment variable or when initializing the class
25
+ #
26
+ # @return a Net::HTTP response object
27
+ ##
28
+ def deliver
29
+ uri = URI.parse(webhook_url)
30
+ Net::HTTP.start(uri.host, uri.port, use_ssl: true, verify_mode: OpenSSL::SSL::VERIFY_NONE) do |http|
31
+ req = Net::HTTP::Post.new(uri)
32
+ req.body = body_json
33
+ req["Content-Type"] = "application/json"
34
+ http.request(req)
35
+ end
36
+ end
37
+
38
+ ##
39
+ # Formats the JSON object to be set on the HTTP request
40
+ #
41
+ # @return a JSON object
42
+ ##
43
+ def body_json
44
+ {
45
+ type: "message",
46
+ attachments: [
47
+ {
48
+ contentType: "application/vnd.microsoft.card.adaptive",
49
+ contentUrl: nil,
50
+ content: content.to_hash
51
+ }
52
+ ]
53
+ }.to_json
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MsTeamsHermes
4
+ ##
5
+ # Module containing Microsoft's style representations
6
+ ##
7
+ module Style
8
+ ##
9
+ # Module containing Microsoft's Colors representation
10
+ # See `Colors` in https://adaptivecards.io/explorer/TextBlock.html
11
+ ##
12
+ module Colors
13
+ DEFAULT = "default"
14
+ ACCENT = "accent"
15
+ GOOD = "good"
16
+ WARNING = "warning"
17
+ ATTENTION = "attention"
18
+ LIGHT = "light"
19
+ DARK = "dark"
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MsTeamsHermes
4
+ ##
5
+ # Module containing Microsoft's style representations
6
+ ##
7
+ module Style
8
+ ##
9
+ # Module containing Microsoft's ContainerStyle representation
10
+ # See `ContainerStyle` in https://adaptivecards.io/explorer/Container.html
11
+ ##
12
+ module ContainerStyle
13
+ DEFAULT = "default"
14
+ ACCENT = "accent"
15
+ GOOD = "good"
16
+ WARNING = "warning"
17
+ ATTENTION = "attention"
18
+ EMPHASIS = "emphasis"
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MsTeamsHermes
4
+ ##
5
+ # Module containing Microsoft's style representations
6
+ ##
7
+ module Style
8
+ ##
9
+ # Module containing Microsoft's FontSize representation
10
+ # See `FontSize` in https://adaptivecards.io/explorer/TextBlock.html
11
+ ##
12
+ module FontSize
13
+ DEFAULT = "default"
14
+ SMALL = "small"
15
+ MEDIUM = "medium"
16
+ LARGE = "large"
17
+ EXTRA_LARGE = "extraLarge"
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MsTeamsHermes
4
+ ##
5
+ # Module containing Microsoft's style representations
6
+ ##
7
+ module Style
8
+ ##
9
+ # Module containing Microsoft's FontType representation
10
+ # See `FontType` in https://adaptivecards.io/explorer/TextBlock.html
11
+ ##
12
+ module FontType
13
+ DEFAULT = "default"
14
+ MONOSPACE = "monospace"
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MsTeamsHermes
4
+ ##
5
+ # Module containing Microsoft's style representations
6
+ ##
7
+ module Style
8
+ ##
9
+ # Module containing Microsoft's FontWeight representation
10
+ # See `FontWeight` in https://adaptivecards.io/explorer/TextBlock.html
11
+ ##
12
+ module FontWeight
13
+ DEFAULT = "default"
14
+ LIGHTER = "lighter"
15
+ BOLDER = "bolder"
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "msteams_hermes/style/colors"
4
+ require "msteams_hermes/style/container_style"
5
+ require "msteams_hermes/style/font_size"
6
+ require "msteams_hermes/style/font_type"
7
+ require "msteams_hermes/style/font_weight"
8
+
9
+ module MsTeamsHermes
10
+ ##
11
+ # Module containing Microsoft's style representations
12
+ ##
13
+ module Style
14
+ include MsTeamsHermes::Style::Colors
15
+ include MsTeamsHermes::Style::ContainerStyle
16
+ include MsTeamsHermes::Style::FontSize
17
+ include MsTeamsHermes::Style::FontType
18
+ include MsTeamsHermes::Style::FontWeight
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MsTeamsHermes
4
+ VERSION = "1.0.0"
5
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "msteams_hermes/version"
4
+ require_relative "msteams_hermes/message"
5
+
6
+ ##
7
+ # MsTeamsHermes module
8
+ ##
9
+ module MsTeamsHermes; end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/msteams_hermes/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "msteams_hermes"
7
+ spec.version = MsTeamsHermes::VERSION
8
+ spec.authors = ["Rafael Rocha"]
9
+ spec.email = "opensource@xing.com"
10
+ spec.date = Time.now.strftime("%Y-%m-%d")
11
+
12
+ spec.summary = "Send messages to any Microsoft Teams' channel as easy as possible."
13
+ spec.description = "This gem helps you sending messages to your Microsoft Teams channels. " \
14
+ "With autonomy to create your own layouts, like UI kits such as React, Flutter, SwiftUI " \
15
+ "(and some others), you will be able to customize it with the objects representations of " \
16
+ "Microsoft's adaptive cards."
17
+ spec.homepage = "https://github.com/xing/msteams_hermes"
18
+ spec.license = "MIT"
19
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
20
+
21
+ spec.metadata["homepage_uri"] = spec.homepage
22
+ spec.metadata["source_code_uri"] = "https://github.com/xing/msteams_hermes"
23
+ spec.metadata["changelog_uri"] = "https://github.com/xing/msteams_hermes/CHANGELOG.md"
24
+
25
+ # Specify which files should be added to the gem when it is released.
26
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
27
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
28
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
29
+ end
30
+ spec.bindir = "exe"
31
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ["lib"]
33
+
34
+ # Uncomment to register a new dependency of your gem
35
+ # spec.add_dependency "example-gem", "~> 1.0"
36
+
37
+ # For more information and examples about making a new gem, checkout our
38
+ # guide at: https://bundler.io/guides/creating_gem.html
39
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: msteams_hermes
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Rafael Rocha
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-11-01 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: This gem helps you sending messages to your Microsoft Teams channels.
14
+ With autonomy to create your own layouts, like UI kits such as React, Flutter, SwiftUI
15
+ (and some others), you will be able to customize it with the objects representations
16
+ of Microsoft's adaptive cards.
17
+ email: opensource@xing.com
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - ".github/workflows/ci.yml"
23
+ - ".gitignore"
24
+ - ".rspec"
25
+ - ".rubocop.yml"
26
+ - CHANGELOG.md
27
+ - CODE_OF_CONDUCT.md
28
+ - Gemfile
29
+ - Gemfile.lock
30
+ - LICENSE.txt
31
+ - README.md
32
+ - Rakefile
33
+ - bin/console
34
+ - bin/setup
35
+ - complex_example.rb
36
+ - lib/msteams_hermes.rb
37
+ - lib/msteams_hermes/actions/base.rb
38
+ - lib/msteams_hermes/actions/open_url.rb
39
+ - lib/msteams_hermes/components/action_set.rb
40
+ - lib/msteams_hermes/components/adaptive_card.rb
41
+ - lib/msteams_hermes/components/base.rb
42
+ - lib/msteams_hermes/components/column.rb
43
+ - lib/msteams_hermes/components/column_set.rb
44
+ - lib/msteams_hermes/components/container.rb
45
+ - lib/msteams_hermes/components/fact_set.rb
46
+ - lib/msteams_hermes/components/text_block.rb
47
+ - lib/msteams_hermes/message.rb
48
+ - lib/msteams_hermes/style.rb
49
+ - lib/msteams_hermes/style/colors.rb
50
+ - lib/msteams_hermes/style/container_style.rb
51
+ - lib/msteams_hermes/style/font_size.rb
52
+ - lib/msteams_hermes/style/font_type.rb
53
+ - lib/msteams_hermes/style/font_weight.rb
54
+ - lib/msteams_hermes/version.rb
55
+ - msteams_hermes.gemspec
56
+ homepage: https://github.com/xing/msteams_hermes
57
+ licenses:
58
+ - MIT
59
+ metadata:
60
+ homepage_uri: https://github.com/xing/msteams_hermes
61
+ source_code_uri: https://github.com/xing/msteams_hermes
62
+ changelog_uri: https://github.com/xing/msteams_hermes/CHANGELOG.md
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: 2.7.0
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubygems_version: 3.2.33
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Send messages to any Microsoft Teams' channel as easy as possible.
82
+ test_files: []