Class: DNSimple::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/dnsimple/client.rb

Class Method Summary collapse

Class Method Details

.base_uriObject



32
33
34
# File 'lib/dnsimple/client.rb', line 32

def self.base_uri
  @@base_uri ||= "https://dnsimple.com"
end

.base_uri=(base_uri) ⇒ Object



36
37
38
# File 'lib/dnsimple/client.rb', line 36

def self.base_uri=(base_uri)
  @@base_uri = base_uri ? base_uri.gsub(/\/$/, '') : nil
end

.config_pathObject



44
45
46
# File 'lib/dnsimple/client.rb', line 44

def self.config_path
  ENV['DNSIMPLE_CONFIG'] || '~/.dnsimple'
end

.credentialsObject



28
29
30
# File 'lib/dnsimple/client.rb', line 28

def self.credentials
  {:username => self.username, :password => self.password}
end

.credentials_loaded?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/dnsimple/client.rb', line 62

def self.credentials_loaded?
  (@@credentials_loaded ||= false) or (defined?(@@username) and defined?(@@password))
end

.debug=(debug) ⇒ Object



6
7
8
# File 'lib/dnsimple/client.rb', line 6

def self.debug=(debug)
  @debug = debug
end

.debug?Boolean

Returns:

  • (Boolean)


3
4
5
# File 'lib/dnsimple/client.rb', line 3

def self.debug?
  @debug
end

.load_credentials(path = config_path) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/dnsimple/client.rb', line 48

def self.load_credentials(path=config_path)
  begin
    credentials = YAML.load(File.new(File.expand_path(path)))
    self.username = credentials['username']
    self.password = credentials['password']
    self.base_uri = credentials['site']
    @@credentials_loaded = true
    "Credentials loaded from #{path}" 
  rescue
    puts "Error loading your credentials: #{$!.message}"
    exit 1
  end
end

.load_credentials_if_necessaryObject



40
41
42
# File 'lib/dnsimple/client.rb', line 40

def self.load_credentials_if_necessary
  load_credentials unless credentials_loaded?
end

.passwordObject

Raises:

  • (RuntimeError)


19
20
21
22
# File 'lib/dnsimple/client.rb', line 19

def self.password
  raise RuntimeError, "You must set your password first: DNSimple::Client.password = 'password'" unless defined?(@@password)
  @@password
end

.password=(password) ⇒ Object



24
25
26
# File 'lib/dnsimple/client.rb', line 24

def self.password=(password)
  @@password = password
end

.standard_optionsObject



66
67
68
# File 'lib/dnsimple/client.rb', line 66

def self.standard_options
  {:format => :json, :headers => {'Accept' => 'application/json'}}
end

.standard_options_with_credentialsObject



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

def self.standard_options_with_credentials
  standard_options.merge({:basic_auth => credentials})
end

.usernameObject

Raises:

  • (RuntimeError)


10
11
12
13
# File 'lib/dnsimple/client.rb', line 10

def self.username
  raise RuntimeError, "You must set your username first: DNSimple::Client.username = 'username'" unless defined?(@@username)
  @@username
end

.username=(username) ⇒ Object



15
16
17
# File 'lib/dnsimple/client.rb', line 15

def self.username=(username)
  @@username = username
end