-
Notifications
You must be signed in to change notification settings - Fork 0
refactor!: introduce opinionated api #33
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
Draft
efcasado
wants to merge
34
commits into
main
Choose a base branch
from
feat-tesla-ecto
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
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 a2f828e
remove dead code
efcasado 6adb7ca
update tests
efcasado 23edcf7
remove dead code
efcasado 082d200
void reasons
efcasado 14e6794
producers
efcasado 45e0576
markets
efcasado 7521fe0
variant
efcasado ae51cfe
import ecto into formatter
efcasado 0e34d89
remove dead code
efcasado b12c416
remove typed_ecto_schema
efcasado 18a99c0
standardize
efcasado db39955
standardize
efcasado a89a487
standardize
efcasado c69b89a
remove dead code
efcasado 867141e
remove dead code
efcasado 7f30d08
remove dead code
efcasado e836eac
skip from documentation
efcasado 155c3bb
user
efcasado e7b2678
sport categories
efcasado 93422ad
sports
efcasado 9c927db
use saxy simpleform
efcasado a48d460
players
efcasado d58e0a2
schedules
efcasado c54044b
venues
efcasado f17d8bd
competitors
efcasado f92dab2
dead code
efcasado 79b8e69
dead code
efcasado e942767
dead code
efcasado 2c15c5e
fixtures
efcasado 3896d9d
remove vale job
efcasado 39dd3b4
fixtures
efcasado e8b5515
dead code
efcasado 78424fe
remove vale config
efcasado File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| # Used by "mix format" | ||
| [ | ||
| import_deps: [:ecto], | ||
| inputs: ["{mix,.formatter}.exs", "{config,lib,test,examples}/**/*.{ex,exs}"] | ||
| ] |
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -13,4 +13,6 @@ erl_crash.dump | |
| hex.config | ||
| *.ez | ||
| uof_messages-*.tar | ||
| *~ | ||
| *~ | ||
| \#* | ||
| .\#* | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,5 @@ | ||
| import Config | ||
|
|
||
| config :uof_api, | ||
| base_url: "https://localhost", | ||
| auth_token: "a-secret-goes-here" |
This file contains hidden or 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,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 |
This file contains hidden or 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,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 |
This file contains hidden or 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,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 |
This file contains hidden or 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,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 |
This file contains hidden or 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,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 |
This file contains hidden or 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,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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.