Class: Dnsimple::Client
- Inherits:
-
Object
- Object
- Dnsimple::Client
- Defined in:
- lib/dnsimple/client.rb,
lib/dnsimple/client/tlds.rb,
lib/dnsimple/client/oauth.rb,
lib/dnsimple/client/zones.rb,
lib/dnsimple/client/billing.rb,
lib/dnsimple/client/clients.rb,
lib/dnsimple/client/domains.rb,
lib/dnsimple/client/accounts.rb,
lib/dnsimple/client/contacts.rb,
lib/dnsimple/client/identity.rb,
lib/dnsimple/client/services.rb,
lib/dnsimple/client/webhooks.rb,
lib/dnsimple/client/registrar.rb,
lib/dnsimple/client/templates.rb,
lib/dnsimple/client/certificates.rb,
lib/dnsimple/client/dns_analytics.rb,
lib/dnsimple/client/zones_records.rb,
lib/dnsimple/client/domains_dnssec.rb,
lib/dnsimple/client/domains_pushes.rb,
lib/dnsimple/client/services_domains.rb,
lib/dnsimple/client/templates_domains.rb,
lib/dnsimple/client/templates_records.rb,
lib/dnsimple/client/vanity_name_servers.rb,
lib/dnsimple/client/zones_distributions.rb,
lib/dnsimple/client/registrar_delegation.rb,
lib/dnsimple/client/domains_collaborators.rb,
lib/dnsimple/client/domains_email_forwards.rb,
lib/dnsimple/client/registrar_auto_renewal.rb,
lib/dnsimple/client/registrar_transfer_lock.rb,
lib/dnsimple/client/registrar_whois_privacy.rb,
lib/dnsimple/client/registrar_registrant_changes.rb,
lib/dnsimple/client/domains_delegation_signer_records.rb
Overview
Client for the DNSimple API
Defined Under Namespace
Modules: Accounts, Billing, Certificates, Contacts, DnsAnalytics, Domains, DomainsCollaborators, DomainsDelegationSignerRecords, DomainsDnssec, DomainsEmailForwards, DomainsPushes, Identity, Oauth, Registrar, RegistrarAutoRenewal, RegistrarDelegation, RegistrarRegistrantChanges, RegistrarTransferLock, RegistrarWhoisPrivacy, Services, ServicesDomains, Templates, TemplatesDomains, TemplatesRecords, Tlds, VanityNameServers, Webhooks, Zones, ZonesDistributions, ZonesRecords Classes: AccountsService, BillingService, CertificatesService, ClientService, ContactsService, DnsAnalyticsService, DomainsService, IdentityService, OauthService, RegistrarService, ServicesService, TemplatesService, TldsService, VanityNameServersService, WebhooksService, ZonesService
Constant Summary collapse
- HEADER_AUTHORIZATION =
"Authorization"
- API_VERSION =
Returns The current API version.
"v2"
Instance Attribute Summary collapse
-
#access_token ⇒ String
Domain API access token for authentication.
-
#domain_api_token ⇒ String
Domain API access token for authentication.
-
#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
-
#accounts ⇒ Dnsimple::Client::AccountsService
The account-related API proxy.
-
#base_url ⇒ String
Base URL for API requests.
-
#billing ⇒ Dnsimple::Client::BillingService
The billing-related API proxy.
-
#certificates ⇒ Dnsimple::Client::CertificatesService
The certificate-related API proxy.
-
#contacts ⇒ Dnsimple::Client::ContactsService
The contact-related API proxy.
-
#delete(path, data = nil, options = {}) ⇒ HTTParty::Response
Make a HTTP DELETE request.
-
#dns_analytics ⇒ Dnsimple::Client::DnsAnalyticsService
The DNS Analytics API proxy.
-
#domains ⇒ Dnsimple::Client::DomainsService
The domain-related API proxy.
-
#execute(method, path, data = nil, options = {}) ⇒ HTTParty::Response
Executes a request, validates and returns the response.
-
#get(path, options = {}) ⇒ HTTParty::Response
Make a HTTP GET request.
-
#identity ⇒ Dnsimple::Client::IdentityService
The identity-related API proxy.
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
-
#oauth ⇒ Dnsimple::Client::OauthService
The oauth-related API proxy.
-
#patch(path, data = nil, options = {}) ⇒ HTTParty::Response
Make a HTTP PATCH request.
-
#post(path, data = nil, options = {}) ⇒ HTTParty::Response
Make a HTTP POST request.
-
#put(path, data = nil, options = {}) ⇒ HTTParty::Response
Make a HTTP PUT request.
-
#registrar ⇒ Dnsimple::Client::RegistrarService
The registrar-related API proxy.
-
#request(method, path, data = nil, options = {}) ⇒ HTTParty::Response
Make a HTTP request.
-
#services ⇒ Dnsimple::Client::ServicesService
The one-click-service-related API proxy.
-
#templates ⇒ Dnsimple::Client::TemplatesService
The templates-related API proxy.
-
#tlds ⇒ Dnsimple::Client::TldsService
The tld-related API proxy.
-
#vanity_name_servers ⇒ Dnsimple::Client::VanityNameServersService
The vanity-name-server-related API proxy.
-
#webhooks ⇒ Dnsimple::Client::WebhooksService
The webhooks-related API proxy.
-
#zones ⇒ Dnsimple::Client::ZonesService
The zone-related API proxy.
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
70 71 72 73 74 75 76 77 78 |
# File 'lib/dnsimple/client.rb', line 70 def initialize( = {}) defaults = Dnsimple::Default. Dnsimple::Default.keys.each do |key| # rubocop:disable Style/HashEachMethods instance_variable_set(:"@#{key}", [key] || defaults[key]) end @services = {} end |
Instance Attribute Details
#access_token ⇒ String
Returns Domain API access token for authentication.
59 60 61 |
# File 'lib/dnsimple/client.rb', line 59 def access_token @access_token end |
#domain_api_token ⇒ String
Returns Domain API access token for authentication.
54 55 56 |
# File 'lib/dnsimple/client.rb', line 54 def domain_api_token @domain_api_token end |
#password ⇒ String
Returns DNSimple password for Basic Authentication.
49 50 51 |
# File 'lib/dnsimple/client.rb', line 49 def password @password end |
#proxy ⇒ String?
Returns Configure address:port values for proxy server.
67 68 69 |
# File 'lib/dnsimple/client.rb', line 67 def proxy @proxy end |
#user_agent ⇒ String
Returns Configure User-Agent header for requests.
63 64 65 |
# File 'lib/dnsimple/client.rb', line 63 def user_agent @user_agent end |
#username ⇒ String
Returns DNSimple username for Basic Authentication.
44 45 46 |
# File 'lib/dnsimple/client.rb', line 44 def username @username end |
Class Method Details
.versioned(path) ⇒ String
Prepends the correct API version to path
.
36 37 38 |
# File 'lib/dnsimple/client.rb', line 36 def self.versioned(path) File.join(API_VERSION, path) end |
Instance Method Details
#accounts ⇒ Dnsimple::Client::AccountsService
Returns The account-related API proxy.
8 9 10 |
# File 'lib/dnsimple/client/clients.rb', line 8 def accounts @services[:accounts] ||= Client::AccountsService.new(self) end |
#base_url ⇒ String
Base URL for API requests.
It defaults to "https://api.dnsimple.com"
. For testing purposes use "https://api.sandbox.dnsimple.com"
.
99 100 101 |
# File 'lib/dnsimple/client.rb', line 99 def base_url Extra.join_uri(@base_url, "") end |
#billing ⇒ Dnsimple::Client::BillingService
Returns The billing-related API proxy.
13 14 15 |
# File 'lib/dnsimple/client/clients.rb', line 13 def billing @services[:billing] ||= Client::BillingService.new(self) end |
#certificates ⇒ Dnsimple::Client::CertificatesService
Returns The certificate-related API proxy.
18 19 20 |
# File 'lib/dnsimple/client/clients.rb', line 18 def certificates @services[:certificates] ||= Client::CertificatesService.new(self) end |
#contacts ⇒ Dnsimple::Client::ContactsService
Returns The contact-related API proxy.
23 24 25 |
# File 'lib/dnsimple/client/clients.rb', line 23 def contacts @services[:contacts] ||= Client::ContactsService.new(self) end |
#delete(path, data = nil, options = {}) ⇒ HTTParty::Response
Make a HTTP DELETE request.
148 149 150 |
# File 'lib/dnsimple/client.rb', line 148 def delete(path, data = nil, = {}) execute :delete, path, data, end |
#dns_analytics ⇒ Dnsimple::Client::DnsAnalyticsService
Returns The DNS Analytics API proxy.
33 34 35 |
# File 'lib/dnsimple/client/clients.rb', line 33 def dns_analytics @services[:dns_analytics] ||= Client::DnsAnalyticsService.new(self) end |
#domains ⇒ Dnsimple::Client::DomainsService
Returns The domain-related API proxy.
28 29 30 |
# File 'lib/dnsimple/client/clients.rb', line 28 def domains @services[:domains] ||= Client::DomainsService.new(self) end |
#execute(method, path, data = nil, options = {}) ⇒ HTTParty::Response
Executes a request, validates and returns the response.
163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/dnsimple/client.rb', line 163 def execute(method, path, data = nil, = {}) response = request(method, path, data, ) case response.code when 200..299 response when 401 raise AuthenticationFailed, response["message"] when 404 raise NotFoundError, response else raise RequestError, response end end |
#get(path, options = {}) ⇒ HTTParty::Response
Make a HTTP GET request.
109 110 111 |
# File 'lib/dnsimple/client.rb', line 109 def get(path, = {}) execute :get, path, nil, .to_h end |
#identity ⇒ Dnsimple::Client::IdentityService
Returns The identity-related API proxy.
38 39 40 |
# File 'lib/dnsimple/client/clients.rb', line 38 def identity @services[:auth] ||= Client::IdentityService.new(self) end |
#oauth ⇒ Dnsimple::Client::OauthService
Returns The oauth-related API proxy.
43 44 45 |
# File 'lib/dnsimple/client/clients.rb', line 43 def oauth @services[:oauth] ||= Client::OauthService.new(self) end |
#patch(path, data = nil, options = {}) ⇒ HTTParty::Response
Make a HTTP PATCH request.
139 140 141 |
# File 'lib/dnsimple/client.rb', line 139 def patch(path, data = nil, = {}) execute :patch, path, data, end |
#post(path, data = nil, options = {}) ⇒ HTTParty::Response
Make a HTTP POST request.
119 120 121 |
# File 'lib/dnsimple/client.rb', line 119 def post(path, data = nil, = {}) execute :post, path, data, end |
#put(path, data = nil, options = {}) ⇒ HTTParty::Response
Make a HTTP PUT request.
129 130 131 |
# File 'lib/dnsimple/client.rb', line 129 def put(path, data = nil, = {}) execute :put, path, data, end |
#registrar ⇒ Dnsimple::Client::RegistrarService
Returns The registrar-related API proxy.
48 49 50 |
# File 'lib/dnsimple/client/clients.rb', line 48 def registrar @services[:registrar] ||= Client::RegistrarService.new(self) end |
#request(method, path, data = nil, 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.
191 192 193 194 195 196 197 198 199 200 |
# File 'lib/dnsimple/client.rb', line 191 def request(method, path, data = nil, = {}) = () if data [:headers]["Content-Type"] = content_type([:headers]) [:body] = content_data([:headers], data) end HTTParty.send(method, base_url + path, ) end |
#services ⇒ Dnsimple::Client::ServicesService
Returns The one-click-service-related API proxy.
53 54 55 |
# File 'lib/dnsimple/client/clients.rb', line 53 def services @services[:services] ||= Client::ServicesService.new(self) end |
#templates ⇒ Dnsimple::Client::TemplatesService
Returns The templates-related API proxy.
58 59 60 |
# File 'lib/dnsimple/client/clients.rb', line 58 def templates @services[:templates] ||= Client::TemplatesService.new(self) end |
#tlds ⇒ Dnsimple::Client::TldsService
Returns The tld-related API proxy.
63 64 65 |
# File 'lib/dnsimple/client/clients.rb', line 63 def tlds @services[:tlds] ||= Client::TldsService.new(self) end |
#vanity_name_servers ⇒ Dnsimple::Client::VanityNameServersService
Returns The vanity-name-server-related API proxy.
68 69 70 |
# File 'lib/dnsimple/client/clients.rb', line 68 def vanity_name_servers @services[:vanity_name_servers] ||= Client::VanityNameServersService.new(self) end |
#webhooks ⇒ Dnsimple::Client::WebhooksService
Returns The webhooks-related API proxy.
78 79 80 |
# File 'lib/dnsimple/client/clients.rb', line 78 def webhooks @services[:webhooks] ||= Client::WebhooksService.new(self) end |
#zones ⇒ Dnsimple::Client::ZonesService
Returns The zone-related API proxy.
73 74 75 |
# File 'lib/dnsimple/client/clients.rb', line 73 def zones @services[:zones] ||= Client::ZonesService.new(self) end |