clearbit 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1ddabe98eebd6f1befcf8790be91277dc728b728
4
- data.tar.gz: 1dd7590d5115c47095d14bc8ab3bdb37ee967573
3
+ metadata.gz: d45b4f5a8d2d1d16d5acce2990114ea4128e859c
4
+ data.tar.gz: cc056730612d1079db10d3c05f8c9ecf375a5674
5
5
  SHA512:
6
- metadata.gz: 9494f07956d9e90758cbbbb017ffe414a859d30a7510e8a682ebf988805361f4c0159d9e9fd0389aa0d09fb7c271b9661b529c53252532364b8feabd3d7b1bd1
7
- data.tar.gz: 4a9bf7ad6d8844c09bb29b02825d5c875aadefb9245357fb3f4c2119e1c2393ee94ee8d6137218add2ae9c781adb11ad58bc3a8243ddbb1f92d2689dfdef855f
6
+ metadata.gz: edd484f91784a5577e09a7aa287bb03f027d6cc695bb9517c1b7a1f391d1aebc31fcb9be9ba5e5980f81256fa1a486dd245db23e85352d9cba8a13694a61910a
7
+ data.tar.gz: fae4a7aa0a63a36caae474e974cc22a0798827baf3951e0e9ca3a8694587cdea898432d48328e6859127fe38ac0364b79646ee30f16db2976e2bdc38605487ec
@@ -18,6 +18,7 @@ module Clearbit
18
18
  key || raise('Clearbit.key not set')
19
19
  end
20
20
 
21
+ autoload :Autocomplete, 'clearbit/autocomplete'
21
22
  autoload :Base, 'clearbit/base'
22
23
  autoload :Enrichment, 'clearbit/enrichment'
23
24
  autoload :Discovery, 'clearbit/discovery'
@@ -26,6 +27,7 @@ module Clearbit
26
27
  autoload :Pending, 'clearbit/pending'
27
28
  autoload :Prospector, 'clearbit/prospector'
28
29
  autoload :Resource, 'clearbit/resource'
30
+ autoload :Risk, 'clearbit/risk'
29
31
  autoload :Watchlist, 'clearbit/watchlist'
30
32
  autoload :Webhook, 'clearbit/webhook'
31
33
 
@@ -0,0 +1,14 @@
1
+ module Clearbit
2
+ module Autocomplete
3
+ class Company < Base
4
+ endpoint 'https://autocomplete.clearbit.com'
5
+ path '/v1'
6
+
7
+ def self.suggest(query)
8
+ response = get 'companies/suggest', query: query
9
+
10
+ self.new(response)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -5,7 +5,7 @@ module Clearbit
5
5
  autoload :PersonCompany, 'clearbit/enrichment/person_company'
6
6
 
7
7
  def find(values)
8
- if domain = values[:domain]
8
+ if values.key?(:domain)
9
9
  result = Company.find(values)
10
10
 
11
11
  if result && result.pending?
@@ -2,15 +2,15 @@ module Clearbit
2
2
  module Enrichment
3
3
  class Company < Base
4
4
  endpoint 'https://company.clearbit.com'
5
- path '/v1/companies'
5
+ path '/v2/companies'
6
6
 
7
7
  def self.find(values)
8
8
  unless values.is_a?(Hash)
9
- values = {:id => values}
9
+ values = { id: values }
10
10
  end
11
11
 
12
- if domain = values.delete(:domain)
13
- response = get(uri(:domain, domain), values)
12
+ if values.key?(:domain)
13
+ response = get(uri(:find), values)
14
14
  elsif id = values.delete(:id)
15
15
  response = get(id, values)
16
16
  else
@@ -30,7 +30,7 @@ module Clearbit
30
30
  end
31
31
 
32
32
  def flag!(attrs = {})
33
- self.class.post(uri('flag'), attrs)
33
+ self.class.post(uri(:flag), attrs)
34
34
  end
35
35
  end
36
36
  end
@@ -2,19 +2,17 @@ module Clearbit
2
2
  module Enrichment
