Packages
Elixir library to consume the public part REST API of FranceTélévisions Video Factory.
Retired package: Security issue - remove for privacy
Current section
Files
Jump to
Current section
Files
lib/client.ex
defmodule ExVideoFactory.Client do
use HTTPotion.Base
@moduledoc """
Documentation for ExVideoFactory.Client.
"""
require Logger
@prod_endpoint "https://gatewayvf.webservices.francetelevisions.fr/v1/"
@preprod_endpoint "https://gatewayvf.webservices.ftv-preprod.fr/v1/"
def process_url(url, options) do
case Application.get_env(:ex_video_factory, :mode, :prod) do
:preprod -> @preprod_endpoint <> url
:prod -> @prod_endpoint <> url
:custom ->
full_url =
case Application.get_env(:ex_video_factory, :endpoint) do
{:system, var} -> System.get_env(var)
key -> key
end
Logger.debug("#{full_url}#{url}")
full_url <> url
_ -> raise(ArgumentError, message: "invalid argument mode, valid are :prod or :preprod")
end
|> prepend_protocol
|> append_query_string(options)
end
defp prepend_protocol(url) do
if url =~ ~r/\Ahttps?:\/\// do
url
else
"http://" <> url
end
end
defp append_query_string(url, options) do
if options[:query] do
url <> "?#{URI.encode_query(options[:query])}"
else
url
end
end
def process_request_headers(headers) do
Keyword.put(headers, :Accept, "application/json")
end
def process_response_body(body) do
body
|> Poison.decode!()
end
end