bas 0.2.0 → 0.3.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 (58) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -0
  3. data/README.md +25 -22
  4. data/lib/bas/formatter/base.rb +2 -2
  5. data/lib/bas/formatter/birthday.rb +8 -4
  6. data/lib/bas/formatter/pto.rb +8 -4
  7. data/lib/bas/formatter/support_emails.rb +7 -3
  8. data/lib/bas/formatter/types/response.rb +16 -0
  9. data/lib/bas/formatter/work_items_limit.rb +8 -4
  10. data/lib/bas/process/base.rb +39 -0
  11. data/lib/bas/{dispatcher → process}/discord/exceptions/invalid_webhook_token.rb +1 -1
  12. data/lib/bas/process/discord/implementation.rb +71 -0
  13. data/lib/bas/{dispatcher → process}/discord/types/response.rb +1 -1
  14. data/lib/bas/{dispatcher → process}/slack/exceptions/invalid_webhook_token.rb +1 -1
  15. data/lib/bas/process/slack/implementation.rb +70 -0
  16. data/lib/bas/{dispatcher → process}/slack/types/response.rb +1 -1
  17. data/lib/bas/process/types/response.rb +16 -0
  18. data/lib/bas/{fetcher → read}/base.rb +8 -8
  19. data/lib/bas/{fetcher → read}/github/base.rb +7 -7
  20. data/lib/bas/{fetcher → read}/github/types/response.rb +1 -1
  21. data/lib/bas/read/github/use_case/repo_issues.rb +17 -0
  22. data/lib/bas/{fetcher → read}/imap/base.rb +7 -7
  23. data/lib/bas/{fetcher → read}/imap/types/response.rb +1 -1
  24. data/lib/bas/read/imap/use_case/support_emails.rb +26 -0
  25. data/lib/bas/{fetcher → read}/notion/base.rb +8 -8
  26. data/lib/bas/{fetcher → read}/notion/helper.rb +1 -1
  27. data/lib/bas/{fetcher → read}/notion/types/response.rb +1 -1
  28. data/lib/bas/{fetcher → read}/notion/use_case/birthday_next_week.rb +6 -6
  29. data/lib/bas/{fetcher → read}/notion/use_case/birthday_today.rb +6 -6
  30. data/lib/bas/{fetcher → read}/notion/use_case/pto_next_week.rb +6 -6
  31. data/lib/bas/{fetcher → read}/notion/use_case/pto_today.rb +6 -6
  32. data/lib/bas/{fetcher → read}/notion/use_case/work_items_limit.rb +5 -5
  33. data/lib/bas/{fetcher → read}/postgres/base.rb +8 -8
  34. data/lib/bas/{fetcher → read}/postgres/helper.rb +1 -1
  35. data/lib/bas/{fetcher → read}/postgres/types/response.rb +1 -1
  36. data/lib/bas/{fetcher → read}/postgres/use_case/pto_today.rb +6 -6
  37. data/lib/bas/{mapper → serialize}/base.rb +7 -7
  38. data/lib/bas/{mapper → serialize}/github/issues.rb +7 -7
  39. data/lib/bas/{mapper → serialize}/imap/support_emails.rb +7 -7
  40. data/lib/bas/{mapper → serialize}/notion/birthday_today.rb +7 -7
  41. data/lib/bas/{mapper → serialize}/notion/pto_today.rb +14 -12
  42. data/lib/bas/{mapper → serialize}/notion/work_items_limit.rb +7 -7
  43. data/lib/bas/{mapper → serialize}/postgres/pto_today.rb +7 -7
  44. data/lib/bas/use_cases/types/config.rb +6 -5
  45. data/lib/bas/use_cases/use_case.rb +13 -10
  46. data/lib/bas/use_cases/use_cases.rb +71 -61
  47. data/lib/bas/version.rb +1 -1
  48. data/lib/bas/write/base.rb +36 -0
  49. data/lib/bas/write/logs/base.rb +33 -0
  50. data/lib/bas/write/logs/use_case/console_log.rb +22 -0
  51. metadata +42 -37
  52. data/lib/bas/dispatcher/base.rb +0 -31
  53. data/lib/bas/dispatcher/discord/implementation.rb +0 -51
  54. data/lib/bas/dispatcher/slack/implementation.rb +0 -51
  55. data/lib/bas/fetcher/github/use_case/repo_issues.rb +0 -17
  56. data/lib/bas/fetcher/imap/use_case/support_emails.rb +0 -26
  57. /data/lib/bas/{fetcher → read}/notion/exceptions/invalid_api_key.rb +0 -0
  58. /data/lib/bas/{fetcher → read}/notion/exceptions/invalid_database_id.rb +0 -0
