bas 0.1.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +10 -0
  3. data/Gemfile +6 -0
  4. data/README.md +27 -24
  5. data/lib/bas/domain/issue.rb +22 -0
  6. data/lib/bas/domain/pto.rb +45 -4
  7. data/lib/bas/formatter/base.rb +2 -2
  8. data/lib/bas/formatter/birthday.rb +8 -4
  9. data/lib/bas/formatter/pto.rb +27 -26
  10. data/lib/bas/formatter/support_emails.rb +7 -3
  11. data/lib/bas/formatter/types/response.rb +16 -0
  12. data/lib/bas/formatter/work_items_limit.rb +8 -4
  13. data/lib/bas/process/base.rb +39 -0
  14. data/lib/bas/{dispatcher → process}/discord/exceptions/invalid_webhook_token.rb +1 -1
  15. data/lib/bas/process/discord/implementation.rb +71 -0
  16. data/lib/bas/{dispatcher → process}/discord/types/response.rb +1 -1
  17. data/lib/bas/{dispatcher → process}/slack/exceptions/invalid_webhook_token.rb +1 -1
  18. data/lib/bas/process/slack/implementation.rb +70 -0
  19. data/lib/bas/{dispatcher → process}/slack/types/response.rb +1 -1
  20. data/lib/bas/process/types/response.rb +16 -0
  21. data/lib/bas/{fetcher → read}/base.rb +8 -8
  22. data/lib/bas/read/github/base.rb +57 -0
  23. data/lib/bas/read/github/types/response.rb +27 -0
  24. data/lib/bas/read/github/use_case/repo_issues.rb +17 -0
  25. data/lib/bas/{fetcher → read}/imap/base.rb +7 -7
  26. data/lib/bas/{fetcher → read}/imap/types/response.rb +1 -1
  27. data/lib/bas/read/imap/use_case/support_emails.rb +26 -0
  28. data/lib/bas/{fetcher → read}/notion/base.rb +8 -8
  29. data/lib/bas/{fetcher → read}/notion/helper.rb +1 -1
  30. data/lib/bas/{fetcher → read}/notion/types/response.rb +1 -1
  31. data/lib/bas/{fetcher → read}/notion/use_case/birthday_next_week.rb +6 -6
  32. data/lib/bas/{fetcher → read}/notion/use_case/birthday_today.rb +6 -6
  33. data/lib/bas/{fetcher → read}/notion/use_case/pto_next_week.rb +6 -6
  34. data/lib/bas/{fetcher → read}/notion/use_case/pto_today.rb +6 -6
  35. data/lib/bas/{fetcher → read}/notion/use_case/work_items_limit.rb +5 -5
  36. data/lib/bas/{fetcher → read}/postgres/base.rb +8 -8
  37. data/lib/bas/{fetcher → read}/postgres/helper.rb +1 -1
  38. data/lib/bas/{fetcher → read}/postgres/types/response.rb +1 -1
  39. data/lib/bas/{fetcher → read}/postgres/use_case/pto_today.rb +6 -6
  40. data/lib/bas/{mapper → serialize}/base.rb +7 -7
  41. data/lib/bas/serialize/github/issues.rb +57 -0
  42. data/lib/bas/{mapper → serialize}/imap/support_emails.rb +7 -7
  43. data/lib/bas/{mapper → serialize}/notion/birthday_today.rb +7 -7
  44. data/lib/bas/serialize/notion/pto_today.rb +75 -0
  45. data/lib/bas/{mapper → serialize}/notion/work_items_limit.rb +7 -7
  46. data/lib/bas/{mapper → serialize}/postgres/pto_today.rb +9 -9
  47. data/lib/bas/use_cases/types/config.rb +6 -5
  48. data/lib/bas/use_cases/use_case.rb +13 -10
  49. data/lib/bas/use_cases/use_cases.rb +71 -59
  50. data/lib/bas/version.rb +1 -1
  51. data/lib/bas/write/base.rb +36 -0
  52. data/lib/bas/write/logs/base.rb +33 -0
  53. data/lib/bas/write/logs/use_case/console_log.rb +22 -0
  54. metadata +43 -33
  55. data/lib/bas/dispatcher/base.rb +0 -31
  56. data/lib/bas/dispatcher/discord/implementation.rb +0 -51
  57. data/lib/bas/dispatcher/slack/implementation.rb +0 -51
  58. data/lib/bas/fetcher/imap/use_case/support_emails.rb +0 -26
  59. data/lib/bas/mapper/notion/pto_today.rb +0 -70
  60. /data/lib/bas/{fetcher → read}/notion/exceptions/invalid_api_key.rb +0 -0
  61. /data/lib/bas/{fetcher → read}/notion/exceptions/invalid_database_id.rb +0 -0
