Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: introduce opinionated api #33

Draft
wants to merge 34 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
c4e31f7
refactor!: introduce opinionated api
efcasado May 10, 2024
a2f828e
remove dead code
efcasado May 11, 2024
6adb7ca
update tests
efcasado May 11, 2024
23edcf7
remove dead code
efcasado May 11, 2024
082d200
void reasons
efcasado May 11, 2024
14e6794
producers
efcasado May 11, 2024
45e0576
markets
efcasado May 11, 2024
7521fe0
variant
efcasado May 11, 2024
ae51cfe
import ecto into formatter
efcasado May 11, 2024
0e34d89
remove dead code
efcasado May 11, 2024
b12c416
remove typed_ecto_schema
efcasado May 11, 2024
18a99c0
standardize
efcasado May 11, 2024
db39955
standardize
efcasado May 11, 2024
a89a487
standardize
efcasado May 12, 2024
c69b89a
remove dead code
efcasado May 12, 2024
867141e
remove dead code
efcasado May 12, 2024
7f30d08
remove dead code
efcasado May 12, 2024
e836eac
skip from documentation
efcasado May 12, 2024
155c3bb
user
efcasado May 12, 2024
e7b2678
sport categories
efcasado May 12, 2024
93422ad
sports
efcasado May 12, 2024
9c927db
use saxy simpleform
efcasado May 20, 2024
a48d460
players
efcasado May 25, 2024
d58e0a2
schedules
efcasado May 25, 2024
c54044b
venues
efcasado May 25, 2024
f17d8bd
competitors
efcasado May 25, 2024
f92dab2
dead code
efcasado May 25, 2024
79b8e69
dead code
efcasado May 25, 2024
e942767
dead code
efcasado May 25, 2024
2c15c5e
fixtures
efcasado May 26, 2024
3896d9d
remove vale job
efcasado May 26, 2024
39dd3b4
fixtures
efcasado May 26, 2024
e8b5515
dead code
efcasado May 26, 2024
78424fe
remove vale config
efcasado May 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .formatter.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Used by "mix format"
[
import_deps: [:ecto],
inputs: ["{mix,.formatter}.exs", "{config,lib,test,examples}/**/*.{ex,exs}"]
]
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ erl_crash.dump
hex.config
*.ez
uof_messages-*.tar
*~
*~
\#*
.\#*
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
Elixir client for Betradar's Unified Odds Feed (UOF) HTTP API.
efcasado marked this conversation as resolved.
Show resolved Hide resolved

This project implements Betradar's Custom Bet, Probability, Recovery and Sports
efcasado marked this conversation as resolved.
Show resolved Hide resolved
APIs, which can be found in the `UOF.API.{CustomBet, Probability, Recovery,
Sports}` modules, respectively.
APIs.
efcasado marked this conversation as resolved.
Show resolved Hide resolved


## Get Started
Expand All @@ -36,7 +35,7 @@ to use.
Fetch all available fixtures.

```elixir
fixtures = UOF.API.Sports.fixtures
{:ok, fixtures} = UOF.API.Fixtures.all()
```

Given a list fixtures, count how many of them there are.
Expand Down
5 changes: 5 additions & 0 deletions config/test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Config

config :uof_api,
base_url: "https://localhost",
auth_token: "a-secret-goes-here"
125 changes: 125 additions & 0 deletions lib/uof/api.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
defmodule UOF.API do
@moduledoc """
Utilities used by the different APIs implemented by this client.
"""
use Tesla, only: [:get, :post], docs: false

plug(Tesla.Middleware.BaseUrl, Application.get_env(:uof_api, :base_url))

plug(Tesla.Middleware.Headers, [
{"accept", "application/xml"},
{"content-type", "application/xml"},
{"x-access-token", Application.get_env(:uof_api, :auth_token)}
])

# plug(Tesla.Middleware.XML, convention: BadgerFish)
plug(Tesla.Middleware.XML, engine: Saxy)

# https://docs.betradar.com/display/BD/UOF+-+Language+Support
@supported_languages [
# Albanian
"sqi",
# Amharic
"am",
# Arabic
"aa",
# Azerbaijan
"aze",
# Bosnian
"bs",
# Brazilian Portuguese
"br",
# Bulgarian
"bg",
# Burmese
"my",
# Chinese (simplified)
"zh",
# Chinese (traditional)
"zht",
# Croation
"hr",
# Czech
"cs",
# Danish
"da",
# Dutch
"nl",
# English
"en",
# Estonian
"et",
# Finnish
"fi",
# French
"fr",
# Georgian
"ka",
# German
"de",
# Greek
"el",
# Hebrew
"heb",
# Hindi
"hi",
# Hungarian
"hu",
# Indonesian
"Id",
# Italian
"it",
# Japanese
"ja",
# Kazakh
"kaz",
# Khmer
"km",
# Korean
"ko",
# Latvian
"lv",
# Lithuanian
"lt",
# Macedonian
"ml",
# Macedonian Cyrillic
"mk",
# Malay
"ms",
# Norwegian
"no",
# Persian/Farsi
"fa",
# Polish
"pl",
# Portuguese
"pt",
# Romanian
"ro",
# Russian
"ru",
# Serbian
"sr",
# Serbian Latin
"srl",
# Slovak
"sk",
# Slovenian
"sl",
# Spanish
"es",
# Swahili
"sw",
# Swedish
"se",
# Thai
"th",
# Turkish
"tr",
# Ukrainian
"ukr",
# Vietnamese
"vi"
]
end
2 changes: 2 additions & 0 deletions lib/uof/api/competitors.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
defmodule UOF.API.Competitors do
end
69 changes: 0 additions & 69 deletions lib/uof/api/descriptions.ex

This file was deleted.