@@ -3,27 +3,27 @@
3
3
  require_relative "../../domain/work_items_limit"
4
4
  require_relative "../base"
5
5
 
6
- module Mapper
6
+ module Serialize
7
7
  module Notion
8
8
  ##
9
- # This class implementats the methods of the Mapper::Base module, specifically designed
10
- # for preparing or shaping work items data coming from a Fetcher::Base implementation.
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
11
  class WorkItemsLimit
12
12
  include Base
13
13
 
14
14
  WORK_ITEM_PARAMS = ["Responsible domain"].freeze
15
15
 
16
- # Implements the logic for shaping the results from a fetcher response.
16
+ # Implements the logic for shaping the results from a reader response.
17
17
  #
18
18
  # <br>
19
19
  # <b>Params:</b>
20
- # * <tt>Fetcher::Notion::Types::Response</tt> notion_response: Notion response object.
20
+ # * <tt>Read::Notion::Types::Response</tt> notion_response: Notion response object.
21
21
  #
22
22
  # <br>
23
- # <b>return</b> <tt>List<Domain::WorkItem></tt> work_items_list, mapped work items to be used by a
23
+ # <b>return</b> <tt>List<Domain::WorkItem></tt> work_items_list, serialized work items to be used by a
24
24
  # Formatter::Base implementation.
25
25
  #
26
- def map(notion_response)
26
+ def execute(notion_response)
27
27
  return [] if notion_response.results.empty?
28
28
 
29
29
  normalized_notion_data = normalize_response(notion_response.results)
@@ -3,24 +3,24 @@
3
3
  require_relative "../../domain/pto"
4
4
  require_relative "../base"
5
5
 
6
- module Mapper
6
+ module Serialize
7
7
  module Postgres
8
8
  ##
9
- # This class implementats the methods of the Mapper::Base module, specifically designed for preparing or
10
- # shaping PTO's data coming from the Fetcher::Postgres::Pto class.
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
11
  #
12
12
  class PtoToday
13
- # Implements the logic for shaping the results from a fetcher response.
13
+ # Implements the logic for shaping the results from a reader response.
14
14
  #
15
15
  # <br>
16
16
  # <b>Params:</b>
17
- # * <tt>Fetcher::Postgres::Types::Response</tt> pg_response: Postgres response object.
17
+ # * <tt>Read::Postgres::Types::Response</tt> pg_response: Postgres response object.
18
18
  #
19
19
  # <br>
20
- # <b>returns</b> <tt>List<Domain::Pto></tt> ptos_list, mapped PTO's to be used by a Formatter::Base
20
+ # <b>returns</b> <tt>List<Domain::Pto></tt> ptos_list, serialized PTO's to be used by a Formatter::Base
21
21
  # implementation.
22
22
  #
23
- def map(pg_response)
23
+ def execute(pg_response)
24
24
  return [] if pg_response.records.empty?
25
25
 
26
26
  ptos = build_map(pg_response)
@@ -6,13 +6,14 @@ module UseCases
6
6
  # Represents a the configuration composing the initial components required by a UseCases::UseCase implementation.
7
7
  #
8
8
  class Config
