Class: NameDotComApi::Client
- Inherits:
-
Object
- Object
- NameDotComApi::Client
- Defined in:
- lib/name_dot_com_api/client.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Instance Method Summary collapse
-
#check_domain(keyword, tlds = nil, services = nil) ⇒ Object
response = client.check_domain(‘example’) response = client.check_domain(‘example’, [ ‘com’, ‘net’, ‘org’ ], [ ‘availability’,‘suggested’ ]).
-
#create_dns_record(domain, hostname, type, content, ttl, priority = nil) ⇒ Object
(also: #add_dns_record)
response = client.create_dns_record(‘example.com’, ‘www’, ‘A’, ‘127.0.0.1’, 300) response = client.create_dns_record(‘example.com’, ‘mail’, ‘MX’, ‘mx3.name.com’, 300, 10).
-
#create_domain(domain, period = 1, nameservers = nil, contacts = nil) ⇒ Object
ns = [ ‘ns1.name.com’, ‘ns2.name.com’, ‘ns3.name.com’ ] response = client.create_domain(‘example.com’, 1, ns, [ { ‘type’ => [ ‘registrant’,‘administrative’,‘technical’,‘billing’ ], ‘first_name’ => ‘John’, ‘last_name’ => ‘Doe’, ‘organization’ => ‘Name.com’, ‘address_1’ => ‘125 Main St’, ‘address_2’ => ‘Suite 300’, ‘city’ => ‘Denver’, ‘state’ => ‘CO’, ‘zip’ => ‘80230’, ‘country’ => ‘US’, ‘phone’ => ‘+1.3035555555’, ‘fax’ => ‘+1.3035555556’, ‘email’ => ‘[email protected]’ } ]).
-
#delete_dns_record(domain, record_id) ⇒ Object
(also: #remove_dns_record)
response = client.delete_dns_record(‘example.com’, 1234).
-
#get_account ⇒ Object
response = client.get_account.
-
#get_domain(domain) ⇒ Object
response = client.get_domain(‘example.com’).
-
#hello ⇒ Object
response = client.hello.
-
#initialize(username, api_token, test_mode = false) ⇒ Client
constructor
A new instance of Client.
-
#list_dns_records(domain) ⇒ Object
response = client.list_dns_records(‘example.com’).
-
#list_domains ⇒ Object
response = client.list_domains.
-
#lock_domain(domain) ⇒ Object
response = client.lock_domain(‘example.com’).
-
#login(username, api_token) ⇒ Object
response = client.login(username, api_token).
-
#logout ⇒ Object
response = client.logout.
-
#unlock_domain(domain) ⇒ Object
response = client.unlock_domain(‘example.com’).
-
#update_domain_contacts(domain, contacts = []) ⇒ Object
response = client.update_domain_contacts(‘mynewdomain.com’, [ { ‘type’ => [ ‘registrant’,‘administrative’,‘technical’,‘billing’ ], ‘first_name’ => ‘John’, ‘last_name’ => ‘Doe’, ‘organization’ => ‘Name.com’, ‘address_1’ => ‘125 Main St’, ‘address_2’ => ‘Suite 300’, ‘city’ => ‘Denver’, ‘state’ => ‘CO’, ‘zip’ => ‘80230’, ‘country’ => ‘US’, ‘phone’ => ‘+1.3035555555’, ‘fax’ => ‘+1.3035555556’, ‘email’ => ‘[email protected]’ } ]).
-
#update_domain_nameservers(domain, nameservers = {}) ⇒ Object
response = client.update_domain_nameservers(‘example.com’, [ ‘ns1.name.com’, ‘ns2.name.com’, ‘ns3.name.com’ ]).
Constructor Details
#initialize(username, api_token, test_mode = false) ⇒ Client
Returns a new instance of Client.
7 8 9 10 11 |
# File 'lib/name_dot_com_api/client.rb', line 7 def initialize(username, api_token, test_mode = false) @connection ||= Connection.new @connection.test_mode = test_mode login username, api_token end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
5 6 7 |
# File 'lib/name_dot_com_api/client.rb', line 5 def connection @connection end |
Instance Method Details
#check_domain(keyword, tlds = nil, services = nil) ⇒ Object
response = client.check_domain(‘example’) response = client.check_domain(‘example’, [ ‘com’, ‘net’, ‘org’ ], [ ‘availability’,‘suggested’ ])
109 110 111 112 113 114 115 |
# File 'lib/name_dot_com_api/client.rb', line 109 def check_domain(keyword, tlds = nil, services = nil) connection.post '/domain/power_check', { 'keyword' => keyword, 'tlds' => tlds || [ 'com' ], # ,'net','org','info','us','biz','tel' ], 'services' => services || [ 'availability' ] # ,'suggested' ] } end |
#create_dns_record(domain, hostname, type, content, ttl, priority = nil) ⇒ Object Also known as: add_dns_record
response = client.create_dns_record(‘example.com’, ‘www’, ‘A’, ‘127.0.0.1’, 300) response = client.create_dns_record(‘example.com’, ‘mail’, ‘MX’, ‘mx3.name.com’, 300, 10)
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/name_dot_com_api/client.rb', line 89 def create_dns_record(domain, hostname, type, content, ttl, priority = nil) body = { 'hostname' => hostname, 'type' => type, 'content' => content, 'ttl' => ttl } body.update!(:priority => priority) if priority connection.post "/dns/create/#{domain}", body end |
#create_domain(domain, period = 1, nameservers = nil, contacts = nil) ⇒ Object
ns = [ ‘ns1.name.com’, ‘ns2.name.com’, ‘ns3.name.com’ ] response = client.create_domain(‘example.com’, 1, ns, [
{ 'type' => [ 'registrant','administrative','technical','billing' ],
'first_name' => 'John',
'last_name' => 'Doe',
'organization' => 'Name.com',
'address_1' => '125 Main St',
'address_2' => 'Suite 300',
'city' => 'Denver',
'state' => 'CO',
'zip' => '80230',
'country' => 'US',
'phone' => '+1.3035555555',
'fax' => '+1.3035555556',
'email' => '[email protected]'
}
])
134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/name_dot_com_api/client.rb', line 134 def create_domain(domain, period = 1, nameservers = nil, contacts = nil) = { 'domain_name' => domain, 'period' => period, 'nameservers' => nameservers, 'contacts' => contacts, 'username' => connection.username } .delete('nameservers') unless nameservers .delete('contacts') unless contacts connection.post '/domain/create', end |
#delete_dns_record(domain, record_id) ⇒ Object Also known as: remove_dns_record
response = client.delete_dns_record(‘example.com’, 1234)
102 103 104 |
# File 'lib/name_dot_com_api/client.rb', line 102 def delete_dns_record(domain, record_id) connection.post "/dns/delete/#{domain}", { :record_id => record_id } end |
#get_account ⇒ Object
response = client.get_account
36 37 38 |
# File 'lib/name_dot_com_api/client.rb', line 36 def get_account connection.get '/account/get' end |
#get_domain(domain) ⇒ Object
response = client.get_domain(‘example.com’)
148 149 150 |
# File 'lib/name_dot_com_api/client.rb', line 148 def get_domain(domain) connection.get "/domain/get/#{domain}" end |
#hello ⇒ Object
response = client.hello
31 32 33 |
# File 'lib/name_dot_com_api/client.rb', line 31 def hello connection.get '/hello' end |
#list_dns_records(domain) ⇒ Object
response = client.list_dns_records(‘example.com’)
83 84 85 |
# File 'lib/name_dot_com_api/client.rb', line 83 def list_dns_records(domain) connection.get "/dns/list/#{domain}" end |
#list_domains ⇒ Object
response = client.list_domains
41 42 43 |
# File 'lib/name_dot_com_api/client.rb', line 41 def list_domains connection.get "/domain/list/#{connection.username}" end |
#lock_domain(domain) ⇒ Object
response = client.lock_domain(‘example.com’)
73 74 75 |
# File 'lib/name_dot_com_api/client.rb', line 73 def lock_domain(domain) connection.get "/domain/lock/#{domain}" end |
#login(username, api_token) ⇒ Object
response = client.login(username, api_token)
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/name_dot_com_api/client.rb', line 14 def login(username, api_token) raise "You are already logged in" if @connection.logged_in? @connection.username ||= username @connection.api_token ||= api_token connection.post '/login', { :username => @connection.username, :api_token => @connection.api_token } end |
#logout ⇒ Object
response = client.logout
26 27 28 |
# File 'lib/name_dot_com_api/client.rb', line 26 def logout connection.get '/logout' end |
#unlock_domain(domain) ⇒ Object
response = client.unlock_domain(‘example.com’)
78 79 80 |
# File 'lib/name_dot_com_api/client.rb', line 78 def unlock_domain(domain) connection.get "/domain/unlock/#{domain}" end |
#update_domain_contacts(domain, contacts = []) ⇒ Object
response = client.update_domain_contacts(‘mynewdomain.com’, [
{ 'type' => [ 'registrant','administrative','technical','billing' ],
'first_name' => 'John',
'last_name' => 'Doe',
'organization' => 'Name.com',
'address_1' => '125 Main St',
'address_2' => 'Suite 300',
'city' => 'Denver',
'state' => 'CO',
'zip' => '80230',
'country' => 'US',
'phone' => '+1.3035555555',
'fax' => '+1.3035555556',
'email' => '[email protected]'
}
])
68 69 70 |
# File 'lib/name_dot_com_api/client.rb', line 68 def update_domain_contacts(domain, contacts = []) connection.post "/domain/update_contacts/#{domain}", { :contacts => contacts } end |
#update_domain_nameservers(domain, nameservers = {}) ⇒ Object
response = client.update_domain_nameservers(‘example.com’, [
'ns1.name.com', 'ns2.name.com', 'ns3.name.com'
])
48 49 50 |
# File 'lib/name_dot_com_api/client.rb', line 48 def update_domain_nameservers(domain, nameservers = {}) connection.post "/domain/update_nameservers/#{domain}", { :nameservers => nameservers } end |