Class: Demandbase::DomainRecord

Inherits:
Record
  • Object
show all
Defined in:
lib/demandbase/domain_record.rb

Instance Attribute Summary

Attributes inherited from Record

#annual_sales, #b2b, #b2c, #city, #company_name, #country, #country_name, #demandbase_sid, #employee_count, #employee_range, #forbes_2000, #fortune_1000, #industry, #latitude, #longitude, #marketing_alias, #phone, #primary_sic, #revenue_range, #state, #stock_ticker, #street_address, #sub_industry, #traffic, #web_site, #zip

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Record

#is_academic?, #is_government?, #is_nonprofit?, #rtid_key

Constructor Details

#initialize(domain) ⇒ DomainRecord

Instantiate a new Demandbase Domain Record from a domain name.

Raises:



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/demandbase/domain_record.rb', line 22

def initialize(domain)
  raise Demandbase::RTIDNotSetError if rtid_key.nil?

  begin
    query = Demandbase::DomainRecord.cleanse_domain(domain)
    url = api_url + "&query=#{query}"
  rescue => e
    raise Demandbase::ParseError
  end

  begin
    response = JSON.parse(RestClient.get(url))

    return nil unless response["domain"]

    @company_name     = response["domain"]["company_name"]
    @demandbase_sid   = response["domain"]["demandbase_sid"]
    @marketing_alias  = response["domain"]["marketing_alias"]
    @industry         = response["domain"]["industry"]
    @sub_industry     = response["domain"]["sub_industry"]
    @employee_count   = response["domain"]["employee_count"]
    @primary_sic      = response["domain"]["primary_sic"]
    @street_address   = response["domain"]["street_address"]
    @city             = response["domain"]["city"]
    @state            = response["domain"]["state"]
    @zip              = response["domain"]["zip"]
    @country          = response["domain"]["country"]
    @country_name     = response["domain"]["country_name"]
    @phone            = response["domain"]["phone"]
    @stock_ticker     = response["domain"]["stock_ticker"]
    @web_site         = response["domain"]["web_site"]
    @annual_sales     = response["domain"]["annual_sales"]
    @revenue_range    = response["domain"]["revenue_range"]
    @employee_range   = response["domain"]["employee_range"]
    @b2b              = response["domain"]["b2b"]
    @b2c              = response["domain"]["b2c"]
    @traffic          = response["domain"]["traffic"]
    @latitude         = response["domain"]["latitude"]
    @longitude        = response["domain"]["longitude"]
    @fortune_1000     = response["domain"]["fortune_1000"]
    @forbes_2000      = response["domain"]["forbes_2000"]
  rescue => e
    raise ServerError
  end
end

Class Method Details

.cleanse_domain(domain) ⇒ Object

Clean the domain of things like 'http(s)://', 'www', '?foo=bar', etc.

Return the domain string.



72
73
74
75
76
77
78
79
80
81
# File 'lib/demandbase/domain_record.rb', line 72

def self.cleanse_domain(domain)
  domain.downcase!
  domain = domain.sub(/^https?\:\/\//, '').sub(/^www./,'')
  domain = domain.split(  "/").first
  domain = domain.split("@").last

  domain = PublicSuffix.parse(domain)
  domain = "#{domain.sld}.#{domain.tld}"
  domain
end

.is_domain(query) ⇒ Object

Ascertain whether the given query string is a valid domain name.

Returns true if it's a valid domain name; false otherwise.



12
13
14
15
16
17
18
19
# File 'lib/demandbase/domain_record.rb', line 12

def self.is_domain(query)
  begin
    result = PublicSuffix.valid?((Demandbase::DomainRecord.cleanse_domain(query)))
    result
  rescue => e
    false
  end
end

Instance Method Details

#api_urlObject

Return the base URL for the Demandbase domain API



5
6
7
# File 'lib/demandbase/domain_record.rb', line 5

def api_url
  "http://api.demandbase.com/api/v1/domain.json?key=#{rtid_key}"
end