9
- attr_reader :fetcher, :mapper, :formatter, :dispatcher
9
+ attr_reader :read, :serialize, :formatter, :process, :write
10
10
 
11
- def initialize(fetcher, mapper, formatter, dispatcher)
12
- @fetcher = fetcher
13
- @mapper = mapper
11
+ def initialize(read, serialize, formatter, process, write)
12
+ @read = read
13
+ @serialize = serialize
14
14
  @formatter = formatter
15
- @dispatcher = dispatcher
15
+ @process = process
16
+ @write = write
16
17
  end
17
18
  end
18
19
  end
@@ -6,7 +6,7 @@ module UseCases
6
6
  # logic flow by coordinating the execution of its components to fulfill a specific use case.
7
7
  #
8
8
  class UseCase
9
- attr_reader :fetcher, :mapper, :formatter, :dispatcher
9
+ attr_reader :read, :serialize, :formatter, :process, :write
10
10
 
11
11
  # Initializes the use case with the necessary components.
12
12
  #
@@ -15,25 +15,28 @@ module UseCases
15
15
  # * <tt>Usecases::Types::Config</tt> config, The components required to instantiate a use case.
16
16
  #
17
17
  def initialize(config)
18
- @fetcher = config.fetcher
19
- @mapper = config.mapper
18
+ @read = config.read
19
+ @serialize = config.serialize
20
20
  @formatter = config.formatter
21
- @dispatcher = config.dispatcher
21
+ @process = config.process
22
+ @write = config.write
22
23
  end
23
24
 
24
- # Executes the use case by orchestrating the sequential execution of the fetcher, mapper, formatter, and dispatcher.
25
+ # Executes the use case by orchestrating the sequential execution of the read, serialize, formatter, and process.
25
26
  #
26
27
  # <br>
27
- # <b>returns</b> <tt>Dispatcher::Discord::Types::Response</tt>
28
+ # <b>returns</b> <tt>Process::Discord::Types::Response</tt>
28
29
  #
29
30
  def perform
30
- response = fetcher.fetch
31
+ response = read.execute
31
32
 
32
- mappings = mapper.map(response)
33
+ serialization = serialize.execute(response)
33
34
 
34
- formatted_payload = formatter.format(mappings)
35
+ format_response = valid_format_response(serialization)
35
36
 
36
- dispatcher.dispatch(formatted_payload)
37
+ process_response = process.execute(format_response)
38
+
39
+ write.execute(process_response)
37
40
  end
38
41
  end
39
42
  end
@@ -1,22 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # fetcher
4
- require_relative "../fetcher/notion/use_case/birthday_today"
5
- require_relative "../fetcher/notion/use_case/birthday_next_week"
6
- require_relative "../fetcher/notion/use_case/pto_today"
7
- require_relative "../fetcher/notion/use_case/pto_next_week"
8
- require_relative "../fetcher/notion/use_case/work_items_limit"
9
- require_relative "../fetcher/postgres/use_case/pto_today"
10
- require_relative "../fetcher/imap/use_case/support_emails"
11
- require_relative "../fetcher/github/use_case/repo_issues"
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
12
 
13
- # mapper
14
- require_relative "../mapper/notion/birthday_today"
15
- require_relative "../mapper/notion/pto_today"
16
- require_relative "../mapper/notion/work_items_limit"
17
- require_relative "../mapper/postgres/pto_today"
18
- require_relative "../mapper/imap/support_emails"
19
- require_relative "../mapper/github/issues"
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
20
 
21
21
  # formatter
22
22
  require_relative "../formatter/birthday"
@@ -24,9 +24,12 @@ require_relative "../formatter/pto"
24
24
  require_relative "../formatter/work_items_limit"
25
25
  require_relative "../formatter/support_emails"
26
26
 
27
- # dispatcher
28
- require_relative "../dispatcher/discord/implementation"
29
- require_relative "../dispatcher/slack/implementation"
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"
30
33
 
31
34
  require_relative "use_case"
