Current section
Files
Jump to
Current section
Files
lib/epik.ex
defmodule Epik do
@moduledoc """
Simple functions for interacting with the [Epik v2 API][1].
[1]: https://docs.userapi.epik.com/v2/
"""
@doc """
Check the status of domain names, including their price and availability.
```elixir
iex(1)> Epik.check_domains(["tribes.host", "fediverse.gold"])
{:ok,
%HTTPoison.Response{
status_code: 200,
body: %{
"code" => 1000,
"data" => %{
"FEDIVERSE.GOLD" => %{
"available" => 1,
"domain" => "FEDIVERSE.GOLD",
"premium" => 0,
"price" => 5.49,
"supported" => 1
},
"TRIBES.HOST" => %{
"available" => 0,
"available_reason" => "in use",
"domain" => "TRIBES.HOST",
"premium" => 0,
"supported" => 1
}
},
"message" => "Command completed successfully."
}
}}
```
"""
@spec check_domains(domains :: [String.t()]) :: {:ok, HTTPoison.Response.t()} | {:error, any()}
def check_domains(domains) when is_list(domains) do
params = %{"DOMAINS" => Enum.join(domains, ",")}
Epik.Client.get("/v2/domains/check", params)
end
@doc """
Register a domain.
```elixir
iex(1)> Epik.register_domain("fedigold.xyz", 1)
{:ok,
%HTTPoison.Response{
status_code: 200,
body: %{
"code" => 1000,
"data" => %{
"FEDIGOLD.XYZ" => %{
"error" => 0,
"message" => "Successfully created",
"payment" => %{
"error" => 0,
"paymentStatus" => true,
"paymentValue" => 0.99,
"period" => "1",
"pricePerPeriod" => 0.99
},
"paymentStatus" => true,
"paymentValue" => 0.99,
"period" => "1",
"pricePerPeriod" => 0.99
}
},
"message" => "Command completed successfully.",
"period" => "1",
"total" => %{
"amount" => 0.99,
"message" => "Withdraw money successfully",
"method" => "Balance",
"success" => true
}
}
}}
```
"""
@spec register_domain(domain :: String.t(), years :: integer()) ::
{:ok, HTTPoison.Response.t()} | {:error, any()}
def register_domain(domain, years)
when is_binary(domain) and is_integer(years) do
domain = URI.encode(domain)
body = %{"PERIOD" => years}
Epik.Client.post("/v2/domains/#{domain}/create", body)
end
end