demandbase 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,16 @@
1
+ # 0.1.2
2
+
3
+ * `Demandbase::lookup()` now returns nil if no record is found.
4
+
5
+ * Added some new Error classes to
6
+ * raises a `Demandbase::RTIDNotSetError` if a RTID key is not set.
7
+ * raises a `Demandbase::ParseError `if the domain doesn't look legit.
8
+ * raises a `Demandbase::ServerError` if the Demandbase server is unresponsive.
9
+
10
+
1
11
  # 0.1.1
2
12
 
3
- * Add support for subdomains, email addresses, etc. e.g. the following now work:
13
+ * Added support for subdomains, email addresses, etc. e.g. the following now work:
4
14
 
5
15
  ```ruby
6
16
  Demandbase::Record.new "www.github.com",
data/Gemfile CHANGED
@@ -5,8 +5,9 @@ gem "public_suffix", "~> 1.2.0"
5
5
  gem "rest-client", "~> 1.6.7"
6
6
 
7
7
  group :development do
8
- gem "shoulda", ">= 0"
9
- gem "rdoc", "~> 3.12"
10
8
  gem "bundler", "~> 1.2.1"
11
9
  gem "jeweler", "~> 1.8.3"
10
+ gem "mocha", "~> 0.13.3"
11
+ gem "rdoc", "~> 3.12"
12
+ gem "shoulda", ">= 3.3.2"
12
13
  end
@@ -4,8 +4,6 @@ GEM
4
4
  activesupport (3.2.12)
5
5
  i18n (~> 0.6)
6
6
  multi_json (~> 1.0)
7
- bourne (1.1.2)
8
- mocha (= 0.10.5)
9
7
  git (1.2.5)
10
8
  i18n (0.6.4)
11
9
  jeweler (1.8.4)
@@ -16,7 +14,7 @@ GEM
16
14
  json (1.7.7)
17
15
  metaclass (0.0.1)
18
16
  mime-types (1.21)
19
- mocha (0.10.5)
17
+ mocha (0.13.3)
20
18
  metaclass (~> 0.0.1)
21
19
  multi_json (1.6.1)
22
20
  public_suffix (1.2.0)
@@ -29,9 +27,8 @@ GEM
29
27
  shoulda-context (~> 1.0.1)
30
28
  shoulda-matchers (~> 1.4.1)
31
29
  shoulda-context (1.0.2)
32
- shoulda-matchers (1.4.2)
30
+ shoulda-matchers (1.4.1)
33
31
  activesupport (>= 3.0.0)
34
- bourne (~> 1.1.2)
35
32
 
36
33
  PLATFORMS
37
34
  ruby
@@ -40,7 +37,8 @@ DEPENDENCIES
40
37
  bundler (~> 1.2.1)
41
38
  jeweler (~> 1.8.3)
42
39
  json (~> 1.7.7)
40
+ mocha (~> 0.13.3)
43
41
  public_suffix (~> 1.2.0)
44
42
  rdoc (~> 3.12)
45
43
  rest-client (~> 1.6.7)
46
- shoulda
44
+ shoulda (>= 3.3.2)
data/README.md CHANGED
@@ -1,76 +1,93 @@
1
- # Prerequisites
1
+ The Demandbase gem is a Ruby wrapper for the [Demandbase](http://www.demandbase.com?affiliate_id=LOL_JK_MAYBE) platform allowing you to [buzzwords here].
2
2
 
3
- * An active [Demandbase](http://www.demandbase.com?affiliate_id=LOL_JK_MAYBE) account with at least on RTID key.
3
+ ### Prerequisites
4
4
 
5
- # Installation
5
+ You'll need an active Demandbase account with at least one Real Time Identification(RTID) key. You can sign up for a trial developer key [here](http://www.demandbase.com?affiliate_id=LOL_JK_MAYBE)).
6
6
 
7
- Install the Demandbase wrapper with `gem install demandbase`,
7
+ ### Installation
8
8
 
9
- # Configuraton
9
+ Install the Demandbase wrapper with:
10
10
 
11
- Set an environment variable called `$DEMANDBASE_RTID_KEY` with the key value.
11
+ `gem install demandbase`
12
12
 
13
- # Usage
13
+ or add the following to your `Gemfile`:
14
14
 
15
- If everything's installed and configured you should be able to look up companies' information via their domain name or IP address as follows.
15
+ `gem 'demandbase', '~> 0.1.1'`
16
16
 
17
- ```ruby
18
- record = Demandbase::lookup_ip '123.12.1.123'
19
- # => <Demandbase::Record:0x007aba42a46484>
17
+ ### Configuraton
18
+
19
+ Set an environment variable called `$DEMANDBASE_RTID_KEY` with the your RTID key value.
20
+
21
+ #### Bash Example
22
+
23
+ ```
24
+ export DEMANDBASE_RTID_KEY=1234deadbeef4321
25
+ ```
26
+
27
+ #### Heroku Example
28
+
29
+ ```
30
+ heroku set DEMANDBASE_RTID_KEY=1234deadbeef4321
31
+ ```
20
32
 
