bas 0.4.0 → 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.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -0
  3. data/README.md +68 -147
  4. data/lib/bas/bot/base.rb +74 -0
  5. data/lib/bas/bot/compare_wip_limit_count.rb +92 -0
  6. data/lib/bas/bot/fetch_birthdays_from_notion.rb +128 -0
  7. data/lib/bas/bot/fetch_domains_wip_counts_from_notion.rb +121 -0
  8. data/lib/bas/bot/fetch_domains_wip_limit_from_notion.rb +134 -0
  9. data/lib/bas/bot/fetch_emails_from_imap.rb +99 -0
  10. data/lib/bas/bot/fetch_next_week_birthdays_from_notion.rb +142 -0
  11. data/lib/bas/bot/fetch_next_week_ptos_from_notion.rb +162 -0
  12. data/lib/bas/bot/fetch_ptos_from_notion.rb +138 -0
  13. data/lib/bas/bot/format_birthdays.rb +97 -0
  14. data/lib/bas/bot/format_emails.rb +124 -0
  15. data/lib/bas/bot/format_wip_limit_exceeded.rb +97 -0
  16. data/lib/bas/bot/garbage_collector.rb +85 -0
  17. data/lib/bas/bot/humanize_pto.rb +119 -0
  18. data/lib/bas/bot/notify_discord.rb +96 -0
  19. data/lib/bas/read/base.rb +10 -23
  20. data/lib/bas/read/default.rb +16 -0
  21. data/lib/bas/read/postgres.rb +44 -0
  22. data/lib/bas/read/types/response.rb +18 -0
  23. data/lib/bas/utils/discord/integration.rb +43 -0
  24. data/lib/bas/utils/exceptions/function_not_implemented.rb +16 -0
  25. data/lib/bas/utils/exceptions/invalid_process_response.rb +16 -0
  26. data/lib/bas/utils/imap/request.rb +76 -0
  27. data/lib/bas/utils/notion/request.rb +45 -0
  28. data/lib/bas/utils/openai/run_assistant.rb +99 -0
  29. data/lib/bas/utils/postgres/request.rb +50 -0
  30. data/lib/bas/version.rb +1 -1
  31. data/lib/bas/write/base.rb +12 -17
  32. data/lib/bas/write/postgres.rb +45 -0
  33. data/lib/bas/write/postgres_update.rb +49 -0
  34. data/lib/bas.rb +1 -3
  35. metadata +30 -67
  36. data/lib/bas/domain/birthday.rb +0 -25
  37. data/lib/bas/domain/email.rb +0 -34
  38. data/lib/bas/domain/exceptions/function_not_implemented.rb +0 -18
  39. data/lib/bas/domain/issue.rb +0 -22
  40. data/lib/bas/domain/notification.rb +0 -23
  41. data/lib/bas/domain/pto.rb +0 -69
  42. data/lib/bas/domain/work_items_limit.rb +0 -25
  43. data/lib/bas/formatter/base.rb +0 -53
  44. data/lib/bas/formatter/birthday.rb +0 -38
  45. data/lib/bas/formatter/exceptions/invalid_data.rb +0 -15
  46. data/lib/bas/formatter/notification.rb +0 -34
  47. data/lib/bas/formatter/pto.rb +0 -89
  48. data/lib/bas/formatter/support_emails.rb +0 -73
  49. data/lib/bas/formatter/types/response.rb +0 -16
  50. data/lib/bas/formatter/work_items_limit.rb +0 -68
  51. data/lib/bas/process/base.rb +0 -39
  52. data/lib/bas/process/discord/exceptions/invalid_webhook_token.rb +0 -16
  53. data/lib/bas/process/discord/implementation.rb +0 -71
  54. data/lib/bas/process/discord/types/response.rb +0 -22
  55. data/lib/bas/process/openai/base.rb +0 -72
  56. data/lib/bas/process/openai/helper.rb +0 -19
  57. data/lib/bas/process/openai/types/response.rb +0 -27
  58. data/lib/bas/process/openai/use_case/humanize_pto.rb +0 -53
  59. data/lib/bas/process/slack/exceptions/invalid_webhook_token.rb +0 -16
  60. data/lib/bas/process/slack/implementation.rb +0 -70
  61. data/lib/bas/process/slack/types/response.rb +0 -21
  62. data/lib/bas/process/types/response.rb +0 -16
  63. data/lib/bas/read/github/base.rb +0 -57
  64. data/lib/bas/read/github/types/response.rb +0 -27
  65. data/lib/bas/read/github/use_case/repo_issues.rb +0 -17
  66. data/lib/bas/read/imap/base.rb +0 -70
  67. data/lib/bas/read/imap/types/response.rb +0 -27
  68. data/lib/bas/read/imap/use_case/support_emails.rb +0 -26
  69. data/lib/bas/read/notion/base.rb +0 -52
  70. data/lib/bas/read/notion/exceptions/invalid_api_key.rb +0 -15
  71. data/lib/bas/read/notion/exceptions/invalid_database_id.rb +0 -15
  72. data/lib/bas/read/notion/helper.rb +0 -21
  73. data/lib/bas/read/notion/types/response.rb +0 -26
  74. data/lib/bas/read/notion/use_case/birthday_next_week.rb +0 -41
  75. data/lib/bas/read/notion/use_case/birthday_today.rb +0 -29
  76. data/lib/bas/read/notion/use_case/notification.rb +0 -28
  77. data/lib/bas/read/notion/use_case/pto_next_week.rb +0 -71
  78. data/lib/bas/read/notion/use_case/pto_today.rb +0 -30
  79. data/lib/bas/read/notion/use_case/work_items_limit.rb +0 -37
  80. data/lib/bas/read/postgres/base.rb +0 -46
  81. data/lib/bas/read/postgres/helper.rb +0 -16
  82. data/lib/bas/read/postgres/types/response.rb +0 -42
  83. data/lib/bas/read/postgres/use_case/pto_today.rb +0 -32
  84. data/lib/bas/serialize/base.rb +0 -30
  85. data/lib/bas/serialize/github/issues.rb +0 -57
  86. data/lib/bas/serialize/imap/support_emails.rb +0 -56
  87. data/lib/bas/serialize/notion/birthday_today.rb +0 -68
  88. data/lib/bas/serialize/notion/notification.rb +0 -56
  89. data/lib/bas/serialize/notion/pto_today.rb +0 -75
  90. data/lib/bas/serialize/notion/work_items_limit.rb +0 -65
  91. data/lib/bas/serialize/postgres/pto_today.rb +0 -47
  92. data/lib/bas/use_cases/types/config.rb +0 -20
  93. data/lib/bas/use_cases/use_case.rb +0 -42
  94. data/lib/bas/use_cases/use_cases.rb +0 -465
  95. data/lib/bas/write/logs/base.rb +0 -33
  96. data/lib/bas/write/logs/use_case/console_log.rb +0 -22
  97. data/lib/bas/write/notion/base.rb +0 -36
  98. data/lib/bas/write/notion/use_case/empty_notification.rb +0 -38
  99. data/lib/bas/write/notion/use_case/notification.rb +0 -38