32
35
  require_relative "./types/config"
@@ -41,11 +44,11 @@ module UseCases
41
44
  # <b>Example</b>
42
45
  #
43
46
  # options = {
44
- # fetch_options: {
47
+ # read_options: {
45
48
  # database_id: NOTION_DATABASE_ID,
46
49
  # secret: NOTION_API_INTEGRATION_SECRET,
47
50
  # },
48
- # dispatch_options: {
51
+ # process_options: {
49
52
  # webhook: "https://discord.com/api/webhooks/1199213527672565760/KmpoIzBet9xYG16oFh8W1RWHbpIqT7UtTBRrhfLcvWZdNiVZCTM-gpil2Qoy4eYEgpdf",
50
53
  # name: "Birthday Bot"
51
54
  # }
@@ -75,11 +78,12 @@ module UseCases
75
78
  # https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks
76
79
  #
77
80
  def self.notify_birthday_from_notion_to_discord(options)
78
- fetcher = Fetcher::Notion::BirthdayToday.new(options[:fetch_options])
79
- mapper = Mapper::Notion::BirthdayToday.new
81
+ read = Read::Notion::BirthdayToday.new(options[:read_options])
82
+ serialize = Serialize::Notion::BirthdayToday.new
80
83
  formatter = Formatter::Birthday.new(options[:format_options])
81
- dispatcher = Dispatcher::Discord::Implementation.new(options[:dispatch_options])
82
- use_case_config = UseCases::Types::Config.new(fetcher, mapper, formatter, dispatcher)
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)
83
87
 
84
88
  UseCases::UseCase.new(use_case_config)
85
89
  end
@@ -89,11 +93,11 @@ module UseCases
89
93
  # <b>Example</b>
90
94
  #
91
95
  # options = {
92
- # fetch_options: {
96
+ # read_options: {
93
97
  # database_id: NOTION_DATABASE_ID,
94
98
  # secret: NOTION_API_INTEGRATION_SECRET,
95
99
  # },
96
- # dispatch_options: {
100
+ # process_options: {
97
101
  # webhook: "https://discord.com/api/webhooks/1199213527672565760/KmpoIzBet9xYG16oFh8W1RWHbpIqT7UtTBRrhfLcvWZdNiVZCTM-gpil2Qoy4eYEgpdf",
98
102
  # name: "Birthday Bot"
99
103
  # },
@@ -127,11 +131,12 @@ module UseCases
127
131
  # https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks
128
132
  #
129
133
  def self.notify_next_week_birthday_from_notion_to_discord(options)
130
- fetcher = Fetcher::Notion::BirthdayNextWeek.new(options[:fetch_options])
131
- mapper = Mapper::Notion::BirthdayToday.new
134
+ read = Read::Notion::BirthdayNextWeek.new(options[:read_options])
135
+ serialize = Serialize::Notion::BirthdayToday.new
132
136
  formatter = Formatter::Birthday.new(options[:format_options])
133
- dispatcher = Dispatcher::Discord::Implementation.new(options[:dispatch_options])
134
- use_case_cofig = UseCases::Types::Config.new(fetcher, mapper, formatter, dispatcher)
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)
135
140
 
136
141
  UseCases::UseCase.new(use_case_cofig)
137
142
  end
@@ -142,11 +147,11 @@ module UseCases
142
147
  # <b>Example</b>
143
148
  #
144
149
  # options = {
145
- # fetch_options: {
150
+ # read_options: {
146
151
  # database_id: NOTION_DATABASE_ID,
147
152
  # secret: NOTION_API_INTEGRATION_SECRET,
148
153
  # },
149
- # dispatch_options: {
154
+ # process_options: {
150
155
  # webhook: "https://discord.com/api/webhooks/1199213527672565760/KmpoIzBet9xYG16oFh8W1RWHbpIqT7UtTBRrhfLcvWZdNiVZCTM-gpil2Qoy4eYEgpdf",
151
156
  # name: "Pto Bot"
