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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +25 -22
- data/lib/bas/formatter/base.rb +2 -2
- data/lib/bas/formatter/birthday.rb +8 -4
- data/lib/bas/formatter/pto.rb +8 -4
- 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/{fetcher → read}/github/base.rb +7 -7
- data/lib/bas/{fetcher → read}/github/types/response.rb +1 -1
- 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/{mapper → serialize}/github/issues.rb +7 -7
- 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/{mapper → serialize}/notion/pto_today.rb +14 -12
- data/lib/bas/{mapper → serialize}/notion/work_items_limit.rb +7 -7
- data/lib/bas/{mapper → serialize}/postgres/pto_today.rb +7 -7
- 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 -61
- 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 +42 -37
- 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/github/use_case/repo_issues.rb +0 -17
- data/lib/bas/fetcher/imap/use_case/support_emails.rb +0 -26
- /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
@@ -7,23 +7,23 @@ require "jwt"
|
|
7
7
|
require_relative "../base"
|
8
8
|
require_relative "./types/response"
|
9
9
|
|
10
|
-
module
|
10
|
+
module Read
|
11
11
|
module Github
|
12
12
|
##
|
13
|
-
# This class is an implementation of the
|
14
|
-
# for
|
13
|
+
# This class is an implementation of the Read::Base interface, specifically designed
|
14
|
+
# for reading data from a GitHub repository.
|
15
15
|
#
|
16
|
-
class Base <
|
16
|
+
class Base < Read::Base
|
17
17
|
protected
|
18
18
|
|
19
|
-
# Implements the data
|
19
|
+
# Implements the data reading logic to get data from a Github repository.
|
20
20
|
# It connects to Github using the octokit gem, authenticates with a github app,
|
21
21
|
# request the data and returns a validated response.
|
22
22
|
#
|
23
|
-
def
|
23
|
+
def read(method, *filter)
|
24
24
|
octokit_response = octokit.public_send(method, *filter)
|
25
25
|
|
26
|
-
|
26
|
+
Read::Github::Types::Response.new(octokit_response)
|
27
27
|
end
|
28
28
|
|
29
29
|
private
|
@@ -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
|
@@ -3,25 +3,25 @@
|
|
3
3
|
require_relative "../../domain/issue"
|
4
4
|
require_relative "../base"
|
5
5
|
|
6
|
-
module
|
6
|
+
module Serialize
|
7
7
|
module Github
|
8
8
|
##
|
9
|
-
# This class
|
10
|
-
# preparing or shaping Github issues data coming from a
|
9
|
+
# This class implements the methods of the Serialize::Base module, specifically designed for
|
10
|
+
# preparing or shaping Github issues data coming from a Read::Base implementation.
|
11
11
|
class Issues
|
12
12
|
include Base
|
13
13
|
|
14
|
-
# Implements the logic for shaping the results from a
|
14
|
+
# Implements the logic for shaping the results from a reader response.
|
15
15
|
#
|
16
16
|
# <br>
|
17
17
|
# <b>Params:</b>
|
18
|
-
# * <tt>
|
18
|
+
# * <tt>Read::Github::Types::Response</tt> github_response: Array of github issues data.
|
19
19
|
#
|
20
20
|
# <br>
|
21
|
-
# <b>return</b> <tt>List<Domain::Issue></tt>
|
21
|
+
# <b>return</b> <tt>List<Domain::Issue></tt> serialized github issues to be used by a
|
22
22
|
# Formatter::Base implementation.
|
23
23
|
#
|
24
|
-
def
|
24
|
+
def execute(github_response)
|
25
25
|
return [] if github_response.results.empty?
|
26
26
|
|
27
27
|
normalized_github_data = normalize_response(github_response.results)
|
@@ -3,25 +3,25 @@
|
|
3
3
|
require_relative "../../domain/email"
|
4
4
|
require_relative "../base"
|
5
5
|
|
6
|
-
module
|
6
|
+
module Serialize
|
7
7
|
module Imap
|
8
8
|
##
|
9
|
-
# This class
|
10
|
-
# preparing or shaping support emails data coming from a
|
9
|
+
# This class implements the methods of the Serialize::Base module, specifically designed for
|
10
|
+
# preparing or shaping support emails data coming from a Read::Base implementation.
|
11
11
|
class SupportEmails
|
12
12
|
include Base
|
13
13
|
|
14
|
-
# Implements the logic for shaping the results from a
|
14
|
+
# Implements the logic for shaping the results from a reader response.
|
15
15
|
#
|
16
16
|
# <br>
|
17
17
|
# <b>Params:</b>
|
18
|
-
# * <tt>
|
18
|
+
# * <tt>Read::Imap::Types::Response</tt> imap_response: Array of imap emails data.
|
19
19
|
#
|
20
20
|
# <br>
|
21
|
-
# <b>return</b> <tt>List<Domain::Email></tt> support_emails_list,
|
21
|
+
# <b>return</b> <tt>List<Domain::Email></tt> support_emails_list, serialized support emails to be used by a
|
22
22
|
# Formatter::Base implementation.
|
23
23
|
#
|
24
|
-
def
|
24
|
+
def execute(imap_response)
|
25
25
|
return [] if imap_response.results.empty?
|
26
26
|
|
27
27
|
normalized_email_data = normalize_response(imap_response.results)
|
@@ -3,27 +3,27 @@
|
|
3
3
|
require_relative "../../domain/birthday"
|
4
4
|
require_relative "../base"
|
5
5
|
|
6
|
-
module
|
6
|
+
module Serialize
|
7
7
|
module Notion
|
8
8
|
##
|
9
|
-
# This class
|
10
|
-
# shaping birthdays data coming from a
|
9
|
+
# This class implements the methods of the Serialize::Base module, specifically designed for preparing or
|
10
|
+
# shaping birthdays data coming from a Read::Base implementation.
|
11
11
|
class BirthdayToday
|
12
12
|
include Base
|
13
13
|
|
14
14
|
BIRTHDAY_PARAMS = ["Complete Name", "BD_this_year"].freeze
|
15
15
|
|
16
|
-
# Implements the logic for shaping the results from a
|
16
|
+
# Implements the logic for shaping the results from a reader response.
|
17
17
|
#
|
18
18
|
# <br>
|
19
19
|
# <b>Params:</b>
|
20
|
-
# * <tt>
|
20
|
+
# * <tt>Read::Notion::Types::Response</tt> notion_response: Notion response object.
|
21
21
|
#
|
22
22
|
# <br>
|
23
|
-
# <b>return</b> <tt>List<Domain::Birthday></tt> birthdays_list,
|
23
|
+
# <b>return</b> <tt>List<Domain::Birthday></tt> birthdays_list, serialized birthdays to be used by a
|
24
24
|
# Formatter::Base implementation.
|
25
25
|
#
|
26
|
-
def
|
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,34 +3,34 @@
|
|
3
3
|
require_relative "../../domain/pto"
|
4
4
|
require_relative "../base"
|
5
5
|
|
6
|
-
module
|
6
|
+
module Serialize
|
7
7
|
module Notion
|
8
8
|
##
|
9
|
-
# This class
|
10
|
-
# shaping PTO's data coming from a
|
9
|
+
# This class implements the methods of the Serialize::Base module, specifically designed for preparing or
|
10
|
+
# shaping PTO's data coming from a Read::Base implementation.
|
11
11
|
#
|
12
12
|
class PtoToday
|
13
13
|
include Base
|
14
14
|
|
15
|
-
PTO_PARAMS = ["
|
15
|
+
PTO_PARAMS = ["Description", "Desde?", "Hasta?"].freeze
|
16
16
|
|
17
|
-
# Implements the logic for shaping the results from a
|
17
|
+
# Implements the logic for shaping the results from a reader response.
|
18
18
|
#
|
19
19
|
# <br>
|
20
20
|
# <b>Params:</b>
|
21
|
-
# * <tt>
|
21
|
+
# * <tt>Read::Notion::Types::Response</tt> notion_response: Notion response object.
|
22
22
|
#
|
23
23
|
# <br>
|
24
|
-
# <b>returns</b> <tt>List<Domain::Pto></tt> ptos_list,
|
24
|
+
# <b>returns</b> <tt>List<Domain::Pto></tt> ptos_list, serialized PTO's to be used by a Formatter::Base
|
25
25
|
# implementation.
|
26
26
|
#
|
27
|
-
def
|
27
|
+
def execute(notion_response)
|
28
28
|
return [] if notion_response.results.empty?
|
29
29
|
|
30
30
|
normalized_notion_data = normalize_response(notion_response.results)
|
31
31
|
|
32
32
|
normalized_notion_data.map do |pto|
|
33
|
-
Domain::Pto.new(pto["
|
33
|
+
Domain::Pto.new(pto["Description"], pto["Desde?"], pto["Hasta?"])
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -43,15 +43,17 @@ module Mapper
|
|
43
43
|
pto_fields = value["properties"].slice(*PTO_PARAMS)
|
44
44
|
|
45
45
|
{
|
46
|
-
"
|
46
|
+
"Description" => extract_description_field_value(pto_fields["Description"]),
|
47
47
|
"Desde?" => extract_date_field_value(pto_fields["Desde?"]),
|
48
48
|
"Hasta?" => extract_date_field_value(pto_fields["Hasta?"])
|
49
49
|
}
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
-
def
|
54
|
-
data["
|
53
|
+
def extract_description_field_value(data)
|
54
|
+
names = data["title"].map { |name| name["plain_text"] }
|
55
|
+
|
56
|
+
names.join(" ")
|
55
57
|
end
|
56
58
|
|
57
59
|
def extract_date_field_value(date)
|