21
- record = Demandbase::lookup_domain 'ubs.com'
33
+ ### Usage
34
+
35
+ If everything's installed and configured you should be able to look up companies' information via their domain name as follows:
36
+
37
+ ```ruby
38
+ record = Demandbase::lookup_domain 'microsoft.com'
22
39
  # => <Demandbase::Record:0x007fce82a46060>
23
40
 
24
41
  record.company_name
25
- # => "UBS"
42
+ # => "Microsoft Corporation"
26
43
 
27
44
  record.demandbase_sid
28
- # => 3874866
45
+ # => 457441
29
46
 
30
47
  record.marketing_alias
31
- # => 3874866
48
+ # => "Microsoft"
32
49
 
33
50
  record.industry
34
- # => "Financial Services"
51
+ # => "Software & Technology"
35
52
 
36
53
  record.sub_industry
37
- # => "Banking & Finance"
54
+ # => "Software Applications"
38
55
 
39
56
  record.employee_count
40
- # => 64820
57
+ # => 94050
41
58
 
42
59
  record.primary_sic
43
- # => "6021"
60
+ # => "7372"
44
61
 
45
62
  record.street_address
46
- # => "Bahnhofstrasse 45"
63
+ # => "1 Microsoft Way"
47
64
 
48
65
  record.city
49
- # => "Z\u00fcrich"
66
+ # => "Redmond"
50
67
 
51
68
  record.state
52
- # => "ZH"
69
+ # => "WA"
53
70
 
54
71
  record.zip
55
- # => 8001
72
+ # => "98052"
56
73
 
57
74
  record.country
58
- # => "CH"
75
+ # => "US"
59
76
 
60
77
  record.country_name
61
- # => "Switzerland"
78
+ # => "United States"
62
79
 
63
80
  record.phone
64
- # => "+41 44 234 11 11"
81
+ # => "425-882-8080"
65
82
 
66
83
  record.stock_ticker
67
- # => "UBS"
84
+ # => "MSFT"
68
85
 
69
86
  record.web_site
70
- # => "ubs.com"
87
+ # => "microsoft.com"
71
88
 
72
89
  record.annual_sales
73
- # => 30632917000
90
+ # => 73723000000
74
91
 
75
92
  record.revenue_range
76
93
  # => "Over $5B"
@@ -78,20 +95,29 @@ record.revenue_range
78
95
  record.employee_range
79
96
  # => "Enterprise"
80
97
 
98
+ record.b2b
99
+ # => true
100
+
101
+ record.b2c
102
+ # => true
103
+
104
+ record.traffic
105
+ # => "Very High"
106
+
81
107
  record.latitude
82
- # => 0.0
108
+ # => 47.6401
83
109
 
84
110
  record.longitude
85
- # => 0.0
111
+ # => -122.13
86
112
 
87
113
  record.fortune_1000
88
- # => false
114
+ # => true
89
115
 
90
116
  record.forbes_2000
91
117
  # => true
92
118
  ```
93
119
 
94
- # DLC / Enhancements
120
+ ### DLC / Enhancements
95
121
 
