Class: Demandbase::IPRecord

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

Instance Attribute Summary collapse

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(ip) ⇒ IPRecord

Instantiate a new Demandbase IP Record from an IP address.



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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# 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

Instance Attribute Details

#audienceObject

Returns the value of attribute audience.



14
15
16
# File 'lib/demandbase/ip_record.rb', line 14

def audience
  @audience
end

#audience_segmentObject

Returns the value of attribute audience_segment.



15
16
17
# File 'lib/demandbase/ip_record.rb', line 15

def audience_segment
  @audience_segment
end

#domestichq_sidObject

Returns the value of attribute domestichq_sid.



18
19
20
# File 'lib/demandbase/ip_record.rb', line 18

def domestichq_sid
  @domestichq_sid
end

#hq_sidObject

Returns the value of attribute hq_sid.



19
20
21
# File 'lib/demandbase/ip_record.rb', line 19

def hq_sid
  @hq_sid
end

#information_levelObject

Returns the value of attribute information_level.



13
14
15
# File 'lib/demandbase/ip_record.rb', line 13

def information_level
  @information_level
end

#ipObject

Returns the value of attribute ip.



12
13
14
# File 'lib/demandbase/ip_record.rb', line 12

def ip
  @ip
end

#ispObject

Returns the value of attribute isp.



20
21
22
# File 'lib/demandbase/ip_record.rb', line 20

def isp
  @isp
end

#registry_area_codeObject

Returns the value of attribute registry_area_code.



7
8
9
# File 'lib/demandbase/ip_record.rb', line 7

def registry_area_code
  @registry_area_code
end

#registry_cityObject

Returns the value of attribute registry_city.



4
5
6
# File 'lib/demandbase/ip_record.rb', line 4

def registry_city
  @registry_city
end

#registry_company_nameObject

Returns the value of attribute registry_company_name.



3
4
5
# File 'lib/demandbase/ip_record.rb', line 3

def registry_company_name
  @registry_company_name
end

#registry_countryObject

Returns the value of attribute registry_country.



8
9
10
# File 'lib/demandbase/ip_record.rb', line 8

def registry_country
  @registry_country
end

#registry_country_codeObject

Returns the value of attribute registry_country_code.



9
10
11
# File 'lib/demandbase/ip_record.rb', line 9

def registry_country_code
  @registry_country_code
end

#registry_latitudeObject

Returns the value of attribute registry_latitude.



10
11
12
# File 'lib/demandbase/ip_record.rb', line 10

def registry_latitude
  @registry_latitude
end

#registry_longitudeObject

Returns the value of attribute registry_longitude.



11
12
13
# File 'lib/demandbase/ip_record.rb', line 11

def registry_longitude
  @registry_longitude
end

#registry_stateObject

Returns the value of attribute registry_state.



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

def registry_state
  @registry_state
end

#registry_zip_codeObject

Returns the value of attribute registry_zip_code.



6
7
8
# File 'lib/demandbase/ip_record.rb', line 6

def registry_zip_code
  @registry_zip_code
end

#worldhq_sidObject

Returns the value of attribute worldhq_sid.



17
18
19
# File 'lib/demandbase/ip_record.rb', line 17

def worldhq_sid
  @worldhq_sid
end

Class Method Details

.is_ip(query) ⇒ Object

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

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



30
31
32
# File 'lib/demandbase/ip_record.rb', line 30

def self.is_ip(query)
  !!(query =~ Resolv::IPv4::Regex)
end

Instance Method Details

#api_urlObject

Return the base URL for the Demandbase IP API



23
24
25
# File 'lib/demandbase/ip_record.rb', line 23

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