demandbase 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
- # 0.0.1
1
+ # 0.1.1
2
+
3
+ * Add support for subdomains, email addresses, etc. e.g. the following now work:
4
+
5
+ ```ruby
6
+ Demandbase::Record.new "www.github.com",
7
+ Demandbase::Record.new "developer.github.com/",
8
+ Demandbase::Record.new "http://www.github.com/",
9
+ Demandbase::Record.new "https://www.github.com",
10
+ Demandbase::Record.new "https://www.github.com/leereilly/demandbase",
11
+ Demandbase::Record.new "lee@github.com"
12
+ ```
13
+
14
+ # 0.1.0
2
15
 
3
16
  * Initial release.
data/Gemfile CHANGED
@@ -1,7 +1,8 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem "json", "~> 1.7.7"
4
- gem "rest-client", "~> 1.6.7"
3
+ gem "json", "~> 1.7.7"
4
+ gem "public_suffix", "~> 1.2.0"
5
+ gem "rest-client", "~> 1.6.7"
5
6
 
6
7
  group :development do
7
8
  gem "shoulda", ">= 0"
data/Gemfile.lock CHANGED
@@ -19,6 +19,7 @@ GEM
19
19
  mocha (0.10.5)
20
20
  metaclass (~> 0.0.1)
21
21
  multi_json (1.6.1)
22
+ public_suffix (1.2.0)
22
23
  rake (10.0.3)
23
24
  rdoc (3.12.2)
24
25
  json (~> 1.4)
@@ -39,6 +40,7 @@ DEPENDENCIES
39
40
  bundler (~> 1.2.1)
40
41
  jeweler (~> 1.8.3)
41
42
  json (~> 1.7.7)
43
+ public_suffix (~> 1.2.0)
42
44
  rdoc (~> 3.12)
43
45
  rest-client (~> 1.6.7)
44
46
  shoulda
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
data/demandbase.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "demandbase"
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
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"]
@@ -42,6 +42,7 @@ Gem::Specification.new do |s|
42
42
 
43
43
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
44
  s.add_runtime_dependency(%q<json>, ["~> 1.7.7"])
45
+ s.add_runtime_dependency(%q<public_suffix>, ["~> 1.2.0"])
45
46
  s.add_runtime_dependency(%q<rest-client>, ["~> 1.6.7"])
46
47
  s.add_development_dependency(%q<shoulda>, [">= 0"])
47
48
  s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
@@ -49,6 +50,7 @@ Gem::Specification.new do |s|
49
50
  s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
50
51
  else
51
52
  s.add_dependency(%q<json>, ["~> 1.7.7"])
53
+ s.add_dependency(%q<public_suffix>, ["~> 1.2.0"])
52
54
  s.add_dependency(%q<rest-client>, ["~> 1.6.7"])
53
55
  s.add_dependency(%q<shoulda>, [">= 0"])
54
56
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
@@ -57,6 +59,7 @@ Gem::Specification.new do |s|
57
59
  end
58
60
  else
59
61
  s.add_dependency(%q<json>, ["~> 1.7.7"])
62
+ s.add_dependency(%q<public_suffix>, ["~> 1.2.0"])
60
63
  s.add_dependency(%q<rest-client>, ["~> 1.6.7"])
61
64
  s.add_dependency(%q<shoulda>, [">= 0"])
62
65
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
data/lib/demandbase.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require 'json'
2
+ require 'public_suffix'
2
3
  require 'rest_client'
4
+
3
5
  require 'demandbase/record'
4
6
 
5
7
  module Demandbase
@@ -34,7 +34,8 @@ module Demandbase
34
34
 
35
35
  # Instantiate a new Demandbase Record from a domain name.
36
36
  def initialize(domain)
37
- url = Demandbase::API_URLS[:domain] + "&query=#{domain}"
37
+ query = cleanse_domain(domain)
38
+ url = Demandbase::API_URLS[:domain] + "&query=#{query}"
38
39
 
39
40
  begin
40
41
  response = JSON.parse(RestClient.get(url))
@@ -68,5 +69,20 @@ module Demandbase
68
69
  puts "Problem querying the server: #{e.inspect}"
69
70
  end
70
71
  end
72
+
73
+ # Clean the domain of things like 'http(s)://', 'www',
74
+ # '?foo=bar', etc.
75
+ #
76
+ # Return the domain string.
77
+ def cleanse_domain(domain)
78
+ domain.downcase!
79
+ domain = domain.sub(/^https?\:\/\//, '').sub(/^www./,'')
80
+ domain = domain.split("/").first
81
+ domain = domain.split("@").last
82
+
83
+ domain = PublicSuffix.parse(domain)
84
+ domain = "#{domain.sld}.#{domain.tld}"
85
+ domain
86
+ end
71
87
  end
72
88
  end
data/test/test_record.rb CHANGED
@@ -36,4 +36,22 @@ class TestDemandbaseRecord < Test::Unit::TestCase
36
36
  assert_equal false, record.fortune_1000 # TODO: fix this test in 2017
37
37
  assert_equal false, record.forbes_2000 # TODO: fix this test in 2016
38
38
  end
39
+
40
+ should "initialize a new record with a subdomain" do
41
+ queries = [
42
+ "github.com",
43
+ "www.github.com",
44
+ "developer.github.com/",
45
+ "http://www.github.com/",
46
+ "https://www.github.com",
47
+ "https://www.github.com/leereilly/demandbase",
48
+ "lee@github.com"
49
+ ]
50
+
51
+ queries.each do |query|
52
+ record = Demandbase::Record.new(query)
53
+ assert_equal "github.com", record.web_site, "with #{query}"
54
+ end
55
+
56
+ end
39
57
  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.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -27,6 +27,22 @@ dependencies:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
29
  version: 1.7.7
30
+ - !ruby/object:Gem::Dependency
31
+ name: public_suffix
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 1.2.0
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.2.0
30
46
  - !ruby/object:Gem::Dependency
31
47
  name: rest-client
32
48
  requirement: !ruby/object:Gem::Requirement
@@ -143,7 +159,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
143
159
  version: '0'
144
160
  segments:
145
161
  - 0
146
- hash: -3613502600391467336
162
+ hash: 2870129740686966598
147
163
  required_rubygems_version: !ruby/object:Gem::Requirement
148
164
  none: false
149
165
  requirements: