microsoft_teams_incoming_webhook_ruby 0.1.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 +7 -0
- data/.github/workflows/ci.yml +36 -0
- data/.github/workflows/publish_to_rubygems.yml +31 -0
- data/.gitignore +10 -0
- data/.rspec +3 -0
- data/.rubocop.yml +36 -0
- data/CHANGELOG.md +11 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Dockerfile +6 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +180 -0
- data/Rakefile +10 -0
- data/bin/console +7 -0
- data/bin/setup +7 -0
- data/lib/microsoft_teams_incoming_webhook_ruby/message.rb +61 -0
- data/lib/microsoft_teams_incoming_webhook_ruby/version.rb +5 -0
- data/lib/microsoft_teams_incoming_webhook_ruby.rb +6 -0
- data/microsoft_teams.png +0 -0
- data/microsoft_teams_incoming_webhook_ruby.gemspec +32 -0
- metadata +135 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: d0c571083b61043cc97cf99f320f91c54fa2bc23724553d3eb4cc862573fcbd7
|
|
4
|
+
data.tar.gz: c54e9204da1e10d72a5ca2c8542d3aa612544af37c2f6c1bc3d3c03f1d7ac7de
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 5d837c4e2ecc294a05666d620be29de5df21a96a6ff6ad444e0f6df7ba5619a138f1ed4aec96cdc962cf98d099d82f3d92fa7b5e7bed4befa7c1efb8831af860
|
|
7
|
+
data.tar.gz: 5f396da0271d571114229429a8c05f9adeb68b52c9b7238b2e467f2ee9b0880a179b877019397cd67ea94888e717b76c5dc8f89730ea094ee78e6852cfbbd10f
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on: [push, pull_request]
|
|
4
|
+
|
|
5
|
+
jobs:
|
|
6
|
+
dockerfile:
|
|
7
|
+
runs-on: ubuntu-latest
|
|
8
|
+
steps:
|
|
9
|
+
- uses: actions/checkout@v2
|
|
10
|
+
|
|
11
|
+
- name: Build Dockerfile
|
|
12
|
+
run: docker build -t microsoft_teams_incoming_webhook_ruby_specs .
|
|
13
|
+
|
|
14
|
+
- name: Run tests inside Docker container
|
|
15
|
+
run: docker run -v $(pwd):/app/ -i microsoft_teams_incoming_webhook_ruby_specs
|
|
16
|
+
|
|
17
|
+
tests:
|
|
18
|
+
runs-on: ubuntu-latest
|
|
19
|
+
strategy:
|
|
20
|
+
matrix:
|
|
21
|
+
ruby-version: [2.3, 2.4, 2.5, 2.6, 2.7, 3.0]
|
|
22
|
+
env:
|
|
23
|
+
CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}}
|
|
24
|
+
steps:
|
|
25
|
+
- uses: actions/checkout@v2
|
|
26
|
+
|
|
27
|
+
- name: Install Ruby ${{ matrix.ruby-version }}
|
|
28
|
+
uses: ruby/setup-ruby@v1
|
|
29
|
+
with:
|
|
30
|
+
ruby-version: ${{ matrix.ruby-version }}
|
|
31
|
+
|
|
32
|
+
- name: Install dependencies
|
|
33
|
+
run: bundle install
|
|
34
|
+
|
|
35
|
+
- name: Run tests with Ruby ${{ matrix.ruby-version }}
|
|
36
|
+
run: bundle exec rake
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
name: Publish to Rubygems
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_dispatch:
|
|
5
|
+
release:
|
|
6
|
+
types: [created]
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
deploy:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v2
|
|
13
|
+
|
|
14
|
+
- name: Install Ruby
|
|
15
|
+
uses: ruby/setup-ruby@v1
|
|
16
|
+
with:
|
|
17
|
+
ruby-version: 3.0
|
|
18
|
+
|
|
19
|
+
- name: Install dependencies
|
|
20
|
+
run: bundle install
|
|
21
|
+
|
|
22
|
+
- name: Publish to Rubygems
|
|
23
|
+
run: |
|
|
24
|
+
mkdir -p $HOME/.gem
|
|
25
|
+
touch $HOME/.gem/credentials
|
|
26
|
+
chmod 0600 $HOME/.gem/credentials
|
|
27
|
+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
|
28
|
+
gem build *.gemspec
|
|
29
|
+
gem push *.gem
|
|
30
|
+
env:
|
|
31
|
+
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
AllCops:
|
|
2
|
+
NewCops: enable
|
|
3
|
+
SuggestExtensions: false
|
|
4
|
+
Exclude:
|
|
5
|
+
- spec/*
|
|
6
|
+
- microsoft_teams_incoming_webhook_ruby.gemspec
|
|
7
|
+
|
|
8
|
+
Gemspec/RequiredRubyVersion:
|
|
9
|
+
Enabled: false
|
|
10
|
+
|
|
11
|
+
Style/Documentation:
|
|
12
|
+
Enabled: false
|
|
13
|
+
|
|
14
|
+
Lint/UnusedMethodArgument:
|
|
15
|
+
Enabled: false
|
|
16
|
+
|
|
17
|
+
Style/WordArray:
|
|
18
|
+
Enabled: false
|
|
19
|
+
|
|
20
|
+
Style/MutableConstant:
|
|
21
|
+
Enabled: false
|
|
22
|
+
|
|
23
|
+
Layout/EmptyLineBetweenDefs:
|
|
24
|
+
Enabled: false
|
|
25
|
+
|
|
26
|
+
Style/SymbolArray:
|
|
27
|
+
Enabled: false
|
|
28
|
+
|
|
29
|
+
Lint/ScriptPermission:
|
|
30
|
+
Enabled: false
|
|
31
|
+
|
|
32
|
+
Layout/LineLength:
|
|
33
|
+
Enabled: false
|
|
34
|
+
|
|
35
|
+
Style/StringLiterals:
|
|
36
|
+
EnforcedStyle: single_quotes
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
## [Unreleased]
|
|
2
|
+
|
|
3
|
+
## [1.0.0] - 2021-09-XX
|
|
4
|
+
|
|
5
|
+
- Initial release
|
|
6
|
+
- Setup of automation for rubygems publishing
|
|
7
|
+
- Setup of CI with Github Actions
|
|
8
|
+
- Setup of Dockerfile for local tests
|
|
9
|
+
- Creation of CHANGELOG.md
|
|
10
|
+
- Setup of RuboCop
|
|
11
|
+
- Setup of CodeCov for CI
|
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
22
|
+
|
|
23
|
+
Examples of unacceptable behavior by participants include:
|
|
24
|
+
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
+
* Public or private harassment
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting the project team at TODO: Write your email address. All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
63
|
+
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
67
|
+
|
|
68
|
+
## Attribution
|
|
69
|
+
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
|
72
|
+
|
|
73
|
+
[homepage]: https://contributor-covenant.org
|
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Dockerfile
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) Pedro Furtado
|
|
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,180 @@
|
|
|
1
|
+
# Microsoft Teams Incoming Webhook Ruby
|
|
2
|
+
|
|
3
|
+
[](https://github.com/pedrofurtado/microsoft_teams_incoming_webhook_ruby/actions/workflows/ci.yml)
|
|
4
|
+
[](https://codecov.io/gh/pedrofurtado/microsoft_teams_incoming_webhook_ruby)
|
|
5
|
+
[](https://codeclimate.com/github/pedrofurtado/microsoft_teams_incoming_webhook_ruby/maintainability)
|
|
6
|
+
[](https://badge.fury.io/rb/microsoft_teams_incoming_webhook_ruby)
|
|
7
|
+
[]()
|
|
8
|
+
[]()
|
|
9
|
+
[](https://github.com/pedrofurtado/microsoft_teams_incoming_webhook_ruby)
|
|
10
|
+
[](https://github.com/rubocop/rubocop)
|
|
11
|
+
|
|
12
|
+
Ruby gem for integration with Microsoft Teams Incoming Webhook.
|
|
13
|
+
|
|
14
|
+
<img style="max-width: 100%;" src="https://github.com/pedrofurtado/microsoft_teams_incoming_webhook_ruby/blob/master/microsoft_teams.png?raw=true" height="100px" />
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
Add this line to your application's Gemfile:
|
|
19
|
+
|
|
20
|
+
```ruby
|
|
21
|
+
gem 'microsoft_teams_incoming_webhook_ruby'
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
And then execute:
|
|
25
|
+
|
|
26
|
+
```shell
|
|
27
|
+
bundle install
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Or install it yourself as:
|
|
31
|
+
|
|
32
|
+
```shell
|
|
33
|
+
gem install microsoft_teams_incoming_webhook_ruby
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Usage
|
|
37
|
+
|
|
38
|
+
### Configuration of Incoming Webhook connector on your Teams channels
|
|
39
|
+
|
|
40
|
+
The first step before using this gem is to configure the connector inside your Team channels.
|
|
41
|
+
|
|
42
|
+
For this purpose, please check the official documentation from Microsoft. It's listed below some useful links:
|
|
43
|
+
|
|
44
|
+
- https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook#create-incoming-webhook-1
|
|
45
|
+
- https://www.youtube.com/watch?v=amvh4rzTCS0
|
|
46
|
+
|
|
47
|
+
### 'Hello World' message sending, for testing
|
|
48
|
+
|
|
49
|
+
Once you have Incoming Webhook configured in Teams channels, you can send a sample `Hello World` message (for testing) with such code like this:
|
|
50
|
+
|
|
51
|
+
```ruby
|
|
52
|
+
require 'microsoft_teams_incoming_webhook_ruby'
|
|
53
|
+
|
|
54
|
+
message = MicrosoftTeamsIncomingWebhookRuby::Message.new do |m|
|
|
55
|
+
m.url = 'YOUR INCOMING WEBHOOK URL HERE'
|
|
56
|
+
m.text = 'Hello World!'
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
message.send
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Note that there are 2 keys that is the minimum required to define a valid message:
|
|
63
|
+
- `url`: The URL of Incoming Webhook connector, generated via Microsoft Teams
|
|
64
|
+
- `text`: The text of your message
|
|
65
|
+
|
|
66
|
+
There are many other possible keys to be sent to Microsoft Incoming Webhook API. But pay attention to always send at least this 2 keys.
|
|
67
|
+
|
|
68
|
+
### Configuration of message structure lately of initialization
|
|
69
|
+
|
|
70
|
+
### Error handling
|
|
71
|
+
|
|
72
|
+
You can build the message with any supported [card fields](https://docs.microsoft.com/en-us/outlook/actionable-messages/message-card-reference#card-fields).
|
|
73
|
+
This example is taken directly from [Microsoft Docs](https://docs.microsoft.com/en-us/outlook/actionable-messages/send-via-connectors)
|
|
74
|
+
```ruby
|
|
75
|
+
require "ms_teams"
|
|
76
|
+
|
|
77
|
+
message = MsTeams::Message.new do |m|
|
|
78
|
+
m.url = "https://outlook.office.com/...."
|
|
79
|
+
m.themeColor = "0072C6"
|
|
80
|
+
m.title = "Visit the Outlook Dev Portal"
|
|
81
|
+
m.text = "Click **Learn More** to learn more about Actionable Messages!"
|
|
82
|
+
m.potentialAction = [
|
|
83
|
+
{
|
|
84
|
+
"@type": "ActionCard",
|
|
85
|
+
"name": "Send Feedback",
|
|
86
|
+
"inputs": [{
|
|
87
|
+
"@type": "TextInput",
|
|
88
|
+
"id": "feedback",
|
|
89
|
+
"isMultiline": true,
|
|
90
|
+
"title": "Let us know what you think about Actionable Messages"
|
|
91
|
+
}],
|
|
92
|
+
"actions": [{
|
|
93
|
+
"@type": "HttpPOST",
|
|
94
|
+
"name": "Send Feedback",
|
|
95
|
+
"isPrimary": true,
|
|
96
|
+
"target": "http://..."
|
|
97
|
+
}]
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
"@type": "OpenUri",
|
|
101
|
+
"name": "Learn More",
|
|
102
|
+
"targets": [
|
|
103
|
+
{ "os": "default", "uri": "https://docs.microsoft.com/outlook/actionable-messages" }
|
|
104
|
+
]
|
|
105
|
+
}
|
|
106
|
+
]
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# You can edit any field after the message has been built by modifying the `builder` object
|
|
110
|
+
message.builder.text = "Something new"
|
|
111
|
+
|
|
112
|
+
message.send
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Error Handling:
|
|
116
|
+
|
|
117
|
+
A non-2xx response code will raise a `MsTeams::Message::FailedRequest` error
|
|
118
|
+
|
|
119
|
+
```ruby
|
|
120
|
+
# ...
|
|
121
|
+
begin
|
|
122
|
+
message.send
|
|
123
|
+
rescue MsTeams::Message::FailedRequest => e
|
|
124
|
+
# Do stuff
|
|
125
|
+
end
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
Building an invalid message object will immediately raise an error
|
|
130
|
+
|
|
131
|
+
```ruby
|
|
132
|
+
message = MsTeams::Message.new do |m|
|
|
133
|
+
# no url set
|
|
134
|
+
m.text = "Hello World"
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
> ArgumentError (`url` cannot be nil. Must be set during initialization)
|
|
138
|
+
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Execute tests/specs
|
|
142
|
+
|
|
143
|
+
To execute gem tests locally, use Docker with the commands below:
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
git clone https://github.com/pedrofurtado/microsoft_teams_incoming_webhook_ruby
|
|
147
|
+
cd microsoft_teams_incoming_webhook_ruby
|
|
148
|
+
docker build -t microsoft_teams_incoming_webhook_ruby_specs .
|
|
149
|
+
|
|
150
|
+
# Then, run this command how many times you want,
|
|
151
|
+
# after editing local files, and so on, to get
|
|
152
|
+
# feedback from test suite of gem.
|
|
153
|
+
docker run -v $(pwd):/app/ -it microsoft_teams_incoming_webhook_ruby_specs
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## Demo
|
|
157
|
+
|
|
158
|
+
...
|
|
159
|
+
|
|
160
|
+
## Another similar gems for reference
|
|
161
|
+
|
|
162
|
+
There are similar open source libraries that shares the same purpose of this gem, such as:
|
|
163
|
+
|
|
164
|
+
- https://github.com/toririn/teams_incoming_clients
|
|
165
|
+
- https://github.com/shirts/microsoft-teams-ruby
|
|
166
|
+
- https://github.com/oooooooo/msteams-ruby-client
|
|
167
|
+
- https://github.com/eduardolagares/msteams_webhook
|
|
168
|
+
|
|
169
|
+
## Contributing
|
|
170
|
+
|
|
171
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/pedrofurtado/microsoft_teams_incoming_webhook_ruby. 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/pedrofurtado/microsoft_teams_incoming_webhook_ruby/blob/master/CODE_OF_CONDUCT.md).
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
## License
|
|
175
|
+
|
|
176
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
177
|
+
|
|
178
|
+
## Code of Conduct
|
|
179
|
+
|
|
180
|
+
Everyone interacting in the microsoft_teams_incoming_webhook_ruby project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/pedrofurtado/microsoft_teams_incoming_webhook_ruby/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/setup
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'net/http'
|
|
4
|
+
require 'json'
|
|
5
|
+
|
|
6
|
+
module MicrosoftTeamsIncomingWebhookRuby
|
|
7
|
+
class Message
|
|
8
|
+
module Error
|
|
9
|
+
class GenericError < StandardError; end
|
|
10
|
+
class InvalidMessage < GenericError; end
|
|
11
|
+
class FailedRequest < GenericError; end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
attr_reader :builder
|
|
15
|
+
|
|
16
|
+
def initialize(&block)
|
|
17
|
+
@builder = OpenStruct.new
|
|
18
|
+
yield @builder
|
|
19
|
+
validate_builder
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def send
|
|
23
|
+
validate_builder
|
|
24
|
+
response = send_by_http
|
|
25
|
+
check_failure_for(response)
|
|
26
|
+
response
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
REQUIRED_FIELDS = ['url', 'text']
|
|
32
|
+
|
|
33
|
+
def validate_builder
|
|
34
|
+
REQUIRED_FIELDS.each do |field|
|
|
35
|
+
raise_error_on(field) if @builder[field].nil? || @builder[field].empty?
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def raise_error_on(field)
|
|
40
|
+
raise Error::InvalidMessage, "'#{field}' must be defined in Message"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def send_by_http
|
|
44
|
+
uri = URI.parse(@builder.url)
|
|
45
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
46
|
+
http.use_ssl = true
|
|
47
|
+
http.post(uri.path, @builder.to_h.to_json, 'Content-Type': 'application/json')
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def check_failure_for(response)
|
|
51
|
+
raise Error::FailedRequest, "The message failed to be sent (HTTP Code #{response.code})" unless success?(response)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def success?(http_response)
|
|
55
|
+
http_code = http_response&.code&.to_i
|
|
56
|
+
http_code_2xx = http_code >= 200 && http_code <= 299
|
|
57
|
+
http_code_3xx = http_code >= 300 && http_code <= 399
|
|
58
|
+
http_code_2xx || http_code_3xx
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
data/microsoft_teams.png
ADDED
|
Binary file
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'lib/microsoft_teams_incoming_webhook_ruby/version'
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = 'microsoft_teams_incoming_webhook_ruby'
|
|
7
|
+
spec.version = MicrosoftTeamsIncomingWebhookRuby::VERSION
|
|
8
|
+
spec.authors = ['Pedro Furtado']
|
|
9
|
+
spec.email = ['pedro.felipe.azevedo.furtado@gmail.com']
|
|
10
|
+
spec.summary = 'Ruby gem for integration with Microsoft Teams Incoming Webhook'
|
|
11
|
+
spec.description = 'Ruby gem for integration with Microsoft Teams Incoming Webhook'
|
|
12
|
+
spec.homepage = 'https://github.com/pedrofurtado/microsoft_teams_incoming_webhook_ruby'
|
|
13
|
+
spec.license = 'MIT'
|
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
|
|
15
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
16
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
|
17
|
+
spec.metadata["changelog_uri"] = "#{spec.homepage}/CHANGELOG.md"
|
|
18
|
+
|
|
19
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
spec.bindir = 'exe'
|
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
25
|
+
spec.require_paths = ['lib']
|
|
26
|
+
|
|
27
|
+
spec.add_development_dependency 'rake'
|
|
28
|
+
spec.add_development_dependency 'rspec'
|
|
29
|
+
spec.add_development_dependency 'webmock'
|
|
30
|
+
spec.add_development_dependency 'rubocop'
|
|
31
|
+
spec.add_development_dependency 'codecov'
|
|
32
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: microsoft_teams_incoming_webhook_ruby
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Pedro Furtado
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2021-09-25 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rake
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rspec
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: webmock
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: rubocop
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: codecov
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ">="
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ">="
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0'
|
|
83
|
+
description: Ruby gem for integration with Microsoft Teams Incoming Webhook
|
|
84
|
+
email:
|
|
85
|
+
- pedro.felipe.azevedo.furtado@gmail.com
|
|
86
|
+
executables: []
|
|
87
|
+
extensions: []
|
|
88
|
+
extra_rdoc_files: []
|
|
89
|
+
files:
|
|
90
|
+
- ".github/workflows/ci.yml"
|
|
91
|
+
- ".github/workflows/publish_to_rubygems.yml"
|
|
92
|
+
- ".gitignore"
|
|
93
|
+
- ".rspec"
|
|
94
|
+
- ".rubocop.yml"
|
|
95
|
+
- CHANGELOG.md
|
|
96
|
+
- CODE_OF_CONDUCT.md
|
|
97
|
+
- Dockerfile
|
|
98
|
+
- Gemfile
|
|
99
|
+
- LICENSE.txt
|
|
100
|
+
- README.md
|
|
101
|
+
- Rakefile
|
|
102
|
+
- bin/console
|
|
103
|
+
- bin/setup
|
|
104
|
+
- lib/microsoft_teams_incoming_webhook_ruby.rb
|
|
105
|
+
- lib/microsoft_teams_incoming_webhook_ruby/message.rb
|
|
106
|
+
- lib/microsoft_teams_incoming_webhook_ruby/version.rb
|
|
107
|
+
- microsoft_teams.png
|
|
108
|
+
- microsoft_teams_incoming_webhook_ruby.gemspec
|
|
109
|
+
homepage: https://github.com/pedrofurtado/microsoft_teams_incoming_webhook_ruby
|
|
110
|
+
licenses:
|
|
111
|
+
- MIT
|
|
112
|
+
metadata:
|
|
113
|
+
homepage_uri: https://github.com/pedrofurtado/microsoft_teams_incoming_webhook_ruby
|
|
114
|
+
source_code_uri: https://github.com/pedrofurtado/microsoft_teams_incoming_webhook_ruby
|
|
115
|
+
changelog_uri: https://github.com/pedrofurtado/microsoft_teams_incoming_webhook_ruby/CHANGELOG.md
|
|
116
|
+
post_install_message:
|
|
117
|
+
rdoc_options: []
|
|
118
|
+
require_paths:
|
|
119
|
+
- lib
|
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
121
|
+
requirements:
|
|
122
|
+
- - ">="
|
|
123
|
+
- !ruby/object:Gem::Version
|
|
124
|
+
version: 2.3.0
|
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
|
+
requirements:
|
|
127
|
+
- - ">="
|
|
128
|
+
- !ruby/object:Gem::Version
|
|
129
|
+
version: '0'
|
|
130
|
+
requirements: []
|
|
131
|
+
rubygems_version: 3.2.22
|
|
132
|
+
signing_key:
|
|
133
|
+
specification_version: 4
|
|
134
|
+
summary: Ruby gem for integration with Microsoft Teams Incoming Webhook
|
|
135
|
+
test_files: []
|