class RegisteredDomains::NameCom::Domains
Get the list of registered domains for an account from name.com Returns an array of domain names.
Attributes
domains[R]
Public Class Methods
new(user, api_key)
click to toggle source
# File lib/registered_domains/name_com.rb, line 12 def initialize(user, api_key) @auth = {username: user, password: api_key} @domains = get end
Public Instance Methods
get()
click to toggle source
# 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