152
157
  # }
@@ -174,11 +179,12 @@ module UseCases
174
179
  # https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks
175
180
  #
176
181
  def self.notify_pto_from_notion_to_discord(options)
177
- fetcher = Fetcher::Notion::PtoToday.new(options[:fetch_options])
178
- mapper = Mapper::Notion::PtoToday.new
182
+ read = Read::Notion::PtoToday.new(options[:read_options])
183
+ serialize = Serialize::Notion::PtoToday.new
179
184
  formatter = Formatter::Pto.new(options[:format_options])
180
- dispatcher = Dispatcher::Discord::Implementation.new(options[:dispatch_options])
181
- use_case_config = UseCases::Types::Config.new(fetcher, mapper, formatter, dispatcher)
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)
182
188
 
183
189
  UseCases::UseCase.new(use_case_config)
184
190
  end
@@ -189,11 +195,11 @@ module UseCases
189
195
  # <b>Example</b>
190
196
  #
191
197
  # options = {
192
- # fetch_options: {
198
+ # read_options: {
193
199
  # database_id: NOTION_DATABASE_ID,
194
200
  # secret: NOTION_API_INTEGRATION_SECRET,
195
201
  # },
196
- # dispatch_options: {
202
+ # process_options: {
197
203
  # webhook: "https://discord.com/api/webhooks/1199213527672565760/KmpoIzBet9xYG16oFh8W1RWHbpIqT7UtTBRrhfLcvWZdNiVZCTM-gpil2Qoy4eYEgpdf",
198
204
  # name: "Pto Bot"
199
205
  # },
@@ -225,11 +231,12 @@ module UseCases
225
231
  # https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks
226
232
  #
227
233
  def self.notify_next_week_pto_from_notion_to_discord(options)
228
- fetcher = Fetcher::Notion::PtoNextWeek.new(options[:fetch_options])
229
- mapper = Mapper::Notion::PtoToday.new
234
+ read = Read::Notion::PtoNextWeek.new(options[:read_options])
235
+ serialize = Serialize::Notion::PtoToday.new
230
236
  formatter = Formatter::Pto.new(options[:format_options])
231
- dispatcher = Dispatcher::Discord::Implementation.new(options[:dispatch_options])
232
- use_case_config = UseCases::Types::Config.new(fetcher, mapper, formatter, dispatcher)
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)
233
240
 
234
241
  UseCases::UseCase.new(use_case_config)
235
242
  end
@@ -240,7 +247,7 @@ module UseCases
240
247
  # <b>Example</b>
241
248
  #
242
249
  # options = {
243
- # fetch_options: {
250
+ # read_options: {
244
251
  # connection: {
245
252
  # host: "localhost",
246
253
  # port: 5432,
@@ -249,7 +256,7 @@ module UseCases
249
256
  # password: "postgres"
250
257
  # }
251
258
  # },
252
- # dispatch_options:{
259
+ # process_options:{
253
260
  # webhook: "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX",
254
261
  # name: "Pto Bot"
255
262
  # },
@@ -279,11 +286,12 @@ module UseCases
279
286
  # https://api.slack.com/messaging/webhooks#create_a_webhook
280
287
  #
281
288
  def self.notify_pto_from_postgres_to_slack(options)
282
- fetcher = Fetcher::Postgres::PtoToday.new(options[:fetch_options])
283
- mapper = Mapper::Postgres::PtoToday.new
289
+ read = Read::Postgres::PtoToday.new(options[:read_options])
290
+ serialize = Serialize::Postgres::PtoToday.new
284
291
  formatter = Formatter::Pto.new(options[:format_options])
285
- dispatcher = Dispatcher::Slack::Implementation.new(options[:dispatch_options])
286
- use_case_config = UseCases::Types::Config.new(fetcher, mapper, formatter, dispatcher)
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)
287
295
 
288
296
  UseCases::UseCase.new(use_case_config)
289
297
  end
