Class: Dnsimple::Client

Inherits:
Object
  • Object
show all
Includes:
Compatibility
Defined in:
lib/dnsimple/client.rb,
lib/dnsimple/client/users_service.rb,
lib/dnsimple/client/client_service.rb,
lib/dnsimple/client/records_service.rb,
lib/dnsimple/client/domains_service.rb,
lib/dnsimple/client/contacts_service.rb,
lib/dnsimple/client/services_service.rb,
lib/dnsimple/client/templates_service.rb,
lib/dnsimple/client/certificates_service.rb,
lib/dnsimple/client/name_servers_service.rb

Overview

Client for the DNSimple API

Defined Under Namespace

Classes: CertificatesService, ClientService, ContactsService, DomainsService, NameServersService, RecordsService, ServicesService, TemplatesService, UsersService

Constant Summary

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"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Compatibility

included

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client



54
55
56
57
58
59
60
61
62
# File 'lib/dnsimple/client.rb', line 54

def initialize(options = {})
  defaults = Dnsimple::Default.options

  Dnsimple::Default.keys.each do |key|
    instance_variable_set(:"@#{key}", options[key] || defaults[key])
  end

  @services = {}
end

Instance Attribute Details

#api_endpointString

Returns Base URL for API requests.

Returns:

  • (String)

    Base URL for API requests.



50
51
52
# File 'lib/dnsimple/client.rb', line 50

def api_endpoint
  @api_endpoint
end

#api_tokenString

Returns API access token for authentication

Returns:

  • (String)

    API access token for authentication

See Also:



50
51
# File 'lib/dnsimple/client.rb', line 50

attr_accessor :api_endpoint, :username, :password, :exchange_token, :api_token, :domain_api_token,
:user_agent, :proxy

#domain_api_tokenString

Returns Domain API access token for authentication

Returns:

  • (String)

    Domain API access token for authentication

See Also:



50
51
# File 'lib/dnsimple/client.rb', line 50

attr_accessor :api_endpoint, :username, :password, :exchange_token, :api_token, :domain_api_token,
:user_agent, :proxy

#exchange_tokenString

Returns Exchange Token for Basic Authentication with 2FA

Returns:

  • (String)

    Exchange Token for Basic Authentication with 2FA

See Also:



50
51
# File 'lib/dnsimple/client.rb', line 50

attr_accessor :api_endpoint, :username, :password, :exchange_token, :api_token, :domain_api_token,
:user_agent, :proxy

#passwordString

Returns DNSimple password for Basic Authentication

Returns:

  • (String)

    DNSimple password for Basic Authentication

See Also:



50
51
# File 'lib/dnsimple/client.rb', line 50

attr_accessor :api_endpoint, :username, :password, :exchange_token, :api_token, :domain_api_token,
:user_agent, :proxy

#proxyString?

Returns Configure address:port values for proxy server

Returns:

  • (String, nil)

    Configure address:port values for proxy server



50
51
# File 'lib/dnsimple/client.rb', line 50

attr_accessor :api_endpoint, :username, :password, :exchange_token, :api_token, :domain_api_token,
:user_agent, :proxy

#user_agentString

Returns Configure User-Agent header for requests.

Returns:

  • (String)

    Configure User-Agent header for requests.



50
51
# File 'lib/dnsimple/client.rb', line 50

attr_accessor :api_endpoint, :username, :password, :exchange_token, :api_token, :domain_api_token,
:user_agent, :proxy

#usernameString

Returns DNSimple username for Basic Authentication

Returns:

  • (String)

    DNSimple username for Basic Authentication



50
51
# File 'lib/dnsimple/client.rb', line 50

attr_accessor :api_endpoint, :username, :password, :exchange_token, :api_token, :domain_api_token,
:user_agent, :proxy

Instance Method Details

#certificatesDnsimple::Client::CertificatesService

Returns The certificate-related API proxy.

Returns:



133
134
135
# File 'lib/dnsimple/client.rb', line 133

def certificates
  @services[:certificates] ||= Client::CertificatesService.new(self)
end

#contactsDnsimple::Client::ContactsService

Returns The contact-related API proxy.

Returns:



138
139
140
# File 'lib/dnsimple/client.rb', line 138