3
3
  class Person < Base
4
4
  endpoint 'https://person.clearbit.com'
5
- path '/v1/people'
5
+ path '/v2/people'
6
6
 
7
7
  def self.find(values)
8
8
  unless values.is_a?(Hash)
9
- values = {:id => values}
9
+ values = { id: values }
10
10
  end
11
11
 
12
- if email = values.delete(:email)
13
- response = get(uri(:email, email), values)
14
-
12
+ if values.key?(:email)
13
+ response = get(uri(:find), values)
15
14
  elsif id = values.delete(:id)
16
15
  response = get(id, values)
17
-
18
16
  else
19
17
  raise ArgumentError, 'Invalid values'
20
18
  end
@@ -33,7 +31,7 @@ module Clearbit
33
31
  end
34
32
 
35
33
  def flag!(attrs = {})
36
- self.class.post(uri('flag'), attrs)
34
+ self.class.post(uri(:flag), attrs)
37
35
  end
38
36
  end
39
37
  end
@@ -2,15 +2,15 @@ module Clearbit
2
2
  module Enrichment
3
3
  class PersonCompany < Base
4
4
  endpoint 'https://person.clearbit.com'
5
- path '/v1/combined'
5
+ path '/v2/combined'
6
6
 
7
7
  def self.find(values)
8
8
  unless values.is_a?(Hash)
9
- values = {:id => values}
9
+ values = { email: values }
10
10
  end
11
11
 
12
- if email = values.delete(:email)
13
- response = get(uri(:email, email), values)
12
+ if values.key?(:email)
13
+ response = get(uri(:find), values)
14
14
  else
15
15
  raise ArgumentError, 'Invalid values'
16
16
  end
@@ -20,7 +20,7 @@ module Clearbit
20
20
  encoded_params = URI.encode_www_form(params)
21
21
 
22
22
  if domain = values.delete(:domain)
23
- raise ArgumentError, 'Invalid domain' unless domain =~ /^([a-z0-9]+)*\.[a-z]{2,5}$/
23
+ raise ArgumentError, 'Invalid domain' unless domain =~ /^[a-z0-9-]+(\.[a-z0-9-]+)*\.[a-z]{2,}$/
24
24
  if encoded_params.empty?
25
25
  "#{ENDPOINT}/#{domain}"
26
26
  else
@@ -7,14 +7,36 @@ module Clearbit
7
7
  self.new get('search', values)
8
8
  end
9
9
 
10
+ def self.find(values)
11
+ unless values.is_a?(Hash)
12
+ values = {:id => values}
13
+ end
14
+
15
+ if id = values.delete(:id)
16
+ response = get(id, values)
17
+
18
+ else
19
+ raise ArgumentError, 'Invalid values'
20
+ end
21
+
22
+ self.new(response)
23
+ rescue Nestful::ResourceNotFound
24
+ end
25
+
26
+ class << self
27
+ alias_method :[], :find
28
+ end
29
+
10
30
  def email
11
31
  email_response.email
12
32
  end
13
33
 
14
- def verified?
34
+ def verified
15
35
  email_response.verified
16
36
  end
17
37
 
38
+ alias_method :verified?, :verified
39
+
18
40
  protected
19
41
 
20
42
  def email_response
@@ -18,7 +18,7 @@ module Clearbit
18
18
  @options ||= {}
19
19
  @options.merge!(value) if value
20
20
 
21
- if superclass.respond_to?(:options)
21
+ if superclass <= Resource && superclass.respond_to?(:options)
22
22
  Nestful::Helpers.deep_merge(superclass.options, @options)
23
23
  else
24
24
  @options
@@ -61,6 +61,13 @@ module Clearbit
61
61
  options.merge!(request_options)
62
62
  end
63
63
 
64
+ if key = options.delete(:key)
65
+ options.merge(
66
+ auth_type: :bearer,
67
+ password: key
68
+ )
69
+ end
70
+
64
71
  [params, options]
65
72
  end
66
73
 
