Class: RegisteredDomains::NameCom::Domains
- Inherits:
-
Object
- Object
- RegisteredDomains::NameCom::Domains
- Defined in:
- lib/registered_domains/name_com.rb
Overview
Get the list of registered domains for an account from name.com Returns an array of domain names.
Instance Attribute Summary collapse
-
#domains ⇒ Object
readonly
Returns the value of attribute domains.
Instance Method Summary collapse
- #get ⇒ Object
-
#initialize(user, api_key) ⇒ Domains
constructor
A new instance of Domains.
Constructor Details
#initialize(user, api_key) ⇒ Domains
Returns a new instance of Domains.
12 13 14 15 16 |
# File 'lib/registered_domains/name_com.rb', line 12 def initialize(user, api_key) @auth = {username: user, password: api_key} @domains = get end |
Instance Attribute Details
#domains ⇒ Object (readonly)
Returns the value of attribute domains.
10 11 12 |
# File 'lib/registered_domains/name_com.rb', line 10 def domains @domains end |
Instance Method Details
#get ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/registered_domains/name_com.rb', line 18 def get url = "https://api.name.com/v4/domains" response = HTTParty.get(url, basic_auth: @auth) response.success? resp = JSON.parse(response) # Handle some known error messages rather than falling through and getting NoMethodError for nils if resp.has_key?('message') if resp['message'] == 'Unauthenticated' raise "Failed to authenticate to #{url}" elsif resp['message'] == 'Permission Denied' raise "#{resp['message']}: #{resp['details']}" else raise resp['message'] end end resp['domains'].map {|d| d['domainName']} end |