class Domainr::Client

Constants

DEFAULT_ENDPOINT

Attributes

client_id[RW]
endpoint[RW]
mashape_key[RW]

Public Class Methods

new(options = {}) click to toggle source
# File lib/domainr/client.rb, line 11
def initialize(options = {})
  @client_id = options.delete(:client_id)
  @mashape_key = options.delete(:mashape_key)
  @endpoint = options.delete(:endpoint) || DEFAULT_ENDPOINT
end

Public Instance Methods

status(domain, options = {}) click to toggle source
# File lib/domainr/client.rb, line 21
def status(domain, options = {})
  perform_get_with_objects('/v2/status', options.merge(domain: domain), 'status', Domainr::Domain)
end

Private Instance Methods

authentication_params() click to toggle source
# File lib/domainr/client.rb, line 45
def authentication_params
  if mashape_key
    {'mashape-key' => mashape_key}
  elsif client_id
    {'client_id' => client_id}
  else
    {}
  end
end
perform_get_with_objects(path, options, response_path, klass) click to toggle source

@param path [String] @param options [Hash] @param response_path [String] @param klass [Class]

# File lib/domainr/client.rb, line 31
def perform_get_with_objects(path, options, response_path, klass)
  perform_request(path, options)[response_path].collect do |element|
    klass.new(element)
  end
end
perform_request(path, params) click to toggle source
# File lib/domainr/client.rb, line 37
def perform_request(path, params)
  response = ::HTTP.headers(accept: 'application/json')
                   .get(endpoint + path, params: params.merge(authentication_params))

  resp = Domainr::HTTP::Response.new(response)
  resp.valid? && resp.body
end