clearbit 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -0
- data/lib/clearbit.rb +1 -0
- data/lib/clearbit/discovery.rb +4 -0
- data/lib/clearbit/ipcompany.rb +22 -0
- data/lib/clearbit/mash.rb +8 -1
- data/lib/clearbit/prospector.rb +2 -2
- data/lib/clearbit/risk.rb +2 -2
- data/lib/clearbit/version.rb +1 -1
- data/lib/clearbit/webhook.rb +13 -6
- data/spec/lib/clearbit/webhook_spec.rb +64 -31
- data/spec/spec_helper.rb +15 -0
- data/spec/support/helpers.rb +9 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28a6d9763ce1327254eff1db10ba5e8e4ade8f0f
|
4
|
+
data.tar.gz: 62547db00a4c25143d67292d20cf872cf997a538
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9bd8dc210b57025b8d860aa095c8f5fd317c4d467ebc7c86897bb9dcfab9126d33481648b8b9252d899a488bea4f308c135bd0e9e6cf9321146c834614c7cc37
|
7
|
+
data.tar.gz: 2523a6eafe9c12cbd60592d5fe73c4cc71e87f245c37681f92d531059909894c4c5c7b3843be1bb14db5a016b54884f3c8186b6c17ae89832771f3849e943c84
|
data/README.md
CHANGED
data/lib/clearbit.rb
CHANGED
@@ -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'
|
data/lib/clearbit/discovery.rb
CHANGED
@@ -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
|
data/lib/clearbit/mash.rb
CHANGED
@@ -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
|
-
|
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
|
|
data/lib/clearbit/prospector.rb
CHANGED
@@ -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
|
data/lib/clearbit/risk.rb
CHANGED
data/lib/clearbit/version.rb
CHANGED
data/lib/clearbit/webhook.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
5
|
-
|
6
|
-
|
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
|
-
|
9
|
-
|
10
|
-
|
17
|
+
expect(result).to eq true
|
18
|
+
end
|
19
|
+
end
|
11
20
|
|
12
|
-
|
21
|
+
context 'invalid signature' do
|
22
|
+
it 'returns false' do
|
23
|
+
signature = generate_signature(clearbit_key, 'A-OK')
|
13
24
|
|
14
|
-
|
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 '
|
19
|
-
|
20
|
-
|
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
|
-
|
23
|
-
|
24
|
-
|
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
|
-
|
29
|
-
|
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
|
-
|
60
|
+
let(:env) do
|
61
|
+
request_body = JSON.dump(id:'123', type: 'person', body: nil, status: 404)
|
38
62
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
-
|
52
|
-
'
|
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
|
data/spec/spec_helper.rb
CHANGED
@@ -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
|
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.
|
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-
|
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:
|