@@ -294,11 +302,11 @@ module UseCases
294
302
  # <b>Example</b>
295
303
  #
296
304
  # options = {
297
- # fetch_options: {
305
+ # read_options: {
298
306
  # database_id: NOTION_DATABASE_ID,
299
307
  # secret: NOTION_API_INTEGRATION_SECRET
300
308
  # },
301
- # dispatch_options: {
309
+ # process_options: {
302
310
  # webhook: "https://discord.com/api/webhooks/1199213527672565760/KmpoIzBet9xYG16oFh8W1RWHbpIqT7UtTBRrhfLcvWZdNiVZCTM-gpil2Qoy4eYEgpdf",
303
311
  # name: "wipLimit"
304
312
  # }
@@ -326,11 +334,12 @@ module UseCases
326
334
  # https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks
327
335
  #
328
336
  def self.notify_wip_limit_from_notion_to_discord(options)
329
- fetcher = Fetcher::Notion::WorkItemsLimit.new(options[:fetch_options])
330
- mapper = Mapper::Notion::WorkItemsLimit.new
337
+ read = Read::Notion::WorkItemsLimit.new(options[:read_options])
338
+ serialize = Serialize::Notion::WorkItemsLimit.new
331
339
  formatter = Formatter::WorkItemsLimit.new(options[:format_options])
332
- dispatcher = Dispatcher::Discord::Implementation.new(options[:dispatch_options])
333
- use_case_config = UseCases::Types::Config.new(fetcher, mapper, formatter, dispatcher)
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)
334
343
 
335
344
  UseCases::UseCase.new(use_case_config)
336
345
  end
@@ -341,7 +350,7 @@ module UseCases
341
350
  # <b>Example</b>
342
351
  #
343
352
  # options = {
344
- # fetch_options: {
353
+ # read_options: {
345
354
  # user: 'info@email.co',
346
355
  # refresh_token: REFRESH_TOKEN,
347
356
  # client_id: CLIENT_ID,
@@ -349,7 +358,7 @@ module UseCases
349
358
  # inbox: 'INBOX',
350
359
  # search_email: 'support@email.co'
351
360
  # },
352
- # dispatch_options: {
361
+ # process_options: {
353
362
  # webhook: "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX",
354
363
  # name: "emailSupport"
355
364
  # }
@@ -368,11 +377,12 @@ module UseCases
368
377
  # https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks
369
378
  #
370
379
  def self.notify_support_email_from_imap_to_discord(options)
371
- fetcher = Fetcher::Imap::SupportEmails.new(options[:fetch_options])
372
- mapper = Mapper::Imap::SupportEmails.new
380
+ read = Read::Imap::SupportEmails.new(options[:read_options])
381
+ serialize = Serialize::Imap::SupportEmails.new
373
382
  formatter = Formatter::SupportEmails.new(options[:format_options])
374
- dispatcher = Dispatcher::Discord::Implementation.new(options[:dispatch_options])
375
- use_case_config = UseCases::Types::Config.new(fetcher, mapper, formatter, dispatcher)
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)
376
386
 
377
387
  UseCases::UseCase.new(use_case_config)
378
388
  end
data/lib/bas/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Bas
4
4
  # Gem version
5
- VERSION = "0.2.0"
5
+ VERSION = "0.3.0"
6
6
  end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../domain/exceptions/function_not_implemented"