@@ -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.1.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-03-26 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,52 +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
37
+ - lib/bas/domain/issue.rb
44
38
  - lib/bas/domain/pto.rb
45
39
  - lib/bas/domain/work_items_limit.rb
46
- - lib/bas/fetcher/base.rb
47
- - lib/bas/fetcher/imap/base.rb
48
- - lib/bas/fetcher/imap/types/response.rb
49
- - lib/bas/fetcher/imap/use_case/support_emails.rb
50
- - lib/bas/fetcher/notion/base.rb
51
- - lib/bas/fetcher/notion/exceptions/invalid_api_key.rb
52
- - lib/bas/fetcher/notion/exceptions/invalid_database_id.rb
53
- - lib/bas/fetcher/notion/helper.rb
54
- - lib/bas/fetcher/notion/types/response.rb
55
- - lib/bas/fetcher/notion/use_case/birthday_next_week.rb
56
- - lib/bas/fetcher/notion/use_case/birthday_today.rb
57
- - lib/bas/fetcher/notion/use_case/pto_next_week.rb
58
- - lib/bas/fetcher/notion/use_case/pto_today.rb
59
- - lib/bas/fetcher/notion/use_case/work_items_limit.rb
60
- - lib/bas/fetcher/postgres/base.rb
61
- - lib/bas/fetcher/postgres/helper.rb
62
- - lib/bas/fetcher/postgres/types/response.rb
63
- - lib/bas/fetcher/postgres/use_case/pto_today.rb
64
40
  - lib/bas/formatter/base.rb
65
41
  - lib/bas/formatter/birthday.rb
66
42
  - lib/bas/formatter/exceptions/invalid_data.rb
67
43
  - lib/bas/formatter/pto.rb
68
44
  - lib/bas/formatter/support_emails.rb
45
+ - lib/bas/formatter/types/response.rb
69
46
  - lib/bas/formatter/work_items_limit.rb
70
- - lib/bas/mapper/base.rb
71
- - lib/bas/mapper/imap/support_emails.rb
72
- - lib/bas/mapper/notion/birthday_today.rb
73
- - lib/bas/mapper/notion/pto_today.rb
74
- - lib/bas/mapper/notion/work_items_limit.rb
75
- - 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
76
83
  - lib/bas/use_cases/types/config.rb
77
84
  - lib/bas/use_cases/use_case.rb
78
85
  - lib/bas/use_cases/use_cases.rb
79
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
80
90
  - renovate.json
81
91
  - sig/business_automation_system.rbs
82
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
@@ -1,51 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../base"
4
- require_relative "./exceptions/invalid_webhook_token"
5
- require_relative "./types/response"
6
-
7
- module Dispatcher
8
- module Discord
9
- ##
10
- # This class is an implementation of the Dispatcher::Base interface, specifically designed
11
- # for dispatching messages to Discord.
12
- #
13
- class Implementation < Base
14
- # Implements the dispatching logic for the Discord use case. It sends a POST request to
15
- # the Discord webhook with the specified payload.
16
- #
17
- # <br>
18
- # <b>Params:</b>
19
- # * <tt>String</tt> payload: Payload to be dispatched to discord.
20
- # <br>
21
- # <b>raises</b> <tt>Exceptions::Discord::InvalidWebookToken</tt> if the provided webhook token is invalid.
22
- #
23
- # <br>
24
- # <b>returns</b> <tt>Dispatcher::Discord::Types::Response</tt>
25
- #
26
- def dispatch(payload)
27
- body = {
28
- username: name,
29
- avatar_url: "",
30
- content: payload
31
- }.to_json
32
- response = HTTParty.post(webhook, { body: body, headers: { "Content-Type" => "application/json" } })
33
-
34
- discord_response = Dispatcher::Discord::Types::Response.new(response)
35
-
36
- validate_response(discord_response)
37
- end
38
-
39
- private
40
-
41
- def validate_response(response)
42
- case response.code
43
- when 50_027
44
- raise Discord::Exceptions::InvalidWebookToken, response.message
45
- else
46
- response
47
- end
48
- end
49
- end
50
- end
51
- end
@@ -1,51 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../base"
4
- require_relative "./exceptions/invalid_webhook_token"
5
- require_relative "./types/response"
6
-
7
- module Dispatcher
8
- module Slack
9
- ##
10
- # This class is an implementation of the Dispatcher::Base interface, specifically designed
11
- # for dispatching messages to Slack.
12
- #
13
- class Implementation < Base
14
- # Implements the dispatching logic for the Slack use case. It sends a POST request to
15
- # the Slack webhook with the specified payload.
16
- #
17
- # <br>
18
- # <b>Params:</b>
19
- # * <tt>String</tt> payload: Payload to be dispatched to slack.
20
- # <br>
21
- # <b>raises</b> <tt>Exceptions::Slack::InvalidWebookToken</tt> if the provided webhook token is invalid.
22
- #
23
- # <br>
24
- # <b>returns</b> <tt>Dispatcher::Slack::Types::Response</tt>
25
- #
26
- def dispatch(payload)
27
- body = {
28
- username: name,
29
- text: payload
30
- }.to_json
31
-
32
- response = HTTParty.post(webhook, { body: body, headers: { "Content-Type" => "application/json" } })
33
-
34
- slack_response = Dispatcher::Discord::Types::Response.new(response)
35
-
36
- validate_response(slack_response)
37
- end
38
-
39
- private
40
-
41
- def validate_response(response)
42
- case response.http_code
43
- when 403
44
- raise Dispatcher::Slack::Exceptions::InvalidWebookToken, response.message
45
- else
46
- response
47
- end
48
- end
49
- end
50
- end
51
- end
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../base"
4
-
5
- module Fetcher
6
- module Imap
7
- ##
8
- # This class is an implementation of the Fetcher::Imap::Base interface, specifically designed
9
- # for fetching support email from a Google Gmail account.
10
- #
11
- class SupportEmails < Imap::Base
12
- TOKEN_URI = "https://oauth2.googleapis.com/token"
13
- EMAIL_DOMAIN = "imap.gmail.com"
14
- EMAIL_PORT = 993
15
-
16
- # Implements the data fetching filter for support emails from Google Gmail.
17
- #
18
- def fetch
19
- yesterday = (Time.now - (60 * 60 * 24)).strftime("%e-%b-%Y")
20
- query = ["TO", config[:search_email], "SINCE", yesterday]
21
-
22
- execute(EMAIL_DOMAIN, EMAIL_PORT, TOKEN_URI, query)
23
- end
24
- end
25
- end
26
- end
@@ -1,70 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../../domain/pto"
4
- require_relative "../base"
5
-
6
- module Mapper
7
- module Notion
8
- ##
9
- # This class implementats the methods of the Mapper::Base module, specifically designed for preparing or
10
- # shaping PTO's data coming from a Fetcher::Base implementation.
11
- #
12
- class PtoToday
13
- include Base
14
-
15
- PTO_PARAMS = ["Person", "Desde?", "Hasta?"].freeze
16
-
17
- # Implements the logic for shaping the results from a fetcher response.
18
- #
19
- # <br>
20
- # <b>Params:</b>
21
- # * <tt>Fetcher::Notion::Types::Response</tt> notion_response: Notion response object.
22
- #
23
- # <br>
24
- # <b>returns</b> <tt>List<Domain::Pto></tt> ptos_list, mapped PTO's to be used by a Formatter::Base
25
- # implementation.
26
- #
27
- def map(notion_response)
28
- return [] if notion_response.results.empty?
29
-
30
- normalized_notion_data = normalize_response(notion_response.results)
31
-
32
- normalized_notion_data.map do |pto|
33
- Domain::Pto.new(pto["Person"], pto["Desde?"], pto["Hasta?"])
34
- end
35
- end
36
-
37
- private
38
-
39
- def normalize_response(response)
40
- return [] if response.nil?
41
-
42
- response.map do |value|
43
- pto_fields = value["properties"].slice(*PTO_PARAMS)
44
-
45
- pto_fields.each do |field, pto_value|
46
- pto_fields[field] = extract_pto_value(field, pto_value)
47
- end
48
-
49
- pto_fields
50
- end
51
- end
52
-
53
- def extract_pto_value(field, value)
54
- case field
55
- when "Person" then extract_person_field_value(value)
56
- when "Desde?" then extract_date_field_value(value)
57
- when "Hasta?" then extract_date_field_value(value)
58
- end
59
- end
60
-
61
- def extract_person_field_value(data)
62
- data["people"][0]["name"]
63
- end
64
-
65
- def extract_date_field_value(data)
66
- data["date"]["start"]
67
- end
68
- end
69
- end
70
- end