clearbit 0.2.3 → 0.2.4

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: d45b4f5a8d2d1d16d5acce2990114ea4128e859c
4
- data.tar.gz: cc056730612d1079db10d3c05f8c9ecf375a5674
3
+ metadata.gz: 28a6d9763ce1327254eff1db10ba5e8e4ade8f0f
4
+ data.tar.gz: 62547db00a4c25143d67292d20cf872cf997a538
5
5
  SHA512:
6
- metadata.gz: edd484f91784a5577e09a7aa287bb03f027d6cc695bb9517c1b7a1f391d1aebc31fcb9be9ba5e5980f81256fa1a486dd245db23e85352d9cba8a13694a61910a
7
- data.tar.gz: fae4a7aa0a63a36caae474e974cc22a0798827baf3951e0e9ca3a8694587cdea898432d48328e6859127fe38ac0364b79646ee30f16db2976e2bdc38605487ec
6
+ metadata.gz: 9bd8dc210b57025b8d860aa095c8f5fd317c4d467ebc7c86897bb9dcfab9126d33481648b8b9252d899a488bea4f308c135bd0e9e6cf9321146c834614c7cc37
7
+ data.tar.gz: 2523a6eafe9c12cbd60592d5fe73c4cc71e87f245c37681f92d531059909894c4c5c7b3843be1bb14db5a016b54884f3c8186b6c17ae89832771f3849e943c84
data/README.md CHANGED
@@ -72,3 +72,9 @@ post '/v1/webhooks/clearbit' do
72
72
  end
73
73
  end