@@ -0,0 +1,18 @@
1
+ module Clearbit
2
+ class Risk < Base
3
+ endpoint 'https://risk.clearbit.com'
4
+ path '/v1'
5
+
6
+ def self.calculate(values = {})
7
+ self.new get('calculate', values)
8
+ end
9
+
10
+ def self.confirmed(values = {})
11
+ self.new post('confirmed', values)
12
+ end
13
+
14
+ def self.flag(values = {})
15
+ self.new post('flag', values)
16
+ end
17
+ end
18
+ end
@@ -1,3 +1,3 @@
1
1
  module Clearbit
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
@@ -12,7 +12,7 @@ describe Clearbit::Enrichment do
12
12
  company: nil
13
13
  }
14
14
 
15
- stub_request(:get, "https://person.clearbit.com/v1/combined/email/test@example.com").
15
+ stub_request(:get, 'https://person.clearbit.com/v2/combined/find?email=test@example.com').
16
16
  with(:headers => {'Authorization'=>'Bearer clearbit_key'}).
17
17
  to_return(:status => 200, :body => body.to_json, headers: {'Content-Type' => 'application/json'})
18
18
 
@@ -25,7 +25,7 @@ describe Clearbit::Enrichment do
25
25
  company: nil
26
26
  }
27
27
 
28
- stub_request(:get, "https://person-stream.clearbit.com/v1/combined/email/test@example.com").
28
+ stub_request(:get, 'https://person-stream.clearbit.com/v2/combined/find?email=test@example.com').
29
29
  with(:headers => {'Authorization'=>'Bearer clearbit_key'}).
30
30
  to_return(:status => 200, :body => body.to_json, headers: {'Content-Type' => 'application/json'})
31
31
 
@@ -38,7 +38,7 @@ describe Clearbit::Enrichment do
38
38
  company: nil
39
39
  }
40
40
 
41
- stub_request(:get, "https://person.clearbit.com/v1/combined/email/test@example.com").
41
+ stub_request(:get, 'https://person.clearbit.com/v2/combined/find?email=test@example.com').
42
42
  with(:headers => {'Authorization'=>'Bearer clearbit_key', 'X-Rated' => 'true'}).
43
43
  to_return(:status => 200, :body => body.to_json, headers: {'Content-Type' => 'application/json'})
44
44
 
@@ -51,7 +51,7 @@ describe Clearbit::Enrichment do
51
51
  company: nil
52
52
  }
53
53
 
54
- stub_request(:get, "https://person.clearbit.com/v1/combined/email/test@example.com").
54
+ stub_request(:get, 'https://person.clearbit.com/v2/combined/find?email=test@example.com').
55
55
  with(:headers => {'Authorization'=>'Bearer clearbit_key'}).
56
56
  to_return(:status => 202, :body => body.to_json, headers: {'Content-Type' => 'application/json'})
57
57
 
@@ -63,7 +63,7 @@ describe Clearbit::Enrichment do
63
63
  it 'should use the Company API if domain is provided' do
64
64
  body = {}
65
65
 
66
- stub_request(:get, "https://company.clearbit.com/v1/companies/domain/example.com").
66
+ stub_request(:get, 'https://company.clearbit.com/v2/companies/find?domain=example.com').
67
67
  with(:headers => {'Authorization'=>'Bearer clearbit_key'}).
68
68
  to_return(:status => 200, :body => body.to_json, headers: {'Content-Type' => 'application/json'})
69
69
 
@@ -75,7 +75,7 @@ describe Clearbit::Enrichment do
75
75
  it 'should call out to the person API' do
76
76
  body = {}
77
77
 
78
- stub_request(:get, "https://person.clearbit.com/v1/people/email/test@example.com").
78
+ stub_request(:get, 'https://person.clearbit.com/v2/people/find?email=test@example.com').
79
79
  with(:headers => {'Authorization'=>'Bearer clearbit_key'}).
80
80
  to_return(:status => 200, :body => body.to_json, headers: {'Content-Type' => 'application/json'})
81
81
 
