ms_teams 1.0.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/.gitignore +15 -0
- data/.rspec +3 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +21 -0
- data/README.md +121 -0
- data/Rakefile +6 -0
- data/bin/setup +8 -0
- data/lib/ms_teams.rb +6 -0
- data/lib/ms_teams/message.rb +69 -0
- data/lib/ms_teams/version.rb +3 -0
- data/ms_teams.gemspec +29 -0
- metadata +102 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6fbb7f62e16f89c6b71560721645badd5d0ddd02753229c92e28788305c09994
|
4
|
+
data.tar.gz: 8fc8cef22666d53c94f0da9b9ff70acb604671c334d6647c73cce75d6b93392f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b7ca3b0e79592a457882e55b26cd8633fb5f307ca4544888872afe2fc77e34783604cc152e7a32c9503092b32b00cf93050655c70457170e1e77d61d58845ecb
|
7
|
+
data.tar.gz: bd9a78cee380a61afec3dce2150e4106aad4d614e4d95df2a0903b2807985b53284876d7fbdcfcd1a13fd98449ceb75b6ec4a139de10a5f32f9c22d79b2e337d
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Kevin Chandler
|
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,121 @@
|
|
1
|
+
# MS-Teams
|
2
|
+
|
3
|
+
A lightweight Ruby gem to send
|
4
|
+
[actionable message cards](https://docs.microsoft.com/en-us/outlook/actionable-messages/send-via-connectors)
|
5
|
+
to an Office 365 group (Microsoft Teams)
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem "ms_teams"
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install ms_teams
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Sending a simple message with just text:
|
26
|
+
|
27
|
+
The most-barebones your message will be will include at least:
|
28
|
+
- `url`: The Incoming Webhook connector generated via Teams
|
29
|
+
- `text`: The text of the message you are sending
|
30
|
+
|
31
|
+
Example:
|
32
|
+
```ruby
|
33
|
+
require "ms_teams"
|
34
|
+
|
35
|
+
message = MsTeams::Message.new do |m|
|
36
|
+
m.url = "https://outlook.office.com/...."
|
37
|
+
m.text = "Hello World!"
|
38
|
+
end
|
39
|
+
|
40
|
+
message.send
|
41
|
+
|
42
|
+
```
|
43
|
+
|
44
|
+
You can build the message with any supported [card fields](https://docs.microsoft.com/en-us/outlook/actionable-messages/message-card-reference#card-fields).
|
45
|
+
This example is taken directly from [Microsoft Docs](https://docs.microsoft.com/en-us/outlook/actionable-messages/send-via-connectors)
|
46
|
+
```ruby
|
47
|
+
require "ms_teams"
|
48
|
+
|
49
|
+
message = MsTeams::Message.new do |m|
|
50
|
+
m.url = "https://outlook.office.com/...."
|
51
|
+
m.themeColor = "0072C6"
|
52
|
+
m.title = "Visit the Outlook Dev Portal"
|
53
|
+
m.text = "Click **Learn More** to learn more about Actionable Messages!"
|
54
|
+
m.potentialAction = [
|
55
|
+
{
|
56
|
+
"@type": "ActionCard",
|
57
|
+
"name": "Send Feedback",
|
58
|
+
"inputs": [{
|
59
|
+
"@type": "TextInput",
|
60
|
+
"id": "feedback",
|
61
|
+
"isMultiline": true,
|
62
|
+
"title": "Let us know what you think about Actionable Messages"
|
63
|
+
}],
|
64
|
+
"actions": [{
|
65
|
+
"@type": "HttpPOST",
|
66
|
+
"name": "Send Feedback",
|
67
|
+
"isPrimary": true,
|
68
|
+
"target": "http://..."
|
69
|
+
}]
|
70
|
+
},
|
71
|
+
{
|
72
|
+
"@type": "OpenUri",
|
73
|
+
"name": "Learn More",
|
74
|
+
"targets": [
|
75
|
+
{ "os": "default", "uri": "https://docs.microsoft.com/outlook/actionable-messages" }
|
76
|
+
]
|
77
|
+
}
|
78
|
+
]
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
# You can edit any field after the message has been built by modifying the `builder` object
|
83
|
+
message.builder.text = "Something new"
|
84
|
+
|
85
|
+
message.send
|
86
|
+
```
|
87
|
+
|
88
|
+
Error Handling:
|
89
|
+
|
90
|
+
A non-2xx response code will raise a `MsTeams::Message::FailedRequest` error
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
# ...
|
94
|
+
begin
|
95
|
+
message.send
|
96
|
+
rescue MsTeams::Message::FailedRequest => e
|
97
|
+
# Do stuff
|
98
|
+
end
|
99
|
+
```
|
100
|
+
|
101
|
+
|
102
|
+
Building an invalid message object will immediately raise an error
|
103
|
+
|
104
|
+
```ruby
|
105
|
+
message = MsTeams::Message.new do |m|
|
106
|
+
# no url set
|
107
|
+
m.text = "Hello World"
|
108
|
+
end
|
109
|
+
|
110
|
+
> ArgumentError (`url` cannot be nil. Must be set during initialization)
|
111
|
+
|
112
|
+
```
|
113
|
+
|
114
|
+
|
115
|
+
## Contributing
|
116
|
+
|
117
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/shirts/microsoft-teams-ruby
|
118
|
+
|
119
|
+
## License
|
120
|
+
|
121
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/setup
ADDED
data/lib/ms_teams.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require "net/http"
|
2
|
+
require "json"
|
3
|
+
|
4
|
+
module MsTeams
|
5
|
+
class Message
|
6
|
+
class FailedRequest < StandardError; end
|
7
|
+
|
8
|
+
# Necessary fields to successfully send a message
|
9
|
+
REQUIRED_FIELDS = %w(text url).freeze
|
10
|
+
|
11
|
+
attr_accessor :builder
|
12
|
+
|
13
|
+
# Initializes Team::Messages and builds an OpenStruct object
|
14
|
+
# from a required block containing arbitrary values
|
15
|
+
# and validates that the required fields are present
|
16
|
+
# @param block [Proc]
|
17
|
+
def initialize( &block )
|
18
|
+
@builder = OpenStruct.new
|
19
|
+
yield @builder
|
20
|
+
validate
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
# POSTs a message to the url.
|
25
|
+
# If the response is not successful it raises
|
26
|
+
# a MsTeams::Message::FailedRequest error
|
27
|
+
# @return response [Net:HTTPResponse]
|
28
|
+
def send
|
29
|
+
uri = URI.parse( @builder.url )
|
30
|
+
http = Net::HTTP.new( uri.host, uri.port )
|
31
|
+
http.use_ssl = true
|
32
|
+
response = http.post( uri.path, @builder.to_h.to_json, "Content-Type": "application/json" )
|
33
|
+
unless successful_response?( response )
|
34
|
+
raise FailedRequest, "Unable to send message successfully. Response code `#{response.code}`"
|
35
|
+
end
|
36
|
+
response
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
# Ensures that the required fields are present
|
41
|
+
# Raises an ArgumentError if the required fields are not present.
|
42
|
+
def validate
|
43
|
+
REQUIRED_FIELDS.each do |field|
|
44
|
+
error( field ) if @builder[field].nil? || @builder[field].empty?
|
45
|
+
end
|
46
|
+
|
47
|
+
true
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
|
54
|
+
def error( field )
|
55
|
+
raise ArgumentError, "`#{field}` cannot be nil. Must be set during initialization"
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
def successful_response?( http_response )
|
60
|
+
code = http_response&.code&.to_i
|
61
|
+
if code < 200 || code >= 300
|
62
|
+
return false
|
63
|
+
end
|
64
|
+
|
65
|
+
true
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
data/ms_teams.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative 'lib/ms_teams/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "ms_teams"
|
5
|
+
spec.version = MsTeams::VERSION
|
6
|
+
spec.authors = ["Kevin Chandler", "Jana Abumeri"]
|
7
|
+
spec.email = ["im.kevin@me.com", "jabumeri@uci.edu"]
|
8
|
+
|
9
|
+
spec.summary = %q{A lightweight Ruby gem to send actionable message cards to an Office 365 group (Microsoft Teams) }
|
10
|
+
spec.homepage = "https://github.com/shirts/microsoft-teams-ruby"
|
11
|
+
spec.license = "MIT"
|
12
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
13
|
+
|
14
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
15
|
+
spec.metadata["source_code_uri"] = "https://github.com/shirts/microsoft-teams-ruby"
|
16
|
+
spec.metadata["changelog_uri"] = "https://github.com/shirts/microsoft-teams-ruby/releases"
|
17
|
+
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
end
|
23
|
+
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_development_dependency "rake", "~> 12.0"
|
27
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
28
|
+
spec.add_development_dependency "webmock", "~> 3.8"
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ms_teams
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kevin Chandler
|
8
|
+
- Jana Abumeri
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2020-04-15 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '12.0'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '12.0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rspec
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '3.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '3.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: webmock
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '3.8'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '3.8'
|
56
|
+
description:
|
57
|
+
email:
|
58
|
+
- im.kevin@me.com
|
59
|
+
- jabumeri@uci.edu
|
60
|
+
executables: []
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- ".gitignore"
|
65
|
+
- ".rspec"
|
66
|
+
- Gemfile
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/setup
|
71
|
+
- lib/ms_teams.rb
|
72
|
+
- lib/ms_teams/message.rb
|
73
|
+
- lib/ms_teams/version.rb
|
74
|
+
- ms_teams.gemspec
|
75
|
+
homepage: https://github.com/shirts/microsoft-teams-ruby
|
76
|
+
licenses:
|
77
|
+
- MIT
|
78
|
+
metadata:
|
79
|
+
homepage_uri: https://github.com/shirts/microsoft-teams-ruby
|
80
|
+
source_code_uri: https://github.com/shirts/microsoft-teams-ruby
|
81
|
+
changelog_uri: https://github.com/shirts/microsoft-teams-ruby/releases
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 2.3.0
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubygems_version: 3.0.1
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: A lightweight Ruby gem to send actionable message cards to an Office 365
|
101
|
+
group (Microsoft Teams)
|
102
|
+
test_files: []
|