Class: ApiClients::NamecheapClient
- Inherits:
-
Object
- Object
- ApiClients::NamecheapClient
- Includes:
- HTTParty
- Defined in:
- lib/api_clients/namecheap_client.rb
Overview
A client for interacting with the Namecheap XML API. Currently supports checking domain availability.
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#api_user ⇒ Object
readonly
Returns the value of attribute api_user.
-
#client_ip ⇒ Object
readonly
Returns the value of attribute client_ip.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
-
#check_domain(domain) ⇒ Object
Public: Check if a domain is available for registration.
-
#initialize ⇒ NamecheapClient
constructor
A new instance of NamecheapClient.
Constructor Details
#initialize ⇒ NamecheapClient
Returns a new instance of NamecheapClient.
14 15 16 17 18 19 |
# File 'lib/api_clients/namecheap_client.rb', line 14 def initialize @api_user = ENV.fetch('NAMECHEAP_API_USER') @api_key = ENV.fetch('NAMECHEAP_API_KEY') @username = ENV.fetch('NAMECHEAP_USERNAME') @client_ip = ENV.fetch('CLIENT_IP') end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
12 13 14 |
# File 'lib/api_clients/namecheap_client.rb', line 12 def api_key @api_key end |
#api_user ⇒ Object (readonly)
Returns the value of attribute api_user.
12 13 14 |
# File 'lib/api_clients/namecheap_client.rb', line 12 def api_user @api_user end |
#client_ip ⇒ Object (readonly)
Returns the value of attribute client_ip.
12 13 14 |
# File 'lib/api_clients/namecheap_client.rb', line 12 def client_ip @client_ip end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
12 13 14 |
# File 'lib/api_clients/namecheap_client.rb', line 12 def username @username end |
Instance Method Details
#check_domain(domain) ⇒ Object
Public: Check if a domain is available for registration.
domain - A String domain name to check (e.g., “example.com”).
Returns true if the domain is available, false otherwise.
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/api_clients/namecheap_client.rb', line 26 def check_domain(domain) response = make_request( command: 'namecheap.domains.check', params: { DomainList: domain } ) available = response.dig('ApiResponse', 'CommandResponse', 'DomainCheckResult', 'Available') available == 'true' rescue StandardError => e warn "Error checking domain '#{domain}': #{e.}" false end |