@@ -87,7 +87,7 @@ describe Clearbit::Enrichment do
87
87
  it 'should call out to the company API' do
88
88
  body = {}
89
89
 
90
- stub_request(:get, "https://company.clearbit.com/v1/companies/domain/example.com").
90
+ stub_request(:get, 'https://company.clearbit.com/v2/companies/find?domain=example.com').
91
91
  with(:headers => {'Authorization'=>'Bearer clearbit_key'}).
92
92
  to_return(:status => 200, :body => body.to_json, headers: {'Content-Type' => 'application/json'})
93
93
 
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe Clearbit::Logo do
4
+ context 'domain validation' do
5
+
6
+ def check_invalid_domain(domain)
7
+ end
8
+
9
+ it 'passes for simple domains' do
10
+ expect {
11
+ Clearbit::Logo.url(domain: 'clearbit.com')
12
+ }.to_not raise_error
13
+ end
14
+
15
+ it 'passes for dashed domains' do
16
+ expect {
17
+ Clearbit::Logo.url(domain: 'clear-bit.com')
18
+ }.to_not raise_error
19
+ end
20
+
21
+ it 'passes for multi-dot TLDs' do
22
+ expect {
23
+ Clearbit::Logo.url(domain: 'bbc.co.uk')
24
+ }.to_not raise_error
25
+
26
+ expect {
27
+ Clearbit::Logo.url(domain: 'clear-bit.co.uk')
28
+ }.to_not raise_error
29
+ end
30
+
31
+ it 'passes for new-style tlds' do
32
+ expect {
33
+ Clearbit::Logo.url(domain: 'clearbit.museum')
34
+ }.to_not raise_error
35
+ end
36
+
37
+ it 'fails for invalid urls' do
38
+ expect {
39
+ Clearbit::Logo.url(domain: 'clearbit')
40
+ }.to raise_error(ArgumentError)
41
+ end
42
+ end
43
+ end
@@ -49,6 +49,6 @@ describe Clearbit::Webhook do
49
49
  end
50
50
 
51
51
  def generate_signature(webhook_body)
52
- 'sha1=' + OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new('sha1'), 'clearbit_key', webhook_body)
52
+ 'sha1=' + OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha1'), 'clearbit_key', webhook_body)
53
53
  end
54
54
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clearbit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex MacCaw
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-25 00:00:00.000000000 Z
11
+ date: 2016-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -143,6 +143,7 @@ files:
143
143
  - examples/version.rb
144
144
  - examples/watchlist.rb
145
145
  - lib/clearbit.rb
146
+ - lib/clearbit/autocomplete.rb
146
147
  - lib/clearbit/base.rb
147
148
  - lib/clearbit/discovery.rb
148
149
  - lib/clearbit/enrichment.rb
@@ -155,11 +156,13 @@ files:
155
156
  - lib/clearbit/pending.rb
156
157
  - lib/clearbit/prospector.rb
157
158
  - lib/clearbit/resource.rb
159
+ - lib/clearbit/risk.rb
158
160
  - lib/clearbit/version.rb
159
161
  - lib/clearbit/watchlist.rb
160
162
  - lib/clearbit/webhook.rb
161
163
  - spec/lib/clearbit/discovery_spec.rb
162
164
  - spec/lib/clearbit/enrichment_spec.rb
165
+ - spec/lib/clearbit/logo_spec.rb
163
166
  - spec/lib/clearbit/prospector_spec.rb
164
167
  - spec/lib/clearbit/webhook_spec.rb
165
168
  - spec/spec_helper.rb
@@ -190,6 +193,7 @@ summary: API client for clearbit.com
190
193
  test_files:
191
194
  - spec/lib/clearbit/discovery_spec.rb
192
195
  - spec/lib/clearbit/enrichment_spec.rb
196
+ - spec/lib/clearbit/logo_spec.rb
193
197
  - spec/lib/clearbit/prospector_spec.rb
194
198
  - spec/lib/clearbit/webhook_spec.rb
195
199
  - spec/spec_helper.rb