bas 0.3.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/CHANGELOG.md +15 -0
  4. data/CONTRIBUTING.md +9 -0
  5. data/README.md +68 -147
  6. data/lib/bas/bot/base.rb +74 -0
  7. data/lib/bas/bot/compare_wip_limit_count.rb +92 -0
  8. data/lib/bas/bot/fetch_birthdays_from_notion.rb +128 -0
  9. data/lib/bas/bot/fetch_domains_wip_counts_from_notion.rb +121 -0
  10. data/lib/bas/bot/fetch_domains_wip_limit_from_notion.rb +134 -0
  11. data/lib/bas/bot/fetch_emails_from_imap.rb +99 -0
  12. data/lib/bas/bot/fetch_next_week_birthdays_from_notion.rb +142 -0
  13. data/lib/bas/bot/fetch_next_week_ptos_from_notion.rb +162 -0
  14. data/lib/bas/bot/fetch_ptos_from_notion.rb +138 -0
  15. data/lib/bas/bot/format_birthdays.rb +97 -0
  16. data/lib/bas/bot/format_emails.rb +124 -0
  17. data/lib/bas/bot/format_wip_limit_exceeded.rb +97 -0
  18. data/lib/bas/bot/garbage_collector.rb +85 -0
  19. data/lib/bas/bot/humanize_pto.rb +119 -0
  20. data/lib/bas/bot/notify_discord.rb +96 -0
  21. data/lib/bas/read/base.rb +10 -23
  22. data/lib/bas/read/default.rb +16 -0
  23. data/lib/bas/read/postgres.rb +44 -0
  24. data/lib/bas/read/types/response.rb +18 -0
  25. data/lib/bas/utils/discord/integration.rb +43 -0
  26. data/lib/bas/utils/exceptions/function_not_implemented.rb +16 -0
  27. data/lib/bas/utils/exceptions/invalid_process_response.rb +16 -0
  28. data/lib/bas/utils/imap/request.rb +76 -0
  29. data/lib/bas/utils/notion/request.rb +45 -0
  30. data/lib/bas/utils/openai/run_assistant.rb +99 -0
  31. data/lib/bas/utils/postgres/request.rb +50 -0
  32. data/lib/bas/version.rb +1 -1
  33. data/lib/bas/write/base.rb +12 -17
  34. data/lib/bas/write/postgres.rb +45 -0
  35. data/lib/bas/write/postgres_update.rb +49 -0
  36. data/lib/bas.rb +1 -3
  37. metadata +31 -57
  38. data/lib/bas/domain/birthday.rb +0 -25
  39. data/lib/bas/domain/email.rb +0 -34
  40. data/lib/bas/domain/exceptions/function_not_implemented.rb +0 -18
  41. data/lib/bas/domain/issue.rb +0 -22
  42. data/lib/bas/domain/pto.rb +0 -69
  43. data/lib/bas/domain/work_items_limit.rb +0 -25
  44. data/lib/bas/formatter/base.rb +0 -53
  45. data/lib/bas/formatter/birthday.rb +0 -38
  46. data/lib/bas/formatter/exceptions/invalid_data.rb +0 -15
  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/slack/exceptions/invalid_webhook_token.rb +0 -16
  56. data/lib/bas/process/slack/implementation.rb +0 -70
  57. data/lib/bas/process/slack/types/response.rb +0 -21
  58. data/lib/bas/process/types/response.rb +0 -16
  59. data/lib/bas/read/github/base.rb +0 -57
  60. data/lib/bas/read/github/types/response.rb +0 -27
  61. data/lib/bas/read/github/use_case/repo_issues.rb +0 -17
  62. data/lib/bas/read/imap/base.rb +0 -70
  63. data/lib/bas/read/imap/types/response.rb +0 -27
  64. data/lib/bas/read/imap/use_case/support_emails.rb +0 -26
  65. data/lib/bas/read/notion/base.rb +0 -52
  66. data/lib/bas/read/notion/exceptions/invalid_api_key.rb +0 -15
  67. data/lib/bas/read/notion/exceptions/invalid_database_id.rb +0 -15
  68. data/lib/bas/read/notion/helper.rb +0 -21
  69. data/lib/bas/read/notion/types/response.rb +0 -26
  70. data/lib/bas/read/notion/use_case/birthday_next_week.rb +0 -41
  71. data/lib/bas/read/notion/use_case/birthday_today.rb +0 -29
  72. data/lib/bas/read/notion/use_case/pto_next_week.rb +0 -71
  73. data/lib/bas/read/notion/use_case/pto_today.rb +0 -30
  74. data/lib/bas/read/notion/use_case/work_items_limit.rb +0 -37
  75. data/lib/bas/read/postgres/base.rb +0 -46
  76. data/lib/bas/read/postgres/helper.rb +0 -16
  77. data/lib/bas/read/postgres/types/response.rb +0 -42
  78. data/lib/bas/read/postgres/use_case/pto_today.rb +0 -32
  79. data/lib/bas/serialize/base.rb +0 -30
  80. data/lib/bas/serialize/github/issues.rb +0 -57
  81. data/lib/bas/serialize/imap/support_emails.rb +0 -56
  82. data/lib/bas/serialize/notion/birthday_today.rb +0 -68
  83. data/lib/bas/serialize/notion/pto_today.rb +0 -75
  84. data/lib/bas/serialize/notion/work_items_limit.rb +0 -65
  85. data/lib/bas/serialize/postgres/pto_today.rb +0 -47
  86. data/lib/bas/use_cases/types/config.rb +0 -20
  87. data/lib/bas/use_cases/use_case.rb +0 -42
  88. data/lib/bas/use_cases/use_cases.rb +0 -389
  89. data/lib/bas/write/logs/base.rb +0 -33
  90. data/lib/bas/write/logs/use_case/console_log.rb +0 -22
