bns 0.1.1 → 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 +9 -0
- data/Gemfile +2 -0
- data/README.md +159 -3
- 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/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 +11 -8
- 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
- metadata +25 -9
- data/lib/bns/fetcher/notion/birthday.rb +0 -53
- data/lib/bns/formatter/discord/birthday.rb +0 -36
- data/lib/bns/formatter/discord/exceptions/invalid_data.rb +0 -17
- data/lib/bns/formatter/discord/pto.rb +0 -49
@@ -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
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,6 +19,7 @@ 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
|
@@ -34,23 +35,38 @@ files:
|
|
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
|
@@ -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,36 +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 < Base
|
13
|
-
# Implements the logic for building a formatted payload with the given template for birthdays.
|
14
|
-
#
|
15
|
-
# <br>
|
16
|
-
# <b>Params:</b>
|
17
|
-
# * <tt>List<Domain::Birthday></tt> birthdays_list: list of mapped birthdays.
|
18
|
-
#
|
19
|
-
# <br>
|
20
|
-
# <b>raises</b> <tt>Formatter::Discord::Exceptions::InvalidData</tt> when invalid data is provided.
|
21
|
-
#
|
22
|
-
# <br>
|
23
|
-
# <b>returns</b> <tt>String</tt> payload: formatted payload suitable for a Discord message.
|
24
|
-
#
|
25
|
-
def format(birthdays_list)
|
26
|
-
raise Formatter::Discord::Exceptions::InvalidData unless birthdays_list.all? do |brithday|
|
27
|
-
brithday.is_a?(Domain::Birthday)
|
28
|
-
end
|
29
|
-
|
30
|
-
birthdays_list.reduce("") do |payload, birthday|
|
31
|
-
payload + build_template(Domain::Birthday::ATTRIBUTES, birthday)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
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
|
@@ -1,49 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "../../domain/pto"
|
4
|
-
require_relative "../base"
|
5
|
-
|
6
|
-
module Formatter
|
7
|
-
module Discord
|
8
|
-
##
|
9
|
-
# This class is an implementation of the Formatter::Base interface, specifically designed for formatting PTO
|
10
|
-
# data in a way suitable for Discord messages.
|
11
|
-
class Pto < Base
|
12
|
-
# Implements the logic for building a formatted payload with the given template for PTO's.
|
13
|
-
#
|
14
|
-
# <br>
|
15
|
-
# <b>Params:</b>
|
16
|
-
# * <tt>List<Domain::Pto></tt> pto_list: List of mapped PTO's.
|
17
|
-
#
|
18
|
-
# <br>
|
19
|
-
# <b>raises</b> <tt>Formatter::Discord::Exceptions::InvalidData</tt> when invalid data is provided.
|
20
|
-
#
|
21
|
-
# <br>
|
22
|
-
# <b>returns</b> <tt>String</tt> payload, formatted payload suitable for a Discord message.
|
23
|
-
#
|
24
|
-
|
25
|
-
def format(ptos_list)
|
26
|
-
raise Formatter::Discord::Exceptions::InvalidData unless ptos_list.all? { |pto| pto.is_a?(Domain::Pto) }
|
27
|
-
|
28
|
-
ptos_list.reduce("") do |payload, pto|
|
29
|
-
built_template = build_template(Domain::Pto::ATTRIBUTES, pto)
|
30
|
-
payload + format_message_by_case(built_template.gsub("\n", ""), pto)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
private
|
35
|
-
|
36
|
-
def format_message_by_case(built_template, pto)
|
37
|
-
if pto.start_date.include?("|")
|
38
|
-
start_time = pto.start_date.split("|")
|
39
|
-
end_time = pto.end_date.split("|")
|
40
|
-
"#{built_template} #{start_time[1]} - #{end_time[1]}\n"
|
41
|
-
elsif pto.start_date == pto.end_date
|
42
|
-
"#{built_template} all day\n"
|
43
|
-
else
|
44
|
-
"#{built_template} #{pto.start_date} - #{pto.end_date}\n"
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|