Class: Domainsbot

Inherits:
Object
  • Object
show all
Defined in:
lib/domainsbot.rb

Constant Summary collapse

BASE_URI =
'https://api.domainsbot.com/v4'
@@api_key =
nil

Class Method Summary collapse

Class Method Details

.api_keyObject



29
# File 'lib/domainsbot.rb', line 29

def self.api_key; @@api_key; end

.api_key=(key) ⇒ Object

Set the API key to be used for all requests

Attributes

  • key - String Domainsbot API Key

Examples

Domainsbot.api_key = "MYAPIKEY"


25
26
27
# File 'lib/domainsbot.rb', line 25

def self.api_key=(key)
    @@api_key = key
end

.build_uri(path, options) ⇒ Object

Helper method for building the URI Shouldn’t ever be called directly



52
53
54
55
56
# File 'lib/domainsbot.rb', line 52

def self.build_uri(path, options) #:nodoc: all
    uri = URI("#{BASE_URI}#{path}")
    uri.query = URI.encode_www_form(options)
    return uri
end

.suggest(options = {q: '', pageSize: 25, tlds: 'com,org,net', format: 'json'}) ⇒ Object

Attributes

  • options - Hash query parameters

Examples

Domainsbot.suggest({q: 'example.com', pageSize: 2, tlds: 'com,org,net'})


41
42
43
44
45
46
47
48
# File 'lib/domainsbot.rb', line 41

def self.suggest(options={q: '', pageSize: 25, tlds: 'com,org,net', format: 'json'})
    options['auth-token'] = @@api_key
    options[:json] = 'json'
    uri = build_uri('/spinner', options)

    response = Net::HTTP.get_response(uri)
    return JSON.parse(response.body)
end