class Demandbase::IPRecord

Attributes

audience[RW]
audience_segment[RW]
domestichq_sid[RW]
hq_sid[RW]
information_level[RW]
ip[RW]
isp[RW]
registry_area_code[RW]
registry_city[RW]
registry_company_name[RW]
registry_country[RW]
registry_country_code[RW]
registry_latitude[RW]
registry_longitude[RW]
registry_state[RW]
registry_zip_code[RW]
worldhq_sid[RW]

Public Class Methods

is_ip(query) click to toggle source

Ascertain whether the given query string is a valid IP address.

Returns true if it’s a valid IP address; false otherwise.

# File lib/demandbase/ip_record.rb, line 30
def self.is_ip(query)
  !!(query =~ Resolv::IPv4::Regex)
end
new(ip) click to toggle source

Instantiate a new Demandbase IP Record from an IP address.

# File lib/demandbase/ip_record.rb, line 35
def initialize(ip)
  raise Demandbase::RTIDNotSetError if rtid_key.nil?

  begin
    url = api_url + "&query=#{ip}"
  rescue => e
    raise Demandbase::ParseError
  end

  begin
    response = JSON.parse(RestClient.get(url))
    return nil unless response

    @registry_company_name  = response["registry_company_name"]
    @registry_city          = response["registry_city"]
    @registry_state         = response["registry_state"]
    @registry_zip_code      = response["registry_zip_code"]
    @registry_area_code     = response["registry_area_code"]
    @registry_country       = response["registry_country"]
    @registry_country_code  = response["registry_country_code"]
    @registry_latitude      = response["registry_latitude"]
    @registry_longitude     = response["registry_longitude"]
    @company_name           = response["company_name"]
    @demandbase_sid         = response["demandbase_sid"]
    @marketing_alias        = response["marketing_alias"]
    @industry               = response["industry"]
    @sub_industry           = response["sub_industry"]
    @employee_count         = response["employee_count"]
    @primary_sic            = response["primary_sic"]
    @street_address         = response["street_address"]
    @city                   = response["city"]
    @state                  = response["state"]
    @zip                    = response["zip"]
    @country                = response["country"]
    @country_name           = response["country_name"]
    @phone                  = response["phone"]
    @stock_ticker           = response["stock_ticker"]
    @web_site               = response["web_site"]
    @annual_sales           = response["annual_sales"]
    @revenue_range          = response["revenue_range"]
    @employee_range         = response["employee_range"]
    @b2b                    = response["b2b"]
    @b2c                    = response["b2c"]
    @traffic                = response["traffic"]
    @latitude               = response["latitude"]
    @longitude              = response["longitude"]
    @fortune_1000           = response["fortune_1000"]
    @forbes_2000            = response["forbes_2000"]
    @ip                     = response["ip"]
    @audience               = response["audience"]
    @audience_segment       = response["audience_segment"]
    @information_level      = response["information_level"]
    @worldhq_sid            = response["worldhq_sid"]
    @domestichq_sid         = response["domestichq_sid"]
    @hq_sid                 = response["hq_sid"]
    @isp                    = response["isp"]
  rescue RestClient::ResourceNotFound => rcrnf
    return nil
  rescue
    raise ServerError
  end
end

Public Instance Methods

api_url() click to toggle source

Return the base URL for the Demandbase IP API

# File lib/demandbase/ip_record.rb, line 23
def api_url
  "http://api.demandbase.com/api/v2/ip.json?key=#{rtid_key}"
end