Class: DNSimple::Client
- Inherits:
-
Object
- Object
- DNSimple::Client
- Defined in:
- lib/dnsimple/client.rb
Class Method Summary collapse
- .base_uri ⇒ Object
- .base_uri=(base_uri) ⇒ Object
- .config_path ⇒ Object
- .credentials ⇒ Object
- .credentials_loaded? ⇒ Boolean
- .debug=(debug) ⇒ Object
- .debug? ⇒ Boolean
- .load_credentials(path = config_path) ⇒ Object
- .load_credentials_if_necessary ⇒ Object
- .password ⇒ Object
- .password=(password) ⇒ Object
- .standard_options ⇒ Object
- .standard_options_with_credentials ⇒ Object
- .username ⇒ Object
- .username=(username) ⇒ Object
Class Method Details
.base_uri ⇒ Object
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_path ⇒ Object
44 45 46 |
# File 'lib/dnsimple/client.rb', line 44 def self.config_path ENV['DNSIMPLE_CONFIG'] || '~/.dnsimple' end |
.credentials ⇒ Object
28 29 30 |
# File 'lib/dnsimple/client.rb', line 28 def self.credentials {:username => self.username, :password => self.password} end |
.credentials_loaded? ⇒ 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
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.(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: #{$!.}" exit 1 end end |
.load_credentials_if_necessary ⇒ Object
40 41 42 |
# File 'lib/dnsimple/client.rb', line 40 def self.load_credentials_if_necessary load_credentials unless credentials_loaded? end |
.password ⇒ Object
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_options ⇒ Object
66 67 68 |
# File 'lib/dnsimple/client.rb', line 66 def self. {:format => :json, :headers => {'Accept' => 'application/json'}} end |
.standard_options_with_credentials ⇒ Object
70 71 72 |
# File 'lib/dnsimple/client.rb', line 70 def self. .merge({:basic_auth => credentials}) end |
.username ⇒ Object
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 |