Class: DNSimple::Client
- Inherits:
-
Object
- Object
- DNSimple::Client
- Defined in:
- lib/dnsimple/client.rb
Class Method Summary collapse
- .api_token ⇒ Object
- .api_token=(api_token) ⇒ Object
-
.base_uri ⇒ String
Gets the qualified API base uri.
-
.base_uri=(value) ⇒ Object
Sets the qualified API base uri.
- .config_path ⇒ Object
- .credentials_loaded? ⇒ Boolean
- .debug=(debug) ⇒ Object
- .debug? ⇒ Boolean
- .delete(path, options = {}) ⇒ Object
- .get(path, options = {}) ⇒ Object
- .http_proxy ⇒ Object
- .http_proxy=(http_proxy) ⇒ Object
- .load_credentials(path = config_path) ⇒ Object
- .load_credentials_if_necessary ⇒ Object
- .password ⇒ Object
- .password=(password) ⇒ Object
- .post(path, options = {}) ⇒ Object
- .put(path, options = {}) ⇒ Object
- .request(method, path, options) ⇒ Object
- .standard_options ⇒ Object
- .username ⇒ Object
- .username=(username) ⇒ Object
Class Method Details
.api_token ⇒ Object
30 31 32 |
# File 'lib/dnsimple/client.rb', line 30 def self.api_token @api_token end |
.api_token=(api_token) ⇒ Object
34 35 36 |
# File 'lib/dnsimple/client.rb', line 34 def self.api_token=(api_token) @api_token = api_token end |
.base_uri ⇒ String
Gets the qualified API base uri.
41 42 43 |
# File 'lib/dnsimple/client.rb', line 41 def self.base_uri @base_uri ||= "https://dnsimple.com" end |
.base_uri=(value) ⇒ Object
Sets the qualified API base uri.
48 49 50 |
# File 'lib/dnsimple/client.rb', line 48 def self.base_uri=(value) @base_uri = value.to_s.chomp("/") end |
.config_path ⇒ Object
64 65 66 |
# File 'lib/dnsimple/client.rb', line 64 def self.config_path ENV['DNSIMPLE_CONFIG'] || '~/.dnsimple' end |
.credentials_loaded? ⇒ Boolean
85 86 87 |
# File 'lib/dnsimple/client.rb', line 85 def self.credentials_loaded? (@credentials_loaded ||= false) or (username and (password or api_token)) end |
.debug=(debug) ⇒ Object
10 11 12 |
# File 'lib/dnsimple/client.rb', line 10 def self.debug=(debug) @debug = debug end |
.debug? ⇒ Boolean
6 7 8 |
# File 'lib/dnsimple/client.rb', line 6 def self.debug? @debug end |
.delete(path, options = {}) ⇒ Object
125 126 127 |
# File 'lib/dnsimple/client.rb', line 125 def self.delete(path, = {}) request :delete, path, end |
.get(path, options = {}) ⇒ Object
113 114 115 |
# File 'lib/dnsimple/client.rb', line 113 def self.get(path, = {}) request :get, path, end |
.http_proxy ⇒ Object
52 53 54 |
# File 'lib/dnsimple/client.rb', line 52 def self.http_proxy @http_proxy end |
.http_proxy=(http_proxy) ⇒ Object
56 57 58 |
# File 'lib/dnsimple/client.rb', line 56 def self.http_proxy=(http_proxy) @http_proxy = http_proxy end |
.load_credentials(path = config_path) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/dnsimple/client.rb', line 68 def self.load_credentials(path = config_path) begin credentials = YAML.load(File.new(File.(path))) self.username ||= credentials['username'] self.password ||= credentials['password'] self.api_token ||= credentials['api_token'] self.base_uri = credentials['site'] if credentials['site'] self.base_uri = credentials['base_uri'] if credentials['base_uri'] self.http_proxy = { :addr => credentials['proxy_addr'], :port => credentials['proxy_port'] } @credentials_loaded = true puts "Credentials loaded from #{path}" rescue => error puts "Error loading your credentials: #{error.}" exit 1 end end |
.load_credentials_if_necessary ⇒ Object
60 61 62 |
# File 'lib/dnsimple/client.rb', line 60 def self.load_credentials_if_necessary load_credentials unless credentials_loaded? end |
.password ⇒ Object
22 23 24 |
# File 'lib/dnsimple/client.rb', line 22 def self.password @password end |
.password=(password) ⇒ Object
26 27 28 |
# File 'lib/dnsimple/client.rb', line 26 def self.password=(password) @password = password end |
.post(path, options = {}) ⇒ Object
117 118 119 |
# File 'lib/dnsimple/client.rb', line 117 def self.post(path, = {}) request :post, path, end |
.put(path, options = {}) ⇒ Object
121 122 123 |
# File 'lib/dnsimple/client.rb', line 121 def self.put(path, = {}) request :put, path, end |
.request(method, path, options) ⇒ Object
129 130 131 132 133 134 135 136 137 138 |
# File 'lib/dnsimple/client.rb', line 129 def self.request(method, path, ) response = HTTParty.send(method, "#{base_uri}/#{path}", .merge()) if response.code == 401 raise AuthenticationFailed end response end |
.standard_options ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/dnsimple/client.rb', line 89 def self. = { :format => :json, :headers => {'Accept' => 'application/json'}, } if http_proxy .merge!( :http_proxyaddr => self.http_proxy[:addr], :http_proxyport => self.http_proxy[:port] ) end if password [:basic_auth] = {:username => username, :password => password} elsif api_token [:headers]['X-DNSimple-Token'] = "#{username}:#{api_token}" else raise Error, 'A password or API token is required for all API requests.' end end |
.username ⇒ Object
14 15 16 |
# File 'lib/dnsimple/client.rb', line 14 def self.username @username end |
.username=(username) ⇒ Object
18 19 20 |
# File 'lib/dnsimple/client.rb', line 18 def self.username=(username) @username = username end |