142 changes: 142 additions & 0 deletions lib/uof/api/descriptions/bet_stop.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
defmodule UOF.API.Descriptions.BetStop do
@moduledoc """
`BetStop` messages are used to indicate that all, or a set of markets should
be instantly suspended (continue to display odds, but don't accept tickets).

`BetStop` messages are sent very rapidly, as soon as a Betradar operator
detects an issue. At the time the `BetStop` is sent, the cause is not always
available (typically not for live matches). The cause of the `BetStop` is
provided in a subsequent `OddsChange` message.
"""
use Ecto.Schema
import Ecto.Changeset
import UOF.API.EctoHelpers

@doc """
List all supported bet stop reasons.
"""
@spec all() :: list(BetStop.t())
def all() do
case UOF.API.get("/descriptions/betstop_reasons.xml") do
{:ok, %_{status: 200, body: resp}} ->
resp
|> UOF.API.Utils.xml_to_map()
|> Map.get("betstop_reasons_descriptions")
|> Map.get("betstop_reason")
|> 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(:description, Ecto.Enum,
values: [
:UNKNOWN,
:POSSIBLE_GOAL,
:POSSIBLE_RED_CARD,
:SCOUT_LOST,
:POSSIBLE_GOAL_HOME,
:POSSIBLE_GOAL_AWAY,
:POSSIBLE_RED_CARD_HOME,
:POSSIBLE_RED_CARD_AWAY,
:POSSIBLE_PENALTY,
:POSSIBLE_PENALTY_HOME,
:POSSIBLE_PENALTY_AWAY,
:CONNECTED_TO_SUPERVISOR,
:MATCH_ENDED,
:GAMEPOINT,
:TIEBREAK,
:POSSIBLE_DIRECT_FOUL_HOME,
:POSSIBLE_DIRECT_FOUL_AWAY,
:POSSIBLE_DIRECT_FOUL,
:DANGEROUS_FREE_KICK_HOME,
:DANGEROUS_FREE_KICK_AWAY,
:DANGEROUS_GOAL_POSITION_HOME,
:DANGEROUS_GOAL_POSITION_AWAY,
:GOAL_UNDER_REVIEW,
:SCORE_UNDER_REVIEW,
:DISCONNECTION,
:POSSIBLE_CHECKOUT,
:MULTIPLE_SUSPENSIONS,
:POSSIBLE_DANGEROUS_FREE_KICK,
:POSSIBLE_DANGEROUS_GOAL_POSITION,
:POSSIBLE_TOUCHDOWN_HOME,
:POSSIBLE_TOUCHDOWN_AWAY,
:POSSIBLE_FIELDGOAL_HOME,
:POSSIBLE_FIELDGOAL_AWAY,
:POSSIBLE_SAFETY_HOME,
:POSSIBLE_SAFETY_AWAY,
:POSSIBLE_TURNOVER_HOME,
:POSSIBLE_TURNOVER_AWAY,
:VIDEO_REVIEW,
:REDZONE_HOME,
:REDZONE_AWAY,
:POSSIBLE_BOUNDARY,
:POSSIBLE_WICKET,
:POSSIBLE_CHALLENGE_HOME,
:POSSIBLE_CHALLENGE_AWAY,
:POSSIBLE_TURNOVER,
:UNKNOWN_OPERATOR,
:FREEBALL,
:DEEP_BALL,
:POSSIBLE_RUN,
:MAINTENANCE,
:BASE_HIT_DELETED,
:MATCH_DELAYED,
:MATCH_POSTPONED,
:SCOUT_DISCONNECTION_TV_SIGNAL,
:POSSIBLE_PENALTY_OFFSETTING,
:POSSIBLE_PUNT_HOME,
:POSSIBLE_PUNT_AWAY,
:POSSIBLE_FOURTH_DOWN_ATTEMPT_HOME,
:POSSIBLE_FOURTH_DOWN_ATTEMPT_AWAY,
:POSSIBLE_ONSIDE_KICK_HOME,
:POSSIBLE_ONSIDE_KICK_AWAY,
:POSSIBLE_CHALLENGE,
:POSSIBLE_CARD,
:DELAYED_PENALTY,
:SHOOTOUT_BEGINS,
:EMPTY_NET,
:POSSIBLE_TRY_HOME,
:POSSIBLE_TRY_AWAY,
:POSSIBLE_DROP_GOAL_HOME,
:POSSIBLE_DROP_GOAL_AWAY,
:POSSIBLE_CARD_HOME,
:POSSIBLE_CARD_AWAY,
:POSSIBLE_PENALTY_HOME_HOCKEY,
:POSSIBLE_PENALTY_AWAY_HOCKEY,
:DELAYED_PENALTY_HOME_HOCKEY,
:DELAYED_PENALTY_AWAY_HOCKEY,
:TWO_MAN_ADVANTAGE_HOME,
:TWO_MAN_ADVANTAGE_AWAY,
:POSSIBLE_FIELD_GOAL,
:ROLLBACK_EVENT,
:POSSIBLE_DROP_KICK_HOME,
:POSSIBLE_DROP_KICK_AWAY,
:POSSIBLE_DROP_KICK,
:POSSIBLE_VIDEO_ASSISTANT_REFEREE,
:FEED_INTERRUPTION,
:POSSIBLE_SCORE,
:POSSIBLE_SCORE_HOME,
:POSSIBLE_SCORE_AWAY,
:POSSIBLE_VIDEO_ASSISTANT_REFEREE_HOME,
:POSSIBLE_VIDEO_ASSISTANT_REFEREE_AWAY
]
)
end

def changeset(model \\ %__MODULE__{}, params) do
model
|> cast(params, [:id, :description])
|> apply
end
end
Loading
Loading