Current section

Files

Jump to
bingex lib bingex user data get_referral.ex
Raw

lib/bingex/user/data/get_referral.ex

defmodule Bingex.User.Data.GetReferral do
@moduledoc """
Represents response content on `Bingex.User.get_referral` request.
"""
alias Bingex.API.Reply
alias Bingex.User.Model.ReferralInfo
defstruct [:referral]
@type t() :: %__MODULE__{
referral: ReferralInfo.t()
}
@spec embed_in_reply(Reply.t()) :: Reply.t(t())
def embed_in_reply(%Reply{payload: payload} = reply) do
case decode(payload) do
{:ok, data} -> Reply.put_data(reply, data)
:error -> reply
end
end
@spec decode(any()) :: {:ok, t()} | :error
def decode(%{"data" => data}) when is_map(data) do
with {:ok, referral} <- ReferralInfo.decode(data) do
{:ok, %__MODULE__{referral: referral}}
end
end
def decode(_data), do: :error
end