Class: ApiClients::NamecheapClient

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeNamecheapClient

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_keyObject (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_userObject (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_ipObject (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

#usernameObject (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.message}"
  false
end