From 53d84b60178d1c947362b1de2665f753626484fb Mon Sep 17 00:00:00 2001 From: danilo silva Date: Sat, 6 Jun 2020 10:32:51 +0000 Subject: [PATCH] refact: small refatcoring to improving coding standard --- lib/podcast_feed.ex | 71 ------------------- lib/podcast_feed/provider/archive/parser.ex | 15 ++-- lib/podcast_feed/repo.ex | 5 -- .../{Utility/Format.ex => utility/format.ex} | 5 +- mix.exs | 25 +++++-- mix.lock | 5 ++ .../provider/archive/parser_test.exs | 4 +- 7 files changed, 39 insertions(+), 91 deletions(-) delete mode 100644 lib/podcast_feed/repo.ex rename lib/podcast_feed/{Utility/Format.ex => utility/format.ex} (76%) diff --git a/lib/podcast_feed.ex b/lib/podcast_feed.ex index 2afd95a..3d2609b 100644 --- a/lib/podcast_feed.ex +++ b/lib/podcast_feed.ex @@ -12,74 +12,3 @@ defmodule PodcastFeed do Archive.Parser.by_identifier(identifier) end end - - -# -# Episode Name 2 -# -# http://podcast.example.com/episode2.mp4 -# -# Sat, 02 Jan 2016 16:00:00 PDT -# -# The full length episode 2 description -# -# -# -# http://podcast.example.com/episode2.mp4 -# -# 19:07 -# -# The full length episode 2 description -# -# -# -# comma,separated,key,words -# -# no -# - - -# -# -# -# http://www.YourSite.com -# en-us -# ©2013 -# your@email.com (Your Name) -# your@email.com (Your Name) -# -# http://www.YourSite.com/ImageSize300X300.jpg -# Title or description of your logo -# http://www.YourSite.com -# -# -# Your Name -# your@email.com -# -# -# -# -# separate, by, comma, and, space -# no -# -# -# Sun, 01 Jan 2012 00:00:00 EST -# Verbose title of the podcast -# College, school, or department owning the podcast -# Verbose description of the podcast. -# Duplicate of above verbose description. -# Short description of the podcast - 255 character max. -# Thu, 02 Feb 2012 00:00:00 EST -# -# Verbose title of the episode -# Verbose description of the episode. -# Duplicate of above verbose description. -# Short description of the episode - 255 character max. -# -# -# http://www.YourSite.com/FILE.EXT -# H:MM:SS -# Thu, 02 Feb 2012 00:00:00 EST -# -# -# diff --git a/lib/podcast_feed/provider/archive/parser.ex b/lib/podcast_feed/provider/archive/parser.ex index 8afcc6d..d992180 100644 --- a/lib/podcast_feed/provider/archive/parser.ex +++ b/lib/podcast_feed/provider/archive/parser.ex @@ -1,4 +1,9 @@ defmodule PodcastFeed.Provider.Archive.Parser do + @moduledoc """ + This module provides a public API for fetching data from archive.org and convert them + in a common podcast data structures. + """ + alias PodcastFeed.Utility.Format alias __MODULE__ @@ -79,15 +84,15 @@ defmodule PodcastFeed.Provider.Archive.Parser do custom_metadata_json |> String.split("\n") |> Enum.join() - |> Poison.decode!() + |> Jason.decode!() end defp parse_custom_metadata_response(_), do: @custom_metadata_defaults defp fetch_archive_metadata(identifier) do metadata_url = Format.compile(@archive_metadata_url, identifier: identifier) - {:ok, 200, _headers, client_ref} = :hackney.get(metadata_url, [], "", [follow_redirect: true, connect_timeout: 30000, recv_timeout: 30000]) + {:ok, 200, _headers, client_ref} = :hackney.get(metadata_url, [], "", [follow_redirect: true, connect_timeout: 30_000, recv_timeout: 30_000]) {:ok, metadata_json} = :hackney.body(client_ref) - metadata_json |> Poison.decode!() + metadata_json |> Jason.decode!() end defp filter_audio_files(files) do @@ -144,11 +149,11 @@ defmodule PodcastFeed.Provider.Archive.Parser do end defp enrich_with_archive_metadata(token) do - %Parser{ token | archive_metadata: fetch_archive_metadata(token.identifier) } + %Parser{token | archive_metadata: fetch_archive_metadata(token.identifier)} end defp enrich_with_custom_metadata(token) do - %Parser{ token | custom_metadata: fetch_custom_metadata(token.identifier) } + %Parser{token | custom_metadata: fetch_custom_metadata(token.identifier)} end end diff --git a/lib/podcast_feed/repo.ex b/lib/podcast_feed/repo.ex deleted file mode 100644 index db6e953..0000000 --- a/lib/podcast_feed/repo.ex +++ /dev/null @@ -1,5 +0,0 @@ -# defmodule PodcastFeed.Repo do -# # use Ecto.Repo, -# # otp_app: :podcast_feed, -# # adapter: Ecto.Adapters.Postgres -# end diff --git a/lib/podcast_feed/Utility/Format.ex b/lib/podcast_feed/utility/format.ex similarity index 76% rename from lib/podcast_feed/Utility/Format.ex rename to lib/podcast_feed/utility/format.ex index 1b7d0a7..84561e3 100644 --- a/lib/podcast_feed/Utility/Format.ex +++ b/lib/podcast_feed/utility/format.ex @@ -1,7 +1,10 @@ defmodule PodcastFeed.Utility.Format do + @moduledoc """ + This module provides utility to format a string + """ def compile(subject, replacements) do replacements |> Enum.reduce(subject, fn {replacement_key, replacement_value}, subject -> String.replace(subject, "{#{replacement_key}}", replacement_value) end) end -end \ No newline at end of file +end diff --git a/mix.exs b/mix.exs index 1a014e8..96116a7 100644 --- a/mix.exs +++ b/mix.exs @@ -5,12 +5,14 @@ defmodule PodcastFeed.MixProject do [ app: :podcast_feed, version: "0.1.0", - elixir: "~> 1.7", + elixir: "~> 1.10", elixirc_paths: elixirc_paths(Mix.env()), compilers: [:phoenix, :gettext] ++ Mix.compilers(), + test_coverage: [tool: ExCoveralls], + preferred_cli_env: [coveralls: :test, e2e: :test, "coveralls.html": :test], start_permanent: Mix.env() == :prod, aliases: aliases(), - deps: deps() + deps: deps(), ] end @@ -34,9 +36,6 @@ defmodule PodcastFeed.MixProject do defp deps do [ {:phoenix, "~> 1.5.3"}, - # {:phoenix_ecto, "~> 4.1"}, - # {:ecto_sql, "~> 3.4"}, - # {:postgrex, ">= 0.0.0"}, {:phoenix_html, "~> 2.11"}, {:phoenix_live_reload, "~> 1.2", only: :dev}, {:phoenix_live_dashboard, "~> 0.2.0"}, @@ -47,9 +46,21 @@ defmodule PodcastFeed.MixProject do {:plug_cowboy, "~> 2.0"}, {:elixir_xml_to_map, "~> 1.0"}, {:calendar, "~> 1.0.0"}, - {:distillery, "~> 2.0"}, - {:poison, "~> 3.1"}, {:hackney, "~> 1.15"}, + ] ++ deps_dev() ++ deps_release() + end + + defp deps_dev do + [ + {:credo, "~> 1.4", only: [:dev, :test], runtime: false}, + {:dialyxir, "~> 1.0", only: [:dev], runtime: false}, + {:excoveralls, "~> 0.7", only: [:dev, :test]} + ] + end + + defp deps_release do + [ + {:distillery, "~> 2.0"} ] end diff --git a/mix.lock b/mix.lock index 0cfdc71..0dbd8e1 100644 --- a/mix.lock +++ b/mix.lock @@ -1,17 +1,22 @@ %{ "artificery": {:hex, :artificery, "0.4.3", "0bc4260f988dcb9dda4b23f9fc3c6c8b99a6220a331534fdf5bf2fd0d4333b02", [:mix], [], "hexpm", "12e95333a30e20884e937abdbefa3e7f5e05609c2ba8cf37b33f000b9ffc0504"}, + "bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm", "7af5c7e09fe1d40f76c8e4f9dd2be7cebd83909f31fee7cd0e9eadc567da8353"}, "calendar": {:hex, :calendar, "1.0.0", "f52073a708528482ec33d0a171954ca610fe2bd28f1e871f247dc7f1565fa807", [:mix], [{:tzdata, "~> 0.5.20 or ~> 0.1.201603 or ~> 1.0", [hex: :tzdata, repo: "hexpm", optional: false]}], "hexpm", "990e9581920c82912a5ee50e62ff5ef96da6b15949a2ee4734f935fdef0f0a6f"}, "certifi": {:hex, :certifi, "2.5.1", "867ce347f7c7d78563450a18a6a28a8090331e77fa02380b4a21962a65d36ee5", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm", "805abd97539caf89ec6d4732c91e62ba9da0cda51ac462380bbd28ee697a8c42"}, "connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], [], "hexpm", "4a0850c9be22a43af9920a71ab17c051f5f7d45c209e40269a1938832510e4d9"}, "cowboy": {:hex, :cowboy, "2.7.0", "91ed100138a764355f43316b1d23d7ff6bdb0de4ea618cb5d8677c93a7a2f115", [:rebar3], [{:cowlib, "~> 2.8.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "~> 1.7.1", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "04fd8c6a39edc6aaa9c26123009200fc61f92a3a94f3178c527b70b767c6e605"}, "cowlib": {:hex, :cowlib, "2.8.0", "fd0ff1787db84ac415b8211573e9a30a3ebe71b5cbff7f720089972b2319c8a4", [:rebar3], [], "hexpm", "79f954a7021b302186a950a32869dbc185523d99d3e44ce430cd1f3289f41ed4"}, + "credo": {:hex, :credo, "1.4.0", "92339d4cbadd1e88b5ee43d427b639b68a11071b6f73854e33638e30a0ea11f5", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "1fd3b70dce216574ce3c18bdf510b57e7c4c85c2ec9cad4bff854abaf7e58658"}, "db_connection": {:hex, :db_connection, "2.2.2", "3bbca41b199e1598245b716248964926303b5d4609ff065125ce98bcd368939e", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm", "642af240d8a8affb93b4ba5a6fcd2bbcbdc327e1a524b825d383711536f8070c"}, "decimal": {:hex, :decimal, "1.8.1", "a4ef3f5f3428bdbc0d35374029ffcf4ede8533536fa79896dd450168d9acdf3c", [:mix], [], "hexpm", "3cb154b00225ac687f6cbd4acc4b7960027c757a5152b369923ead9ddbca7aec"}, + "dialyxir": {:hex, :dialyxir, "1.0.0", "6a1fa629f7881a9f5aaf3a78f094b2a51a0357c843871b8bc98824e7342d00a5", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "aeb06588145fac14ca08d8061a142d52753dbc2cf7f0d00fc1013f53f8654654"}, "distillery": {:hex, :distillery, "2.1.1", "f9332afc2eec8a1a2b86f22429e068ef35f84a93ea1718265e740d90dd367814", [:mix], [{:artificery, "~> 0.2", [hex: :artificery, repo: "hexpm", optional: false]}], "hexpm", "bbc7008b0161a6f130d8d903b5b3232351fccc9c31a991f8fcbf2a12ace22995"}, "ecto": {:hex, :ecto, "3.4.4", "a2c881e80dc756d648197ae0d936216c0308370332c5e77a2325a10293eef845", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "cc4bd3ad62abc3b21fb629f0f7a3dab23a192fca837d257dd08449fba7373561"}, "ecto_sql": {:hex, :ecto_sql, "3.4.4", "d28bac2d420f708993baed522054870086fd45016a9d09bb2cd521b9c48d32ea", [:mix], [{:db_connection, "~> 2.2", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.4.3", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.3.0 or ~> 0.4.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.15.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.0", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "edb49af715dd72f213b66adfd0f668a43c17ed510b5d9ac7528569b23af57fe8"}, "elixir_xml_to_map": {:hex, :elixir_xml_to_map, "1.0.1", "8eaac89644e033f472e19f66a88288a3e36a621cf695a7fd323a1dc481b15c15", [:mix], [{:erlsom, "~>1.4", [hex: :erlsom, repo: "hexpm", optional: false]}], "hexpm", "630e61fc23496c0981e6e605f5505bd477d29c2449d929453e1a762aa364fa99"}, + "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"}, "erlsom": {:hex, :erlsom, "1.5.0", "c5a5cdd0ee0e8dca62bcc4b13ff08da24fdefc16ccd8b25282a2fda2ba1be24a", [:rebar3], [], "hexpm", "55a9dbf9cfa77fcfc108bd8e2c4f9f784dea228a8f4b06ea10b684944946955a"}, + "excoveralls": {:hex, :excoveralls, "0.12.3", "2142be7cb978a3ae78385487edda6d1aff0e482ffc6123877bb7270a8ffbcfe0", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "568a3e616c264283f5dea5b020783ae40eef3f7ee2163f7a67cbd7b35bcadada"}, "file_system": {:hex, :file_system, "0.2.8", "f632bd287927a1eed2b718f22af727c5aeaccc9a98d8c2bd7bff709e851dc986", [:mix], [], "hexpm", "97a3b6f8d63ef53bd0113070102db2ce05352ecf0d25390eb8d747c2bde98bca"}, "gettext": {:hex, :gettext, "0.18.0", "406d6b9e0e3278162c2ae1de0a60270452c553536772167e2d701f028116f870", [:mix], [], "hexpm", "c3f850be6367ebe1a08616c2158affe4a23231c70391050bf359d5f92f66a571"}, "hackney": {:hex, :hackney, "1.15.2", "07e33c794f8f8964ee86cebec1a8ed88db5070e52e904b8f12209773c1036085", [:rebar3], [{:certifi, "2.5.1", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "6.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.5", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm", "e0100f8ef7d1124222c11ad362c857d3df7cb5f4204054f9f0f4a728666591fc"}, diff --git a/test/podcast_feed/provider/archive/parser_test.exs b/test/podcast_feed/provider/archive/parser_test.exs index 0274e8c..49e55c9 100644 --- a/test/podcast_feed/provider/archive/parser_test.exs +++ b/test/podcast_feed/provider/archive/parser_test.exs @@ -9,8 +9,8 @@ defmodule PodcastFeed.Provider.Archive.ParserTest do token = %Parser{ identifier: "incontri-a-piano-terra", - archive_metadata: Poison.decode!(json_metadata), - custom_metadata: Poison.decode!(json_custom), + archive_metadata: Jason.decode!(json_metadata), + custom_metadata: Jason.decode!(json_custom), } {:ok, token: token}