bas 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/Gemfile +6 -0
- data/README.md +27 -24
- data/lib/bas/domain/issue.rb +22 -0
- data/lib/bas/domain/pto.rb +45 -4
- data/lib/bas/formatter/base.rb +2 -2
- data/lib/bas/formatter/birthday.rb +8 -4
- data/lib/bas/formatter/pto.rb +27 -26
- data/lib/bas/formatter/support_emails.rb +7 -3
- data/lib/bas/formatter/types/response.rb +16 -0
- data/lib/bas/formatter/work_items_limit.rb +8 -4
- data/lib/bas/process/base.rb +39 -0
- data/lib/bas/{dispatcher → process}/discord/exceptions/invalid_webhook_token.rb +1 -1
- data/lib/bas/process/discord/implementation.rb +71 -0
- data/lib/bas/{dispatcher → process}/discord/types/response.rb +1 -1
- data/lib/bas/{dispatcher → process}/slack/exceptions/invalid_webhook_token.rb +1 -1
- data/lib/bas/process/slack/implementation.rb +70 -0
- data/lib/bas/{dispatcher → process}/slack/types/response.rb +1 -1
- data/lib/bas/process/types/response.rb +16 -0
- data/lib/bas/{fetcher → read}/base.rb +8 -8
- data/lib/bas/read/github/base.rb +57 -0
- data/lib/bas/read/github/types/response.rb +27 -0
- data/lib/bas/read/github/use_case/repo_issues.rb +17 -0
- data/lib/bas/{fetcher → read}/imap/base.rb +7 -7
- data/lib/bas/{fetcher → read}/imap/types/response.rb +1 -1
- data/lib/bas/read/imap/use_case/support_emails.rb +26 -0
- data/lib/bas/{fetcher → read}/notion/base.rb +8 -8
- data/lib/bas/{fetcher → read}/notion/helper.rb +1 -1
- data/lib/bas/{fetcher → read}/notion/types/response.rb +1 -1
- data/lib/bas/{fetcher → read}/notion/use_case/birthday_next_week.rb +6 -6
- data/lib/bas/{fetcher → read}/notion/use_case/birthday_today.rb +6 -6
- data/lib/bas/{fetcher → read}/notion/use_case/pto_next_week.rb +6 -6
- data/lib/bas/{fetcher → read}/notion/use_case/pto_today.rb +6 -6
- data/lib/bas/{fetcher → read}/notion/use_case/work_items_limit.rb +5 -5
- data/lib/bas/{fetcher → read}/postgres/base.rb +8 -8
- data/lib/bas/{fetcher → read}/postgres/helper.rb +1 -1
- data/lib/bas/{fetcher → read}/postgres/types/response.rb +1 -1
- data/lib/bas/{fetcher → read}/postgres/use_case/pto_today.rb +6 -6
- data/lib/bas/{mapper → serialize}/base.rb +7 -7
- data/lib/bas/serialize/github/issues.rb +57 -0
- data/lib/bas/{mapper → serialize}/imap/support_emails.rb +7 -7
- data/lib/bas/{mapper → serialize}/notion/birthday_today.rb +7 -7
- data/lib/bas/serialize/notion/pto_today.rb +75 -0
- data/lib/bas/{mapper → serialize}/notion/work_items_limit.rb +7 -7
- data/lib/bas/{mapper → serialize}/postgres/pto_today.rb +9 -9
- data/lib/bas/use_cases/types/config.rb +6 -5
- data/lib/bas/use_cases/use_case.rb +13 -10
- data/lib/bas/use_cases/use_cases.rb +71 -59
- data/lib/bas/version.rb +1 -1
- data/lib/bas/write/base.rb +36 -0
- data/lib/bas/write/logs/base.rb +33 -0
- data/lib/bas/write/logs/use_case/console_log.rb +22 -0
- metadata +43 -33
- data/lib/bas/dispatcher/base.rb +0 -31
- data/lib/bas/dispatcher/discord/implementation.rb +0 -51
- data/lib/bas/dispatcher/slack/implementation.rb +0 -51
- data/lib/bas/fetcher/imap/use_case/support_emails.rb +0 -26
- data/lib/bas/mapper/notion/pto_today.rb +0 -70
- /data/lib/bas/{fetcher → read}/notion/exceptions/invalid_api_key.rb +0 -0
- /data/lib/bas/{fetcher → read}/notion/exceptions/invalid_database_id.rb +0 -0
@@ -0,0 +1,70 @@
|
|
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 Process
|
8
|
+
module Slack
|
9
|
+
##
|
10
|
+
# This class is an implementation of the Process::Base interface, specifically designed
|
11
|
+
# for sending messages to Slack.
|
12
|
+
#
|
13
|
+
class Implementation < Base
|
14
|
+
attr_reader :webhook, :name
|
15
|
+
|
16
|
+
# Initializes the process with essential configuration parameters.
|
17
|
+
#
|
18
|
+
def initialize(config = {})
|
19
|
+
super(config)
|
20
|
+
|
21
|
+
@webhook = config[:webhook]
|
22
|
+
@name = config[:name]
|
23
|
+
end
|
24
|
+
|
25
|
+
# Implements the sending process logic for the Slack use case. It sends a POST request to
|
26
|
+
# the Slack webhook with the specified payload.
|
27
|
+
#
|
28
|
+
# <br>
|
29
|
+
# <b>Params:</b>
|
30
|
+
# * <tt>Formatter::Types::Response</tt> formatter response: standard formatter response
|
31
|
+
# with the Payload to be send to slack.
|
32
|
+
# <br>
|
33
|
+
# <b>raises</b> <tt>Exceptions::Slack::InvalidWebookToken</tt> if the provided webhook
|
34
|
+
# token is invalid.
|
35
|
+
#
|
36
|
+
# <br>
|
37
|
+
# <b>returns</b> <tt>Process::Types::Response</tt>
|
38
|
+
#
|
39
|
+
def execute(format_response)
|
40
|
+
response = valid_format_response(format_response)
|
41
|
+
|
42
|
+
body = post_body(response.data)
|
43
|
+
|
44
|
+
response = HTTParty.post(webhook, { body: body, headers: { "Content-Type" => "application/json" } })
|
45
|
+
|
46
|
+
slack_response = Process::Discord::Types::Response.new(response)
|
47
|
+
|
48
|
+
validate_response(slack_response)
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def post_body(payload)
|
54
|
+
{
|
55
|
+
username: name,
|
56
|
+
text: payload
|
57
|
+
}.to_json
|
58
|
+
end
|
59
|
+
|
60
|
+
def validate_response(response)
|
61
|
+
case response.http_code
|
62
|
+
when 403
|
63
|
+
raise Process::Slack::Exceptions::InvalidWebookToken, response.message
|
64
|
+
else
|
65
|
+
Process::Types::Response.new(response)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Process
|
4
|
+
module Types
|
5
|
+
##
|
6
|
+
# Represents a response received from a Process. It encapsulates the formatted data to be used by
|
7
|
+
# a Write component.
|
8
|
+
class Response
|
9
|
+
attr_reader :data
|
10
|
+
|
11
|
+
def initialize(response)
|
12
|
+
@data = response
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -2,41 +2,41 @@
|
|
2
2
|
|
3
3
|
require_relative "../domain/exceptions/function_not_implemented"
|
4
4
|
|
5
|
-
module
|
5
|
+
module Read
|
6
6
|
##
|
7
|
-
# The
|
7
|
+
# The Read::Base class serves as the foundation for implementing specific data readers within the Read module.
|
8
8
|
# Operating as an interface, this class defines essential attributes and methods, providing a blueprint for creating
|
9
|
-
# custom
|
9
|
+
# custom readers tailored to different data sources.
|
10
10
|
#
|
11
11
|
class Base
|
12
12
|
attr_reader :config
|
13
13
|
|
14
|
-
# Initializes the
|
14
|
+
# Initializes the reader with essential configuration parameters.
|
15
15
|
#
|
16
16
|
def initialize(config)
|
17
17
|
@config = config
|
18
18
|
end
|
19
19
|
|
20
|
-
# A method meant to
|
20
|
+
# A method meant to execute the read request from an specific source depending on the implementation.
|
21
21
|
# Must be overridden by subclasses, with specific logic based on the use case.
|
22
22
|
#
|
23
23
|
# <br>
|
24
24
|
# <b>raises</b> <tt>Domain::Exceptions::FunctionNotImplemented</tt> when missing implementation.
|
25
25
|
#
|
26
|
-
def
|
26
|
+
def execute
|
27
27
|
raise Domain::Exceptions::FunctionNotImplemented
|
28
28
|
end
|
29
29
|
|
30
30
|
protected
|
31
31
|
|
32
|
-
# A method meant to
|
32
|
+
# A method meant to read from the source, retrieven the required data
|
33
33
|
# from an specific filter configuration depending on the use case implementation.
|
34
34
|
# Must be overridden by subclasses, with specific logic based on the use case.
|
35
35
|
#
|
36
36
|
# <br>
|
37
37
|
# <b>raises</b> <tt>Domain::Exceptions::FunctionNotImplemented</tt> when missing implementation.
|
38
38
|
#
|
39
|
-
def
|
39
|
+
def read(*_filters)
|
40
40
|
raise Domain::Exceptions::FunctionNotImplemented
|
41
41
|
end
|
42
42
|
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "octokit"
|
4
|
+
require "openssl"
|
5
|
+
require "jwt"
|
6
|
+
|
7
|
+
require_relative "../base"
|
8
|
+
require_relative "./types/response"
|
9
|
+
|
10
|
+
module Read
|
11
|
+
module Github
|
12
|
+
##
|
13
|
+
# This class is an implementation of the Read::Base interface, specifically designed
|
14
|
+
# for reading data from a GitHub repository.
|
15
|
+
#
|
16
|
+
class Base < Read::Base
|
17
|
+
protected
|
18
|
+
|
19
|
+
# Implements the data reading logic to get data from a Github repository.
|
20
|
+
# It connects to Github using the octokit gem, authenticates with a github app,
|
21
|
+
# request the data and returns a validated response.
|
22
|
+
#
|
23
|
+
def read(method, *filter)
|
24
|
+
octokit_response = octokit.public_send(method, *filter)
|
25
|
+
|
26
|
+
Read::Github::Types::Response.new(octokit_response)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def octokit
|
32
|
+
Octokit::Client.new(bearer_token: access_token)
|
33
|
+
end
|
34
|
+
|
35
|
+
def access_token
|
36
|
+
app = Octokit::Client.new(client_id: config[:app_id], bearer_token: jwt)
|
37
|
+
|
38
|
+
app.create_app_installation_access_token(config[:installation_id])[:token]
|
39
|
+
end
|
40
|
+
|
41
|
+
def jwt
|
42
|
+
private_pem = File.read(config[:secret_path])
|
43
|
+
private_key = OpenSSL::PKey::RSA.new(private_pem)
|
44
|
+
|
45
|
+
JWT.encode(jwt_payload, private_key, "RS256")
|
46
|
+
end
|
47
|
+
|
48
|
+
def jwt_payload
|
49
|
+
{
|
50
|
+
iat: Time.now.to_i - 60,
|
51
|
+
exp: Time.now.to_i + (10 * 60),
|
52
|
+
iss: config[:app_id]
|
53
|
+
}
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Read
|
4
|
+
module Github
|
5
|
+
module Types
|
6
|
+
##
|
7
|
+
# Represents a response received from the Octokit Github client. It encapsulates essential
|
8
|
+
# information about the response, providing a structured way to handle and analyze
|
9
|
+
# it's responses.
|
10
|
+
class Response
|
11
|
+
attr_reader :status_code, :message, :results
|
12
|
+
|
13
|
+
def initialize(response)
|
14
|
+
if response.empty?
|
15
|
+
@status_code = 404
|
16
|
+
@message = "no result were found"
|
17
|
+
@results = []
|
18
|
+
else
|
19
|
+
@status_code = 200
|
20
|
+
@message = "success"
|
21
|
+
@results = response
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../base"
|
4
|
+
|
5
|
+
module Read
|
6
|
+
module Github
|
7
|
+
##
|
8
|
+
# This class is an implementation of the Read::Github::Base interface, specifically designed
|
9
|
+
# for reading issues from a Github repository.
|
10
|
+
#
|
11
|
+
class RepoIssues < Github::Base
|
12
|
+
def execute
|
13
|
+
read("list_issues", config[:repo])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -6,25 +6,25 @@ require "gmail_xoauth"
|
|
6
6
|
require_relative "../base"
|
7
7
|
require_relative "./types/response"
|
8
8
|
|
9
|
-
module
|
9
|
+
module Read
|
10
10
|
module Imap
|
11
11
|
##
|
12
|
-
# This class is an implementation of the
|
13
|
-
# for
|
12
|
+
# This class is an implementation of the Read::Base interface, specifically designed
|
13
|
+
# for reading data from an IMAP server.
|
14
14
|
#
|
15
|
-
class Base <
|
15
|
+
class Base < Read::Base
|
16
16
|
protected
|
17
17
|
|
18
|
-
# Implements the
|
18
|
+
# Implements the reading logic for emails data from an IMAP server.
|
19
19
|
# It connects to an IMAP server inbox, request emails base on a filter,
|
20
20
|
# and returns a validated response.
|
21
21
|
#
|
22
|
-
def
|
22
|
+
def read(email_domain, email_port, token_uri, query)
|
23
23
|
access_token = refresh_token(token_uri)
|
24
24
|
|
25
25
|
imap_fetch(email_domain, email_port, query, access_token)
|
26
26
|
|
27
|
-
|
27
|
+
Read::Imap::Types::Response.new(@emails)
|
28
28
|
end
|
29
29
|
|
30
30
|
private
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../base"
|
4
|
+
|
5
|
+
module Read
|
6
|
+
module Imap
|
7
|
+
##
|
8
|
+
# This class is an implementation of the Read::Imap::Base interface, specifically designed
|
9
|
+
# for reading 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 reading filter for support emails from Google Gmail.
|
17
|
+
#
|
18
|
+
def execute
|
19
|
+
yesterday = (Time.now - (60 * 60 * 24)).strftime("%d-%b-%Y")
|
20
|
+
query = ["TO", config[:search_email], "SINCE", yesterday]
|
21
|
+
|
22
|
+
read(EMAIL_DOMAIN, EMAIL_PORT, TOKEN_URI, query)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -8,18 +8,18 @@ require_relative "./exceptions/invalid_database_id"
|
|
8
8
|
require_relative "./types/response"
|
9
9
|
require_relative "./helper"
|
10
10
|
|
11
|
-
module
|
11
|
+
module Read
|
12
12
|
module Notion
|
13
13
|
##
|
14
|
-
# This class is an implementation of the
|
15
|
-
# for
|
14
|
+
# This class is an implementation of the Read::Base interface, specifically designed
|
15
|
+
# for reading data from Notion.
|
16
16
|
#
|
17
|
-
class Base <
|
17
|
+
class Base < Read::Base
|
18
18
|
NOTION_BASE_URL = "https://api.notion.com"
|
19
19
|
|
20
20
|
protected
|
21
21
|
|
22
|
-
# Implements the
|
22
|
+
# Implements the read logic for data from Notion. It sends a POST
|
23
23
|
# request to the Notion API to query the specified database and returns a validated response.
|
24
24
|
#
|
25
25
|
# <br>
|
@@ -28,14 +28,14 @@ module Fetcher
|
|
28
28
|
# <b>raises</b> <tt>Exceptions::Notion::InvalidDatabaseId</tt> if the Database id provided is incorrect
|
29
29
|
# or invalid.
|
30
30
|
#
|
31
|
-
def
|
31
|
+
def read(filter)
|
32
32
|
url = "#{NOTION_BASE_URL}/v1/databases/#{config[:database_id]}/query"
|
33
33
|
|
34
34
|
httparty_response = HTTParty.post(url, { body: filter.to_json, headers: headers })
|
35
35
|
|
36
|
-
notion_response =
|
36
|
+
notion_response = Read::Notion::Types::Response.new(httparty_response)
|
37
37
|
|
38
|
-
|
38
|
+
Read::Notion::Helper.validate_response(notion_response)
|
39
39
|
end
|
40
40
|
|
41
41
|
private
|
@@ -2,18 +2,18 @@
|
|
2
2
|
|
3
3
|
require_relative "../base"
|
4
4
|
|
5
|
-
module
|
5
|
+
module Read
|
6
6
|
module Notion
|
7
7
|
##
|
8
|
-
# This class is an implementation of the
|
9
|
-
# for
|
8
|
+
# This class is an implementation of the Read::Notion::Base interface, specifically designed
|
9
|
+
# for reading next week birthdays data from Notion.
|
10
10
|
#
|
11
11
|
class BirthdayNextWeek < Notion::Base
|
12
12
|
DAYS_BEFORE_NOTIFY = 8
|
13
13
|
|
14
|
-
# Implements the data
|
14
|
+
# Implements the data reading filter for next week Birthdays data from Notion.
|
15
15
|
#
|
16
|
-
def
|
16
|
+
def execute
|
17
17
|
filter = {
|
18
18
|
filter: {
|
19
19
|
or: [
|
@@ -22,7 +22,7 @@ module Fetcher
|
|
22
22
|
}
|
23
23
|
}
|
24
24
|
|
25
|
-
|
25
|
+
read(filter)
|
26
26
|
end
|
27
27
|
|
28
28
|
private
|
@@ -2,16 +2,16 @@
|
|
2
2
|
|
3
3
|
require_relative "../base"
|
4
4
|
|
5
|
-
module
|
5
|
+
module Read
|
6
6
|
module Notion
|
7
7
|
##
|
8
|
-
# This class is an implementation of the
|
9
|
-
# for
|
8
|
+
# This class is an implementation of the Read::Notion::Base interface, specifically designed
|
9
|
+
# for reading birthday data from Notion.
|
10
10
|
#
|
11
11
|
class BirthdayToday < Notion::Base
|
12
|
-
# Implements the
|
12
|
+
# Implements the reading filter for todays Birthdays data from Notion.
|
13
13
|
#
|
14
|
-
def
|
14
|
+
def execute
|
15
15
|
today = Time.now.utc.strftime("%F").to_s
|
16
16
|
|
17
17
|
filter = {
|
@@ -22,7 +22,7 @@ module Fetcher
|
|
22
22
|
}
|
23
23
|
}
|
24
24
|
|
25
|
-
|
25
|
+
read(filter)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
@@ -2,19 +2,19 @@
|
|
2
2
|
|
3
3
|
require_relative "../base"
|
4
4
|
|
5
|
-
module
|
5
|
+
module Read
|
6
6
|
module Notion
|
7
7
|
##
|
8
|
-
# This class is an implementation of the
|
9
|
-
# for
|
8
|
+
# This class is an implementation of the Read::Notion::Base interface, specifically designed
|
9
|
+
# for reading next week Paid Time Off (PTO) data from Notion.
|
10
10
|
#
|
11
11
|
class PtoNextWeek < Notion::Base
|
12
|
-
# Implements the
|
12
|
+
# Implements the reading filter for next week PTO's data from Notion.
|
13
13
|
#
|
14
|
-
def
|
14
|
+
def execute
|
15
15
|
filter = build_filter
|
16
16
|
|
17
|
-
|
17
|
+
read(filter)
|
18
18
|
end
|
19
19
|
|
20
20
|
private
|
@@ -2,16 +2,16 @@
|
|
2
2
|
|
3
3
|
require_relative "../base"
|
4
4
|
|
5
|
-
module
|
5
|
+
module Read
|
6
6
|
module Notion
|
7
7
|
##
|
8
|
-
# This class is an implementation of the
|
9
|
-
# for
|
8
|
+
# This class is an implementation of the Read::Notion::Base interface, specifically designed
|
9
|
+
# for reading Paid Time Off (PTO) data from Notion.
|
10
10
|
#
|
11
11
|
class PtoToday < Notion::Base
|
12
|
-
# Implements the
|
12
|
+
# Implements the reading filter for todays PTO's data from Notion.
|
13
13
|
#
|
14
|
-
def
|
14
|
+
def execute
|
15
15
|
today = Time.now.utc.strftime("%F").to_s
|
16
16
|
|
17
17
|
filter = {
|
@@ -23,7 +23,7 @@ module Fetcher
|
|
23
23
|
}
|
24
24
|
}
|
25
25
|
|
26
|
-
|
26
|
+
read(filter)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
@@ -2,16 +2,16 @@
|
|
2
2
|
|
3
3
|
require_relative "../base"
|
4
4
|
|
5
|
-
module
|
5
|
+
module Read
|
6
6
|
module Notion
|
7
7
|
##
|
8
|
-
# This class is an implementation of the
|
8
|
+
# This class is an implementation of the Read::Notion::Base interface, specifically designed
|
9
9
|
# for counting "in progress" work items from work item database in Notion.
|
10
10
|
#
|
11
11
|
class WorkItemsLimit < Notion::Base
|
12
|
-
# Implements the data
|
12
|
+
# Implements the data reading count of "in progress" work items from Notion.
|
13
13
|
#
|
14
|
-
def
|
14
|
+
def execute
|
15
15
|
filter = {
|
16
16
|
filter: {
|
17
17
|
"and": [
|
@@ -21,7 +21,7 @@ module Fetcher
|
|
21
21
|
}
|
22
22
|
}
|
23
23
|
|
24
|
-
|
24
|
+
read(filter)
|
25
25
|
end
|
26
26
|
|
27
27
|
private
|
@@ -6,28 +6,28 @@ require_relative "../base"
|
|
6
6
|
require_relative "./types/response"
|
7
7
|
require_relative "./helper"
|
8
8
|
|
9
|
-
module
|
9
|
+
module Read
|
10
10
|
module Postgres
|
11
11
|
##
|
12
|
-
# This class is an implementation of the
|
13
|
-
# for
|
12
|
+
# This class is an implementation of the Read::Base interface, specifically designed
|
13
|
+
# for reading data from Postgres.
|
14
14
|
#
|
15
|
-
class Base <
|
15
|
+
class Base < Read::Base
|
16
16
|
protected
|
17
17
|
|
18
|
-
# Implements the
|
18
|
+
# Implements the read logic from a Postgres database. It use the PG gem
|
19
19
|
# to request data from a local or external database and returns a validated response.
|
20
20
|
#
|
21
21
|
# Gem: pg (https://rubygems.org/gems/pg)
|
22
22
|
#
|
23
|
-
def
|
23
|
+
def read(query)
|
24
24
|
pg_connection = PG::Connection.new(config[:connection])
|
25
25
|
|
26
26
|
pg_result = execute_query(pg_connection, query)
|
27
27
|
|
28
|
-
postgres_response =
|
28
|
+
postgres_response = Read::Postgres::Types::Response.new(pg_result)
|
29
29
|
|
30
|
-
|
30
|
+
Read::Postgres::Helper.validate_response(postgres_response)
|
31
31
|
end
|
32
32
|
|
33
33
|
private
|
@@ -2,17 +2,17 @@
|
|
2
2
|
|
3
3
|
require_relative "../base"
|
4
4
|
|
5
|
-
module
|
5
|
+
module Read
|
6
6
|
module Postgres
|
7
7
|
##
|
8
|
-
# This class is an implementation of the
|
9
|
-
# for
|
8
|
+
# This class is an implementation of the Read::Postgres::Base interface, specifically designed
|
9
|
+
# for reading Paid Time Off (PTO) data from a Postgres Database.
|
10
10
|
#
|
11
11
|
class PtoToday < Base
|
12
|
-
# Implements the data
|
12
|
+
# Implements the data reading query for todays PTO data from a Postgres database.
|
13
13
|
#
|
14
|
-
def
|
15
|
-
|
14
|
+
def execute
|
15
|
+
read(build_query)
|
16
16
|
end
|
17
17
|
|
18
18
|
private
|
@@ -2,28 +2,28 @@
|
|
2
2
|
|
3
3
|
require_relative "../domain/exceptions/function_not_implemented"
|
4
4
|
|
5
|
-
module
|
5
|
+
module Serialize
|
6
6
|
##
|
7
|
-
# The
|
8
|
-
#
|
7
|
+
# The Serialize::Base module serves as the foundation for implementing specific data shaping logic within the
|
8
|
+
# Serialize module. Defines essential methods, that provide a blueprint for organizing or shaping data in a manner
|
9
9
|
# suitable for downstream formatting processes.
|
10
10
|
#
|
11
11
|
module Base
|
12
|
-
# An method meant to prepare or organize the data coming from an implementation of the
|
12
|
+
# An method meant to prepare or organize the data coming from an implementation of the Read::Base interface.
|
13
13
|
# Must be overridden by subclasses, with specific logic based on the use case.
|
14
14
|
#
|
15
15
|
# <br>
|
16
16
|
# <b>Params:</b>
|
17
|
-
# * <tt>
|
17
|
+
# * <tt>Read::Notion::Types::Response</tt> response: Response produced by a reader.
|
18
18
|
#
|
19
19
|
# <br>
|
20
20
|
#
|
21
21
|
# <b>raises</b> <tt>Domain::Exceptions::FunctionNotImplemented</tt> when missing implementation.
|
22
22
|
# <br>
|
23
23
|
#
|
24
|
-
# <b>returns</b> <tt>List<Domain::></tt>
|
24
|
+
# <b>returns</b> <tt>List<Domain::></tt> Serialize list of data, ready to be formatted.
|
25
25
|
#
|
26
|
-
def
|
26
|
+
def execute(_response)
|
27
27
|
raise Domain::Exceptions::FunctionNotImplemented
|
28
28
|
end
|
29
29
|
end
|