Current section
Files
Jump to
Current section
Files
lib/api_brasil/data/loterias.ex
defmodule ApiBrasil.Data.Loterias do
@moduledoc """
Loterias (device-based): `POST /loterias/{sorteio}/*`.
O `sorteio` é o nome do jogo (ex: `megasena`, `lotofacil`, `quina`).
{:ok, envelope} = ApiBrasil.Data.Loterias.latest(client, "megasena")
ApiBrasil.Core.DeviceResponse.response(envelope)
{:ok, _concurso} = ApiBrasil.Data.Loterias.resultado(client, "megasena", 2700)
"""
use ApiBrasil.Core.Service
@doc "Consulta um concurso: `POST /loterias/{sorteio}/{concurso}`."
@spec resultado(Client.t(), String.t(), integer() | String.t(), term(), keyword()) ::
{:ok, DeviceResponse.t()} | {:error, Error.t()}
def resultado(client, sorteio, concurso, body \\ nil, opts \\ []) do
path = "loterias/#{Service.encode_path(sorteio)}/#{Service.encode_path(concurso)}"
with {:ok, json} <- Service.post(client, path, body, opts) do
{:ok, DeviceResponse.new(json)}
end
end
@doc "Como `resultado/5`, mas levanta `ApiBrasil.Core.Error` em caso de falha."
@spec resultado!(Client.t(), String.t(), integer() | String.t(), term(), keyword()) ::
DeviceResponse.t()
def resultado!(client, sorteio, concurso, body \\ nil, opts \\ []) do
Service.unwrap!(resultado(client, sorteio, concurso, body, opts))
end
@doc "Consulta o último resultado: `POST /loterias/{sorteio}/latest`."
@spec latest(Client.t(), String.t(), term(), keyword()) ::
{:ok, DeviceResponse.t()} | {:error, Error.t()}
def latest(client, sorteio, body \\ nil, opts \\ []) do
path = "loterias/#{Service.encode_path(sorteio)}/latest"
with {:ok, json} <- Service.post(client, path, body, opts) do
{:ok, DeviceResponse.new(json)}
end
end
@doc "Como `latest/4`, mas levanta `ApiBrasil.Core.Error` em caso de falha."
@spec latest!(Client.t(), String.t(), term(), keyword()) :: DeviceResponse.t()
def latest!(client, sorteio, body \\ nil, opts \\ []) do
Service.unwrap!(latest(client, sorteio, body, opts))
end
end