74
74
  ```
75
+
76
+ The global Clearbit.key can be overriden for multi-tenant apps using multiple Clearbit keys like so:
77
+
78
+ ```ruby
79
+ webhook = Clearbit::Webhook.new(env, 'CLEARBIT_KEY')
80
+ ```
@@ -21,6 +21,7 @@ module Clearbit
21
21
  autoload :Autocomplete, 'clearbit/autocomplete'
22
22
  autoload :Base, 'clearbit/base'
23
23
  autoload :Enrichment, 'clearbit/enrichment'
24
+ autoload :IPCompany, 'clearbit/ipcompany'
24
25
  autoload :Discovery, 'clearbit/discovery'
25
26
  autoload :Logo, 'clearbit/logo'
26
27
  autoload :Mash, 'clearbit/mash'
@@ -33,6 +33,10 @@ module Clearbit
33
33
  search.each(&block)
34
34
  end
35
35
  end
36
+
37
+ def map(&block)
38
+ each.map(&block)
39
+ end
36
40
  end
37
41
 
38
42
  def self.search(values = {})
@@ -0,0 +1,22 @@
1
+ module Clearbit
2
+ class IPCompany < Base
3
+ endpoint 'https://ipcompany.clearbit.com'
4
+ path '/v1/companies'
5
+
6
+ def self.find(values)
7
+ if ip = values.delete(:ip)
8
+ response = get(uri(:ip, ip), values)
9
+
10
+ else
11
+ raise ArgumentError, 'Invalid values'
12
+ end
13
+
14
+ self.new(response)
15
+ rescue Nestful::ResourceNotFound
16
+ end
17
+
18
+ class << self
19
+ alias_method :[], :find
20
+ end
21
+ end
22
+ end
@@ -136,7 +136,14 @@ module Clearbit
136
136
  # Will return true if the Mash has had a key
137
137
  # set in addition to normal respond_to? functionality.
138
138
  def respond_to?(method_name, include_private=false)
139
- return true if key?(method_name) || method_name.to_s.slice(/[=?!_]\Z/)
139
+ camelized_name = camelize(method_name.to_s)
140
+
141
+ if key?(method_name) ||
142
+ key?(camelized_name) ||
143
+ method_name.to_s.slice(/[=?!_]\Z/)
144
+ return true
145
+ end
146
+
140
147
  super
141
148
  end
142
149
 
@@ -28,11 +28,11 @@ module Clearbit
28
28
  end
29
29
 
30
30
  def email
31
- email_response.email
31
+ self[:email] || email_response.email
32
32
  end
33
33
 
34
34
  def verified
35
- email_response.verified
35
+ self[:verified] || email_response.verified
36
36
  end
37
37
 
38
38
  alias_method :verified?, :verified
@@ -8,11 +8,11 @@ module Clearbit
8
8
  end
9
9
 
10
10
  def self.confirmed(values = {})
11
- self.new post('confirmed', values)
11
+ post('confirmed', values)
12
12
  end
13
13
 
14
14
  def self.flag(values = {})
15
- self.new post('flag', values)
15
+ post('flag', values)
16
16
  end
17
17
  end
18
18
  end
@@ -1,3 +1,3 @@
1
1
  module Clearbit
2
- VERSION = "0.2.3"
2
+ VERSION = '0.2.4'
3
3
  end
@@ -8,18 +8,25 @@ module Clearbit
8
8
  Clearbit.key!
9
9
  end
10
10
 
11
- def self.valid?(request_signature, body)
11
+ def self.valid?(request_signature, body, key = nil)
12
12
  return false unless request_signature && body
13
13
 
14
- signature = 'sha1=' + OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha1'), clearbit_key, body)
14
+ # The global Clearbit.key can be overriden for multi-tenant apps using multiple Clearbit keys
15
+ key = key || clearbit_key
16
+
17
+ signature = generate_signature(key, body)
15
18
  Rack::Utils.secure_compare(request_signature, signature)
16
19
  end
17
20
 
18
- def self.valid!(signature, body)
19
- valid?(signature, body) ? true : raise(Errors::InvalidWebhookSignature.new)
21
+ def self.valid!(signature, body, key = nil)
22
+ valid?(signature, body, key) ? true : raise(Errors::InvalidWebhookSignature.new)
23
+ end
24
+
25
+ def self.generate_signature(key, body)
26
+ 'sha1=' + OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha1'), key, body)
20
27
  end
21
28
 
22
- def initialize(env)
29
+ def initialize(env, key = nil)
23
30
  request = Rack::Request.new(env)
24
31
 
25
32
  request.body.rewind
@@ -27,7 +34,7 @@ module Clearbit
27
34
  signature = request.env['HTTP_X_REQUEST_SIGNATURE']
28
35
  body = request.body.read
29
36
 
30
- self.class.valid!(signature, body)
37
+ self.class.valid!(signature, body, key)
31
38
 
32
39
  merge!(JSON.parse(body))
33
40
  end
@@ -1,46 +1,75 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Clearbit::Webhook do
4
- before do |example|
5
- Clearbit.key = 'clearbit_key'
6
- end
3
+ describe Clearbit::Webhook, 'valid!' do
4
+ let(:clearbit_key) { 'clearbit_key' }
5
+
6
+ context 'clearbit key set globally' do
7
+ before do
8
+ Clearbit.key = clearbit_key
9
+ end
10
+
11
+ context 'valid signature' do
12
+ it 'returns true' do
13
+ signature = generate_signature(clearbit_key, 'A-OK')
14
+
15
+ result = Clearbit::Webhook.valid!(signature, 'A-OK')
7
16
 
8
- context 'valid signature' do
9
- it 'returns true' do
10
- signature = generate_signature('A-OK')
17
+ expect(result).to eq true
18
+ end
19
+ end
11
20
 
12
- result = Clearbit::Webhook.valid!(signature, 'A-OK')
21
+ context 'invalid signature' do
22
+ it 'returns false' do
23
+ signature = generate_signature(clearbit_key, 'A-OK')
13
24
 
14
- expect(result).to eq true
25
+ expect {
26
+ Clearbit::Webhook.valid!(signature, 'TAMPERED_WITH_BODY_BEWARE!')
27
+ }.to raise_error(Clearbit::Errors::InvalidWebhookSignature)
28
+ end
15
29
  end
16
30
  end
17
31
 
18
- context 'invalid signature' do
19
- it 'returns false' do
20
- signature = generate_signature('A-OK')
32
+ context 'clearbit key set locally' do
33
+ context 'valid signature' do
34
+ it 'returns true' do
35
+ clearbit_key = 'clearbit_key'
36
+ signature = generate_signature(clearbit_key, 'A-OK')
37
+
38
+ result = Clearbit::Webhook.valid!(signature, 'A-OK', clearbit_key)
39
+
40
+ expect(result).to eq true
41
+ end
42
+ end
43
+
44
+ context 'invalid signature' do
45
+ it 'returns false' do
46
+ clearbit_key = 'clearbit_key'
47
+ signature = generate_signature(clearbit_key, 'A-OK')
21
48
 
22
- expect {
23
- Clearbit::Webhook.valid!(signature, 'TAMPERED_WITH_BODY_BEWARE!')
24
- }.to raise_error(Clearbit::Errors::InvalidWebhookSignature)
49
+ expect {
50
+ Clearbit::Webhook.valid!(signature, 'TAMPERED_WITH_BODY_BEWARE!', clearbit_key)
51
+ }.to raise_error(Clearbit::Errors::InvalidWebhookSignature)
52
+ end
25
53
  end
26
54
  end
55
+ end
27
56
 
28
- context 'initialize' do
29
- it 'returns a mash' do
30
- request_body = JSON.dump({
31
- id: '123',
32
- type: 'person',
33
- body: nil,
34
- status: 404
35
- })
57
+ describe Clearbit::Webhook, 'initialize' do
58
+ let(:clearbit_key) { 'clearbit_key' }
36
59
 
37
- request_signature = generate_signature(request_body)
60
+ let(:env) do
61
+ request_body = JSON.dump(id:'123', type: 'person', body: nil, status: 404)
38
62
 
39
- env = Rack::MockRequest.env_for('/webhook',
40
- method: 'POST',
41
- input: request_body,
42
- 'HTTP_X_REQUEST_SIGNATURE' => request_signature
43
- )
63
+ Rack::MockRequest.env_for('/webhook',
64
+ method: 'POST',
65
+ input: request_body,
66
+ 'HTTP_X_REQUEST_SIGNATURE' => generate_signature(clearbit_key, request_body)
67
+ )
68
+ end
69
+
70
+ context 'clearbit key set globally' do
71
+ it 'returns a mash' do
72
+ Clearbit.key = 'clearbit_key'
44
73
 
45
74
  webhook = Clearbit::Webhook.new(env)
46
75
 
@@ -48,7 +77,11 @@ describe Clearbit::Webhook do
48
77
  end
49
78
  end
50
79
 
51
- def generate_signature(webhook_body)
52
- 'sha1=' + OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha1'), 'clearbit_key', webhook_body)
80
+ context 'clearbit key set locally' do
81
+ it 'returns a mash' do
82
+ webhook = Clearbit::Webhook.new(env, 'clearbit_key')
83
+
84
+ expect(webhook.status).to eq 404
85
+ end
53
86
  end
54
87
  end
@@ -9,3 +9,18 @@ require 'webmock/rspec'
9
9
 
10
10
  # Library
11
11
  require 'clearbit'
12
+
13
+ Dir[File.expand_path('spec/support/**/*.rb')].each { |file| require file }
14
+
15
+ RSpec.configure do |config|
16
+ config.include Spec::Support::Helpers
17
+ config.order = 'random'
18
+
19
+ config.expect_with :rspec do |c|
20
+ c.syntax = :expect
21
+ end
22
+
23
+ config.before :each do
24
+ Clearbit.key = nil
25
+ end
26
+ end
@@ -0,0 +1,9 @@
1
+ module Spec
2
+ module Support
3
+ module Helpers
4
+ def generate_signature(clearbit_key, webhook_body)
5
+ 'sha1=' + OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha1'), clearbit_key, webhook_body)
6
+ end
7
+ end
8
+ end
9
+ 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.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex MacCaw
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-23 00:00:00.000000000 Z
11
+ date: 2016-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -151,6 +151,7 @@ files:
151
151
  - lib/clearbit/enrichment/person.rb
152
152
  - lib/clearbit/enrichment/person_company.rb
153
153
  - lib/clearbit/errors/invalid_webhook_signature.rb
154
+ - lib/clearbit/ipcompany.rb
154
155
  - lib/clearbit/logo.rb
155
156
  - lib/clearbit/mash.rb
156
157
  - lib/clearbit/pending.rb
@@ -166,6 +167,7 @@ files:
166
167
  - spec/lib/clearbit/prospector_spec.rb
167
168
  - spec/lib/clearbit/webhook_spec.rb
168
169
  - spec/spec_helper.rb
170
+ - spec/support/helpers.rb
169
171
  homepage: https://github.com/maccman/clearbit-ruby
170
172
  licenses:
171
173
  - MIT
@@ -197,4 +199,5 @@ test_files:
197
199
  - spec/lib/clearbit/prospector_spec.rb
198
200
  - spec/lib/clearbit/webhook_spec.rb
199
201
  - spec/spec_helper.rb
202
+ - spec/support/helpers.rb
200
203
  has_rdoc: