Class: Dnsimple::Client
- Inherits:
-
Object
- Object
- Dnsimple::Client
- Includes:
- Compatibility
- Defined in:
- lib/dnsimple/client.rb,
lib/dnsimple/client/users.rb,
lib/dnsimple/client/clients.rb,
lib/dnsimple/client/domains.rb,
lib/dnsimple/client/contacts.rb,
lib/dnsimple/client/services.rb,
lib/dnsimple/client/registrar.rb,
lib/dnsimple/client/templates.rb,
lib/dnsimple/client/certificates.rb,
lib/dnsimple/client/name_servers.rb,
lib/dnsimple/client/domains_zones.rb,
lib/dnsimple/client/domains_privacy.rb,
lib/dnsimple/client/domains_records.rb,
lib/dnsimple/client/domains_sharing.rb,
lib/dnsimple/client/domains_forwards.rb,
lib/dnsimple/client/services_domains.rb,
lib/dnsimple/client/templates_domains.rb,
lib/dnsimple/client/templates_records.rb,
lib/dnsimple/client/domains_autorenewal.rb,
lib/dnsimple/client/vanity_name_servers.rb
Overview
Client for the DNSimple API
Defined Under Namespace
Modules: Certificates, Contacts, Domains, DomainsAutorenewal, DomainsForwards, DomainsPrivacy, DomainsRecords, DomainsSharing, DomainsZones, NameServers, Registrar, Services, ServicesDomains, Templates, TemplatesDomains, TemplatesRecords, Users, VanityNameServers Classes: CertificatesService, ClientService, ContactsService, DomainsService, NameServersService, RegistrarService, ServicesService, TemplatesService, UsersService
Constant Summary collapse
- HEADER_2FA_STRICT =
"X-DNSimple-2FA-Strict"
- HEADER_API_TOKEN =
"X-DNSimple-Token"
- HEADER_DOMAIN_API_TOKEN =
"X-DNSimple-Domain-Token"
- HEADER_OTP_TOKEN =
"X-DNSimple-OTP"
- HEADER_EXCHANGE_TOKEN =
"X-DNSimple-OTP-Token"
- API_VERSION =
Returns The current API version.
"v1"
Instance Attribute Summary collapse
-
#api_endpoint ⇒ String
Base URL for API requests.
-
#api_token ⇒ String
API access token for authentication.
-
#domain_api_token ⇒ String
Domain API access token for authentication.
-
#exchange_token ⇒ String
Exchange Token for Basic Authentication with 2FA.
-
#password ⇒ String
DNSimple password for Basic Authentication.
-
#proxy ⇒ String?
Configure address:port values for proxy server.
-
#user_agent ⇒ String
Configure User-Agent header for requests.
-
#username ⇒ String
DNSimple username for Basic Authentication.
Class Method Summary collapse
-
.versioned(path) ⇒ String
Prepends the correct API version to
path
.
Instance Method Summary collapse
-
#certificates ⇒ Dnsimple::Client::CertificatesService
The certificate-related API proxy.
-
#contacts ⇒ Dnsimple::Client::ContactsService
The contact-related API proxy.
-
#delete(path, options = {}) ⇒ HTTParty::Response
Make a HTTP DELETE request.
-
#domains ⇒ Dnsimple::Client::DomainsService
The domain-related API proxy.
-
#execute(method, path, data, options = {}) ⇒ HTTParty::Response
Executes a request, validates and returns the response.
-
#get(path, options = {}) ⇒ HTTParty::Response
Make a HTTP GET request.
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
-
#name_servers ⇒ Dnsimple::Client::NameServersService
The name server-related API proxy.
-
#post(path, options = {}) ⇒ HTTParty::Response
Make a HTTP POST request.
-
#put(path, options = {}) ⇒ HTTParty::Response
Make a HTTP PUT request.
-
#registrar ⇒ Dnsimple::Client::RegistrarService
The registrar-related API proxy.
-
#request(method, path, data, options = {}) ⇒ HTTParty::Response
Make a HTTP request.
-
#services ⇒ Dnsimple::Client::ServicesService
The service-related API proxy.
-
#templates ⇒ Dnsimple::Client::TemplatesService
The template-related API proxy.
-
#users ⇒ Dnsimple::Client::UsersService
The user-related API proxy.
Methods included from Compatibility
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
58 59 60 61 62 63 64 65 66 |
# File 'lib/dnsimple/client.rb', line 58 def initialize( = {}) defaults = Dnsimple::Default. Dnsimple::Default.keys.each do |key| instance_variable_set(:"@#{key}", [key] || defaults[key]) end @services = {} end |
Instance Attribute Details
#api_endpoint ⇒ String
Returns Base URL for API requests.
54 55 56 |
# File 'lib/dnsimple/client.rb', line 54 def api_endpoint @api_endpoint end |
#api_token ⇒ String
Returns API access token for authentication.
54 55 |
# File 'lib/dnsimple/client.rb', line 54 attr_accessor :api_endpoint, :username, :password, :exchange_token, :api_token, :domain_api_token, :user_agent, :proxy |
#domain_api_token ⇒ String
Returns Domain API access token for authentication.
54 55 |
# File 'lib/dnsimple/client.rb', line 54 attr_accessor :api_endpoint, :username, :password, :exchange_token, :api_token, :domain_api_token, :user_agent, :proxy |
#exchange_token ⇒ String
Returns Exchange Token for Basic Authentication with 2FA.
54 55 |
# File 'lib/dnsimple/client.rb', line 54 attr_accessor :api_endpoint, :username, :password, :exchange_token, :api_token, :domain_api_token, :user_agent, :proxy |
#password ⇒ String
Returns DNSimple password for Basic Authentication.
54 55 |
# File 'lib/dnsimple/client.rb', line 54 attr_accessor :api_endpoint, :username, :password, :exchange_token, :api_token, :domain_api_token, :user_agent, :proxy |
#proxy ⇒ String?
Returns Configure address:port values for proxy server.
54 55 |
# File 'lib/dnsimple/client.rb', line 54 attr_accessor :api_endpoint, :username, :password, :exchange_token, :api_token, :domain_api_token, :user_agent, :proxy |
#user_agent ⇒ String
Returns Configure User-Agent header for requests.
54 55 |
# File 'lib/dnsimple/client.rb', line 54 attr_accessor :api_endpoint, :username, :password, :exchange_token, :api_token, :domain_api_token, :user_agent, :proxy |
#username ⇒ String
Returns DNSimple username for Basic Authentication.
54 55 |
# File 'lib/dnsimple/client.rb', line 54 attr_accessor :api_endpoint, :username, :password, :exchange_token, :api_token, :domain_api_token, :user_agent, :proxy |
Class Method Details
.versioned(path) ⇒ String
Prepends the correct API version to path
.
28 29 30 |
# File 'lib/dnsimple/client.rb', line 28 def self.versioned(path) File.join(API_VERSION, path) end |
Instance Method Details
#certificates ⇒ Dnsimple::Client::CertificatesService
Returns The certificate-related API proxy.
5 6 7 |
# File 'lib/dnsimple/client/clients.rb', line 5 def certificates @services[:certificates] ||= Client::CertificatesService.new(self) end |
#contacts ⇒ Dnsimple::Client::ContactsService
Returns The contact-related API proxy.
10 11 12 |
# File 'lib/dnsimple/client/clients.rb', line 10 def contacts @services[:contacts] ||= Client::ContactsService.new(self) end |
#delete(path, options = {}) ⇒ HTTParty::Response
Make a HTTP DELETE request.
101 102 103 |
# File 'lib/dnsimple/client.rb', line 101 def delete(path, = {}) execute :delete, path, end |
#domains ⇒ Dnsimple::Client::DomainsService
Returns The domain-related API proxy.
15 16 17 |
# File 'lib/dnsimple/client/clients.rb', line 15 def domains @services[:domains] ||= Client::DomainsService.new(self) end |
#execute(method, path, data, options = {}) ⇒ HTTParty::Response
Executes a request, validates and returns the response.
116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/dnsimple/client.rb', line 116 def execute(method, path, data, = {}) response = request(method, path, data, ) case response.code when 200..299 response when 401 raise (response.headers[HEADER_OTP_TOKEN] == "required" ? TwoFactorAuthenticationRequired : AuthenticationFailed), response["message"] when 404 raise NotFoundError.new(response) else raise RequestError.new(response) end end |
#get(path, options = {}) ⇒ HTTParty::Response
Make a HTTP GET request.
74 75 76 |
# File 'lib/dnsimple/client.rb', line 74 def get(path, = {}) execute :get, path, end |
#name_servers ⇒ Dnsimple::Client::NameServersService
Returns The name server-related API proxy.
20 21 22 |
# File 'lib/dnsimple/client/clients.rb', line 20 def name_servers @services[:name_servers] ||= Client::NameServersService.new(self) end |
#post(path, options = {}) ⇒ HTTParty::Response
Make a HTTP POST request.
83 84 85 |
# File 'lib/dnsimple/client.rb', line 83 def post(path, = {}) execute :post, path, end |
#put(path, options = {}) ⇒ HTTParty::Response
Make a HTTP PUT request.
92 93 94 |
# File 'lib/dnsimple/client.rb', line 92 def put(path, = {}) execute :put, path, end |
#registrar ⇒ Dnsimple::Client::RegistrarService
Returns The registrar-related API proxy.
25 26 27 |
# File 'lib/dnsimple/client/clients.rb', line 25 def registrar @services[:registrar] ||= Client::RegistrarService.new(self) end |
#request(method, path, data, options = {}) ⇒ HTTParty::Response
Make a HTTP request.
This method doesn’t validate the response and never raise errors even in case of HTTP error codes, except for connection errors raised by the underlying HTTP client.
Therefore, it’s up to the caller to properly handle and validate the response.
144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/dnsimple/client.rb', line 144 def request(method, path, data, = {}) if data.is_a?(Hash) [:query] = data.delete(:query) if data.key?(:query) [:headers] = data.delete(:headers) if data.key?(:headers) end if !data.empty? [:body] = data end HTTParty.send(method, api_endpoint + path, Extra.deep_merge!(, )) end |
#services ⇒ Dnsimple::Client::ServicesService
Returns The service-related API proxy.
30 31 32 |
# File 'lib/dnsimple/client/clients.rb', line 30 def services @services[:services] ||= Client::ServicesService.new(self) end |
#templates ⇒ Dnsimple::Client::TemplatesService
Returns The template-related API proxy.
35 36 37 |
# File 'lib/dnsimple/client/clients.rb', line 35 def templates @services[:templates] ||= Client::TemplatesService.new(self) end |
#users ⇒ Dnsimple::Client::UsersService
Returns The user-related API proxy.
40 41 42 |
# File 'lib/dnsimple/client/clients.rb', line 40 def users @services[:users] ||= Client::UsersService.new(self) end |