Module: Demandbase

Defined in:
lib/demandbase.rb,
lib/demandbase/error.rb,
lib/demandbase/record.rb,
lib/demandbase/ip_record.rb,
lib/demandbase/domain_record.rb

Defined Under Namespace

Classes: DomainRecord, Error, IPRecord, ParseError, RTIDNotSetError, Record, ServerError

Constant Summary collapse

ACADEMIC_SIC_CODES =

Standard Industrial Classification (SIC) codes for organizations providing elementary, secondary, tertiary, or quaternary education.

See github.com/leereilly/csi/blob/master/lib/data/master.toml for a complete list.

[
  "82",   # educational services
  "821",  # elementary and secondary schools
  "8211", # elementary and secondary schools
  "822",  # colleges, universities, professional schools and junior colleges
  "8221", # colleges, universities, and professional schools
  "8222", # junior colleges and technical institutes
  "824",  # vocational schools
  "8243", # data processing schools
  "8244", # business and secretarila schools
  "8249", # vocational schools, not elsewhere classified
  "829",  # schools and educational services, not elsewhere classified
  "8299"  # schools and educational services, not elsewhere classified
]
GOVERNMENT_SIC_CODES =

SIC codes for government.

[
  "91",   # executive, legislative, and general government, except finance
  "911",  # executive offices
  "9111", # executive offices
  "912",  # legislative bodies
  "9121", # legislative bodies
  "913",  # executive and legislative offices combined
  "9131", # executive and legislative offices combined
  "919",  # general government, not elsewhere classified
  "9199", # general government, not elsewhere classified
  "92",   # justice, public order, and safety
  "921",  # courts
  "9211", # courts
  "922",  # public order and safety
  "9221", # police protection
  "9222", # legal counsel and prosecution
  "9223", # correctional institutions
  "9224", # fire protection
  "9229", # public order and safety, not elsewhere classified
  "93",   # public finance, taxation, and monetary policy
  "931",  # public finance, taxation, and monetary policy
  "9311", # public finance, taxation, and monetary policy
  "94",   # administration of human resource programs
  "941",  # administration of educational programs
  "9411", # administration of educational programs
  "943",  # administration of public health programs
  "9431", # administration of educational programs
  "944",  # administration of social, human resource and income maintenance programs
  "9441", # administration of social, human resource and income maintenance prorgrams
  "945",  # administration of veterans' affairs, except health and insurance
  "9451", # administration of veterans' affairs, except health and insurance
  "95",   # administration of environmental quality and housing programs
  "951",  # administration of environmental quality programs
  "9511", # air and water resource and solid waste management
  "9512", # land, mineral, wildlife, and forest conservation
  "953",  # administration of housing and urban development progr
  "9531", # administration of housing programs
  "9532", # administration of urban planning and community and rural development
  "96",   # administration of economic programs
  "961",  # administration of general economic programs
  "9611", # administration of general economic programs
  "962",  # regulation and administration of transportation programs
  "9621", # regulation and administration of transportation programs
  "963",  # regulation and administration of communications, electric, gas, and other utilities
  "9631", # regulation and administration of communications, electric, gas, and other utilities
  "964",  # regulation of agricultural marketing and commodities
  "9641", # regulation of agricultural marketing and commodities
  "965",  # regulation, licensing, and inspection of miscellaneous commercial
  "9561", # regulation, licensing, and inspection of miscellaneous commercial
  "966",  # space research and technology
  "9661", # space research and technology
  "977",  # national security and international affairs
  "971",  # national security
  "9711", # national security
  "972",  # international affairs
  "9721"  # international affairs
]
NONPROFIT_SIC_CODES =

SIC codes for registered nonprofits.

[
  "6732", # Educational, religious, and charitable Trusts
  "864",  # Civic, social, and fraternal associations
  "8641", # Civic, social, and fraternal associations
  "865",  # Political organizations
  "8651", # Political organizations
  "866",  # Religious organizations
  "8661", # Religious organizations
  "869",  # Membership organizations, not elsewhere classified
  "8699"  # Membership organizations, not elsewhere classified
]

Class Method Summary collapse

Class Method Details

.is_academic?(domain) ⇒ Boolean

Find out if a particular domain is associated with an academic institution.

Returns true if it looks like an academic organization; false otherwise.

Raises a Demandbase::RTIDNotSetError if a RTID key is not set. Raises a Demandbase::ParseError if the domain doesn’t look legit. Raises a Demandbase::ServerError if the Demandbase server is unresponsive.

Returns:

  • (Boolean)


144
145
146
147
148
149
150
151
152
# File 'lib/demandbase.rb', line 144

def is_academic?(domain)
  record = Demandbase::DomainRecord.new(domain)

  if record && ACADEMIC_SIC_CODES.include?(record.primary_sic)
    return true
  else
    return false
  end
end

.is_government?(domain) ⇒ Boolean

Find out if a particular domain is associated with an government agency.

Returns true if it looks like an government agency; false otherwise.

Raises a Demandbase::RTIDNotSetError if a RTID key is not set. Raises a Demandbase::ParseError if the domain doesn’t look legit. Raises a Demandbase::ServerError if the Demandbase server is unresponsive.

Returns:

  • (Boolean)


162
163
164
165
166
167
168
169
170
# File 'lib/demandbase.rb', line 162

def is_government?(domain)
  record = Demandbase::DomainRecord.new(domain)

  if record && GOVERNMENT_SIC_CODES.include?(record.primary_sic)
    return true
  else
    return false
  end
end

.is_nonprofit?(domain) ⇒ Boolean

Find out if a particular domain is associated with a nonprofit.

Returns true if it looks like a nonprofit; false otherwise.

Raises a Demandbase::RTIDNotSetError if a RTID key is not set. Raises a Demandbase::ParseError if the domain doesn’t look legit. Raises a Demandbase::ServerError if the Demandbase server is unresponsive.

Returns:

  • (Boolean)


180
181
182
183
184
185
186
187
188
# File 'lib/demandbase.rb', line 180

def is_nonprofit?(domain)
  record = Demandbase::DomainRecord.new(domain)

  if record && NONPROFIT_SIC_CODES.include?(record.primary_sic)
    return true
  else
    return false
  end
end

.lookup(query) ⇒ Object Also known as: lazy_lookup

Look up a Demandbase record for a given domain name.

Returns a Demandbase::Record if the record is found; nil otherwise.

Raises a Demandbase::RTIDNotSetError if a RTID key is not set. Raises a Demandbase::ParseError if the domain doesn’t look legit. Raises a Demandbase::ServerError if the Demandbase server is unresponsive.



125
126
127
128
129
130
131
132
133
# File 'lib/demandbase.rb', line 125

def lookup(query)
  if Demandbase::IPRecord.is_ip(query)
    Demandbase::IPRecord.new(query)
  elsif Demandbase::DomainRecord.is_domain(query)
    Demandbase::DomainRecord.new(query)
  else
    raise Demandbase::ParseError
  end
end

.lookup_domain(query) ⇒ Object Also known as: lookup_domain_name



112
113
114
# File 'lib/demandbase.rb', line 112

def lookup_domain(query)
  Demandbase::DomainRecord.new(query)
end

.lookup_ip(query) ⇒ Object Also known as: lookup_ip_address



107
108
109
# File 'lib/demandbase.rb', line 107

def lookup_ip(query)
  Demandbase::IPRecord.new(query)
end