Skip to content

Commit

Permalink
Refactor some class function size and names
Browse files Browse the repository at this point in the history
  • Loading branch information
L-Zuluaga committed Jan 15, 2024
1 parent a632a5c commit 04ac2ba
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 28 deletions.
7 changes: 1 addition & 6 deletions lib/bns/dispatcher/discord.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ def dispatch(payload)
content: payload
}.to_json

response = HTTParty.post(webhook, {
body: body,
headers: {
"Content-Type" => "application/json"
}
})
HTTParty.post(webhook, { body: body, headers: { "Content-Type" => "application/json" } })
end
end
end
2 changes: 1 addition & 1 deletion lib/bns/fetcher/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def fetch
raise "Not implemented yet."
end

def format_response(_response)
def normalize_response(_response)
raise "Not implemented yet."
end
end
Expand Down
47 changes: 26 additions & 21 deletions lib/bns/fetcher/birthday/notion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,48 @@ module Birthday
class Notion < Base
def fetch
url = "#{config[:base_url]}/v1/databases/#{config[:database_id]}/query"
headers = {
"Authorization" => "Bearer #{config[:secret]}",
"Content-Type" => "application/json",
"Notion-Version" => "2022-06-28"
}

response = HTTParty.post(url, {
body: config[:filter].to_json,
headers: {
"Authorization" => "Bearer #{config[:secret]}",
"Content-Type" => "application/json",
"Notion-Version" => "2022-06-28"
}
})
response = HTTParty.post(url, { body: config[:filter].to_json, headers: headers })

format_response(response["results"])
normalize_response(response["results"])
end

def format_response(response)
formatted_response = []
def normalize_response(response)
normalized_response = []

response.map do |value|
formatted_value = {}
properties = value["properties"]
properties.delete("Name")

properties.each do |k, v|
if k == "Full Name"
formatted_value["name"] = extract_rich_text_field_value(v)
else
formatted_value["birth_date"] = extract_date_field_value(v)
end
end
formatted_value = normalize(properties)

formatted_response.append(formatted_value)
normalized_response.append(formatted_value)
end

formatted_response
normalized_response
end

private

def normalize(properties)
normalized_value = {}

properties.each do |k, v|
if k == "Full Name"
normalized_value["name"] = extract_rich_text_field_value(v)
else
normalized_value["birth_date"] = extract_date_field_value(v)
end
end

normalized_value
end

def extract_rich_text_field_value(data)
data["rich_text"][0]["plain_text"]
end
Expand Down

0 comments on commit 04ac2ba

Please sign in to comment.