Namecheap Elixir
Elixir client library for interacting with the Namecheap API.
The goal of this library is to facilitate the creation and management of domains. We do not plan to implement all features (but merge requests are welcome).
iex(1)> Namecheap.check_domains(["tribes.host", "us.xyz"])
{:ok,
[
%Namecheap.DomainCheckResult{
available: false,
description: "",
domain: "tribes.host",
eap_fee: #Decimal<0>,
error_no: "0",
icann_fee: #Decimal<0>,
is_premium: false,
premium_registration_price: #Decimal<0>,
premium_renewal_price: #Decimal<0>,
premium_restore_price: #Decimal<0>,
premium_transfer_price: #Decimal<0>
},
%Namecheap.DomainCheckResult{
available: true,
description: "",
domain: "us.xyz",
eap_fee: #Decimal<0.0>,
error_no: "0",
icann_fee: #Decimal<0>,
is_premium: true,
premium_registration_price: #Decimal<13000.0>,
premium_renewal_price: #Decimal<13000.0>,
premium_restore_price: #Decimal<65.0>,
premium_transfer_price: #Decimal<13000.0>
}
]}
About the Namecheap API
The Namecheap API has a single endpoint:
https://api.namecheap.com/xml.response
All requests go through this one endpoint, using query strings to perform different operations. All responses return XML data in a structured format.
There is not a 1:1 representation of XML in Elixir. The closest thing we have is structs, but that can't discern attributes from content inside the tags. As a result, this library creates abstractions over the XML entities returned by Namecheap, representing them as structs in a native format.
Requests are a bit easier because query params can be represented as maps. Namecheap never requires you to send data in the request body, so we only ever need to parse XML from the response, never build it.
GET and POST work the same for all API operations, but the Namecheap docs recommends using POST for some operations, so we just use POST throughout the library.
Installation
The package can be installed
by adding namecheap
to your list of dependencies in mix.exs
:
def deps do
[
{:namecheap, "~> 0.1.0"}
]
end
Configuration
You will then need to configure Namecheap for your application.
import Config
config :namecheap,
api_user: "example",
api_key: "********************************",
endpoint: "https://api.namecheap.com/xml.response"
Supported options
api_user
(required): Username of your Namecheap account.api_key
(required): API key generated from your Namecheap account.endpoint
(required): The endpoint to use for requests. You should set this to Namecheap's production endpoint in production, and their sandbox endpoint in development. There is no default for safety reasons.user_name
(optional): Username on which each command is executed. Defaults to the value ofapi_user
.client_ip
(optional): Nobody knows the purpose of this, but Namecheap requires it with every request. We pass the loopback address127.0.0.1
by default, but feel free to override it.parser
(optional): AnyFloki.HTMLParser
compatible parser module. Defaults toNamecheap.Parser
.
License
Namecheap Elixir is licensed under the MIT license.
See LICENSE.md
for a full copy of the license.