-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: auto generate badges on homepage (#5)
## Features - Database and Configuration: - Use DATABASE_URL if available, otherwise use config (c95f4fd) - Badge Management: - Always center badges in display (6b0ef20) - Filter and remove expired badges (d2064ce) - Send badges to frontend (f0d1548) - Iterate over badges (aa8f6e9) - Implement logic to fetch JSON of all user badges from Credly (3d4be31) - HTTP Requests: - Add HTTPoison for handling HTTP requests (0dc1318) ## Documentation - Blog: - Add documentation for fetching posts (71307f3)
- Loading branch information
1 parent
3fe1dc8
commit 7835e8b
Showing
7 changed files
with
121 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
defmodule Portfolio.Credly do | ||
def fetch_data do | ||
headers = [{"Accept", "application/json"}] | ||
|
||
case HTTPoison.get( | ||
"https://www.credly.com/users/tristan-jahnke/badges", | ||
headers | ||
) do | ||
{:ok, | ||
%HTTPoison.Response{ | ||
status_code: 200, | ||
body: body | ||
}} -> | ||
data = Jason.decode!(body) | ||
filtered_data = filter_expired_badges(data["data"]) | ||
{:ok, %{"data" => filtered_data}} | ||
|
||
{:error, _} -> | ||
{:error, "Failed to get Credly badges."} | ||
end | ||
end | ||
|
||
defp filter_expired_badges(badges) do | ||
Enum.filter(badges, fn badge -> | ||
expires_at = badge["expires_at"] | ||
|
||
if expires_at == nil or | ||
NaiveDateTime.compare(NaiveDateTime.from_iso8601!(expires_at), NaiveDateTime.utc_now()) == | ||
:gt do | ||
true | ||
else | ||
false | ||
end | ||
end) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,19 @@ | ||
defmodule Portfolio.Repo do | ||
require Logger | ||
|
||
use Ecto.Repo, | ||
otp_app: :portfolio, | ||
adapter: Ecto.Adapters.Postgres | ||
|
||
def init(_type, config) do | ||
database_url = System.get_env("DATABASE_URL") | ||
|
||
if database_url == nil do | ||
Logger.debug("$DATABASE_URL not set, using config") | ||
{:ok, config} | ||
else | ||
Logger.debug("Configuring database using $DATABASE_URL") | ||
{:ok, Keyword.put(config, :url, database_url)} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters