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 all 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}"]
]
26 changes: 0 additions & 26 deletions .github/workflows/vale.yml

This file was deleted.

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: 0 additions & 5 deletions .vale.ini

This file was deleted.

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
21 changes: 21 additions & 0 deletions lib/uof/api/competitors.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
defmodule UOF.API.Competitors do
use Ecto.Schema
import Ecto.Changeset
import UOF.API.EctoHelpers

def show(id, lang \\ "en") do
case UOF.API.get("/sports/#{lang}/competitors/#{id}/profile.xml") do
{:ok, %_{status: 200, body: resp}} ->
resp
|> UOF.API.Utils.xml_to_map()
|> Map.get("competitor_profile")
|> bubble_up("jerseys", "jersey")
|> bubble_up("players", "player")
|> UOF.API.Competitors.CompetitorProfile.changeset()
|> apply

{:error, _} = error ->
error
end
end
end
41 changes: 41 additions & 0 deletions lib/uof/api/competitors/competitor.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
defmodule UOF.API.Competitors.Competitor do
@moduledoc false
use Ecto.Schema
import Ecto.Changeset

@primary_key false

embedded_schema do
field :id
field :name
field :state
field :country
field :country_code
field :abbreviation
field :qualifier
field :virtual
field :gender
field :short_name
embeds_one :sport, UOF.API.Sports.Sport
embeds_one :category, UOF.API.Sports.Category
# embeds_many, :reference_id
end

def changeset(model \\ %__MODULE__{}, params) do
model
|> cast(params, [
:id,
:name,
:state,
:country,
:country_code,
:abbreviation,
:qualifier,
:virtual,
:gender,
:short_name
])
|> cast_embed(:sport)
|> cast_embed(:category)
end
end
25 changes: 25 additions & 0 deletions lib/uof/api/competitors/competitor_profile.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
defmodule UOF.API.Competitors.CompetitorProfile do
@moduledoc false
use Ecto.Schema
import Ecto.Changeset

@primary_key false

embedded_schema do
embeds_one :competitor, UOF.API.Competitors.Competitor
embeds_one :manager, UOF.API.Competitors.Manager
embeds_one :venue, UOF.API.Venues.Venue
embeds_many :jerseys, UOF.API.Competitors.Jersey
embeds_many :players, UOF.API.Players.Player
end

def changeset(model \\ %__MODULE__{}, params) do
model
|> cast(params, [])
|> cast_embed(:competitor)
|> cast_embed(:manager)
|> cast_embed(:venue)
|> cast_embed(:jerseys)
|> cast_embed(:players)
end
end
34 changes: 34 additions & 0 deletions lib/uof/api/competitors/jersey.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
defmodule UOF.API.Competitors.Jersey do
@moduledoc false
use Ecto.Schema
import Ecto.Changeset

@primary_key false

embedded_schema do
field :type
field :base
field :sleeve
field :number
field :stripes, :boolean
field :horizontal_stripes, :boolean
field :squares, :boolean
field :split, :boolean
field :shirt_type
end

def changeset(model \\ %__MODULE__{}, params) do
model
|> cast(params, [
:type,
:base,
:sleeve,
:number,
:stripes,
:horizontal_stripes,
:squares,
:split,
:shirt_type
])
end
end
24 changes: 24 additions & 0 deletions lib/uof/api/competitors/manager.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
defmodule UOF.API.Competitors.Manager do
@moduledoc false
use Ecto.Schema
import Ecto.Changeset

@primary_key false

embedded_schema do
field :id
field :name
field :country_code
field :nationality
end

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