Module: DnsMadeEasy

Defined in:
lib/dnsmadeeasy.rb,
lib/dnsmadeeasy.rb,
lib/dnsmadeeasy/runner.rb,
lib/dnsmadeeasy/version.rb,
lib/dnsmadeeasy/api/client.rb,
lib/dnsmadeeasy/credentials.rb,
lib/dnsmadeeasy/credentials/api_keys.rb,
lib/dnsmadeeasy/credentials/yaml_file.rb

Defined Under Namespace

Modules: Api, Credentials Classes: APIKeyAndSecretMissingError, AbstractMethodError, AuthenticationError, Error, InvalidCredentialKeys, InvalidCredentialsFormatError, NoSuchAccountError, Runner

Constant Summary collapse

API_BASE_URL_PRODUCTION =
'https://api.dnsmadeeasy.com/V2.0'
API_BASE_URL_SANDBOX =
'https://sandboxapi.dnsmadeeasy.com/V2.0'
VERSION =
'0.3.0'.freeze

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.default_api_keyObject

Returns the value of attribute default_api_key.



26
27
28
# File 'lib/dnsmadeeasy.rb', line 26

def default_api_key
  @default_api_key
end

.default_api_secretObject

Returns the value of attribute default_api_secret.



26
27
28
# File 'lib/dnsmadeeasy.rb', line 26

def default_api_secret
  @default_api_secret
end

Class Method Details

.api_key=(value) ⇒ Object



51
52
53
# File 'lib/dnsmadeeasy.rb', line 51

def api_key=(value)
  self.default_api_key = value
end

.api_secret=(value) ⇒ Object



55
56
57
# File 'lib/dnsmadeeasy.rb', line 55

def api_secret=(value)
  self.default_api_secret = value
end

.client(**options) ⇒ Object



59
60
61
# File 'lib/dnsmadeeasy.rb', line 59

def client(**options)
  @client ||= create_client(false, **options)
end

.configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (DnsMadeEasy)

    the object that the method was called on



29
30
31
# File 'lib/dnsmadeeasy.rb', line 29

def configure
  yield(self) if block_given?
end

.configure_from_file(file = nil, account_name = nil, encryption_key = nil) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/dnsmadeeasy.rb', line 33

def configure_from_file(file = nil,
                         = nil,
                        encryption_key = nil)

  credentials = ::DnsMadeEasy::Credentials.keys_from_file(
    filename:       file || ::DnsMadeEasy::Credentials.default_credentials_path(user: ENV['USER']),
    account_name:   ,
    encryption_key: encryption_key)
  if credentials
    configure do |config|
      config.api_key    = credentials.api_key
      config.api_secret = credentials.api_secret
    end
  else
    raise APIKeyAndSecretMissingError, "Unable to load valid api keys from #{file}!"
  end
end

.create_client(sandbox = false, api_key: self.default_api_key, api_secret: self.default_api_secret, **options) ⇒ Object



67
68
69
70
71
72
73
74
# File 'lib/dnsmadeeasy.rb', line 67

def create_client(sandbox = false,
                  api_key: self.default_api_key,
                  api_secret: self.default_api_secret,

                  **options)
  raise APIKeyAndSecretMissingError, 'Please set #api_key and #api_secret' unless api_key && api_secret
  ::DnsMadeEasy::Api::Client.new(api_key, api_secret, sandbox, **options)
end

.method_missing(method, *args, &block) ⇒ Object

Basically delegate it all to the Client instance if the method call is supported.



79
80
81
82
83
84
85
# File 'lib/dnsmadeeasy.rb', line 79

def method_missing(method, *args, &block)
  if client.respond_to?(method)
    client.send(method, *args, &block)
  else
    super(method, *args, &block)
  end
end

.sandbox_client(**options) ⇒ Object



63
64
65
# File 'lib/dnsmadeeasy.rb', line 63

def sandbox_client(**options)
  @sandbox_client ||= create_client(true, **options)
end