Packages

An Elixir client for Betradar's Unified Odds Feed (UOF) API

Current section

Files

Jump to
uof_api lib uof api utils http.ex
Raw

lib/uof/api/utils/http.ex

defmodule UOF.API.Utils.HTTP do
@moduledoc false
import Logger
def get(schema, path, params \\ []) do
base_url = Application.get_env(:uof_api, :base_url)
auth_token = Application.get_env(:uof_api, :auth_token)
url = Enum.join([base_url | path], "/")
response =
Req.get!(url,
headers: %{"x-access-token" => auth_token},
params: params
).body
debug("response=#{response}")
case Application.get_env(:uof_api, :parse, true) do
true ->
Saxaboom.parse(response, schema)
false ->
response
end
end
def post(schema, path, body) do
base_url = Application.get_env(:uof_api, :base_url)
auth_token = Application.get_env(:uof_api, :auth_token)
url = Enum.join([base_url | path], "/")
Logger.debug(body)
response =
Req.post!(url,
headers: %{
"x-access-token" => auth_token,
"content-type" => "application/xml",
"accept" => "application/xml"
},
body: body
).body
debug("response=#{response}")
case Application.get_env(:uof_api, :parse, true) do
true ->
Saxaboom.parse(response, schema)
false ->
response
end
end
end