Class: NamecheapClient
- Inherits:
-
Object
- Object
- NamecheapClient
- Defined in:
- lib/namecheap-client.rb
Overview
require ‘pry’
Constant Summary collapse
- API_URL =
'https://api.namecheap.com/xml.response'
Instance Method Summary collapse
-
#add_dns_record(domain, record_type, host_name, address, ttl = '1800') ⇒ Object
Add DNS record to a domain.
-
#initialize(api_user:, api_key:, username:, client_ip:) ⇒ NamecheapClient
constructor
A new instance of NamecheapClient.
-
#list_domains ⇒ Object
List all domains in the account.
-
#remove_dns_record(domain, record_type, host_name) ⇒ Object
Remove DNS record from a domain.
Constructor Details
#initialize(api_user:, api_key:, username:, client_ip:) ⇒ NamecheapClient
Returns a new instance of NamecheapClient.
9 10 11 12 13 14 |
# File 'lib/namecheap-client.rb', line 9 def initialize(api_user:, api_key:, username:, client_ip:) @api_user = api_user @api_key = api_key @username = username @client_ip = client_ip end |
Instance Method Details
#add_dns_record(domain, record_type, host_name, address, ttl = '1800') ⇒ Object
Add DNS record to a domain
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/namecheap-client.rb', line 27 def add_dns_record(domain, record_type, host_name, address, ttl = '1800') # First, get existing records existing_records = get_dns_records(domain) # Add the new record existing_records << { 'Type' => record_type, 'Name' => host_name, 'Address' => address, 'TTL' => ttl } # Set the records set_dns_records(domain, existing_records) end |
#list_domains ⇒ Object
List all domains in the account
17 18 19 20 21 22 23 24 |
# File 'lib/namecheap-client.rb', line 17 def list_domains params = { 'Command' => 'namecheap.domains.getList', 'PageSize' => '100' } response = make_request(params) parse_domain_list(response) end |
#remove_dns_record(domain, record_type, host_name) ⇒ Object
Remove DNS record from a domain
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/namecheap-client.rb', line 44 def remove_dns_record(domain, record_type, host_name) # Get existing records existing_records = get_dns_records(domain) # Remove the specified record(s) updated_records = existing_records.reject do |record| record['Type'] == record_type && record['Name'] == host_name end # Set the updated records set_dns_records(domain, updated_records) end |