4
+
5
+ module Write
6
+ ##
7
+ # The Write::Base class serves as the foundation for implementing specific data write within the Write module.
8
+ # Operating as an interface, this class defines essential attributes and methods, providing a blueprint for creating
9
+ # a custom write.
10
+ #
11
+ class Base
12
+ attr_reader :config
13
+
14
+ # Initializes the write with essential configuration parameters.
15
+ #
16
+ def initialize(config = {})
17
+ @config = config
18
+ end
19
+
20
+ # A method meant to execute the write request to an specific destination depending on the implementation.
21
+ # Must be overridden by subclasses, with specific logic based on the use case.
22
+ #
23
+ # <br>
24
+ # <b>raises</b> <tt>Domain::Exceptions::FunctionNotImplemented</tt> when missing implementation.
25
+ #
26
+ def execute(_process_response)
27
+ raise Domain::Exceptions::FunctionNotImplemented
28
+ end
29
+
30
+ protected
31
+
32
+ def write(_method, _data)
33
+ raise Domain::Exceptions::FunctionNotImplemented
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,33 @@
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
@@ -0,0 +1,22 @@
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
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bas
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.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-04-04 00:00:00.000000000 Z
11
+ date: 2024-04-16 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A versatile business automation system offering key components for building
14
14
  various use cases. It provides an easy-to-use tool for implementing automation
@@ -31,57 +31,62 @@ files:
31
31
  - Rakefile
32
32
  - SECURITY.md
33
33
  - lib/bas.rb
34
- - lib/bas/dispatcher/base.rb
35
- - lib/bas/dispatcher/discord/exceptions/invalid_webhook_token.rb
36
- - lib/bas/dispatcher/discord/implementation.rb
37
- - lib/bas/dispatcher/discord/types/response.rb
38
- - lib/bas/dispatcher/slack/exceptions/invalid_webhook_token.rb
39
- - lib/bas/dispatcher/slack/implementation.rb
40
- - lib/bas/dispatcher/slack/types/response.rb
41
34
  - lib/bas/domain/birthday.rb
42
35
  - lib/bas/domain/email.rb
43
36
  - lib/bas/domain/exceptions/function_not_implemented.rb
44
37
  - lib/bas/domain/issue.rb
45
38
  - lib/bas/domain/pto.rb
46
39
  - lib/bas/domain/work_items_limit.rb
47
- - lib/bas/fetcher/base.rb
48
- - lib/bas/fetcher/github/base.rb
49
- - lib/bas/fetcher/github/types/response.rb
50
- - lib/bas/fetcher/github/use_case/repo_issues.rb
51
- - lib/bas/fetcher/imap/base.rb
52
- - lib/bas/fetcher/imap/types/response.rb
53
- - lib/bas/fetcher/imap/use_case/support_emails.rb
54
- - lib/bas/fetcher/notion/base.rb
55
- - lib/bas/fetcher/notion/exceptions/invalid_api_key.rb
56
- - lib/bas/fetcher/notion/exceptions/invalid_database_id.rb
57
- - lib/bas/fetcher/notion/helper.rb
58
- - lib/bas/fetcher/notion/types/response.rb
59
- - lib/bas/fetcher/notion/use_case/birthday_next_week.rb
60
- - lib/bas/fetcher/notion/use_case/birthday_today.rb
61
- - lib/bas/fetcher/notion/use_case/pto_next_week.rb
62
- - lib/bas/fetcher/notion/use_case/pto_today.rb
63
- - lib/bas/fetcher/notion/use_case/work_items_limit.rb
64
- - lib/bas/fetcher/postgres/base.rb
65
- - lib/bas/fetcher/postgres/helper.rb
66
- - lib/bas/fetcher/postgres/types/response.rb
67
- - lib/bas/fetcher/postgres/use_case/pto_today.rb
68
40
  - lib/bas/formatter/base.rb
69
41
  - lib/bas/formatter/birthday.rb
70
42
  - lib/bas/formatter/exceptions/invalid_data.rb
71
43
  - lib/bas/formatter/pto.rb
72
44
  - lib/bas/formatter/support_emails.rb
45
+ - lib/bas/formatter/types/response.rb
73
46
  - lib/bas/formatter/work_items_limit.rb