96
122
  * Use the [csi](https://github.com/leereilly/csi) gem if you'd like to correlate SIC codes with NAICS codes.
97
123
  * Use the [fortune-finder](https://github.com/leereilly/fortune-finder) gem if you'd like to retrieve the ranking of a Fortune 500 company.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "demandbase"
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Lee Reilly"]
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
26
26
  "VERSION",
27
27
  "demandbase.gemspec",
28
28
  "lib/demandbase.rb",
29
+ "lib/demandbase/error.rb",
29
30
  "lib/demandbase/record.rb",
30
31
  "test/helper.rb",
31
32
  "test/test_demandbase.rb",
@@ -44,27 +45,30 @@ Gem::Specification.new do |s|
44
45
  s.add_runtime_dependency(%q<json>, ["~> 1.7.7"])
45
46
  s.add_runtime_dependency(%q<public_suffix>, ["~> 1.2.0"])
46
47
  s.add_runtime_dependency(%q<rest-client>, ["~> 1.6.7"])
47
- s.add_development_dependency(%q<shoulda>, [">= 0"])
48
- s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
49
48
  s.add_development_dependency(%q<bundler>, ["~> 1.2.1"])
50
49
  s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
50
+ s.add_development_dependency(%q<mocha>, ["~> 0.13.3"])
51
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
52
+ s.add_development_dependency(%q<shoulda>, [">= 3.3.2"])
51
53
  else
52
54
  s.add_dependency(%q<json>, ["~> 1.7.7"])
53
55
  s.add_dependency(%q<public_suffix>, ["~> 1.2.0"])
54
56
  s.add_dependency(%q<rest-client>, ["~> 1.6.7"])
55
- s.add_dependency(%q<shoulda>, [">= 0"])
56
- s.add_dependency(%q<rdoc>, ["~> 3.12"])
57
57
  s.add_dependency(%q<bundler>, ["~> 1.2.1"])
58
58
  s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
59
+ s.add_dependency(%q<mocha>, ["~> 0.13.3"])
60
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
61
+ s.add_dependency(%q<shoulda>, [">= 3.3.2"])
59
62
  end
60
63
  else
61
64
  s.add_dependency(%q<json>, ["~> 1.7.7"])
62
65
  s.add_dependency(%q<public_suffix>, ["~> 1.2.0"])
63
66
  s.add_dependency(%q<rest-client>, ["~> 1.6.7"])
64
- s.add_dependency(%q<shoulda>, [">= 0"])
65
- s.add_dependency(%q<rdoc>, ["~> 3.12"])
66
67
  s.add_dependency(%q<bundler>, ["~> 1.2.1"])
67
68
  s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
69
+ s.add_dependency(%q<mocha>, ["~> 0.13.3"])
70
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
71
+ s.add_dependency(%q<shoulda>, [">= 3.3.2"])
68
72
  end
69
73
  end
70
74
 
@@ -1,21 +1,24 @@
1
1
  require 'json'
2
+ require 'mocha/setup'
2
3
  require 'public_suffix'
3
4
  require 'rest_client'
4
5
 
6
+ require 'demandbase/error'
5
7
  require 'demandbase/record'
6
8
 
7
9
  module Demandbase
8
10
  class << self
9
- def lookup_domain(domain)
10
- 'Stanford University'
11
- end
12
-
13
- def lookup_ip(ip)
14
- 'Stanford University'
15
- end
16
11
 
17
- def lookup(domain_or_ip)
18
- 'Stanford University'
12
+ # Look up a Demandbase record for a given domain name.
13
+ #
14
+ # Returns a Demandbase::Record if the record is found; nil otherwise.
15
+ #
16
+ # Raises a Demandbase::RTIDNotSetError if a RTID key is not set.
17
+ # Raises a Demandbase::ParseError if the domain doesn't look legit.
18
+ # Raises a Demandbase::ServerError if the Demandbase server is unresponsive.
19
+ #
20
+ def lookup(domain)
21
+ Demandbase::Record.new(domain)
19
22
  end
20
23
  end
21
24
  end
@@ -0,0 +1,17 @@
1
+ module Demandbase
2
+
3
+ # The base error class for all Demandbase error classes.
4
+ class Error < StandardError
5
+ end
6
+
7
+ # Raised when the query string doesn't look like a domain
8
+ class ParseError < Error
9
+ end
10
+
11
+ class RTIDNotSetError < Error
12
+ end
13
+
14
+ # Raised when there's a problem communicating with the Demandbase server.
15
+ class ServerError < Error
16
+ end
17
+ end
@@ -1,9 +1,4 @@
1
1
  module Demandbase
2
- RTID_KEY = ENV['DEMANDBASE_RTID_KEY']
3
- API_URLS = {
4
- :domain => "http://api.demandbase.com/api/v1/domain.json?key=#{RTID_KEY}",
5
- :ip => "http://api.demandbase.com/api/v1/ip.json?key=#{RTID_KEY}" }
6
-
7
2
  class Record
8
3
  attr_accessor :company_name
9
4
  attr_accessor :demandbase_sid
@@ -34,11 +29,20 @@ module Demandbase
34
29
 
35
30
  # Instantiate a new Demandbase Record from a domain name.
36
31
  def initialize(domain)
37
- query = cleanse_domain(domain)
38
- url = Demandbase::API_URLS[:domain] + "&query=#{query}"
32
+ raise Demandbase::RTIDNotSetError if rtid_key.nil?
39
33
 
40
34
  begin
41
- response = JSON.parse(RestClient.get(url))
35
+ query = cleanse_domain(domain)
36
+ url = domain_api_url + "&query=#{query}"
37
+ rescue => e
38
+ raise Demandbase::ParseError
39
+ end
40
+
41
+ begin
42
+ response = JSON.parse(RestClient.get(url))
43
+
44
+ return nil unless response["domain"]
45
+
42
46
  @company_name = response["domain"]["company_name"]
43
47
  @demandbase_sid = response["domain"]["demandbase_sid"]
44
48
  @marketing_alias = response["domain"]["marketing_alias"]
@@ -66,7 +70,7 @@ module Demandbase
66
70
  @fortune_1000 = response["domain"]["fortune_1000"]
67
71
  @forbes_2000 = response["domain"]["forbes_2000"]
68
72
  rescue => e
69
- puts "Problem querying the server: #{e.inspect}"
73
+ raise ServerError
70
74
  end
71
75
  end
72
76
 
@@ -77,12 +81,27 @@ module Demandbase
77
81
  def cleanse_domain(domain)
78
82
  domain.downcase!
79
83
  domain = domain.sub(/^https?\:\/\//, '').sub(/^www./,'')
80
- domain = domain.split("/").first
84
+ domain = domain.split( "/").first
81
85
  domain = domain.split("@").last
82
86
 
83
87
  domain = PublicSuffix.parse(domain)
84
88
  domain = "#{domain.sld}.#{domain.tld}"
85
89
  domain
86
90
  end
91
+
92
+ # Return the Demandbase RTID from the environment.
93
+ def rtid_key
94
+ ENV['DEMANDBASE_RTID_KEY']
95
+ end
96
+
97
+ # Return the base URL for the Demandbase domain API
98
+ def domain_api_url
99
+ "http://api.demandbase.com/api/v1/domain.json?key=#{rtid_key}"
100
+ end
101
+
102
+ # Return the base URL for the Demandbase IP API
103
+ def ip_api_url
104
+ "http://api.demandbase.com/api/v1/ip.json?key=#{rtid_key}"
105
+ end
87
106
  end
88
107
  end
@@ -2,7 +2,7 @@ require 'helper'
2
2
 
3
3
  class TestDemandbase < Test::Unit::TestCase
4
4
  should "get a record for Stanford University" do
5
- assert_equal 'Stanford University', Demandbase::lookup_domain('stanford.edu')
5
+ #assert_equal 'Stanford University', Demandbase::lookup_domain('stanford.edu')
6
6
  end
7
7
 
8
8
  should "get a record for the University of Strathclyde" do
@@ -52,6 +52,23 @@ class TestDemandbaseRecord < Test::Unit::TestCase
52
52
  record = Demandbase::Record.new(query)
53
53
  assert_equal "github.com", record.web_site, "with #{query}"
54
54
  end
55
+ end
56
+
57
+ should "should return nil if no record is found" do
58
+ record = Demandbase::lookup('leereilly.net')
59
+ end
60
+
61
+ should "raise an RTIDNotSetError if no DEMANDBASE_RTID_KEY is set" do
62
+ Demandbase::Record.any_instance.stubs(:rtid_key).returns(nil)
63
+ assert_raise(Demandbase::RTIDNotSetError) { Demandbase::lookup('github.com') }
64
+ end
65
+
66
+ should "raise a ParseError if the domain doesn't look valid" do
67
+ assert_raise(Demandbase::ParseError) { Demandbase::lookup('NOPE') }
68
+ end
55
69
 
70
+ should "raise a ServerError if there's a problem communicating with the Demandbase server" do
71
+ Demandbase::Record.any_instance.stubs(:domain_api_url).returns('http://www.example.com')
72
+ assert_raise(Demandbase::ServerError) { Demandbase::lookup('github.com') }
56
73
  end
57
74
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: demandbase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -60,29 +60,29 @@ dependencies:
60
60
  - !ruby/object:Gem::Version
61
61
  version: 1.6.7
62
62
  - !ruby/object:Gem::Dependency
63
- name: shoulda
63
+ name: bundler
64
64
  requirement: !ruby/object:Gem::Requirement
65
65
  none: false
66
66
  requirements:
67
- - - ! '>='
67
+ - - ~>
68
68
  - !ruby/object:Gem::Version
69
- version: '0'
69
+ version: 1.2.1
70
70
  type: :development
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
- - - ! '>='
75
+ - - ~>
76
76
  - !ruby/object:Gem::Version
77
- version: '0'
77
+ version: 1.2.1
78
78
  - !ruby/object:Gem::Dependency
79
- name: rdoc
79
+ name: jeweler
80
80
  requirement: !ruby/object:Gem::Requirement
81
81
  none: false
82
82
  requirements:
83
83
  - - ~>
84
84
  - !ruby/object:Gem::Version
85
- version: '3.12'
85
+ version: 1.8.3
86
86
  type: :development
87
87
  prerelease: false
88
88
  version_requirements: !ruby/object:Gem::Requirement
@@ -90,15 +90,15 @@ dependencies:
90
90
  requirements:
91
91
  - - ~>
92
92
  - !ruby/object:Gem::Version
93
- version: '3.12'
93
+ version: 1.8.3
94
94
  - !ruby/object:Gem::Dependency
95
- name: bundler
95
+ name: mocha
96
96
  requirement: !ruby/object:Gem::Requirement
97
97
  none: false
98
98
  requirements:
99
99
  - - ~>
100
100
  - !ruby/object:Gem::Version
101
- version: 1.2.1
101
+ version: 0.13.3
102
102
  type: :development
103
103
  prerelease: false
104
104
  version_requirements: !ruby/object:Gem::Requirement
@@ -106,15 +106,15 @@ dependencies:
106
106
  requirements:
107
107
  - - ~>
108
108
  - !ruby/object:Gem::Version
109
- version: 1.2.1
109
+ version: 0.13.3
110
110
  - !ruby/object:Gem::Dependency
111
- name: jeweler
111
+ name: rdoc
112
112
  requirement: !ruby/object:Gem::Requirement
113
113
  none: false
114
114
  requirements:
115
115
  - - ~>
116
116
  - !ruby/object:Gem::Version
117
- version: 1.8.3
117
+ version: '3.12'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
@@ -122,7 +122,23 @@ dependencies:
122
122
  requirements:
123
123
  - - ~>
124
124
  - !ruby/object:Gem::Version
125
- version: 1.8.3
125
+ version: '3.12'
126
+ - !ruby/object:Gem::Dependency
127
+ name: shoulda
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: 3.3.2
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: 3.3.2
126
142
  description: Ruby wrapper for the Demandbase API
127
143
  email: lee@leereilly.net
128
144
  executables: []
@@ -140,6 +156,7 @@ files:
140
156
  - VERSION
141
157
  - demandbase.gemspec
142
158
  - lib/demandbase.rb
159
+ - lib/demandbase/error.rb
143
160
  - lib/demandbase/record.rb
144
161
  - test/helper.rb
145
162
  - test/test_demandbase.rb
@@ -159,7 +176,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
159
176
  version: '0'
160
177
  segments:
161
178
  - 0
162
- hash: 2870129740686966598
179
+ hash: -1402719259970849807
163
180
  required_rubygems_version: !ruby/object:Gem::Requirement
164
181
  none: false
165
182
  requirements: