Skip to content

Commit

Permalink
feat: add UOF.API.variants/{0, 1}
Browse files Browse the repository at this point in the history
  • Loading branch information
efcasado committed Apr 27, 2024
1 parent 8144ad2 commit 5cac1bc
Show file tree
Hide file tree
Showing 8 changed files with 7,619 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/uof/api/mappings/outcome.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule UOF.API.Mappings.Outcome do
use Saxaboom.Mapper

document do
attribute(:id, cast: :integer)
attribute(:id)
attribute(:name)
end
end
9 changes: 9 additions & 0 deletions lib/uof/api/mappings/outcome_mapping.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
defmodule UOF.API.Mappings.OutcomeMapping do
use Saxaboom.Mapper

document do
attribute(:outcome_id)
attribute(:product_outcome_id)
attribute(:product_outcome_name)
end
end
14 changes: 14 additions & 0 deletions lib/uof/api/mappings/outcome_mappings.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
defmodule UOF.API.Mappings.OutcomeMappings do
use Saxaboom.Mapper

alias UOF.API.Mappings.OutcomeMapping

document do
attribute(:product_id, cast: :integer)
attribute(:product_ids)
attribute(:sport_id)
attribute(:market_id, cast: :integer)
attribute(:product_market_id)
elements(:mapping_outcome, as: :outcome_mappings, into: %OutcomeMapping{})
end
end
11 changes: 11 additions & 0 deletions lib/uof/api/mappings/variant.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
defmodule UOF.API.Mappings.Variant do
use Saxaboom.Mapper

alias UOF.API.Mappings.{OutcomeMappings, Outcome}

document do
attribute(:id)
elements(:outcome, as: :outcomes, into: %Outcome{})
elements(:mapping, as: :mappings, into: %OutcomeMappings{})
end
end
9 changes: 9 additions & 0 deletions lib/uof/api/mappings/variant_descriptions.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
defmodule UOF.API.Mappings.VariantDescriptions do
use Saxaboom.Mapper

alias UOF.API.Mappings.Variant

document do
elements(:variant, as: :variants, into: %Variant{})
end
end
9 changes: 9 additions & 0 deletions lib/uof_api.ex
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ defmodule UOF.API do
HTTP.get(endpoint, %UOF.API.Mappings.BettingStatusDescriptions{})
end

@doc """
Get a list of all variants and which markets they are used for.
"""
def variants(lang \\ "en") do
endpoint = ["descriptions", lang, "variants.xml"]

HTTP.get(endpoint, %UOF.API.Mappings.VariantDescriptions{})
end

@doc """
Describe all currently avbailable producers and their ids.
"""
Expand Down
7,538 changes: 7,538 additions & 0 deletions test/data/variants.xml

Large diffs are not rendered by default.

29 changes: 28 additions & 1 deletion test/uof_api_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ defmodule UOF.API.Test do
assert market.id == 282
assert market.name == "Innings 1 to 5th top - {$competitor1} total"
assert market.groups == "all|score|4.5_innings"
assert Enum.map(market.outcomes, & &1.id) == [13, 12]
assert Enum.map(market.outcomes, & &1.id) == ["13", "12"]
end

test "can parse 'descriptions/:lang/match_status.xml' response" do
Expand Down Expand Up @@ -99,6 +99,33 @@ defmodule UOF.API.Test do
assert reason.description == "OTHER"
end

test "can parse 'descriptions/:lang/variants.xml' response" do
data = File.read!("test/data/variants.xml")

{:ok, %UOF.API.Mappings.VariantDescriptions{variants: variants}} =
Saxaboom.parse(data, %UOF.API.Mappings.VariantDescriptions{})

assert Enum.count(variants) == 144
variant = hd(variants)
assert variant.id == "sr:correct_score:after:4"
assert Enum.count(variant.outcomes) == 5
outcome = hd(variant.outcomes)
assert outcome.id == "sr:correct_score:after:4:1530"
assert outcome.name == "4:0"
assert Enum.count(variant.mappings) == 1
mapping = hd(variant.mappings)
assert mapping.product_id == 3
assert mapping.product_ids == "3"
assert mapping.sport_id == "sr:sport:22"
assert mapping.market_id == 1262
assert mapping.product_market_id == "960"
assert Enum.count(mapping.outcome_mappings) == 5
outcome_mapping = hd(mapping.outcome_mappings)
assert outcome_mapping.outcome_id == "sr:correct_score:after:4:1530"
assert outcome_mapping.product_outcome_id == "26"
assert outcome_mapping.product_outcome_name == "4:0"
end

test "can parse 'descriptions/producers.xml' response" do
data = File.read!("test/data/producers.xml")

Expand Down

0 comments on commit 5cac1bc

Please sign in to comment.