refact: small refatcoring to improving coding standard
This commit is contained in:
parent
f74322d4d6
commit
53d84b6017
7 changed files with 39 additions and 91 deletions
|
@ -12,74 +12,3 @@ defmodule PodcastFeed do
|
|||
Archive.Parser.by_identifier(identifier)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# <item>
|
||||
# <title>Episode Name 2</title>
|
||||
# <link>
|
||||
# http://podcast.example.com/episode2.mp4
|
||||
# </link>
|
||||
# <pubDate>Sat, 02 Jan 2016 16:00:00 PDT</pubDate>
|
||||
# <description>
|
||||
# The full length episode 2 description
|
||||
# </description>
|
||||
# <enclosure url="http://podcasts.example.com/episode.mp4" length="36715125" type="audio/mpeg"/>
|
||||
# <guid>
|
||||
# http://podcast.example.com/episode2.mp4
|
||||
# </guid>
|
||||
# <itunes:duration>19:07</itunes:duration>
|
||||
# <itunes:summary>
|
||||
# The full length episode 2 description
|
||||
# </itunes:summary>
|
||||
# <itunes:image href="http://www.example.com/image3000x3000.png"/>
|
||||
# <itunes:keywords>
|
||||
# comma,separated,key,words
|
||||
# </itunes:keywords>
|
||||
# <itunes:explicit>no</itunes:explicit>
|
||||
# </item>
|
||||
|
||||
|
||||
# <?xml version="1.0" encoding="utf-8"?>
|
||||
# <rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:itunesu="http://www.itunesu.com/feed" version="2.0">
|
||||
# <channel>
|
||||
# <link>http://www.YourSite.com</link>
|
||||
# <language>en-us</language>
|
||||
# <copyright>©2013</copyright>
|
||||
# <webMaster>your@email.com (Your Name)</webMaster>
|
||||
# <managingEditor>your@email.com (Your Name)</managingEditor>
|
||||
# <image>
|
||||
# <url>http://www.YourSite.com/ImageSize300X300.jpg</url>
|
||||
# <title>Title or description of your logo</title>
|
||||
# <link>http://www.YourSite.com</link>
|
||||
# </image>
|
||||
# <itunes:owner>
|
||||
# <itunes:name>Your Name</itunes:name>
|
||||
# <itunes:email>your@email.com</itunes:email>
|
||||
# </itunes:owner>
|
||||
# <itunes:category text="Education">
|
||||
# <itunes:category text="Higher Education" />
|
||||
# </itunes:category>
|
||||
# <itunes:keywords>separate, by, comma, and, space</itunes:keywords>
|
||||
# <itunes:explicit>no</itunes:explicit>
|
||||
# <itunes:image href="http://www.YourSite.com/ImageSize300X300.jpg" />
|
||||
# <atom:link href="http://www.YourSite.com/feed.xml" rel="self" type="application/rss+xml" />
|
||||
# <pubDate>Sun, 01 Jan 2012 00:00:00 EST</pubDate>
|
||||
# <title>Verbose title of the podcast</title>
|
||||
# <itunes:author>College, school, or department owning the podcast</itunes:author>
|
||||
# <description>Verbose description of the podcast.</description>
|
||||
# <itunes:summary>Duplicate of above verbose description.</itunes:summary>
|
||||
# <itunes:subtitle>Short description of the podcast - 255 character max.</itunes:subtitle>
|
||||
# <lastBuildDate>Thu, 02 Feb 2012 00:00:00 EST</lastBuildDate>
|
||||
# <item>
|
||||
# <title>Verbose title of the episode</title>
|
||||
# <description>Verbose description of the episode.</description>
|
||||
# <itunes:summary>Duplicate of above verbose description.</itunes:summary>
|
||||
# <itunes:subtitle>Short description of the episode - 255 character max.</itunes:subtitle>
|
||||
# <itunesu:category itunesu:code="112" />
|
||||
# <enclosure url="http://www.YourSite.com/FILE.EXT" type="audio/mpeg" length="1" />
|
||||
# <guid>http://www.YourSite.com/FILE.EXT</guid>
|
||||
# <itunes:duration>H:MM:SS</itunes:duration>
|
||||
# <pubDate>Thu, 02 Feb 2012 00:00:00 EST</pubDate>
|
||||
# </item>
|
||||
# </channel>
|
||||
# </rss>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
# defmodule PodcastFeed.Repo do
|
||||
# # use Ecto.Repo,
|
||||
# # otp_app: :podcast_feed,
|
||||
# # adapter: Ecto.Adapters.Postgres
|
||||
# end
|
|
@ -1,4 +1,7 @@
|
|||
defmodule PodcastFeed.Utility.Format do
|
||||
@moduledoc """
|
||||
This module provides utility to format a string
|
||||
"""
|
||||
|
||||
def compile(subject, replacements) do
|
||||
replacements
|
25
mix.exs
25
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
|
||||
|
||||
|
|
5
mix.lock
5
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"},
|
||||
|
|
|
@ -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}
|
||||
|
|
Loading…
Reference in a new issue