def contacts
  @services[:contacts] ||= Client::ContactsService.new(self)
end

#delete(path, options = {}) ⇒ HTTParty::Response

Make a HTTP DELETE request.

Parameters:

  • url (String)

    The path, relative to #api_endpoint

  • options (Hash) (defaults to: {})

    Query and header params for request

Returns:

  • (HTTParty::Response)


97
98
99
# File 'lib/dnsimple/client.rb', line 97

def delete(path, options = {})
  request :delete, path, options
end

#domainsDnsimple::Client::DomainsService

Returns The domain-related API proxy.

Returns:



143
144
145
# File 'lib/dnsimple/client.rb', line 143

def domains
  @services[:domains] ||= Client::DomainsService.new(self)
end

#get(path, options = {}) ⇒ HTTParty::Response

Make a HTTP GET request.

Parameters:

  • url (String)

    The path, relative to #api_endpoint

  • options (Hash) (defaults to: {})

    Query and header params for request

Returns:

  • (HTTParty::Response)


70
71
72
# File 'lib/dnsimple/client.rb', line 70

def get(path, options = {})
  request :get, path, options
end

#name_serversDnsimple::Client::NameServersService

Returns The name server-related API proxy.

Returns:



148
149
150
# File 'lib/dnsimple/client.rb', line 148

def name_servers
  @services[:name_servers] ||= Client::NameServersService.new(self)
end

#post(path, options = {}) ⇒ HTTParty::Response

Make a HTTP POST request.

Parameters:

  • url (String)

    The path, relative to #api_endpoint

  • options (Hash) (defaults to: {})

    Body and header params for request

Returns:

  • (HTTParty::Response)


79
80
81
# File 'lib/dnsimple/client.rb', line 79

def post(path, options = {})
  request :post, path, options
end

#put(path, options = {}) ⇒ HTTParty::Response

Make a HTTP PUT request.

Parameters:

  • url (String)

    The path, relative to #api_endpoint

  • options (Hash) (defaults to: {})

    Body and header params for request

Returns:

  • (HTTParty::Response)


88
89
90
# File 'lib/dnsimple/client.rb', line 88

def put(path, options = {})
  request :put, path, options
end

#recordsDnsimple::Client::RecordsService

Returns The record-related API proxy.

Returns:



153
154
155
# File 'lib/dnsimple/client.rb', line 153

def records
  @services[:records] ||= Client::RecordsService.new(self)
end

#request(method, path, data, options = {}) ⇒ HTTParty::Response

Make a HTTP request.

Parameters:

  • method (String)

    The HTTP method

  • url (String)

    The path, relative to #api_endpoint

  • options (Hash) (defaults to: {})

    Query and header params for request

Returns:

  • (HTTParty::Response)


108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/dnsimple/client.rb', line 108

def request(method, path, data, options = {})
  if data.is_a?(Hash)
    options[:query]   = data.delete(:query)   if data.key?(:query)
    options[:headers] = data.delete(:headers) if data.key?(:headers)
  end
  if !data.empty?
    options[:body] = data
  end

  response = HTTParty.send(method, api_endpoint + path, Extra.deep_merge!(base_options, options))

  case response.code
  when 200..299
    response
  when 401
    raise (response.headers[HEADER_OTP_TOKEN] == "required" ? TwoFactorAuthenticationRequired : AuthenticationFailed), response["message"]
  when 404
    raise RecordNotFound.new(response)
  else
    raise RequestError.new(response)
  end
end

#servicesDnsimple::Client::ServicesService

Returns The service-related API proxy.

Returns:



158
159
160
# File 'lib/dnsimple/client.rb', line 158

def services
  @services[:services] ||= Client::ServicesService.new(self)
end

#templatesDnsimple::Client::TemplatesService

Returns The template-related API proxy.

Returns:



163
164
165
# File 'lib/dnsimple/client.rb', line 163

def templates
  @services[:templates] ||= Client::TemplatesService.new(self)
end

#usersDnsimple::Client::UsersService

Returns The user-related API proxy.

Returns:



168
169
170
# File 'lib/dnsimple/client.rb', line 168

def users
  @services[:users] ||= Client::UsersService.new(self)
end