-
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.
- Loading branch information
Showing
8 changed files
with
101 additions
and
67 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# https://docs.betradar.com/display/BD/UOF+-+Producers | ||
defmodule UOF.API.Descriptions.Producer do | ||
@moduledoc """ | ||
Unified Odds Feed handles data from multiple sources, which are called | ||
odds or message producers. | ||
""" | ||
use Ecto.Schema | ||
import Ecto.Changeset | ||
import UOF.API.EctoHelpers | ||
|
||
@doc """ | ||
List all available producers. | ||
""" | ||
@spec all() :: list(VoidReason.t()) | ||
def all() do | ||
case UOF.API.get("/descriptions/producers.xml") do | ||
{:ok, %_{status: 200, body: resp}} -> | ||
resp | ||
|> Map.get("producers") | ||
|> Map.get("producer") | ||
|> Enum.map(fn x -> | ||
{:ok, x} = changeset(x) | ||
x | ||
end) | ||
|
||
{:error, _} = error -> | ||
error | ||
end | ||
end | ||
|
||
@primary_key false | ||
|
||
embedded_schema do | ||
field(:id, :integer) | ||
field(:name, :string) | ||
field(:description, :string) | ||
field(:api_url, :string) | ||
field(:active, :boolean) | ||
field(:scope, {:array, Ecto.Enum}, values: [:live, :prematch, :virtual]) | ||
field(:stateful_recovery_window_in_minutes, :integer) | ||
end | ||
|
||
def changeset(model \\ %__MODULE__{}, params) do | ||
model | ||
|> cast(prepare(params), [ | ||
:id, | ||
:name, | ||
:description, | ||
:api_url, | ||
:active, | ||
:scope, | ||
:stateful_recovery_window_in_minutes | ||
]) | ||
|> case do | ||
%Ecto.Changeset{valid?: true} = changeset -> | ||
{:ok, apply_changes(changeset)} | ||
|
||
%Ecto.Changeset{} = changeset -> | ||
{:error, {params, traverse_errors(changeset)}} | ||
end | ||
end | ||
|
||
defp prepare(params) do | ||
params | ||
|> rename_fields | ||
|> prepare_scope | ||
end | ||
|
||
defp prepare_scope(params) do | ||
scope = String.split(params["scope"], "|") | ||
Map.put(params, "scope", scope) | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,28 @@ | ||
defmodule UOF.API.Descriptions.Producer.Test do | ||
use ExUnit.Case | ||
|
||
setup do | ||
:ok = Application.put_env(:tesla, UOF.API, adapter: Tesla.Mock) | ||
|
||
Tesla.Mock.mock(fn | ||
%{method: :get} -> | ||
resp = File.read!("test/data/producers.xml") | ||
%Tesla.Env{status: 200, headers: [{"content-type", "application/xml"}], body: resp} | ||
end) | ||
|
||
:ok | ||
end | ||
|
||
test "can parse UOF.API.Descriptions.Producer.all/0 response" do | ||
resp = UOF.API.Descriptions.Producer.all() | ||
|
||
assert Enum.count(resp) == 15 | ||
assert hd(resp).id == 1 | ||
assert hd(resp).name == "LO" | ||
assert hd(resp).description == "Live Odds" | ||
assert hd(resp).api_url == "https://stgapi.betradar.com/v1/liveodds/" | ||
assert hd(resp).active == true | ||
assert hd(resp).scope == [:live] | ||
assert hd(resp).stateful_recovery_window_in_minutes == 600 | ||
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