customer_miner 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +8 -0
- data/Gemfile.lock +46 -7
- data/README.md +1 -1
- data/customer_miner.gemspec +2 -1
- data/lib/customer_miner/cli.rb +17 -11
- data/lib/customer_miner/query.rb +33 -23
- data/lib/customer_miner/version.rb +1 -1
- data/spec/customer_miner/query_spec.rb +44 -0
- metadata +25 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0db83956f2fa755f345170f0def3c28e14b9cd61
|
4
|
+
data.tar.gz: e3987c101c8b571c0515673f259ba18c649cd2de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f7bd2fa3692862f8c3deb6dc390e50df14d55ddbad41857d605f5386cacc1c57ba1c66c793815cb0e9f4f2451d01da33a5b64a278e96060d651d9b978ff361a
|
7
|
+
data.tar.gz: 874f1f122bc6c42ebfeb91005b999b4140034708af3780e34bdd825f05a056c8cb54b5e1d961f3c4eb086322f1fae74431b575b7c30584f39a5c74ed47bf8d51
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,29 +1,68 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
customer_miner (0.0.
|
5
|
-
httparty (~> 0.15.5)
|
4
|
+
customer_miner (0.0.4)
|
6
5
|
thor (~> 0.19.4)
|
7
6
|
typhoeus (~> 1.1)
|
8
7
|
|
9
8
|
GEM
|
10
9
|
remote: https://rubygems.org/
|
11
10
|
specs:
|
11
|
+
addressable (2.5.0)
|
12
|
+
public_suffix (~> 2.0, >= 2.0.2)
|
13
|
+
clearbit (0.2.7)
|
14
|
+
nestful (~> 1.1.0)
|
15
|
+
coderay (1.1.1)
|
16
|
+
concurrent-ruby (1.0.5)
|
17
|
+
crack (0.4.3)
|
18
|
+
safe_yaml (~> 1.0.0)
|
19
|
+
diff-lcs (1.3)
|
12
20
|
ethon (0.10.1)
|
13
21
|
ffi (>= 1.3.0)
|
14
|
-
ffi (1.9.
|
15
|
-
|
16
|
-
|
17
|
-
|
22
|
+
ffi (1.9.18)
|
23
|
+
hashdiff (0.3.2)
|
24
|
+
method_source (0.8.2)
|
25
|
+
nestful (1.1.1)
|
26
|
+
pry (0.10.4)
|
27
|
+
coderay (~> 1.1.0)
|
28
|
+
method_source (~> 0.8.1)
|
29
|
+
slop (~> 3.4)
|
30
|
+
public_suffix (2.0.5)
|
31
|
+
rspec (3.6.0)
|
32
|
+
rspec-core (~> 3.6.0)
|
33
|
+
rspec-expectations (~> 3.6.0)
|
34
|
+
rspec-mocks (~> 3.6.0)
|
35
|
+
rspec-core (3.6.0)
|
36
|
+
rspec-support (~> 3.6.0)
|
37
|
+
rspec-expectations (3.6.0)
|
38
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
39
|
+
rspec-support (~> 3.6.0)
|
40
|
+
rspec-mocks (3.6.0)
|
41
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
42
|
+
rspec-support (~> 3.6.0)
|
43
|
+
rspec-support (3.6.0)
|
44
|
+
safe_yaml (1.0.4)
|
45
|
+
slop (3.6.0)
|
18
46
|
thor (0.19.4)
|
47
|
+
thread (0.2.2)
|
19
48
|
typhoeus (1.1.2)
|
20
49
|
ethon (>= 0.9.0)
|
50
|
+
webmock (2.3.2)
|
51
|
+
addressable (>= 2.3.6)
|
52
|
+
crack (>= 0.3.2)
|
53
|
+
hashdiff
|
21
54
|
|
22
55
|
PLATFORMS
|
23
56
|
ruby
|
24
57
|
|
25
58
|
DEPENDENCIES
|
59
|
+
clearbit
|
60
|
+
concurrent-ruby (~> 1.0.5)
|
26
61
|
customer_miner!
|
62
|
+
pry
|
63
|
+
rspec
|
64
|
+
thread
|
65
|
+
webmock
|
27
66
|
|
28
67
|
BUNDLED WITH
|
29
|
-
1.
|
68
|
+
1.15.0
|
data/README.md
CHANGED
data/customer_miner.gemspec
CHANGED
@@ -17,6 +17,7 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.license = 'MIT'
|
18
18
|
|
19
19
|
s.add_dependency('thor',["~> 0.19.4"])
|
20
|
-
s.add_dependency('httparty',["~> 0.15.5"])
|
21
20
|
s.add_dependency('typhoeus',["~> 1.1"])
|
21
|
+
s.add_development_dependency("rspec")
|
22
|
+
s.add_development_dependency("webmock")
|
22
23
|
end
|
data/lib/customer_miner/cli.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'thor'
|
2
2
|
require 'customer_miner/version'
|
3
3
|
require 'customer_miner/query'
|
4
|
+
require 'concurrent'
|
5
|
+
require 'thread/pool'
|
4
6
|
|
5
7
|
module CustomerMiner
|
6
8
|
class CLI< Thor
|
@@ -24,19 +26,23 @@ module CustomerMiner
|
|
24
26
|
end
|
25
27
|
|
26
28
|
desc 'query', 'query customer data and generate csv file'
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
option :file, required: true, banner: './your-clearbit.csv',
|
30
|
+
desc: "CSV file export from Google Analytics"
|
31
|
+
option :roles, required: false, banner: "marketing,operations",
|
32
|
+
desc: "Roles you want to get. You can get available role in"\
|
33
|
+
" http://support.clearbit.com/article/120-employment-role-and-seniority"
|
34
|
+
def query
|
35
|
+
file = options[:file]
|
32
36
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
+
if options[:roles]
|
38
|
+
roles = options[:roles].split(',')
|
39
|
+
else
|
40
|
+
roles = ['marketing']
|
41
|
+
end
|
37
42
|
|
38
|
-
|
39
|
-
|
43
|
+
secret_key_file_path = "#{Dir.home}/.customer_miner"
|
44
|
+
secret_key = File.read(secret_key_file_path)
|
45
|
+
Query.new(file: file, roles: roles, secret_key: secret_key).perform
|
40
46
|
end
|
41
47
|
end
|
42
48
|
end
|
data/lib/customer_miner/query.rb
CHANGED
@@ -1,12 +1,29 @@
|
|
1
1
|
require 'csv'
|
2
2
|
require 'json'
|
3
|
-
require '
|
3
|
+
require 'clearbit'
|
4
|
+
require 'thread/pool'
|
5
|
+
require 'concurrent'
|
4
6
|
|
5
7
|
module CustomerMiner
|
6
8
|
class Query
|
7
|
-
|
9
|
+
VALID_ROLES = ['ceo', 'communications', 'consulting', 'customer_service',
|
10
|
+
'education', 'engineering', 'finance', 'founder', 'health_professional',
|
11
|
+
'human_resources', 'information_technology', 'legal', 'marketing',
|
12
|
+
'operations', 'owner', 'president', 'product', 'public_relations',
|
13
|
+
'real_estate', 'recruiting', 'research', 'sales']
|
14
|
+
|
15
|
+
def initialize(file:, roles:, secret_key:)
|
8
16
|
@file = file
|
9
17
|
@secret_key = secret_key
|
18
|
+
unless roles.kind_of? Array
|
19
|
+
raise ArgumentError, "`roles` must be array"
|
20
|
+
end
|
21
|
+
roles.each do |role|
|
22
|
+
unless VALID_ROLES.include?(role)
|
23
|
+
raise ArgumentError, "Invalid role #{role}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
@roles = roles
|
10
27
|
end
|
11
28
|
|
12
29
|
def perform
|
@@ -26,29 +43,22 @@ module CustomerMiner
|
|
26
43
|
end
|
27
44
|
|
28
45
|
def query_clearbit(domains)
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
domain: domain,
|
37
|
-
|
38
|
-
}
|
39
|
-
|
40
|
-
req = Typhoeus::Request.new(url, options)
|
41
|
-
hydra.queue(req)
|
42
|
-
req
|
46
|
+
Clearbit.key = @secret_key
|
47
|
+
result = Concurrent::Array.new
|
48
|
+
pool = Thread.pool(4)
|
49
|
+
domains.each do |domain|
|
50
|
+
pool.process do
|
51
|
+
people = Clearbit::Prospector.search(domain: domain, roles: @roles)
|
52
|
+
if people.size > 0
|
53
|
+
result << { domain: domain, people: people }
|
54
|
+
end
|
55
|
+
puts "complete #{domain}"
|
56
|
+
end
|
43
57
|
end
|
44
|
-
|
58
|
+
|
59
|
+
pool.shutdown
|
45
60
|
puts "complete requests"
|
46
|
-
|
47
|
-
res_hash = JSON.parse(request.response.body)
|
48
|
-
emails = res_hash.map { |person| person['email']}
|
49
|
-
domain = request.options[:params][:domain]
|
50
|
-
{ domain: domain, people: res_hash }
|
51
|
-
end
|
61
|
+
result
|
52
62
|
end
|
53
63
|
|
54
64
|
def build_csv(res)
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'customer_miner/query'
|
2
|
+
require 'webmock/rspec'
|
3
|
+
require 'json'
|
4
|
+
require 'clearbit'
|
5
|
+
|
6
|
+
describe 'Query' do
|
7
|
+
describe '#perform' do
|
8
|
+
let(:domains) do
|
9
|
+
['codementor.io', 'twitter.com']
|
10
|
+
end
|
11
|
+
let(:mock_rows) do
|
12
|
+
domains.map do |domain|
|
13
|
+
{ 'Clearbit Company Domain' => domain }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
let(:file) { 'the-file' }
|
17
|
+
let(:secret_key) { 'the-secret_key' }
|
18
|
+
let(:roles) { ['product'] }
|
19
|
+
let(:query) do
|
20
|
+
CustomerMiner::Query.new(file: file, roles: roles, secret_key: secret_key)
|
21
|
+
end
|
22
|
+
before :each do
|
23
|
+
allow(CSV).to receive(:read).and_return(mock_rows)
|
24
|
+
allow(File).to receive(:open)
|
25
|
+
mock_people = [{ 'name' => { 'fullName' => 'user-fullname' } }]
|
26
|
+
allow(Clearbit::Prospector).to receive(:search).and_return(mock_people)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should request clearbit" do
|
30
|
+
query.perform
|
31
|
+
|
32
|
+
domains.each do |domain|
|
33
|
+
expect(Clearbit::Prospector).to have_received(:search).with(domain: domain, roles: roles)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should build csv file" do
|
38
|
+
query.perform
|
39
|
+
|
40
|
+
file_path = "#{Dir.pwd}/result.csv"
|
41
|
+
expect(File).to have_received(:open).with(file_path, 'w')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: customer_miner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ocowchun
|
@@ -25,33 +25,47 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 0.19.4
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: typhoeus
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: '1.1'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: '1.1'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
48
|
-
type: :
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
description: Fetch customer data using Clearbit API
|
56
70
|
email: ocowchun@gmail.com
|
57
71
|
executables:
|
@@ -69,6 +83,7 @@ files:
|
|
69
83
|
- lib/customer_miner/query.rb
|
70
84
|
- lib/customer_miner/version.rb
|
71
85
|
- script/build
|
86
|
+
- spec/customer_miner/query_spec.rb
|
72
87
|
homepage: https://github.com/ocowchun/customer_miner
|
73
88
|
licenses:
|
74
89
|
- MIT
|