Skip to content

Commit

Permalink
user
Browse files Browse the repository at this point in the history
  • Loading branch information
efcasado committed May 12, 2024
1 parent e836eac commit 155c3bb
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 29 deletions.
15 changes: 0 additions & 15 deletions lib/uof/api/mappings/bookmaker_details.ex

This file was deleted.

30 changes: 27 additions & 3 deletions lib/uof/api/users.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,39 @@ defmodule UOF.API.Users do
@moduledoc """
API used for administrative purposes.
"""
alias UOF.API.Utils.HTTP
use Ecto.Schema
import Ecto.Changeset
import UOF.API.EctoHelpers

@doc """
Get information about the token being used, including information such as
the caller's bookmaker id and when the caller's access token will expire.
"""
def whoami do
endpoint = ["users", "whoami.xml"]
case UOF.API.get("/users/whoami.xml") do
{:ok, %_{status: 200, body: resp}} ->
resp
|> Map.get("bookmaker_details")
|> changeset

HTTP.get(%UOF.API.Mappings.BookmakerDetails{}, endpoint)
{:error, _} = error ->
error
end
end

@primary_key false

embedded_schema do
field :expire_at, :string
field :bookmaker_id, :string
field :virtual_host, :string
end

def changeset(model \\ %__MODULE__{}, params) do
params = sanitize(params)

model
|> cast(params, [:expire_at, :bookmaker_id, :virtual_host])
|> apply
end
end
20 changes: 9 additions & 11 deletions test/uof/api/users_test.exs
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
defmodule UOF.API.Users.Test do
use ExUnit.Case
import Mock

# mock http requests towards Betradar and use recorded responses instead
setup_with_mocks([
{UOF.API.Utils.HTTP, [:passthrough],
[
get: fn schema, endpoint ->
data = File.read!("test/data/" <> Enum.at(endpoint, -1))
Saxaboom.parse(data, schema)
end
]}
]) do
setup do
:ok = Application.put_env(:tesla, UOF.API, adapter: Tesla.Mock)

Tesla.Mock.mock(fn
%{method: :get} ->
resp = File.read!("test/data/whoami.xml")
%Tesla.Env{status: 200, headers: [{"content-type", "application/xml"}], body: resp}
end)

:ok
end

Expand Down

0 comments on commit 155c3bb

Please sign in to comment.