74
- - lib/bas/mapper/base.rb
75
- - lib/bas/mapper/github/issues.rb
76
- - lib/bas/mapper/imap/support_emails.rb
77
- - lib/bas/mapper/notion/birthday_today.rb
78
- - lib/bas/mapper/notion/pto_today.rb
79
- - lib/bas/mapper/notion/work_items_limit.rb
80
- - lib/bas/mapper/postgres/pto_today.rb
47
+ - lib/bas/process/base.rb
48
+ - lib/bas/process/discord/exceptions/invalid_webhook_token.rb
49
+ - lib/bas/process/discord/implementation.rb
50
+ - lib/bas/process/discord/types/response.rb
51
+ - lib/bas/process/slack/exceptions/invalid_webhook_token.rb
52
+ - lib/bas/process/slack/implementation.rb
53
+ - lib/bas/process/slack/types/response.rb
54
+ - lib/bas/process/types/response.rb
55
+ - lib/bas/read/base.rb
56
+ - lib/bas/read/github/base.rb
57
+ - lib/bas/read/github/types/response.rb
58
+ - lib/bas/read/github/use_case/repo_issues.rb
59
+ - lib/bas/read/imap/base.rb
60
+ - lib/bas/read/imap/types/response.rb
61
+ - lib/bas/read/imap/use_case/support_emails.rb
62
+ - lib/bas/read/notion/base.rb
63
+ - lib/bas/read/notion/exceptions/invalid_api_key.rb
64
+ - lib/bas/read/notion/exceptions/invalid_database_id.rb
65
+ - lib/bas/read/notion/helper.rb
66
+ - lib/bas/read/notion/types/response.rb
67
+ - lib/bas/read/notion/use_case/birthday_next_week.rb
68
+ - lib/bas/read/notion/use_case/birthday_today.rb
69
+ - lib/bas/read/notion/use_case/pto_next_week.rb
70
+ - lib/bas/read/notion/use_case/pto_today.rb
71
+ - lib/bas/read/notion/use_case/work_items_limit.rb
72
+ - lib/bas/read/postgres/base.rb
73
+ - lib/bas/read/postgres/helper.rb
74
+ - lib/bas/read/postgres/types/response.rb
75
+ - lib/bas/read/postgres/use_case/pto_today.rb
76
+ - lib/bas/serialize/base.rb
77
+ - lib/bas/serialize/github/issues.rb
78
+ - lib/bas/serialize/imap/support_emails.rb
79
+ - lib/bas/serialize/notion/birthday_today.rb
80
+ - lib/bas/serialize/notion/pto_today.rb
81
+ - lib/bas/serialize/notion/work_items_limit.rb
82
+ - lib/bas/serialize/postgres/pto_today.rb
81
83
  - lib/bas/use_cases/types/config.rb
82
84
  - lib/bas/use_cases/use_case.rb
83
85
  - lib/bas/use_cases/use_cases.rb
84
86
  - lib/bas/version.rb
87
+ - lib/bas/write/base.rb
88
+ - lib/bas/write/logs/base.rb
89
+ - lib/bas/write/logs/use_case/console_log.rb
85
90
  - renovate.json
86
91
  - sig/business_automation_system.rbs
87
92
  homepage: https://github.com/kommitters/bas
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../domain/exceptions/function_not_implemented"
4
-
5
- module Dispatcher
6
- ##
7
- # Serves as a foundational structure for implementing specific dispatchers. Acting as an interface,
8
- # this class defines essential attributes and methods, providing a blueprint for creating custom
9
- # dispatchers tailored to different platforms or services.
10
- #
11
- class Base
12
- attr_reader :webhook, :name
13
-
14
- # Initializes the dispatcher with essential configuration parameters.
15
- #
16
- def initialize(config)
17
- @webhook = config[:webhook]
18
- @name = config[:name]
19
- end
20
-
21
- # A method meant to send messages to an specific destination depending on the implementation.
22
- # Must be overridden by subclasses, with specific logic based on the use case.
23
- #
24
- # <br>
25
- # <b>returns</b> a <tt>Discord::Response</tt>
26
- #
27
- def dispatch(_payload)
28
- raise Domain::Exceptions::FunctionNotImplemented
29
- end
30
- end
31
- end