@@ -1,465 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # read
4
- require_relative "../read/notion/use_case/birthday_today"
5
- require_relative "../read/notion/use_case/birthday_next_week"
6
- require_relative "../read/notion/use_case/pto_today"
7
- require_relative "../read/notion/use_case/pto_next_week"
8
- require_relative "../read/notion/use_case/notification"
9
- require_relative "../read/notion/use_case/work_items_limit"
10
- require_relative "../read/postgres/use_case/pto_today"
11
- require_relative "../read/imap/use_case/support_emails"
12
- require_relative "../read/github/use_case/repo_issues"
13
-
14
- # serialize
15
- require_relative "../serialize/notion/birthday_today"
16
- require_relative "../serialize/notion/pto_today"
17
- require_relative "../serialize/notion/work_items_limit"
18
- require_relative "../serialize/notion/notification"
19
- require_relative "../serialize/postgres/pto_today"
20
- require_relative "../serialize/imap/support_emails"
21
- require_relative "../serialize/github/issues"
22
-
23
- # formatter
24
- require_relative "../formatter/birthday"
25
- require_relative "../formatter/pto"
26
- require_relative "../formatter/work_items_limit"
27
- require_relative "../formatter/support_emails"
28
- require_relative "../formatter/notification"
29
-
30
- # process
31
- require_relative "../process/discord/implementation"
32
- require_relative "../process/slack/implementation"
33
- require_relative "../process/openai/use_case/humanize_pto"
34
-
35
- # write
36
- require_relative "../write/logs/use_case/console_log"
37
- require_relative "../write/notion/use_case/notification"
38
- require_relative "../write/notion/use_case/empty_notification"
39
-
40
- require_relative "use_case"
41
- require_relative "./types/config"
42
-
43
- ##
44
- # This module provides factory methods for use cases within the system. Each method
45
- # represents a use case implementation introduced in the system.
46
- #
47
- module UseCases
48
- # Provides an instance of the Birthdays notifications from Notion to Discord use case implementation.
49
- #
50
- # <b>Example</b>
51
- #
52
- # options = {
53
- # read_options: {
54
- # database_id: NOTION_DATABASE_ID,
55
- # secret: NOTION_API_INTEGRATION_SECRET,
56
- # },
57
- # process_options: {
58
- # webhook: "https://discord.com/api/webhooks/1199213527672565760/KmpoIzBet9xYG16oFh8W1RWHbpIqT7UtTBRrhfLcvWZdNiVZCTM-gpil2Qoy4eYEgpdf",
59
- # name: "Birthday Bot"
60
- # }
61
- # }
62
- #
63
- # use_case = UseCases.notify_birthday_from_notion_to_discord(options)
64
- # use_case.perform
65
- #
66
- # #################################################################################
67
- #
68
- # Requirements:
69
- # * Notion database ID, from a database with the following structure:
70
- #
71
- # _________________________________________________________________________________
72
- # | Complete Name (text) | BD_this_year (formula) | BD (date) |
73
- # | -------------------- | --------------------------- | ------------------------ |
74
- # | John Doe | January 24, 2024 | January 24, 2000 |
75
- # | Jane Doe | June 20, 2024 | June 20, 2000 |
76
- # ---------------------------------------------------------------------------------
77
- # With the following formula for the BD_this_year column:
78
- # dateAdd(prop("BD"), year(now()) - year(prop("BD")), "years")
79
- #
80
- # * A Notion secret, which can be obtained, by creating an integration here: `https://developers.notion.com/`,
81
- # browsing on the <View my integations> option, and selecting the <New Integration> or <Create new>
82
- # integration** buttons.
83
- # * A webhook key, which can be generated directly on discrod on the desired channel, following this instructions:
84
- # https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks
85
- #
86
- def self.notify_birthday_from_notion_to_discord(options)
87
- read = Read::Notion::BirthdayToday.new(options[:read_options])
88
- serialize = Serialize::Notion::BirthdayToday.new
89
- formatter = Formatter::Birthday.new(options[:format_options])
90
- process = Process::Discord::Implementation.new(options[:process_options])
91
- write = Write::Logs::ConsoleLog.new
92
- use_case_config = UseCases::Types::Config.new(read, serialize, formatter, process, write)
93
-
94
- UseCases::UseCase.new(use_case_config)
95
- end
96
-
97
- # Provides an instance of the next week Birthdays notifications from Notion to Discord use case implementation.
98
- #
99
- # <b>Example</b>
100
- #
101
- # options = {
102
- # read_options: {
103
- # database_id: NOTION_DATABASE_ID,
104
- # secret: NOTION_API_INTEGRATION_SECRET,
105
- # },
106
- # process_options: {
107
- # webhook: "https://discord.com/api/webhooks/1199213527672565760/KmpoIzBet9xYG16oFh8W1RWHbpIqT7UtTBRrhfLcvWZdNiVZCTM-gpil2Qoy4eYEgpdf",
108
- # name: "Birthday Bot"
109
- # },
110
- # format_options: {
111
- # template: "individual_name, Wishing you a very happy birthday! Enjoy your special day! :birthday: :gift:",
112
- # timezone: "-05:00"
113
- # }
114
- # }
115
- #
116
- # use_case = UseCases.notify_next_week_birthday_from_notion_to_discord(options)
117
- # use_case.perform
118
- #
119
- # #################################################################################
120
- #
121
- # Requirements:
122
- # * Notion database ID, from a database with the following structure:
123
- #
124
- # _________________________________________________________________________________
125
- # | Complete Name (text) | BD_this_year (formula) | BD (date) |
126
- # | -------------------- | --------------------------- | ------------------------ |
127
- # | John Doe | January 24, 2024 | January 24, 2000 |
128
- # | Jane Doe | June 20, 2024 | June 20, 2000 |
129
- # ---------------------------------------------------------------------------------
130
- # With the following formula for the BD_this_year column:
131
- # dateAdd(prop("BD"), year(now()) - year(prop("BD")), "years")
132
- #
133
- # * A Notion secret, which can be obtained, by creating an integration here: `https://developers.notion.com/`,
134
- # browsing on the <View my integations> option, and selecting the <New Integration> or <Create new>
135
- # integration** buttons.
136
- # * A webhook key, which can be generated directly on discrod on the desired channel, following this instructions:
137
- # https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks
138
- #
139
- def self.notify_next_week_birthday_from_notion_to_discord(options)
140
- read = Read::Notion::BirthdayNextWeek.new(options[:read_options])
141
- serialize = Serialize::Notion::BirthdayToday.new
142
- formatter = Formatter::Birthday.new(options[:format_options])
143
- process = Process::Discord::Implementation.new(options[:process_options])
144
- write = Write::Logs::ConsoleLog.new
145
- use_case_cofig = UseCases::Types::Config.new(read, serialize, formatter, process, write)
146
-
147
- UseCases::UseCase.new(use_case_cofig)
148
- end
149
-
150
- # Provides an instance of the PTO notifications from Notion to Discord use case implementation.
151
- #
152
- # <br>
153
- # <b>Example</b>
154
- #
155
- # options = {
156
- # read_options: {
157
- # database_id: NOTION_DATABASE_ID,
158
- # secret: NOTION_API_INTEGRATION_SECRET,
159
- # use_case_title: "PTO"
160
- # },
161
- # format_options: {
162
- # template: ":beach: individual_name is on PTO",
163
- # timezone: "-05:00"
164
- # },
165
- # process_options: {
166
- # webhook: "https://discord.com/api/webhooks/1199213527672565760/KmpoIzBet9xYG16oFh8W1RWHbpIqT7UtTBRrhfLcvWZdNiVZCTM-gpil2Qoy4eYEgpdf",
167
- # name: "notificationBOT"
168
- # },
169
- # write_options: {
170
- # secret: NOTION_API_INTEGRATION_SECRET,
171
- # page_id: WRITE_NOTION_PAGE_ID
172
- # }
173
- # }
174
- #
175
- # use_case = UseCases.notify_pto_from_notion_to_discord(options)
176
- # use_case.perform
177
- #
178
- # #################################################################################
179
- #
180
- # Requirements:
181
- # * Notion database ID, from a database with the following structure:
182
- #
183
- # ________________________________________________________________________________________________________
184
- # | Person (person) | Desde? (date) | Hasta? (date) |
185
- # | -------------------- | --------------------------------------- | ------------------------------------ |
186
- # | John Doe | January 24, 2024 | January 27, 2024 |
187
- # | Jane Doe | November 11, 2024 2:00 PM | November 11, 2024 6:00 PM |
188
- # ---------------------------------------------------------------------------------------------------------
189
- #
190
- # * Write Notion page ID, from a page with a "Notification" text property.
191
- # This property will be updated with the humanized notification.
192
- # * A Notion secret, which can be obtained, by creating an integration here: `https://developers.notion.com/`,
193
- # browsing on the <View my integations> option, and selecting the <New Integration> or <Create new>
194
- # integration** buttons.
195
- # * A webhook key, which can be generated directly on discrod on the desired channel, following this instructions:
196
- # https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks
197
- #
198
- def self.notify_pto_from_notion_to_discord(options)
199
- read = Read::Notion::Notification.new(options[:read_options])
200
- serialize = Serialize::Notion::Notification.new
201
- formatter = Formatter::Notification.new(options[:format_options])
202
- process = Process::Discord::Implementation.new(options[:process_options])
203
- write = Write::Notion::EmptyNotification.new(options[:write_options])
204
-
205
- use_case_config = UseCases::Types::Config.new(read, serialize, formatter, process, write)
206
-
207
- UseCases::UseCase.new(use_case_config)
208
- end
209
-
210
- # Provides an instance of the humanized PTO write from Notion to Notion use case implementation.
211
- #
212
- # <br>
213
- # <b>Example</b>
214
- #
215
- # options = {
216
- # read_options: {
217
- # database_id: READ_NOTION_DATABASE_ID,
218
- # secret: NOTION_API_INTEGRATION_SECRET
219
- # },
220
- # format_options: {
221
- # template: ":beach: individual_name is on PTO",
222
- # timezone: "-05:00"
223
- # },
224
- # process_options: {
225
- # secret: OPENAI_API_SECRET_KEY,
226
- # model: "gpt-4",
227
- # timezone: "-05:00"
228
- # },
229
- # write_options: {
230
- # secret: NOTION_API_INTEGRATION_SECRET,
231
- # page_id: WRITE_NOTION_PAGE_ID,
232
- # }
233
- # }
234
- #
235
- # use_case = UseCases.write_humanized_pto_from_notion_to_notion(options)
236
- # use_case.perform
237
- #
238
- # #################################################################################
239
- #
240
- # Requirements:
241
- # * Read Notion database ID, from a database with the following structure:
242
- #
243
- # ________________________________________________________________________________________________________
244
- # | Person (person) | Desde? (date) | Hasta? (date) |
245
- # | -------------------- | --------------------------------------- | ------------------------------------ |
246
- # | John Doe | January 24, 2024 | January 27, 2024 |
247
- # | Jane Doe | November 11, 2024 2:00 PM | November 11, 2024 6:00 PM |
248
- # ---------------------------------------------------------------------------------------------------------
249
- #
250
- # * Write Notion page ID, from a page with a "Notification" text property.
251
- # This property will be updated with the humanized notification.
252
- # * A Notion secret, which can be obtained, by creating an integration here: `https://developers.notion.com/`,
253
- # browsing on the <View my integations> option, and selecting the <New Integration> or <Create new>
254
- # integration** buttons. This should have permission to update.
255
- #
256
- def self.write_humanized_pto_from_notion_to_notion(options)
257
- read = Read::Notion::PtoToday.new(options[:read_options])
258
- serialize = Serialize::Notion::PtoToday.new
259
- formatter = Formatter::Pto.new(options[:format_options])
260
- process = Process::OpenAI::HumanizePto.new(options[:process_options])
261
- write = Write::Notion::Notification.new(options[:write_options])
262
-
263
- use_case_config = UseCases::Types::Config.new(read, serialize, formatter, process, write)
264
-
265
- UseCases::UseCase.new(use_case_config)
266
- end
267
-
268
- # Provides an instance of the next week PTO notifications from Notion to Discord use case implementation.
269
- #
270
- # <br>
271
- # <b>Example</b>
272
- #
273
- # options = {
274
- # read_options: {
275
- # database_id: NOTION_DATABASE_ID,
276
- # secret: NOTION_API_INTEGRATION_SECRET,
277
- # },
278
- # process_options: {
279
- # webhook: "https://discord.com/api/webhooks/1199213527672565760/KmpoIzBet9xYG16oFh8W1RWHbpIqT7UtTBRrhfLcvWZdNiVZCTM-gpil2Qoy4eYEgpdf",
280
- # name: "Pto Bot"
281
- # },
282
- # format_options: {
283
- # template: ":beach: individual_name its going to be on PTO next week,",
284
- # timezone: "-05:00"
285
- # }
286
- # }
287
- #
288
- # use_case = UseCases.notify_next_week_pto_from_notion_to_discord(options)
289
- # use_case.perform
290
- #
291
- # #################################################################################
292
- #
293
- # Requirements:
294
- # * Notion database ID, from a database with the following structure:
295
- #
296
- # ________________________________________________________________________________________________________
297
- # | Person (person) | Desde? (date) | Hasta? (date) |
298
- # | -------------------- | --------------------------------------- | ------------------------------------ |
299
- # | John Doe | January 24, 2024 | January 27, 2024 |
300
- # | Jane Doe | November 11, 2024 2:00 PM | November 11, 2024 6:00 PM |
301
- # ---------------------------------------------------------------------------------------------------------
302
- #
303
- # * A Notion secret, which can be obtained, by creating an integration here: `https://developers.notion.com/`,
304
- # browsing on the <View my integations> option, and selecting the <New Integration> or <Create new>
305
- # integration** buttons.
306
- # * A webhook key, which can be generated directly on discrod on the desired channel, following this instructions:
307
- # https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks
308
- #
309
- def self.notify_next_week_pto_from_notion_to_discord(options)
310
- read = Read::Notion::PtoNextWeek.new(options[:read_options])
311
- serialize = Serialize::Notion::PtoToday.new
312
- formatter = Formatter::Pto.new(options[:format_options])
313
- process = Process::Discord::Implementation.new(options[:process_options])
314
- write = Write::Logs::ConsoleLog.new
315
- use_case_config = UseCases::Types::Config.new(read, serialize, formatter, process, write)
316
-
317
- UseCases::UseCase.new(use_case_config)
318
- end
319
-
320
- # Provides an instance of the PTO notifications from Postgres to Slack use case implementation.
321
- #
322
- # <br>
323
- # <b>Example</b>
324
- #
325
- # options = {
326
- # read_options: {
327
- # connection: {
328
- # host: "localhost",
329
- # port: 5432,
330
- # dbname: "db_pto",
331
- # user: "postgres",
332
- # password: "postgres"
333
- # }
334
- # },
335
- # process_options:{
336
- # webhook: "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX",
337
- # name: "Pto Bot"
338
- # },
339
- # format_options: {
340
- # template: "Custom template",
341
- # timezone: "-05:00"
342
- # }
343
- # }
344
- #
345
- # use_case = UseCases.notify_pto_from_postgres_to_slack(options)
346
- # use_case.perform
347
- #
348
- # #################################################################################
349
- #
350
- # Requirements:
351
- # * A connection to a Postgres database and a table with the following structure:
352
- #
353
- # Column | Type | Collation | Nullable | Default
354
- # -----------------+------------------------+-----------+----------+------------------------------
355
- # id | integer | | not null | generated always as identity
356
- # create_time | date | | |
357
- # individual_name | character varying(255) | | |
358
- # start_date | date | | |
359
- # end_date | date | | |
360
- #
361
- # * A webhook key, which can be generated directly on slack on the desired channel, following this instructions:
362
- # https://api.slack.com/messaging/webhooks#create_a_webhook
363
- #
364
- def self.notify_pto_from_postgres_to_slack(options)
365
- read = Read::Postgres::PtoToday.new(options[:read_options])
366
- serialize = Serialize::Postgres::PtoToday.new
367
- formatter = Formatter::Pto.new(options[:format_options])
368
- process = Process::Slack::Implementation.new(options[:process_options])
369
- write = Write::Logs::ConsoleLog.new
370
- use_case_config = UseCases::Types::Config.new(read, serialize, formatter, process, write)
371
-
372
- UseCases::UseCase.new(use_case_config)
373
- end
374
-
375
- # Provides an instance of the Work Items wip limit notifications from Notion to Discord use case implementation.
376
- #
377
- # <br>
378
- # <b>Example</b>
379
- #
380
- # options = {
381
- # read_options: {
382
- # database_id: NOTION_DATABASE_ID,
383
- # secret: NOTION_API_INTEGRATION_SECRET
384
- # },
385
- # process_options: {
386
- # webhook: "https://discord.com/api/webhooks/1199213527672565760/KmpoIzBet9xYG16oFh8W1RWHbpIqT7UtTBRrhfLcvWZdNiVZCTM-gpil2Qoy4eYEgpdf",
387
- # name: "wipLimit"
388
- # }
389
- # }
390
- #
391
- # use_case = UseCases.notify_wip_limit_from_notion_to_discord(options)
392
- # use_case.perform
393
- #
394
- # #################################################################################
395
- #
396
- # Requirements:
397
- # * Notion database ID, from a database with the following structure:
398
- #
399
- # _________________________________________________________________________________
400
- # | OK | Status | Responsible Domain |
401
- # | -------------------- | --------------------------- | ------------------------ |
402
- # | ✅ | In Progress | "kommit.admin" |
403
- # | 🚩 | Fail | "kommit.ops" |
404
- # ---------------------------------------------------------------------------------
405
- #
406
- # * A Notion secret, which can be obtained, by creating an integration here: `https://developers.notion.com/`,
407
- # browsing on the <View my integations> option, and selecting the <New Integration> or <Create new>
408
- # integration** buttons.
409
- # * A webhook key, which can be generated directly on discrod on the desired channel, following this instructions:
410
- # https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks
411
- #
412
- def self.notify_wip_limit_from_notion_to_discord(options)
413
- read = Read::Notion::WorkItemsLimit.new(options[:read_options])
414
- serialize = Serialize::Notion::WorkItemsLimit.new
415
- formatter = Formatter::WorkItemsLimit.new(options[:format_options])
416
- process = Process::Discord::Implementation.new(options[:process_options])
417
- write = Write::Logs::ConsoleLog.new
418
- use_case_config = UseCases::Types::Config.new(read, serialize, formatter, process, write)
419
-
420
- UseCases::UseCase.new(use_case_config)
421
- end
422
-
423
- # Provides an instance of the support emails from an google IMAP server to Discord use case implementation.
424
- #
425
- # <br>
426
- # <b>Example</b>
427
- #
428
- # options = {
429
- # read_options: {
430
- # user: 'info@email.co',
431
- # refresh_token: REFRESH_TOKEN,
432
- # client_id: CLIENT_ID,
433
- # client_secret: CLIENT_SECRET,
434
- # inbox: 'INBOX',
435
- # search_email: 'support@email.co'
436
- # },
437
- # process_options: {
438
- # webhook: "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX",
439
- # name: "emailSupport"
440
- # }
441
- # }
442
- #
443
- # use_case = UseCases.notify_support_email_from_imap_to_discord(options)
444
- # use_case.perform
445
- #
446
- # #################################################################################
447
- #
448
- # Requirements:
449
- # * A google gmail account with IMAP support activated.
450
- # * A set of authorization parameters like a client_id, client_secret, and a resfresh_token. To
451
- # generate them, follow this instructions: https://developers.google.com/identity/protocols/oauth2
452
- # * A webhook key, which can be generated directly on discrod on the desired channel, following this instructions:
453
- # https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks
454
- #
455
- def self.notify_support_email_from_imap_to_discord(options)
456
- read = Read::Imap::SupportEmails.new(options[:read_options])
457
- serialize = Serialize::Imap::SupportEmails.new
458
- formatter = Formatter::SupportEmails.new(options[:format_options])
459
- process = Process::Discord::Implementation.new(options[:process_options])
460
- write = Write::Logs::ConsoleLog.new
461
- use_case_config = UseCases::Types::Config.new(read, serialize, formatter, process, write)
462
-
463
- UseCases::UseCase.new(use_case_config)
464
- end
465
- end
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../base"
4
-
5
- module Write
6
- module Logs
7
- ##
8
- # This class is an implementation of the Write::Base interface, specifically designed
9
- # for writting logs as a STDOUT.
10
- #
11
- class Base < Write::Base
12
- attr_reader :logger
13
-
14
- # Initializes the write with essential configuration parameters like the logger
15
- # using the Logger gem.
16
- #
17
- def initialize(config = {})
18
- super(config)
19
-
20
- @logger = Logger.new($stdout)
21
- end
22
-
23
- protected
24
-
25
- # Implements the writing logic to write logs data as STOUT. It uses the Logger
26
- # gem and execute the given method (info, error, etc) to write the log
27
- #
28
- def write(method, log_message)
29
- @logger.send(method, log_message)
30
- end
31
- end
32
- end
33
- end
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../base"
4
-
5
- module Write
6
- module Logs
7
- ##
8
- # This class is an implementation of the Write::Logs::Base interface, specifically designed
9
- # to write logs as STDOUT
10
- class ConsoleLog < Logs::Base
11
- # Implements the writting process logic for the ConsoleLog use case.
12
- #
13
- # <br>
14
- # <b>Params:</b>
15
- # * <tt>Process::Types::Response</tt> process response: standard process response with the data to be logged.
16
- #
17
- def execute(_process_response)
18
- write("info", "Process Executed")
19
- end
20
- end
21
- end
22
- end
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../base"
4
-
5
- module Write
6
- module Notion
7
- ##
8
- # This class is an implementation of the Write::Base interface, specifically designed
9
- # to create or update pages in a Notion database.
10
- #
11
- class Base < Write::Base
12
- NOTION_BASE_URL = "https://api.notion.com"
13
-
14
- protected
15
-
16
- # Implements the writing logic to create or update pages in a Notion.database. It sends
17
- # a request to the Notion API given the method (post, patch, etc), endpoint and body.
18
- #
19
- def write(method, endpoint, body)
20
- url = "#{NOTION_BASE_URL}#{endpoint}"
21
-
22
- HTTParty.send(method, url, { body: body.to_json, headers: })
23
- end
24
-
25
- private
26
-
27
- def headers
28
- {
29
- "Authorization" => "Bearer #{config[:secret]}",
30
- "Content-Type" => "application/json",
31
- "Notion-Version" => "2022-06-28"
32
- }
33
- end
34
- end
35
- end
36
- end
@@ -1,38 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../base"
4
-
5
- module Write
6
- module Notion
7
- ##
8
- # This class is an implementation of the Write::Notion::Base interface, specifically designed
9
- # to update an existing page in a Notion database to write an empty text.
10
- class EmptyNotification < Notion::Base
11
- # Implements the writting process logic for the Notification use case.
12
- #
13
- # <br>
14
- # <b>Params:</b>
15
- # * <tt>Process::Types::Response</tt> process response: standard process response.
16
- #
17
- def execute(_process_response)
18
- endpoint = "/v1/pages/#{config[:page_id]}"
19
-
20
- body = body("")
21
-
22
- write("patch", endpoint, body)
23
- end
24
-
25
- private
26
-
27
- def body(content)
28
- {
29
- properties: {
30
- Notification: {
31
- rich_text: [{ text: { content: } }]
32
- }
33
- }
34
- }
35
- end
36
- end
37
- end
38
- end
@@ -1,38 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../base"
4
-
5
- module Write
6
- module Notion
7
- ##
8
- # This class is an implementation of the Write::OpenAI::Base interface, specifically designed
9
- # to update an existing page on a Notion database to write the notification text.
10
- class Notification < Notion::Base
11
- # Implements the writting process logic for the Notification use case.
12
- #
13
- # <br>
14
- # <b>Params:</b>
15
- # * <tt>Process::Types::Response</tt> process response: standard process response with the data to be updated.
16
- #
17
- def execute(process_response)
18
- endpoint = "/v1/pages/#{config[:page_id]}"
19
-
20
- body = body(process_response.data.choices[0]["message"]["content"])
21
-
22
- write("patch", endpoint, body)
23
- end
24
-
25
- private
26
-
27
- def body(content)
28
- {
29
- properties: {
30
- Notification: {
31
- rich_text: [{ text: { content: } }]
32
- }
33
- }
34
- }
35
- end
36
- end
37
- end
38
- end