@@ -1,65 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../../domain/work_items_limit"
4
- require_relative "../base"
5
-
6
- module Serialize
7
- module Notion
8
- ##
9
- # This class implements the methods of the Serialize::Base module, specifically designed
10
- # for preparing or shaping work items data coming from a Read::Base implementation.
11
- class WorkItemsLimit
12
- include Base
13
-
14
- WORK_ITEM_PARAMS = ["Responsible domain"].freeze
15
-
16
- # Implements the logic for shaping the results from a reader response.
17
- #
18
- # <br>
19
- # <b>Params:</b>
20
- # * <tt>Read::Notion::Types::Response</tt> notion_response: Notion response object.
21
- #
22
- # <br>
23
- # <b>return</b> <tt>List<Domain::WorkItem></tt> work_items_list, serialized work items to be used by a
24
- # Formatter::Base implementation.
25
- #
26
- def execute(notion_response)
27
- return [] if notion_response.results.empty?
28
-
29
- normalized_notion_data = normalize_response(notion_response.results)
30
-
31
- domain_items_count = count_domain_items(normalized_notion_data)
32
-
33
- domain_items_count.map do |domain, items_count|
34
- Domain::WorkItemsLimit.new(domain, items_count)
35
- end
36
- end
37
-
38
- private
39
-
40
- def normalize_response(results)
41
- return [] if results.nil?
42
-
43
- results.map do |value|
44
- work_item_fields = value["properties"].slice(*WORK_ITEM_PARAMS)
45
-
46
- work_item_fields.each do |field, work_item_value|
47
- work_item_fields[field] = extract_domain_field_value(work_item_value)
48
- end
49
-
50
- work_item_fields
51
- end
52
- end
53
-
54
- def extract_domain_field_value(data)
55
- data["select"]["name"]
56
- end
57
-
58
- def count_domain_items(work_items_list)
59
- domain_work_items = work_items_list.group_by { |work_item| work_item["Responsible domain"] }
60
-
61
- domain_work_items.transform_values(&:count)
62
- end
63
- end
64
- end
65
- end
@@ -1,47 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../../domain/pto"
4
- require_relative "../base"
5
-
6
- module Serialize
7
- module Postgres
8
- ##
9
- # This class implements the methods of the Serialize::Base module, specifically designed for preparing or
10
- # shaping PTO's data coming from the Read::Postgres::Pto class.
11
- #
12
- class PtoToday
13
- # Implements the logic for shaping the results from a reader response.
14
- #
15
- # <br>
16
- # <b>Params:</b>
17
- # * <tt>Read::Postgres::Types::Response</tt> pg_response: Postgres response object.
18
- #
19
- # <br>
20
- # <b>returns</b> <tt>List<Domain::Pto></tt> ptos_list, serialized PTO's to be used by a Formatter::Base
21
- # implementation.
22
- #
23
- def execute(pg_response)
24
- return [] if pg_response.records.empty?
25
-
26
- ptos = build_map(pg_response)
27
-
28
- ptos.map do |pto|
29
- name = pto["name"]
30
- start_date = { from: pto["start_date"], to: nil }
31
- end_date = { from: pto["end_date"], to: nil }
32
-
33
- Domain::Pto.new(name, start_date, end_date)
34
- end
35
- end
36
-
37
- private
38
-
39
- def build_map(pg_response)
40
- fields = pg_response.fields
41
- values = pg_response.records
42
-
43
- values.map { |value| Hash[fields.zip(value)] }
44
- end
45
- end
46
- end
47
- end
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module UseCases
4
- module Types
5
- ##
6
- # Represents a the configuration composing the initial components required by a UseCases::UseCase implementation.
7
- #
8
- class Config
9
- attr_reader :read, :serialize, :formatter, :process, :write
10
-
11
- def initialize(read, serialize, formatter, process, write)
12
- @read = read
13
- @serialize = serialize
14
- @formatter = formatter
15
- @process = process
16
- @write = write
17
- end
18
- end
19
- end
20
- end
@@ -1,42 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module UseCases
4
- ##
5
- # The UseCases::UseCase class represents a generic structure for use cases within the system. It encapsulates the
6
- # logic flow by coordinating the execution of its components to fulfill a specific use case.
7
- #
8
- class UseCase
9
- attr_reader :read, :serialize, :formatter, :process, :write
10
-
11
- # Initializes the use case with the necessary components.
12
- #
13
- # <br>
14
- # <b>Params:</b>
15
- # * <tt>Usecases::Types::Config</tt> config, The components required to instantiate a use case.
16
- #
17
- def initialize(config)
18
- @read = config.read
19
- @serialize = config.serialize
20
- @formatter = config.formatter
21
- @process = config.process
22
- @write = config.write
23
- end
24
-
25
- # Executes the use case by orchestrating the sequential execution of the read, serialize, formatter, and process.
26
- #
27
- # <br>
28
- # <b>returns</b> <tt>Process::Discord::Types::Response</tt>
29
- #
30
- def perform
31
- response = read.execute
32
-
33
- serialization = serialize.execute(response)
34
-
35
- format_response = formatter.format(serialization)
36
-
37
- process_response = process.execute(format_response)
38
-
39
- write.execute(process_response)
40
- end
41
- end
42
- end
@@ -1,389 +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/work_items_limit"
9
- require_relative "../read/postgres/use_case/pto_today"
10
- require_relative "../read/imap/use_case/support_emails"
11
- require_relative "../read/github/use_case/repo_issues"
12
-
13
- # serialize
14
- require_relative "../serialize/notion/birthday_today"
15
- require_relative "../serialize/notion/pto_today"
16
- require_relative "../serialize/notion/work_items_limit"
17
- require_relative "../serialize/postgres/pto_today"
18
- require_relative "../serialize/imap/support_emails"
19
- require_relative "../serialize/github/issues"
20
-
21
- # formatter
22
- require_relative "../formatter/birthday"
23
- require_relative "../formatter/pto"
24
- require_relative "../formatter/work_items_limit"
25
- require_relative "../formatter/support_emails"
26
-
27
- # process
28
- require_relative "../process/discord/implementation"
29
- require_relative "../process/slack/implementation"
30
-
31
- # write
32
- require_relative "../write/logs/use_case/console_log"
33
-
34
- require_relative "use_case"
35
- require_relative "./types/config"
36
-
37
- ##
38
- # This module provides factory methods for use cases within the system. Each method
39
- # represents a use case implementation introduced in the system.
40
- #
41
- module UseCases
42
- # Provides an instance of the Birthdays notifications from Notion to Discord use case implementation.
43
- #
44
- # <b>Example</b>
45
- #
46
- # options = {
47
- # read_options: {
48
- # database_id: NOTION_DATABASE_ID,
49
- # secret: NOTION_API_INTEGRATION_SECRET,
50
- # },
51
- # process_options: {
52
- # webhook: "https://discord.com/api/webhooks/1199213527672565760/KmpoIzBet9xYG16oFh8W1RWHbpIqT7UtTBRrhfLcvWZdNiVZCTM-gpil2Qoy4eYEgpdf",
53
- # name: "Birthday Bot"
54
- # }
55
- # }
56
- #
57
- # use_case = UseCases.notify_birthday_from_notion_to_discord(options)
58
- # use_case.perform
59
- #
60
- # #################################################################################
61
- #
62
- # Requirements:
63
- # * Notion database ID, from a database with the following structure:
64
- #
65
- # _________________________________________________________________________________
66
- # | Complete Name (text) | BD_this_year (formula) | BD (date) |
67
- # | -------------------- | --------------------------- | ------------------------ |
68
- # | John Doe | January 24, 2024 | January 24, 2000 |
69
- # | Jane Doe | June 20, 2024 | June 20, 2000 |
70
- # ---------------------------------------------------------------------------------
71
- # With the following formula for the BD_this_year column:
72
- # dateAdd(prop("BD"), year(now()) - year(prop("BD")), "years")
73
- #
74
- # * A Notion secret, which can be obtained, by creating an integration here: `https://developers.notion.com/`,
75
- # browsing on the <View my integations> option, and selecting the <New Integration> or <Create new>
76
- # integration** buttons.
77
- # * A webhook key, which can be generated directly on discrod on the desired channel, following this instructions:
78
- # https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks
79
- #
80
- def self.notify_birthday_from_notion_to_discord(options)
81
- read = Read::Notion::BirthdayToday.new(options[:read_options])
82
- serialize = Serialize::Notion::BirthdayToday.new
83
- formatter = Formatter::Birthday.new(options[:format_options])
84
- process = Process::Discord::Implementation.new(options[:process_options])
85
- write = Write::Logs::ConsoleLog.new
86
- use_case_config = UseCases::Types::Config.new(read, serialize, formatter, process, write)
87
-
88
- UseCases::UseCase.new(use_case_config)
89
- end
90
-
91
- # Provides an instance of the next week Birthdays notifications from Notion to Discord use case implementation.
92
- #
93
- # <b>Example</b>
94
- #
95
- # options = {
96
- # read_options: {
97
- # database_id: NOTION_DATABASE_ID,
98
- # secret: NOTION_API_INTEGRATION_SECRET,
99
- # },
100
- # process_options: {
101
- # webhook: "https://discord.com/api/webhooks/1199213527672565760/KmpoIzBet9xYG16oFh8W1RWHbpIqT7UtTBRrhfLcvWZdNiVZCTM-gpil2Qoy4eYEgpdf",
102
- # name: "Birthday Bot"
103
- # },
104
- # format_options: {
105
- # template: "individual_name, Wishing you a very happy birthday! Enjoy your special day! :birthday: :gift:",
106
- # timezone: "-05:00"
107
- # }
108
- # }
109
- #
110
- # use_case = UseCases.notify_next_week_birthday_from_notion_to_discord(options)
111
- # use_case.perform
112
- #
113
- # #################################################################################
114
- #
115
- # Requirements:
116
- # * Notion database ID, from a database with the following structure:
117
- #
118
- # _________________________________________________________________________________
119
- # | Complete Name (text) | BD_this_year (formula) | BD (date) |
120
- # | -------------------- | --------------------------- | ------------------------ |
121
- # | John Doe | January 24, 2024 | January 24, 2000 |
122
- # | Jane Doe | June 20, 2024 | June 20, 2000 |
123
- # ---------------------------------------------------------------------------------
124
- # With the following formula for the BD_this_year column:
125
- # dateAdd(prop("BD"), year(now()) - year(prop("BD")), "years")
126
- #
127
- # * A Notion secret, which can be obtained, by creating an integration here: `https://developers.notion.com/`,
128
- # browsing on the <View my integations> option, and selecting the <New Integration> or <Create new>
129
- # integration** buttons.
130
- # * A webhook key, which can be generated directly on discrod on the desired channel, following this instructions:
131
- # https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks
132
- #
133
- def self.notify_next_week_birthday_from_notion_to_discord(options)
134
- read = Read::Notion::BirthdayNextWeek.new(options[:read_options])
135
- serialize = Serialize::Notion::BirthdayToday.new
136
- formatter = Formatter::Birthday.new(options[:format_options])
137
- process = Process::Discord::Implementation.new(options[:process_options])
138
- write = Write::Logs::ConsoleLog.new
139
- use_case_cofig = UseCases::Types::Config.new(read, serialize, formatter, process, write)
140
-
141
- UseCases::UseCase.new(use_case_cofig)
142
- end
143
-
144
- # Provides an instance of the PTO notifications from Notion to Discord use case implementation.
145
- #
146
- # <br>
147
- # <b>Example</b>
148
- #
149
- # options = {
150
- # read_options: {
151
- # database_id: NOTION_DATABASE_ID,
152
- # secret: NOTION_API_INTEGRATION_SECRET,
153
- # },
154
- # process_options: {
155
- # webhook: "https://discord.com/api/webhooks/1199213527672565760/KmpoIzBet9xYG16oFh8W1RWHbpIqT7UtTBRrhfLcvWZdNiVZCTM-gpil2Qoy4eYEgpdf",
156
- # name: "Pto Bot"
157
- # }
158
- # }
159
- #
160
- # use_case = UseCases.notify_pto_from_notion_to_discord(options)
161
- # use_case.perform
162
- #
163
- # #################################################################################
164
- #
165
- # Requirements:
166
- # * Notion database ID, from a database with the following structure:
167
- #
168
- # ________________________________________________________________________________________________________
169
- # | Person (person) | Desde? (date) | Hasta? (date) |
170
- # | -------------------- | --------------------------------------- | ------------------------------------ |
171
- # | John Doe | January 24, 2024 | January 27, 2024 |
172
- # | Jane Doe | November 11, 2024 2:00 PM | November 11, 2024 6:00 PM |
173
- # ---------------------------------------------------------------------------------------------------------
174
- #
175
- # * A Notion secret, which can be obtained, by creating an integration here: `https://developers.notion.com/`,
176
- # browsing on the <View my integations> option, and selecting the <New Integration> or <Create new>
177
- # integration** buttons.
178
- # * A webhook key, which can be generated directly on discrod on the desired channel, following this instructions:
179
- # https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks
180
- #
181
- def self.notify_pto_from_notion_to_discord(options)
182
- read = Read::Notion::PtoToday.new(options[:read_options])
183
- serialize = Serialize::Notion::PtoToday.new
184
- formatter = Formatter::Pto.new(options[:format_options])
185
- process = Process::Discord::Implementation.new(options[:process_options])
186
- write = Write::Logs::ConsoleLog.new
187
- use_case_config = UseCases::Types::Config.new(read, serialize, formatter, process, write)
188
-
189
- UseCases::UseCase.new(use_case_config)
190
- end
191
-
192
- # Provides an instance of the next week PTO notifications from Notion to Discord use case implementation.
193
- #
194
- # <br>
195
- # <b>Example</b>
196
- #
197
- # options = {
198
- # read_options: {
199
- # database_id: NOTION_DATABASE_ID,
200
- # secret: NOTION_API_INTEGRATION_SECRET,
201
- # },
202
- # process_options: {
203
- # webhook: "https://discord.com/api/webhooks/1199213527672565760/KmpoIzBet9xYG16oFh8W1RWHbpIqT7UtTBRrhfLcvWZdNiVZCTM-gpil2Qoy4eYEgpdf",
204
- # name: "Pto Bot"
205
- # },
206
- # format_options: {
207
- # template: ":beach: individual_name its going to be on PTO next week,",
208
- # timezone: "-05:00"
209
- # }
210
- # }
211
- #
212
- # use_case = UseCases.notify_next_week_pto_from_notion_to_discord(options)
213
- # use_case.perform
214
- #
215
- # #################################################################################
216
- #
217
- # Requirements:
218
- # * Notion database ID, from a database with the following structure:
219
- #
220
- # ________________________________________________________________________________________________________
221
- # | Person (person) | Desde? (date) | Hasta? (date) |
222
- # | -------------------- | --------------------------------------- | ------------------------------------ |
223
- # | John Doe | January 24, 2024 | January 27, 2024 |
224
- # | Jane Doe | November 11, 2024 2:00 PM | November 11, 2024 6:00 PM |
225
- # ---------------------------------------------------------------------------------------------------------
226
- #
227
- # * A Notion secret, which can be obtained, by creating an integration here: `https://developers.notion.com/`,
228
- # browsing on the <View my integations> option, and selecting the <New Integration> or <Create new>
229
- # integration** buttons.
230
- # * A webhook key, which can be generated directly on discrod on the desired channel, following this instructions:
231
- # https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks
232
- #
233
- def self.notify_next_week_pto_from_notion_to_discord(options)
234
- read = Read::Notion::PtoNextWeek.new(options[:read_options])
235
- serialize = Serialize::Notion::PtoToday.new
236
- formatter = Formatter::Pto.new(options[:format_options])
237
- process = Process::Discord::Implementation.new(options[:process_options])
238
- write = Write::Logs::ConsoleLog.new
239
- use_case_config = UseCases::Types::Config.new(read, serialize, formatter, process, write)
240
-
241
- UseCases::UseCase.new(use_case_config)
242
- end
243
-
244
- # Provides an instance of the PTO notifications from Postgres to Slack use case implementation.
245
- #
246
- # <br>
247
- # <b>Example</b>
248
- #
249
- # options = {
250
- # read_options: {
251
- # connection: {
252
- # host: "localhost",
253
- # port: 5432,
254
- # dbname: "db_pto",
255
- # user: "postgres",
256
- # password: "postgres"
257
- # }
258
- # },
259
- # process_options:{
260
- # webhook: "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX",
261
- # name: "Pto Bot"
262
- # },
263
- # format_options: {
264
- # template: "Custom template",
265
- # timezone: "-05:00"
266
- # }
267
- # }
268
- #
269
- # use_case = UseCases.notify_pto_from_postgres_to_slack(options)
270
- # use_case.perform
271
- #
272
- # #################################################################################
273
- #
274
- # Requirements:
275
- # * A connection to a Postgres database and a table with the following structure:
276
- #
277
- # Column | Type | Collation | Nullable | Default
278
- # -----------------+------------------------+-----------+----------+------------------------------
279
- # id | integer | | not null | generated always as identity
280
- # create_time | date | | |
281
- # individual_name | character varying(255) | | |
282
- # start_date | date | | |
283
- # end_date | date | | |
284
- #
285
- # * A webhook key, which can be generated directly on slack on the desired channel, following this instructions:
286
- # https://api.slack.com/messaging/webhooks#create_a_webhook
287
- #
288
- def self.notify_pto_from_postgres_to_slack(options)
289
- read = Read::Postgres::PtoToday.new(options[:read_options])
290
- serialize = Serialize::Postgres::PtoToday.new
291
- formatter = Formatter::Pto.new(options[:format_options])
292
- process = Process::Slack::Implementation.new(options[:process_options])
293
- write = Write::Logs::ConsoleLog.new
294
- use_case_config = UseCases::Types::Config.new(read, serialize, formatter, process, write)
295
-
296
- UseCases::UseCase.new(use_case_config)
297
- end
298
-
299
- # Provides an instance of the Work Items wip limit notifications from Notion to Discord use case implementation.
300
- #
301
- # <br>
302
- # <b>Example</b>
303
- #
304
- # options = {
305
- # read_options: {
306
- # database_id: NOTION_DATABASE_ID,
307
- # secret: NOTION_API_INTEGRATION_SECRET
308
- # },
309
- # process_options: {
310
- # webhook: "https://discord.com/api/webhooks/1199213527672565760/KmpoIzBet9xYG16oFh8W1RWHbpIqT7UtTBRrhfLcvWZdNiVZCTM-gpil2Qoy4eYEgpdf",
311
- # name: "wipLimit"
312
- # }
313
- # }
314
- #
315
- # use_case = UseCases.notify_wip_limit_from_notion_to_discord(options)
316
- # use_case.perform
317
- #
318
- # #################################################################################
319
- #
320
- # Requirements:
321
- # * Notion database ID, from a database with the following structure:
322
- #
323
- # _________________________________________________________________________________
324
- # | OK | Status | Responsible Domain |
325
- # | -------------------- | --------------------------- | ------------------------ |
326
- # | ✅ | In Progress | "kommit.admin" |
327
- # | 🚩 | Fail | "kommit.ops" |
328
- # ---------------------------------------------------------------------------------
329
- #
330
- # * A Notion secret, which can be obtained, by creating an integration here: `https://developers.notion.com/`,
331
- # browsing on the <View my integations> option, and selecting the <New Integration> or <Create new>
332
- # integration** buttons.
333
- # * A webhook key, which can be generated directly on discrod on the desired channel, following this instructions:
334
- # https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks
335
- #
336
- def self.notify_wip_limit_from_notion_to_discord(options)
337
- read = Read::Notion::WorkItemsLimit.new(options[:read_options])
338
- serialize = Serialize::Notion::WorkItemsLimit.new
339
- formatter = Formatter::WorkItemsLimit.new(options[:format_options])
340
- process = Process::Discord::Implementation.new(options[:process_options])
341
- write = Write::Logs::ConsoleLog.new
342
- use_case_config = UseCases::Types::Config.new(read, serialize, formatter, process, write)
343
-
344
- UseCases::UseCase.new(use_case_config)
345
- end
346
-
347
- # Provides an instance of the support emails from an google IMAP server to Discord use case implementation.
348
- #
349
- # <br>
350
- # <b>Example</b>
351
- #
352
- # options = {
353
- # read_options: {
354
- # user: 'info@email.co',
355
- # refresh_token: REFRESH_TOKEN,
356
- # client_id: CLIENT_ID,
357
- # client_secret: CLIENT_SECRET,
358
- # inbox: 'INBOX',
359
- # search_email: 'support@email.co'
360
- # },
361
- # process_options: {
362
- # webhook: "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX",
363
- # name: "emailSupport"
364
- # }
365
- # }
366
- #
367
- # use_case = UseCases.notify_support_email_from_imap_to_discord(options)
368
- # use_case.perform
369
- #
370
- # #################################################################################
371
- #
372
- # Requirements:
373
- # * A google gmail account with IMAP support activated.
374
- # * A set of authorization parameters like a client_id, client_secret, and a resfresh_token. To
375
- # generate them, follow this instructions: https://developers.google.com/identity/protocols/oauth2
376
- # * A webhook key, which can be generated directly on discrod on the desired channel, following this instructions:
377
- # https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks
378
- #
379
- def self.notify_support_email_from_imap_to_discord(options)
380
- read = Read::Imap::SupportEmails.new(options[:read_options])
381
- serialize = Serialize::Imap::SupportEmails.new
382
- formatter = Formatter::SupportEmails.new(options[:format_options])
383
- process = Process::Discord::Implementation.new(options[:process_options])
384
- write = Write::Logs::ConsoleLog.new
385
- use_case_config = UseCases::Types::Config.new(read, serialize, formatter, process, write)
386
-
387
- UseCases::UseCase.new(use_case_config)
388
- end
389
- 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