huginn_outlook_agent 0.1.10
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/LICENSE.txt +7 -0
- data/lib/huginn_outlook_agent/outlook_agent.rb +392 -0
- data/lib/huginn_outlook_agent.rb +4 -0
- data/spec/outlook_agent_spec.rb +13 -0
- metadata +90 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1d6fb7195c08ef6d5a95fdb6f8b8c4bbe7025ee86ed9bb8e387de7bf08877da8
|
4
|
+
data.tar.gz: 3a22e3439c3f45ca62b0e8e40bf78fbf7280c4bd63c6a5b1c351e7c52968d25c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5fc5699e4cb621181a13a66991f4d65ad2c2b6d73758dcbd6394a4ce93267ab9a4143c9d6cbb7823b8361a4cec553239067bac19ef159990bc05417c0cfe91bc
|
7
|
+
data.tar.gz: 724d9f0e4a0f2c4daced17fca1f06e28a18273572f9023e5abe4956ca93db00050ff80f9cc8d2ed1395e8f174ab0dce32221ddb1a726728ac4ca99b9d2b293b3
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (c) 2024 Nicolas Germain
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,392 @@
|
|
1
|
+
module Agents
|
2
|
+
class OutlookAgent < Agent
|
3
|
+
include FormConfigurable
|
4
|
+
can_dry_run!
|
5
|
+
no_bulk_receive!
|
6
|
+
default_schedule '5m'
|
7
|
+
|
8
|
+
description do
|
9
|
+
<<-MD
|
10
|
+
The Outlook Agent interacts with the graph api to check the arrival of new emails, send them, etc...
|
11
|
+
|
12
|
+
`debug` is used for verbose mode.
|
13
|
+
|
14
|
+
`client_id` is the id of your app.
|
15
|
+
|
16
|
+
`client_secret` is the secret of your app.
|
17
|
+
|
18
|
+
`access_token` is a token created for your app.
|
19
|
+
|
20
|
+
`refresh_token` is needed to refresh access_token.
|
21
|
+
|
22
|
+
`folder` is the wanted folder where you want to check new emails.
|
23
|
+
|
24
|
+
`raw_email` if you want MIME format content.
|
25
|
+
|
26
|
+
`emit_events` is for creating an event.
|
27
|
+
|
28
|
+
`type` is for the wanted action like get_new_emails / send_email.
|
29
|
+
|
30
|
+
`expected_receive_period_in_days` is used to determine if the Agent is working. Set it to the maximum number of days
|
31
|
+
that you anticipate passing without this Agent receiving an incoming Event.
|
32
|
+
MD
|
33
|
+
end
|
34
|
+
|
35
|
+
event_description <<-MD
|
36
|
+
Events look like this:
|
37
|
+
|
38
|
+
{
|
39
|
+
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('XXXXXXXXXXXXXXXXX')/messages/$entity",
|
40
|
+
"@odata.etag": "W/\"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\"",
|
41
|
+
"id": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
|
42
|
+
"createdDateTime": "2024-09-27T21:29:15Z",
|
43
|
+
"lastModifiedDateTime": "2024-09-27T21:29:15Z",
|
44
|
+
"changeKey": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
|
45
|
+
"categories": [
|
46
|
+
|
47
|
+
],
|
48
|
+
"receivedDateTime": "2024-09-27T21:29:15Z",
|
49
|
+
"sentDateTime": "2024-09-27T21:29:09Z",
|
50
|
+
"hasAttachments": false,
|
51
|
+
"internetMessageId": "<XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX>",
|
52
|
+
"subject": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
|
53
|
+
"bodyPreview": "XXXXXXXXXXXXXXX",
|
54
|
+
"importance": "normal",
|
55
|
+
"parentFolderId": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
|
56
|
+
"conversationId": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
|
57
|
+
"conversationIndex": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
|
58
|
+
"isDeliveryReceiptRequested": null,
|
59
|
+
"isReadReceiptRequested": false,
|
60
|
+
"isRead": false,
|
61
|
+
"isDraft": false,
|
62
|
+
"webLink": "https://outlook.live.com/owa/?ItemID=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX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XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX>"
|
67
|
+
},
|
68
|
+
"sender": {
|
69
|
+
"emailAddress": {
|
70
|
+
"name": "XXXXXXXXXXXXXXX",
|
71
|
+
"address": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
|
72
|
+
}
|
73
|
+
},
|
74
|
+
"from": {
|
75
|
+
"emailAddress": {
|
76
|
+
"name": "XXXXXXXXXXXXXXX",
|
77
|
+
"address": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
|
78
|
+
}
|
79
|
+
},
|
80
|
+
"toRecipients": [
|
81
|
+
{
|
82
|
+
"emailAddress": {
|
83
|
+
"name": "XXXXXXXXXXXXXXXXXXXXXXXX",
|
84
|
+
"address": "XXXXXXXXXXXXXXXXXXXXXXXX"
|
85
|
+
}
|
86
|
+
}
|
87
|
+
],
|
88
|
+
"ccRecipients": [
|
89
|
+
{
|
90
|
+
"emailAddress": {
|
91
|
+
"name": "XXXXXXXXXXXXXXXXXXXXXXXX",
|
92
|
+
"address": "XXXXXXXXXXXXXXXXXXXXXXXX"
|
93
|
+
}
|
94
|
+
}
|
95
|
+
],
|
96
|
+
"bccRecipients": [
|
97
|
+
|
98
|
+
],
|
99
|
+
"replyTo": [
|
100
|
+
|
101
|
+
],
|
102
|
+
"flag": {
|
103
|
+
"flagStatus": "notFlagged"
|
104
|
+
}
|
105
|
+
}
|
106
|
+
MD
|
107
|
+
|
108
|
+
def default_options
|
109
|
+
{
|
110
|
+
'client_id' => '{% credential outlook_client_id %}',
|
111
|
+
'client_secret' => '{% credential outlook_client_secret %}',
|
112
|
+
'access_token' => '{% credential outlook_access_token %}',
|
113
|
+
'refresh_token' => '',
|
114
|
+
'folder' => '',
|
115
|
+
'debug' => 'false',
|
116
|
+
'raw_email' => 'false',
|
117
|
+
'emit_events' => 'true',
|
118
|
+
'expected_receive_period_in_days' => '2',
|
119
|
+
}
|
120
|
+
end
|
121
|
+
|
122
|
+
form_configurable :client_id, type: :string
|
123
|
+
form_configurable :client_secret, type: :string
|
124
|
+
form_configurable :refresh_token, type: :string
|
125
|
+
form_configurable :access_token, type: :string
|
126
|
+
form_configurable :folder, type: :string
|
127
|
+
form_configurable :debug, type: :boolean
|
128
|
+
form_configurable :raw_email, type: :boolean
|
129
|
+
form_configurable :emit_events, type: :boolean
|
130
|
+
form_configurable :expected_receive_period_in_days, type: :string
|
131
|
+
form_configurable :type, type: :array, values: ['get_new_emails', 'send_email']
|
132
|
+
def validate_options
|
133
|
+
errors.add(:base, "type has invalid value: should be 'get_new_emails', 'send_email'") if interpolated['type'].present? && !%w(get_new_emails send_email).include?(interpolated['type'])
|
134
|
+
|
135
|
+
unless options['client_id'].present?
|
136
|
+
errors.add(:base, "client_id is a required field")
|
137
|
+
end
|
138
|
+
|
139
|
+
unless options['client_secret'].present?
|
140
|
+
errors.add(:base, "client_secret is a required field")
|
141
|
+
end
|
142
|
+
|
143
|
+
unless options['folder'].present?
|
144
|
+
errors.add(:base, "folder is a required field")
|
145
|
+
end
|
146
|
+
|
147
|
+
unless options['access_token'].present?
|
148
|
+
errors.add(:base, "access_token is a required field")
|
149
|
+
end
|
150
|
+
|
151
|
+
unless options['refresh_token'].present?
|
152
|
+
errors.add(:base, "refresh_token is a required field")
|
153
|
+
end
|
154
|
+
|
155
|
+
if options.has_key?('raw_email') && boolify(options['raw_email']).nil?
|
156
|
+
errors.add(:base, "if provided, raw_email must be true or false")
|
157
|
+
end
|
158
|
+
|
159
|
+
if options.has_key?('emit_events') && boolify(options['emit_events']).nil?
|
160
|
+
errors.add(:base, "if provided, emit_events must be true or false")
|
161
|
+
end
|
162
|
+
|
163
|
+
if options.has_key?('debug') && boolify(options['debug']).nil?
|
164
|
+
errors.add(:base, "if provided, debug must be true or false")
|
165
|
+
end
|
166
|
+
|
167
|
+
unless options['expected_receive_period_in_days'].present? && options['expected_receive_period_in_days'].to_i > 0
|
168
|
+
errors.add(:base, "Please provide 'expected_receive_period_in_days' to indicate how many days can pass before this Agent is considered to be not working")
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
def working?
|
173
|
+
event_created_within?(options['expected_receive_period_in_days']) && !recent_error_logs?
|
174
|
+
end
|
175
|
+
|
176
|
+
def receive(incoming_events)
|
177
|
+
incoming_events.each do |event|
|
178
|
+
interpolate_with(event) do
|
179
|
+
log event
|
180
|
+
trigger_action
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
def check
|
186
|
+
trigger_action
|
187
|
+
end
|
188
|
+
|
189
|
+
private
|
190
|
+
|
191
|
+
def set_credential(name, value)
|
192
|
+
c = user.user_credentials.find_or_initialize_by(credential_name: name)
|
193
|
+
c.credential_value = value
|
194
|
+
c.save!
|
195
|
+
end
|
196
|
+
|
197
|
+
def log_curl_output(code,body)
|
198
|
+
|
199
|
+
log "request status : #{code}"
|
200
|
+
|
201
|
+
if interpolated['debug'] == 'true'
|
202
|
+
log "body"
|
203
|
+
log body
|
204
|
+
end
|
205
|
+
|
206
|
+
end
|
207
|
+
|
208
|
+
def token_refresh()
|
209
|
+
|
210
|
+
uri = URI.parse("https://login.microsoftonline.com/consumers/oauth2/v2.0/token")
|
211
|
+
request = Net::HTTP::Post.new(uri)
|
212
|
+
request.body = "client_id=#{interpolated['client_id']}&client_secret=#{interpolated['client_secret']}&refresh_token=#{interpolated['refresh_token']}&grant_type=refresh_token&scope=https://graph.microsoft.com/Mail.Read offline_access"
|
213
|
+
|
214
|
+
req_options = {
|
215
|
+
use_ssl: uri.scheme == "https",
|
216
|
+
}
|
217
|
+
|
218
|
+
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
219
|
+
http.request(request)
|
220
|
+
end
|
221
|
+
|
222
|
+
log_curl_output(response.code,response.body)
|
223
|
+
|
224
|
+
payload = JSON.parse(response.body)
|
225
|
+
if interpolated['access_token'] != payload['access_token']
|
226
|
+
set_credential("outlook_access_token", payload['access_token'])
|
227
|
+
if interpolated['debug'] == 'true'
|
228
|
+
log "outlook_access_token credential updated"
|
229
|
+
end
|
230
|
+
end
|
231
|
+
current_timestamp = Time.now.to_i
|
232
|
+
memory['expires_at'] = payload['expires_in'] + current_timestamp
|
233
|
+
|
234
|
+
end
|
235
|
+
|
236
|
+
def check_token_validity()
|
237
|
+
|
238
|
+
if memory['expires_at'].nil?
|
239
|
+
token_refresh()
|
240
|
+
else
|
241
|
+
timestamp_to_compare = memory['expires_at']
|
242
|
+
current_timestamp = Time.now.to_i
|
243
|
+
# difference_in_hours = (timestamp_to_compare - current_timestamp) / 3600.0
|
244
|
+
# if difference_in_hours < 2
|
245
|
+
difference_in_minutes = (timestamp_to_compare - current_timestamp) / 60.0
|
246
|
+
if difference_in_minutes < 10
|
247
|
+
token_refresh()
|
248
|
+
else
|
249
|
+
log "refresh not needed"
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
def get_email(email_id)
|
255
|
+
url = "https://graph.microsoft.com/v1.0/me/messages/#{email_id}"
|
256
|
+
if interpolated['raw_email'] == 'true'
|
257
|
+
url = url + '/$value'
|
258
|
+
end
|
259
|
+
uri = URI.parse(url)
|
260
|
+
request = Net::HTTP::Get.new(uri)
|
261
|
+
request.content_type = "application/json"
|
262
|
+
request["Authorization"] = "Bearer #{interpolated['access_token']}"
|
263
|
+
|
264
|
+
req_options = {
|
265
|
+
use_ssl: uri.scheme == "https",
|
266
|
+
}
|
267
|
+
|
268
|
+
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
269
|
+
http.request(request)
|
270
|
+
end
|
271
|
+
|
272
|
+
log_curl_output(response.code,response.body)
|
273
|
+
|
274
|
+
if interpolated['raw_email'] == 'true'
|
275
|
+
result = {}
|
276
|
+
result['id'] = email_id
|
277
|
+
# result['raw_mail'] = response.body.gsub(/(?:\n\r?|\r\n?)/, '<br>')
|
278
|
+
result['raw_mail'] = response.body
|
279
|
+
log "raw_mail"
|
280
|
+
log result['raw_mail']
|
281
|
+
|
282
|
+
return result
|
283
|
+
else
|
284
|
+
payload = JSON.parse(response.body)
|
285
|
+
return payload
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
def send_email()
|
290
|
+
|
291
|
+
check_token_validity()
|
292
|
+
uri = URI.parse("https://graph.microsoft.com/v1.0/me/messages")
|
293
|
+
request = Net::HTTP::Post.new(uri)
|
294
|
+
request.content_type = "application/json"
|
295
|
+
request.body = JSON.dump({
|
296
|
+
"subject" => "Did you see last night's game?",
|
297
|
+
"importance" => "Low",
|
298
|
+
"body" => {
|
299
|
+
"contentType" => "HTML",
|
300
|
+
"content" => "They were <b>awesome</b>!"
|
301
|
+
},
|
302
|
+
"toRecipients" => [
|
303
|
+
{
|
304
|
+
"emailAddress" => {
|
305
|
+
"address" => "AdeleV@contoso.com"
|
306
|
+
}
|
307
|
+
}
|
308
|
+
]
|
309
|
+
})
|
310
|
+
|
311
|
+
req_options = {
|
312
|
+
use_ssl: uri.scheme == "https",
|
313
|
+
}
|
314
|
+
|
315
|
+
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
316
|
+
http.request(request)
|
317
|
+
end
|
318
|
+
|
319
|
+
log_curl_output(response.code,response.body)
|
320
|
+
|
321
|
+
payload = JSON.parse(response.body)
|
322
|
+
|
323
|
+
if interpolated['emit_events'] == 'true'
|
324
|
+
create_event payload: payload
|
325
|
+
end
|
326
|
+
end
|
327
|
+
|
328
|
+
def get_new_emails()
|
329
|
+
|
330
|
+
check_token_validity()
|
331
|
+
uri = URI.parse("https://graph.microsoft.com/v1.0/me/mailFolders/#{interpolated['folder']}/messages?$format=json&$top=20&$select=id")
|
332
|
+
request = Net::HTTP::Get.new(uri)
|
333
|
+
request.content_type = "application/json"
|
334
|
+
request["Authorization"] = "Bearer #{interpolated['access_token']}"
|
335
|
+
|
336
|
+
req_options = {
|
337
|
+
use_ssl: uri.scheme == "https",
|
338
|
+
}
|
339
|
+
|
340
|
+
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
341
|
+
http.request(request)
|
342
|
+
end
|
343
|
+
|
344
|
+
log_curl_output(response.code,response.body)
|
345
|
+
|
346
|
+
payload = JSON.parse(response.body)
|
347
|
+
if payload != memory['last_status']
|
348
|
+
payload['value'].each do |email_data|
|
349
|
+
found = false
|
350
|
+
if !memory['last_status'].nil? and memory['last_status'].present?
|
351
|
+
last_status = memory['last_status']
|
352
|
+
if interpolated['debug'] == 'true'
|
353
|
+
log "email_data"
|
354
|
+
log email_data
|
355
|
+
end
|
356
|
+
last_status['value'].each do |email_databis|
|
357
|
+
if email_data['id'] == email_databis['id']
|
358
|
+
found = true
|
359
|
+
end
|
360
|
+
if interpolated['debug'] == 'true'
|
361
|
+
log "found is #{found}!"
|
362
|
+
log "email_databis"
|
363
|
+
log email_databis
|
364
|
+
end
|
365
|
+
end
|
366
|
+
end
|
367
|
+
if found == false
|
368
|
+
create_event payload: get_email(email_data['id'])
|
369
|
+
else
|
370
|
+
if interpolated['debug'] == 'true'
|
371
|
+
log "found is #{found}"
|
372
|
+
end
|
373
|
+
end
|
374
|
+
end
|
375
|
+
memory['last_status'] = payload
|
376
|
+
end
|
377
|
+
|
378
|
+
end
|
379
|
+
|
380
|
+
def trigger_action
|
381
|
+
|
382
|
+
case interpolated['type']
|
383
|
+
when "get_new_emails"
|
384
|
+
get_new_emails()
|
385
|
+
when "send_email"
|
386
|
+
send_email()
|
387
|
+
else
|
388
|
+
log "Error: type has an invalid value (#{interpolated['type']})"
|
389
|
+
end
|
390
|
+
end
|
391
|
+
end
|
392
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
require 'huginn_agent/spec_helper'
|
3
|
+
|
4
|
+
describe Agents::OutlookAgent do
|
5
|
+
before(:each) do
|
6
|
+
@valid_options = Agents::OutlookAgent.new.default_options
|
7
|
+
@checker = Agents::OutlookAgent.new(:name => "OutlookAgent", :options => @valid_options)
|
8
|
+
@checker.user = users(:bob)
|
9
|
+
@checker.save!
|
10
|
+
end
|
11
|
+
|
12
|
+
pending "add specs here"
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: huginn_outlook_agent
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.10
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nicolas Germain
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-09-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.1.0
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.1.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 12.3.3
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 12.3.3
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: huginn_agent
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Write a longer description or delete this line.
|
56
|
+
email:
|
57
|
+
- ngermain@hihouhou.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- LICENSE.txt
|
63
|
+
- lib/huginn_outlook_agent.rb
|
64
|
+
- lib/huginn_outlook_agent/outlook_agent.rb
|
65
|
+
- spec/outlook_agent_spec.rb
|
66
|
+
homepage: https://github.com/hihouhou/huginn_outlook_agent
|
67
|
+
licenses:
|
68
|
+
- MIT
|
69
|
+
metadata: {}
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubygems_version: 3.3.3
|
86
|
+
signing_key:
|
87
|
+
specification_version: 4
|
88
|
+
summary: Write a short summary, because Rubygems requires one.
|
89
|
+
test_files:
|
90
|
+
- spec/outlook_agent_spec.rb
|