bns 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/._.rspec_status +0 -0
- data/CHANGELOG.md +13 -0
- data/Gemfile +2 -0
- data/README.md +163 -4
- data/SECURITY.md +13 -0
- data/lib/bns/dispatcher/discord/exceptions/invalid_webhook_token.rb +2 -2
- data/lib/bns/dispatcher/discord/implementation.rb +1 -1
- data/lib/bns/dispatcher/slack/exceptions/invalid_webhook_token.rb +16 -0
- data/lib/bns/dispatcher/slack/implementation.rb +51 -0
- data/lib/bns/dispatcher/slack/types/response.rb +21 -0
- data/lib/bns/domain/birthday.rb +2 -0
- data/lib/bns/domain/pto.rb +2 -0
- data/lib/bns/domain/work_items_limit.rb +39 -0
- data/lib/bns/fetcher/base.rb +13 -0
- data/lib/bns/fetcher/notion/{pto.rb → base.rb} +11 -7
- data/lib/bns/fetcher/notion/types/response.rb +1 -1
- data/lib/bns/fetcher/notion/use_case/birthday_next_week.rb +41 -0
- data/lib/bns/fetcher/notion/use_case/birthday_today.rb +29 -0
- data/lib/bns/fetcher/notion/use_case/pto_next_week.rb +71 -0
- data/lib/bns/fetcher/notion/use_case/pto_today.rb +30 -0
- data/lib/bns/fetcher/notion/use_case/work_items_limit.rb +37 -0
- data/lib/bns/fetcher/postgres/base.rb +46 -0
- data/lib/bns/fetcher/postgres/helper.rb +16 -0
- data/lib/bns/fetcher/postgres/types/response.rb +42 -0
- data/lib/bns/fetcher/postgres/use_case/pto_today.rb +32 -0
- data/lib/bns/formatter/base.rb +27 -3
- data/lib/bns/formatter/birthday.rb +34 -0
- data/lib/bns/formatter/exceptions/invalid_data.rb +15 -0
- data/lib/bns/formatter/pto.rb +76 -0
- data/lib/bns/formatter/work_items_limit.rb +43 -0
- data/lib/bns/mapper/notion/{birthday.rb → birthday_today.rb} +13 -21
- data/lib/bns/mapper/notion/{pto.rb → pto_today.rb} +15 -41
- data/lib/bns/mapper/notion/work_items_limit.rb +65 -0
- data/lib/bns/mapper/postgres/pto_today.rb +47 -0
- data/lib/bns/use_cases/use_cases.rb +227 -49
- data/lib/bns/version.rb +1 -1
- data/renovate.json +6 -0
- metadata +27 -10
- data/Gemfile.lock +0 -91
- data/lib/bns/fetcher/notion/birthday.rb +0 -53
- data/lib/bns/formatter/discord/birthday.rb +0 -43
- data/lib/bns/formatter/discord/exceptions/invalid_data.rb +0 -17
- data/lib/bns/formatter/discord/pto.rb +0 -52
@@ -1,14 +1,24 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "../fetcher/notion/
|
4
|
-
require_relative "../
|
5
|
-
require_relative "../
|
3
|
+
require_relative "../fetcher/notion/use_case/birthday_today"
|
4
|
+
require_relative "../fetcher/notion/use_case/birthday_next_week"
|
5
|
+
require_relative "../fetcher/notion/use_case/pto_today"
|
6
|
+
require_relative "../fetcher/notion/use_case/pto_next_week"
|
7
|
+
require_relative "../fetcher/notion/use_case/work_items_limit"
|
8
|
+
require_relative "../fetcher/postgres/use_case/pto_today"
|
6
9
|
|
7
|
-
require_relative "../
|
8
|
-
require_relative "../mapper/notion/
|
9
|
-
require_relative "../
|
10
|
+
require_relative "../mapper/notion/birthday_today"
|
11
|
+
require_relative "../mapper/notion/pto_today"
|
12
|
+
require_relative "../mapper/notion/work_items_limit"
|
13
|
+
require_relative "../mapper/postgres/pto_today"
|
14
|
+
|
15
|
+
require_relative "../formatter/birthday"
|
16
|
+
require_relative "../formatter/pto"
|
17
|
+
require_relative "../formatter/work_items_limit"
|
10
18
|
|
11
19
|
require_relative "../dispatcher/discord/implementation"
|
20
|
+
require_relative "../dispatcher/slack/implementation"
|
21
|
+
|
12
22
|
require_relative "use_case"
|
13
23
|
require_relative "./types/config"
|
14
24
|
|
@@ -21,33 +31,70 @@ module UseCases
|
|
21
31
|
#
|
22
32
|
# <b>Example</b>
|
23
33
|
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
# "date": {
|
29
|
-
# "equals": today
|
30
|
-
# }
|
31
|
-
# }
|
32
|
-
# ]
|
34
|
+
# options = {
|
35
|
+
# fetch_options: {
|
36
|
+
# database_id: NOTION_DATABASE_ID,
|
37
|
+
# secret: NOTION_API_INTEGRATION_SECRET,
|
33
38
|
# },
|
34
|
-
#
|
39
|
+
# dispatch_options: {
|
40
|
+
# webhook: "https://discord.com/api/webhooks/1199213527672565760/KmpoIzBet9xYG16oFh8W1RWHbpIqT7UtTBRrhfLcvWZdNiVZCTM-gpil2Qoy4eYEgpdf",
|
41
|
+
# name: "Birthday Bot"
|
42
|
+
# }
|
35
43
|
# }
|
36
44
|
#
|
45
|
+
# use_case = UseCases.notify_birthday_from_notion_to_discord(options)
|
46
|
+
# use_case.perform
|
47
|
+
#
|
48
|
+
# #################################################################################
|
49
|
+
#
|
50
|
+
# Requirements:
|
51
|
+
# * Notion database ID, from a database with the following structure:
|
52
|
+
#
|
53
|
+
# _________________________________________________________________________________
|
54
|
+
# | Complete Name (text) | BD_this_year (formula) | BD (date) |
|
55
|
+
# | -------------------- | --------------------------- | ------------------------ |
|
56
|
+
# | John Doe | January 24, 2024 | January 24, 2000 |
|
57
|
+
# | Jane Doe | June 20, 2024 | June 20, 2000 |
|
58
|
+
# ---------------------------------------------------------------------------------
|
59
|
+
# With the following formula for the BD_this_year column:
|
60
|
+
# dateAdd(prop("BD"), year(now()) - year(prop("BD")), "years")
|
61
|
+
#
|
62
|
+
# * A Notion secret, which can be obtained, by creating an integration here: `https://developers.notion.com/`,
|
63
|
+
# browsing on the <View my integations> option, and selecting the <New Integration> or <Create new>
|
64
|
+
# integration** buttons.
|
65
|
+
# * A webhook key, which can be generated directly on discrod on the desired channel, following this instructions:
|
66
|
+
# https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks
|
67
|
+
#
|
68
|
+
def self.notify_birthday_from_notion_to_discord(options)
|
69
|
+
fetcher = Fetcher::Notion::BirthdayToday.new(options[:fetch_options])
|
70
|
+
mapper = Mapper::Notion::BirthdayToday.new
|
71
|
+
formatter = Formatter::Birthday.new(options[:format_options])
|
72
|
+
dispatcher = Dispatcher::Discord::Implementation.new(options[:dispatch_options])
|
73
|
+
use_case_config = UseCases::Types::Config.new(fetcher, mapper, formatter, dispatcher)
|
74
|
+
|
75
|
+
UseCases::UseCase.new(use_case_config)
|
76
|
+
end
|
77
|
+
|
78
|
+
# Provides an instance of the next week Birthdays notifications from Notion to Discord use case implementation.
|
79
|
+
#
|
80
|
+
# <b>Example</b>
|
81
|
+
#
|
37
82
|
# options = {
|
38
83
|
# fetch_options: {
|
39
|
-
# base_url: "https://api.notion.com",
|
40
84
|
# database_id: NOTION_DATABASE_ID,
|
41
85
|
# secret: NOTION_API_INTEGRATION_SECRET,
|
42
|
-
# filter: filter
|
43
86
|
# },
|
44
87
|
# dispatch_options: {
|
45
88
|
# webhook: "https://discord.com/api/webhooks/1199213527672565760/KmpoIzBet9xYG16oFh8W1RWHbpIqT7UtTBRrhfLcvWZdNiVZCTM-gpil2Qoy4eYEgpdf",
|
46
89
|
# name: "Birthday Bot"
|
90
|
+
# },
|
91
|
+
# format_options: {
|
92
|
+
# template: "individual_name, Wishing you a very happy birthday! Enjoy your special day! :birthday: :gift:",
|
93
|
+
# timezone: "-05:00"
|
47
94
|
# }
|
48
95
|
# }
|
49
96
|
#
|
50
|
-
# use_case = UseCases.
|
97
|
+
# use_case = UseCases.notify_next_week_birthday_from_notion_to_discord(options)
|
51
98
|
# use_case.perform
|
52
99
|
#
|
53
100
|
# #################################################################################
|
@@ -70,10 +117,10 @@ module UseCases
|
|
70
117
|
# * A webhook key, which can be generated directly on discrod on the desired channel, following this instructions:
|
71
118
|
# https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks
|
72
119
|
#
|
73
|
-
def self.
|
74
|
-
fetcher = Fetcher::Notion::
|
75
|
-
mapper = Mapper::Notion::
|
76
|
-
formatter = Formatter::
|
120
|
+
def self.notify_next_week_birthday_from_notion_to_discord(options)
|
121
|
+
fetcher = Fetcher::Notion::BirthdayNextWeek.new(options[:fetch_options])
|
122
|
+
mapper = Mapper::Notion::BirthdayToday.new
|
123
|
+
formatter = Formatter::Birthday.new(options[:format_options])
|
77
124
|
dispatcher = Dispatcher::Discord::Implementation.new(options[:dispatch_options])
|
78
125
|
use_case_cofig = UseCases::Types::Config.new(fetcher, mapper, formatter, dispatcher)
|
79
126
|
|
@@ -85,31 +132,10 @@ module UseCases
|
|
85
132
|
# <br>
|
86
133
|
# <b>Example</b>
|
87
134
|
#
|
88
|
-
# "filter": {
|
89
|
-
# "and": [
|
90
|
-
# {
|
91
|
-
# property: "Desde?",
|
92
|
-
# date: {
|
93
|
-
# "on_or_before": today
|
94
|
-
# }
|
95
|
-
# },
|
96
|
-
# {s
|
97
|
-
# property: "Hasta?",
|
98
|
-
# date: {
|
99
|
-
# "on_or_after": today
|
100
|
-
# }
|
101
|
-
# }
|
102
|
-
# ]
|
103
|
-
# },
|
104
|
-
# "sorts": []
|
105
|
-
# }
|
106
|
-
#
|
107
135
|
# options = {
|
108
136
|
# fetch_options: {
|
109
|
-
# base_url: "https://api.notion.com",
|
110
137
|
# database_id: NOTION_DATABASE_ID,
|
111
138
|
# secret: NOTION_API_INTEGRATION_SECRET,
|
112
|
-
# filter: filter
|
113
139
|
# },
|
114
140
|
# dispatch_options: {
|
115
141
|
# webhook: "https://discord.com/api/webhooks/1199213527672565760/KmpoIzBet9xYG16oFh8W1RWHbpIqT7UtTBRrhfLcvWZdNiVZCTM-gpil2Qoy4eYEgpdf",
|
@@ -139,12 +165,164 @@ module UseCases
|
|
139
165
|
# https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks
|
140
166
|
#
|
141
167
|
def self.notify_pto_from_notion_to_discord(options)
|
142
|
-
fetcher = Fetcher::Notion::
|
143
|
-
mapper = Mapper::Notion::
|
144
|
-
formatter = Formatter::
|
168
|
+
fetcher = Fetcher::Notion::PtoToday.new(options[:fetch_options])
|
169
|
+
mapper = Mapper::Notion::PtoToday.new
|
170
|
+
formatter = Formatter::Pto.new(options[:format_options])
|
145
171
|
dispatcher = Dispatcher::Discord::Implementation.new(options[:dispatch_options])
|
146
|
-
|
172
|
+
use_case_config = UseCases::Types::Config.new(fetcher, mapper, formatter, dispatcher)
|
147
173
|
|
148
|
-
UseCases::UseCase.new(
|
174
|
+
UseCases::UseCase.new(use_case_config)
|
175
|
+
end
|
176
|
+
|
177
|
+
# Provides an instance of the next week PTO notifications from Notion to Discord use case implementation.
|
178
|
+
#
|
179
|
+
# <br>
|
180
|
+
# <b>Example</b>
|
181
|
+
#
|
182
|
+
# options = {
|
183
|
+
# fetch_options: {
|
184
|
+
# database_id: NOTION_DATABASE_ID,
|
185
|
+
# secret: NOTION_API_INTEGRATION_SECRET,
|
186
|
+
# },
|
187
|
+
# dispatch_options: {
|
188
|
+
# webhook: "https://discord.com/api/webhooks/1199213527672565760/KmpoIzBet9xYG16oFh8W1RWHbpIqT7UtTBRrhfLcvWZdNiVZCTM-gpil2Qoy4eYEgpdf",
|
189
|
+
# name: "Pto Bot"
|
190
|
+
# },
|
191
|
+
# format_options: {
|
192
|
+
# template: ":beach: individual_name its going to be on PTO next week,",
|
193
|
+
# timezone: "-05:00"
|
194
|
+
# }
|
195
|
+
# }
|
196
|
+
#
|
197
|
+
# use_case = UseCases.notify_next_week_pto_from_notion_to_discord(options)
|
198
|
+
# use_case.perform
|
199
|
+
#
|
200
|
+
# #################################################################################
|
201
|
+
#
|
202
|
+
# Requirements:
|
203
|
+
# * Notion database ID, from a database with the following structure:
|
204
|
+
#
|
205
|
+
# ________________________________________________________________________________________________________
|
206
|
+
# | Person (person) | Desde? (date) | Hasta? (date) |
|
207
|
+
# | -------------------- | --------------------------------------- | ------------------------------------ |
|
208
|
+
# | John Doe | January 24, 2024 | January 27, 2024 |
|
209
|
+
# | Jane Doe | November 11, 2024 2:00 PM | November 11, 2024 6:00 PM |
|
210
|
+
# ---------------------------------------------------------------------------------------------------------
|
211
|
+
#
|
212
|
+
# * A Notion secret, which can be obtained, by creating an integration here: `https://developers.notion.com/`,
|
213
|
+
# browsing on the <View my integations> option, and selecting the <New Integration> or <Create new>
|
214
|
+
# integration** buttons.
|
215
|
+
# * A webhook key, which can be generated directly on discrod on the desired channel, following this instructions:
|
216
|
+
# https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks
|
217
|
+
#
|
218
|
+
def self.notify_next_week_pto_from_notion_to_discord(options)
|
219
|
+
fetcher = Fetcher::Notion::PtoNextWeek.new(options[:fetch_options])
|
220
|
+
mapper = Mapper::Notion::PtoToday.new
|
221
|
+
formatter = Formatter::Pto.new(options[:format_options])
|
222
|
+
dispatcher = Dispatcher::Discord::Implementation.new(options[:dispatch_options])
|
223
|
+
use_case_config = UseCases::Types::Config.new(fetcher, mapper, formatter, dispatcher)
|
224
|
+
|
225
|
+
UseCases::UseCase.new(use_case_config)
|
226
|
+
end
|
227
|
+
|
228
|
+
# Provides an instance of the PTO notifications from Postgres to Slack use case implementation.
|
229
|
+
#
|
230
|
+
# <br>
|
231
|
+
# <b>Example</b>
|
232
|
+
#
|
233
|
+
# options = {
|
234
|
+
# fetch_options: {
|
235
|
+
# connection: {
|
236
|
+
# host: "localhost",
|
237
|
+
# port: 5432,
|
238
|
+
# dbname: "db_pto",
|
239
|
+
# user: "postgres",
|
240
|
+
# password: "postgres"
|
241
|
+
# }
|
242
|
+
# },
|
243
|
+
# dispatch_options:{
|
244
|
+
# webhook: "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX",
|
245
|
+
# name: "Pto Bot"
|
246
|
+
# },
|
247
|
+
# format_options: {
|
248
|
+
# template: "Custom template",
|
249
|
+
# timezone: "-05:00"
|
250
|
+
# }
|
251
|
+
# }
|
252
|
+
#
|
253
|
+
# use_case = UseCases.notify_pto_from_postgres_to_slack(options)
|
254
|
+
# use_case.perform
|
255
|
+
#
|
256
|
+
# #################################################################################
|
257
|
+
#
|
258
|
+
# Requirements:
|
259
|
+
# * A connection to a Postgres database and a table with the following structure:
|
260
|
+
#
|
261
|
+
# Column | Type | Collation | Nullable | Default
|
262
|
+
# -----------------+------------------------+-----------+----------+------------------------------
|
263
|
+
# id | integer | | not null | generated always as identity
|
264
|
+
# create_time | date | | |
|
265
|
+
# individual_name | character varying(255) | | |
|
266
|
+
# start_date | date | | |
|
267
|
+
# end_date | date | | |
|
268
|
+
#
|
269
|
+
# * A webhook key, which can be generated directly on slack on the desired channel, following this instructions:
|
270
|
+
# https://api.slack.com/messaging/webhooks#create_a_webhook
|
271
|
+
#
|
272
|
+
def self.notify_pto_from_postgres_to_slack(options)
|
273
|
+
fetcher = Fetcher::Postgres::PtoToday.new(options[:fetch_options])
|
274
|
+
mapper = Mapper::Postgres::PtoToday.new
|
275
|
+
formatter = Formatter::Pto.new(options[:format_options])
|
276
|
+
dispatcher = Dispatcher::Slack::Implementation.new(options[:dispatch_options])
|
277
|
+
use_case_config = UseCases::Types::Config.new(fetcher, mapper, formatter, dispatcher)
|
278
|
+
|
279
|
+
UseCases::UseCase.new(use_case_config)
|
280
|
+
end
|
281
|
+
|
282
|
+
# Provides an instance of the Work Items wip limit notifications from Notion to Discord use case implementation.
|
283
|
+
#
|
284
|
+
# <br>
|
285
|
+
# <b>Example</b>
|
286
|
+
#
|
287
|
+
# options = {
|
288
|
+
# fetch_options: {
|
289
|
+
# database_id: NOTION_DATABASE_ID,
|
290
|
+
# secret: NOTION_API_INTEGRATION_SECRET
|
291
|
+
# },
|
292
|
+
# dispatch_options: {
|
293
|
+
# webhook: "https://discord.com/api/webhooks/1199213527672565760/KmpoIzBet9xYG16oFh8W1RWHbpIqT7UtTBRrhfLcvWZdNiVZCTM-gpil2Qoy4eYEgpdf",
|
294
|
+
# name: "wipLimit"
|
295
|
+
# }
|
296
|
+
# }
|
297
|
+
#
|
298
|
+
# use_case = UseCases.notify_wip_limit_from_notion_to_discord(options)
|
299
|
+
# use_case.perform
|
300
|
+
#
|
301
|
+
# #################################################################################
|
302
|
+
#
|
303
|
+
# Requirements:
|
304
|
+
# * Notion database ID, from a database with the following structure:
|
305
|
+
#
|
306
|
+
# _________________________________________________________________________________
|
307
|
+
# | OK | Status | Responsible Domain |
|
308
|
+
# | -------------------- | --------------------------- | ------------------------ |
|
309
|
+
# | ✅ | In Progress | "kommit.admin" |
|
310
|
+
# | 🚩 | Fail | "kommit.ops" |
|
311
|
+
# ---------------------------------------------------------------------------------
|
312
|
+
#
|
313
|
+
# * A Notion secret, which can be obtained, by creating an integration here: `https://developers.notion.com/`,
|
314
|
+
# browsing on the <View my integations> option, and selecting the <New Integration> or <Create new>
|
315
|
+
# integration** buttons.
|
316
|
+
# * A webhook key, which can be generated directly on discrod on the desired channel, following this instructions:
|
317
|
+
# https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks
|
318
|
+
#
|
319
|
+
def self.notify_wip_limit_from_notion_to_discord(options)
|
320
|
+
fetcher = Fetcher::Notion::WorkItemsLimit.new(options[:fetch_options])
|
321
|
+
mapper = Mapper::Notion::WorkItemsLimit.new
|
322
|
+
formatter = Formatter::WorkItemsLimit.new(options[:format_options])
|
323
|
+
dispatcher = Dispatcher::Discord::Implementation.new(options[:dispatch_options])
|
324
|
+
use_case_config = UseCases::Types::Config.new(fetcher, mapper, formatter, dispatcher)
|
325
|
+
|
326
|
+
UseCases::UseCase.new(use_case_config)
|
149
327
|
end
|
150
328
|
end
|
data/lib/bns/version.rb
CHANGED
data/renovate.json
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bns
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kommitters Open Source
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-02-
|
11
|
+
date: 2024-02-29 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A versatile business notification system offering key components for
|
14
14
|
building various use cases. It provides an easy-to-use tool for implementing
|
@@ -19,42 +19,59 @@ executables: []
|
|
19
19
|
extensions: []
|
20
20
|
extra_rdoc_files: []
|
21
21
|
files:
|
22
|
+
- "._.rspec_status"
|
22
23
|
- ".rspec"
|
23
24
|
- ".rubocop.yml"
|
24
25
|
- CHANGELOG.md
|
25
26
|
- CODE_OF_CONDUCT.md
|
26
27
|
- CONTRIBUTING.md
|
27
28
|
- Gemfile
|
28
|
-
- Gemfile.lock
|
29
29
|
- LICENSE
|
30
30
|
- README.md
|
31
31
|
- Rakefile
|
32
|
+
- SECURITY.md
|
32
33
|
- lib/bns.rb
|
33
34
|
- lib/bns/dispatcher/base.rb
|
34
35
|
- lib/bns/dispatcher/discord/exceptions/invalid_webhook_token.rb
|
35
36
|
- lib/bns/dispatcher/discord/implementation.rb
|
36
37
|
- lib/bns/dispatcher/discord/types/response.rb
|
38
|
+
- lib/bns/dispatcher/slack/exceptions/invalid_webhook_token.rb
|
39
|
+
- lib/bns/dispatcher/slack/implementation.rb
|
40
|
+
- lib/bns/dispatcher/slack/types/response.rb
|
37
41
|
- lib/bns/domain/birthday.rb
|
38
42
|
- lib/bns/domain/exceptions/function_not_implemented.rb
|
39
43
|
- lib/bns/domain/pto.rb
|
44
|
+
- lib/bns/domain/work_items_limit.rb
|
40
45
|
- lib/bns/fetcher/base.rb
|
41
|
-
- lib/bns/fetcher/notion/
|
46
|
+
- lib/bns/fetcher/notion/base.rb
|
42
47
|
- lib/bns/fetcher/notion/exceptions/invalid_api_key.rb
|
43
48
|
- lib/bns/fetcher/notion/exceptions/invalid_database_id.rb
|
44
49
|
- lib/bns/fetcher/notion/helper.rb
|
45
|
-
- lib/bns/fetcher/notion/pto.rb
|
46
50
|
- lib/bns/fetcher/notion/types/response.rb
|
51
|
+
- lib/bns/fetcher/notion/use_case/birthday_next_week.rb
|
52
|
+
- lib/bns/fetcher/notion/use_case/birthday_today.rb
|
53
|
+
- lib/bns/fetcher/notion/use_case/pto_next_week.rb
|
54
|
+
- lib/bns/fetcher/notion/use_case/pto_today.rb
|
55
|
+
- lib/bns/fetcher/notion/use_case/work_items_limit.rb
|
56
|
+
- lib/bns/fetcher/postgres/base.rb
|
57
|
+
- lib/bns/fetcher/postgres/helper.rb
|
58
|
+
- lib/bns/fetcher/postgres/types/response.rb
|
59
|
+
- lib/bns/fetcher/postgres/use_case/pto_today.rb
|
47
60
|
- lib/bns/formatter/base.rb
|
48
|
-
- lib/bns/formatter/
|
49
|
-
- lib/bns/formatter/
|
50
|
-
- lib/bns/formatter/
|
61
|
+
- lib/bns/formatter/birthday.rb
|
62
|
+
- lib/bns/formatter/exceptions/invalid_data.rb
|
63
|
+
- lib/bns/formatter/pto.rb
|
64
|
+
- lib/bns/formatter/work_items_limit.rb
|
51
65
|
- lib/bns/mapper/base.rb
|
52
|
-
- lib/bns/mapper/notion/
|
53
|
-
- lib/bns/mapper/notion/
|
66
|
+
- lib/bns/mapper/notion/birthday_today.rb
|
67
|
+
- lib/bns/mapper/notion/pto_today.rb
|
68
|
+
- lib/bns/mapper/notion/work_items_limit.rb
|
69
|
+
- lib/bns/mapper/postgres/pto_today.rb
|
54
70
|
- lib/bns/use_cases/types/config.rb
|
55
71
|
- lib/bns/use_cases/use_case.rb
|
56
72
|
- lib/bns/use_cases/use_cases.rb
|
57
73
|
- lib/bns/version.rb
|
74
|
+
- renovate.json
|
58
75
|
- sig/business_notification_system.rbs
|
59
76
|
homepage: https://github.com/kommitters/bns
|
60
77
|
licenses:
|
data/Gemfile.lock
DELETED
@@ -1,91 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
bns (0.1.0)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: https://rubygems.org/
|
8
|
-
specs:
|
9
|
-
addressable (2.8.6)
|
10
|
-
public_suffix (>= 2.0.2, < 6.0)
|
11
|
-
ast (2.4.2)
|
12
|
-
crack (0.4.5)
|
13
|
-
rexml
|
14
|
-
diff-lcs (1.5.0)
|
15
|
-
docile (1.4.0)
|
16
|
-
hashdiff (1.1.0)
|
17
|
-
httparty (0.21.0)
|
18
|
-
mini_mime (>= 1.0.0)
|
19
|
-
multi_xml (>= 0.5.2)
|
20
|
-
json (2.7.1)
|
21
|
-
language_server-protocol (3.17.0.3)
|
22
|
-
mini_mime (1.1.5)
|
23
|
-
multi_xml (0.6.0)
|
24
|
-
parallel (1.24.0)
|
25
|
-
parser (3.3.0.3)
|
26
|
-
ast (~> 2.4.1)
|
27
|
-
racc
|
28
|
-
public_suffix (5.0.4)
|
29
|
-
racc (1.7.3)
|
30
|
-
rainbow (3.1.1)
|
31
|
-
rake (13.1.0)
|
32
|
-
regexp_parser (2.9.0)
|
33
|
-
rexml (3.2.6)
|
34
|
-
rspec (3.12.0)
|
35
|
-
rspec-core (~> 3.12.0)
|
36
|
-
rspec-expectations (~> 3.12.0)
|
37
|
-
rspec-mocks (~> 3.12.0)
|
38
|
-
rspec-core (3.12.2)
|
39
|
-
rspec-support (~> 3.12.0)
|
40
|
-
rspec-expectations (3.12.3)
|
41
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
42
|
-
rspec-support (~> 3.12.0)
|
43
|
-
rspec-mocks (3.12.6)
|
44
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
45
|
-
rspec-support (~> 3.12.0)
|
46
|
-
rspec-support (3.12.1)
|
47
|
-
rubocop (1.59.0)
|
48
|
-
json (~> 2.3)
|
49
|
-
language_server-protocol (>= 3.17.0)
|
50
|
-
parallel (~> 1.10)
|
51
|
-
parser (>= 3.2.2.4)
|
52
|
-
rainbow (>= 2.2.2, < 4.0)
|
53
|
-
regexp_parser (>= 1.8, < 3.0)
|
54
|
-
rexml (>= 3.2.5, < 4.0)
|
55
|
-
rubocop-ast (>= 1.30.0, < 2.0)
|
56
|
-
ruby-progressbar (~> 1.7)
|
57
|
-
unicode-display_width (>= 2.4.0, < 3.0)
|
58
|
-
rubocop-ast (1.30.0)
|
59
|
-
parser (>= 3.2.1.0)
|
60
|
-
ruby-progressbar (1.13.0)
|
61
|
-
simplecov (0.22.0)
|
62
|
-
docile (~> 1.1)
|
63
|
-
simplecov-html (~> 0.11)
|
64
|
-
simplecov_json_formatter (~> 0.1)
|
65
|
-
simplecov-html (0.12.3)
|
66
|
-
simplecov-lcov (0.8.0)
|
67
|
-
simplecov_json_formatter (0.1.4)
|
68
|
-
unicode-display_width (2.5.0)
|
69
|
-
vcr (6.2.0)
|
70
|
-
webmock (3.19.1)
|
71
|
-
addressable (>= 2.8.0)
|
72
|
-
crack (>= 0.3.2)
|
73
|
-
hashdiff (>= 0.4.0, < 2.0.0)
|
74
|
-
|
75
|
-
PLATFORMS
|
76
|
-
arm64-darwin-23
|
77
|
-
x86_64-linux
|
78
|
-
|
79
|
-
DEPENDENCIES
|
80
|
-
bns!
|
81
|
-
httparty
|
82
|
-
rake (~> 13.0)
|
83
|
-
rspec (~> 3.0)
|
84
|
-
rubocop (~> 1.21)
|
85
|
-
simplecov
|
86
|
-
simplecov-lcov (~> 0.8.0)
|
87
|
-
vcr
|
88
|
-
webmock
|
89
|
-
|
90
|
-
BUNDLED WITH
|
91
|
-
2.4.10
|
@@ -1,53 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "httparty"
|
4
|
-
require "date"
|
5
|
-
|
6
|
-
require_relative "../base"
|
7
|
-
require_relative "./exceptions/invalid_api_key"
|
8
|
-
require_relative "./exceptions/invalid_database_id"
|
9
|
-
require_relative "./types/response"
|
10
|
-
require_relative "./helper"
|
11
|
-
|
12
|
-
module Fetcher
|
13
|
-
module Notion
|
14
|
-
##
|
15
|
-
# This class is an implementation of the Fetcher::Base interface, specifically designed
|
16
|
-
# for fetching birthday data from Notion.
|
17
|
-
#
|
18
|
-
class Birthday < Base
|
19
|
-
# Implements the data fetching logic for Birthdays data from Notion. It sends a POST
|
20
|
-
# request to the Notion API to query the specified database and returns a validated response.
|
21
|
-
#
|
22
|
-
# <br>
|
23
|
-
# <b>raises</b> <tt>Exceptions::Notion::InvalidApiKey</tt> if the API key provided is incorrect or invalid.
|
24
|
-
#
|
25
|
-
# <b>raises</b> <tt>Exceptions::Notion::InvalidDatabaseId</tt> if the Database id provided is incorrect
|
26
|
-
# or invalid.
|
27
|
-
#
|
28
|
-
def fetch
|
29
|
-
url = build_url(config[:base_url], config[:database_id])
|
30
|
-
|
31
|
-
httparty_response = HTTParty.post(url, { body: config[:filter].to_json, headers: headers })
|
32
|
-
|
33
|
-
notion_response = Fetcher::Notion::Types::Response.new(httparty_response)
|
34
|
-
|
35
|
-
Fetcher::Notion::Helper.validate_response(notion_response)
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
def headers
|
41
|
-
{
|
42
|
-
"Authorization" => "Bearer #{config[:secret]}",
|
43
|
-
"Content-Type" => "application/json",
|
44
|
-
"Notion-Version" => "2022-06-28"
|
45
|
-
}
|
46
|
-
end
|
47
|
-
|
48
|
-
def build_url(base, database_id)
|
49
|
-
"#{base}/v1/databases/#{database_id}/query"
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "../../domain/birthday"
|
4
|
-
require_relative "../base"
|
5
|
-
require_relative "./exceptions/invalid_data"
|
6
|
-
|
7
|
-
module Formatter
|
8
|
-
module Discord
|
9
|
-
##
|
10
|
-
# This class implementats the methods of the Formatter::Base module, specifically designed for formatting birthday
|
11
|
-
# data in a way suitable for Discord messages.
|
12
|
-
class Birthday
|
13
|
-
include Base
|
14
|
-
|
15
|
-
# Implements the logic for building a formatted payload with the given template for birthdays.
|
16
|
-
#
|
17
|
-
# <br>
|
18
|
-
# <b>Params:</b>
|
19
|
-
# * <tt>List<Domain::Birthday></tt> birthdays_list: list of mapped birthdays.
|
20
|
-
#
|
21
|
-
# <br>
|
22
|
-
# <b>raises</b> <tt>Formatter::Discord::Exceptions::InvalidData</tt> when invalid data is provided.
|
23
|
-
#
|
24
|
-
# <br>
|
25
|
-
# <b>returns</b> <tt>String</tt> payload: formatted payload suitable for a Discord message.
|
26
|
-
#
|
27
|
-
def format(birthdays_list)
|
28
|
-
raise Formatter::Discord::Exceptions::InvalidData unless birthdays_list.all? do |brithday|
|
29
|
-
brithday.is_a?(Domain::Birthday)
|
30
|
-
end
|
31
|
-
|
32
|
-
template = "NAME, Wishing you a very happy birthday! Enjoy your special day! :birthday: :gift:"
|
33
|
-
payload = ""
|
34
|
-
|
35
|
-
birthdays_list.each do |birthday|
|
36
|
-
payload += "#{template.gsub("NAME", birthday.individual_name)}\n"
|
37
|
-
end
|
38
|
-
|
39
|
-
payload
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Formatter
|
4
|
-
module Discord
|
5
|
-
module Exceptions
|
6
|
-
##
|
7
|
-
# Provides a domain-specific representation for errors that occurs when trying to process invalid
|
8
|
-
# data on a Fetcher::Base implementation
|
9
|
-
#
|
10
|
-
class InvalidData < StandardError
|
11
|
-
def initialize(message = "")
|
12
|
-
super(message)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|