Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solve #13 - Rename the Fetcher to Read #17

Merged
merged 7 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ notifications to a Discord channel.

A *Use Case* object, consists on 4 main components, having it's own responsibility:

### 1. Fetcher - Obtaining the data
### 1. Read - Obtaining the data

Specifically, a fetcher is an object in charged of bringing data from a data source. The gem already provides the base interface
for building your own fetcher for your specific data source, or rely on already built classes if they match your purpose.
Specifically, a reader is an object in charged of bringing data from a data source. The gem already provides the base interface
for building your own reader for your specific data source, or rely on already built classes if they match your purpose.

The base interface for a fetcher can be found under the `bas/fetcher/base.rb` class. Since this is a implementation of the `Fetcher::Base`
The base interface for a reader can be found under the `bas/read/base.rb` class. Since this is a implementation of the `Read::Base`
for bringing data from a Notion database, it was created on a new namespace for that data source, it can be found under
`/bas/fetcher/notion/use_case/birthday_today.rb`. It implements specific logic for fetching the data and validating the response.
`/bas/read/notion/use_case/birthday_today.rb`. It implements specific logic for reading the data and validating the response.

### 2. Mapper - Shaping it

Expand Down Expand Up @@ -139,7 +139,7 @@ filter = {
}

options = {
fetch_options: {
read_options: {
base_url: "https://api.notion.com",
database_id: NOTION_DATABASE_ID,
secret: NOTION_API_INTEGRATION_SECRET,
Expand Down Expand Up @@ -235,7 +235,7 @@ module Notifier
# Service description
class UseCaseName
def self.notify(*)
options = { fetch_options:, dispatch_options: }
options = { read_options:, dispatch_options: }

begin
use_case = UseCases.use_case_build_function(options)
Expand All @@ -246,18 +246,18 @@ module Notifier
end
end

def self.fetch_options
def self.read_options
{
base_url: NOTION_BASE_URL,
database_id: NOTION_DATABASE_ID,
secret: NOTION_SECRET,
filter: {
filter: { "and": fetch_filter }
filter: { "and": read_filter }
}
}
end

def self.fetch_filter
def self.read_filter
today = Common::TimeZone.set_colombia_time_zone.strftime('%F').to_s

[
Expand Down
17 changes: 0 additions & 17 deletions lib/bas/fetcher/github/use_case/repo_issues.rb

This file was deleted.

26 changes: 0 additions & 26 deletions lib/bas/fetcher/imap/use_case/support_emails.rb

This file was deleted.

4 changes: 2 additions & 2 deletions lib/bas/mapper/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ module Mapper
# suitable for downstream formatting processes.
#
module Base
# An method meant to prepare or organize the data coming from an implementation of the Fetcher::Base interface.
# An method meant to prepare or organize the data coming from an implementation of the Read::Base interface.
# Must be overridden by subclasses, with specific logic based on the use case.
#
# <br>
# <b>Params:</b>
# * <tt>Fetcher::Notion::Types::Response</tt> response: Response produced by a fetcher.
# * <tt>Read::Notion::Types::Response</tt> response: Response produced by a reader.
#
# <br>
#
Expand Down
6 changes: 3 additions & 3 deletions lib/bas/mapper/github/issues.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ module Mapper
module Github
##
# This class implementats the methods of the Mapper::Base module, specifically designed for
# preparing or shaping Github issues data coming from a Fetcher::Base implementation.
# preparing or shaping Github issues data coming from a Read::Base implementation.
class Issues
include Base

# Implements the logic for shaping the results from a fetcher response.
# Implements the logic for shaping the results from a reader response.
#
# <br>
# <b>Params:</b>
# * <tt>Fetcher::Github::Types::Response</tt> github_response: Array of github issues data.
# * <tt>Read::Github::Types::Response</tt> github_response: Array of github issues data.
#
# <br>
# <b>return</b> <tt>List<Domain::Issue></tt> mapped github issues to be used by a
Expand Down
6 changes: 3 additions & 3 deletions lib/bas/mapper/imap/support_emails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ module Mapper
module Imap
##
# This class implementats the methods of the Mapper::Base module, specifically designed for
# preparing or shaping support emails data coming from a Fetcher::Base implementation.
# preparing or shaping support emails data coming from a Read::Base implementation.
class SupportEmails
include Base

# Implements the logic for shaping the results from a fetcher response.
# Implements the logic for shaping the results from a reader response.
#
# <br>
# <b>Params:</b>
# * <tt>Fetcher::Imap::Types::Response</tt> imap_response: Array of imap emails data.
# * <tt>Read::Imap::Types::Response</tt> imap_response: Array of imap emails data.
#
# <br>
# <b>return</b> <tt>List<Domain::Email></tt> support_emails_list, mapped support emails to be used by a
Expand Down
6 changes: 3 additions & 3 deletions lib/bas/mapper/notion/birthday_today.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ module Mapper
module Notion
##
# This class implementats the methods of the Mapper::Base module, specifically designed for preparing or
# shaping birthdays data coming from a Fetcher::Base implementation.
# shaping birthdays data coming from a Read::Base implementation.
class BirthdayToday
include Base

BIRTHDAY_PARAMS = ["Complete Name", "BD_this_year"].freeze

# Implements the logic for shaping the results from a fetcher response.
# Implements the logic for shaping the results from a reader response.
#
# <br>
# <b>Params:</b>
# * <tt>Fetcher::Notion::Types::Response</tt> notion_response: Notion response object.
# * <tt>Read::Notion::Types::Response</tt> notion_response: Notion response object.
#
# <br>
# <b>return</b> <tt>List<Domain::Birthday></tt> birthdays_list, mapped birthdays to be used by a
Expand Down
18 changes: 10 additions & 8 deletions lib/bas/mapper/notion/pto_today.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ module Mapper
module Notion
##
# This class implementats the methods of the Mapper::Base module, specifically designed for preparing or
# shaping PTO's data coming from a Fetcher::Base implementation.
# shaping PTO's data coming from a Read::Base implementation.
#
class PtoToday
include Base

PTO_PARAMS = ["Person", "Desde?", "Hasta?"].freeze
PTO_PARAMS = ["Description", "Desde?", "Hasta?"].freeze

# Implements the logic for shaping the results from a fetcher response.
# Implements the logic for shaping the results from a reader response.
#
# <br>
# <b>Params:</b>
# * <tt>Fetcher::Notion::Types::Response</tt> notion_response: Notion response object.
# * <tt>Read::Notion::Types::Response</tt> notion_response: Notion response object.
#
# <br>
# <b>returns</b> <tt>List<Domain::Pto></tt> ptos_list, mapped PTO's to be used by a Formatter::Base
Expand All @@ -30,7 +30,7 @@ def map(notion_response)
normalized_notion_data = normalize_response(notion_response.results)

normalized_notion_data.map do |pto|
Domain::Pto.new(pto["Person"], pto["Desde?"], pto["Hasta?"])
Domain::Pto.new(pto["Description"], pto["Desde?"], pto["Hasta?"])
end
end

Expand All @@ -43,15 +43,17 @@ def normalize_response(response)
pto_fields = value["properties"].slice(*PTO_PARAMS)

{
"Person" => extract_person_field_value(pto_fields["Person"]),
"Description" => extract_description_field_value(pto_fields["Description"]),
"Desde?" => extract_date_field_value(pto_fields["Desde?"]),
"Hasta?" => extract_date_field_value(pto_fields["Hasta?"])
}
end
end

def extract_person_field_value(data)
data["people"][0]["name"]
def extract_description_field_value(data)
names = data["title"].map { |name| name["plain_text"] }

names.join(" ")
end

def extract_date_field_value(date)
Expand Down
6 changes: 3 additions & 3 deletions lib/bas/mapper/notion/work_items_limit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ module Mapper
module Notion
##
# This class implementats the methods of the Mapper::Base module, specifically designed
# for preparing or shaping work items data coming from a Fetcher::Base implementation.
# for preparing or shaping work items data coming from a Read::Base implementation.
class WorkItemsLimit
include Base

WORK_ITEM_PARAMS = ["Responsible domain"].freeze

# Implements the logic for shaping the results from a fetcher response.
# Implements the logic for shaping the results from a reader response.
#
# <br>
# <b>Params:</b>
# * <tt>Fetcher::Notion::Types::Response</tt> notion_response: Notion response object.
# * <tt>Read::Notion::Types::Response</tt> notion_response: Notion response object.
#
# <br>
# <b>return</b> <tt>List<Domain::WorkItem></tt> work_items_list, mapped work items to be used by a
Expand Down
6 changes: 3 additions & 3 deletions lib/bas/mapper/postgres/pto_today.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ module Mapper
module Postgres
##
# This class implementats the methods of the Mapper::Base module, specifically designed for preparing or
# shaping PTO's data coming from the Fetcher::Postgres::Pto class.
# shaping PTO's data coming from the Read::Postgres::Pto class.
#
class PtoToday
# Implements the logic for shaping the results from a fetcher response.
# Implements the logic for shaping the results from a reader response.
#
# <br>
# <b>Params:</b>
# * <tt>Fetcher::Postgres::Types::Response</tt> pg_response: Postgres response object.
# * <tt>Read::Postgres::Types::Response</tt> pg_response: Postgres response object.
#
# <br>
# <b>returns</b> <tt>List<Domain::Pto></tt> ptos_list, mapped PTO's to be used by a Formatter::Base
Expand Down
16 changes: 8 additions & 8 deletions lib/bas/fetcher/base.rb → lib/bas/read/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,41 @@

require_relative "../domain/exceptions/function_not_implemented"

module Fetcher
module Read
##
# The Fetcher::Base class serves as the foundation for implementing specific data fetchers within the Fetcher module.
# The Read::Base class serves as the foundation for implementing specific data readers within the Read module.
# Operating as an interface, this class defines essential attributes and methods, providing a blueprint for creating
# custom fetchers tailored to different data sources.
# custom readers tailored to different data sources.
#
class Base
attr_reader :config

# Initializes the fetcher with essential configuration parameters.
# Initializes the reader with essential configuration parameters.
#
def initialize(config)
@config = config
end

# A method meant to fetch data from an specific source depending on the implementation.
# A method meant to execute the read request from an specific source depending on the implementation.
# Must be overridden by subclasses, with specific logic based on the use case.
#
# <br>
# <b>raises</b> <tt>Domain::Exceptions::FunctionNotImplemented</tt> when missing implementation.
#
def fetch
def execute
raise Domain::Exceptions::FunctionNotImplemented
end

protected

# A method meant to execute the fetch request, retrieven the required data
# A method meant to read from the source, retrieven the required data
# from an specific filter configuration depending on the use case implementation.
# Must be overridden by subclasses, with specific logic based on the use case.
#
# <br>
# <b>raises</b> <tt>Domain::Exceptions::FunctionNotImplemented</tt> when missing implementation.
#
def execute
def read(*_filters)
raise Domain::Exceptions::FunctionNotImplemented
end
end
Expand Down
14 changes: 7 additions & 7 deletions lib/bas/fetcher/github/base.rb → lib/bas/read/github/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@
require_relative "../base"
require_relative "./types/response"

module Fetcher
module Read
module Github
##
# This class is an implementation of the Fetcher::Base interface, specifically designed
# for fetching data from a GitHub repository.
# This class is an implementation of the Read::Base interface, specifically designed
# for reading data from a GitHub repository.
#
class Base < Fetcher::Base
class Base < Read::Base
protected

# Implements the data fetching logic to get data from a Github repository.
# Implements the data reading logic to get data from a Github repository.
# It connects to Github using the octokit gem, authenticates with a github app,
# request the data and returns a validated response.
#
def execute(method, *filter)
def read(method, *filter)
octokit_response = octokit.public_send(method, *filter)

Fetcher::Github::Types::Response.new(octokit_response)
Read::Github::Types::Response.new(octokit_response)
end

private
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

module Fetcher
module Read
module Github
module Types
##
Expand Down
17 changes: 17 additions & 0 deletions lib/bas/read/github/use_case/repo_issues.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

require_relative "../base"

module Read
module Github
##
# This class is an implementation of the Read::Github::Base interface, specifically designed
# for reading issues from a Github repository.
#
class RepoIssues < Github::Base
def execute
read("list_issues", config[:repo])
end
end
end
end
Loading
Loading