Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
clearbit
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
prospector
clearbit
Commits
0716f356
Commit
0716f356
authored
Jan 19, 2015
by
Alex MacCaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor and add watchlist support
parent
001b6908
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
130 additions
and
76 deletions
+130
-76
client.js
src/client.js
+16
-15
company.js
src/company.js
+14
-13
person.js
src/person.js
+23
-20
resource.js
src/resource.js
+48
-28
watchlist.js
src/watchlist.js
+29
-0
No files found.
src/client.js
View file @
0716f356
...
@@ -12,23 +12,30 @@ var pkg = require('../package.json');
...
@@ -12,23 +12,30 @@ var pkg = require('../package.json');
function
ClearbitClient
(
config
)
{
function
ClearbitClient
(
config
)
{
config
=
config
||
{};
config
=
config
||
{};
assert
(
this
instanceof
ClearbitClient
,
'Client must be called with new'
);
assert
(
this
instanceof
ClearbitClient
,
'Client must be called with new'
);
assert
(
!!
config
.
key
,
'An API key must be provided'
);
this
.
key
=
config
.
key
;
this
.
key
=
config
.
key
||
process
.
env
.
CLEARBIT_KEY
;
assert
(
!!
this
.
key
,
'An API key must be provided'
);
this
.
Company
=
require
(
'./company'
).
Company
(
this
);
this
.
Person
=
require
(
'./person'
).
Person
(
this
);
this
.
Person
=
require
(
'./person'
).
Person
(
this
);
this
.
PersonCompany
=
require
(
'./person'
).
PersonCompany
(
this
);
this
.
PersonCompany
=
require
(
'./person'
).
PersonCompany
(
this
);
this
.
Company
=
require
(
'./company'
)(
this
);
this
.
Watchlist
=
require
(
'./watchlist'
).
Watchlist
(
this
);
this
.
WatchlistEntity
=
require
(
'./watchlist'
).
WatchlistEntity
(
this
);
this
.
WatchlistIndividual
=
require
(
'./watchlist'
).
WatchlistIndividual
(
this
);
}
}
var
base
=
'https://%s%s.clearbit.com/v%s'
;
var
ENDPOINT
=
'https://%s%s.clearbit.com/v%s'
;
ClearbitClient
.
prototype
.
base
=
function
(
options
)
{
ClearbitClient
.
prototype
.
endpoint
=
function
(
options
)
{
options
=
_
.
defaults
(
options
,
{
options
=
_
.
defaults
(
options
,
{
version
:
'1'
,
version
:
'1'
,
stream
:
false
stream
:
false
});
});
assert
(
options
.
api
,
'An API must be specified'
);
assert
(
options
.
api
,
'An API must be specified'
);
return
util
.
format
.
apply
(
util
,
[
return
util
.
format
.
apply
(
util
,
[
base
,
ENDPOINT
,
options
.
api
,
options
.
api
,
options
.
stream
?
'-stream'
:
''
,
options
.
stream
?
'-stream'
:
''
,
options
.
version
options
.
version
...
@@ -39,25 +46,19 @@ ClearbitClient.prototype.url = function (options) {
...
@@ -39,25 +46,19 @@ ClearbitClient.prototype.url = function (options) {
_
.
defaults
(
options
,
{
_
.
defaults
(
options
,
{
path
:
''
path
:
''
});
});
return
this
.
base
(
options
)
+
options
.
path
;
return
this
.
endpoint
(
options
)
+
options
.
path
;
};
};
function
generateQuery
()
{
var
query
=
_
.
omit
(
_
.
extend
.
apply
(
_
,
[{}].
concat
([].
slice
.
apply
(
arguments
))),
_
.
isUndefined
);
return
_
.
isEmpty
(
query
)
?
undefined
:
query
;
}
ClearbitClient
.
prototype
.
request
=
function
(
options
)
{
ClearbitClient
.
prototype
.
request
=
function
(
options
)
{
options
=
_
.
defaults
(
options
,
{
options
=
_
.
defaults
(
options
,
{
method
:
'get'
,
method
:
'get'
,
query
:
{}
query
:
{}
});
});
return
needle
.
requestAsync
(
return
needle
.
requestAsync
(
options
.
method
,
options
.
method
,
this
.
url
(
options
),
this
.
url
(
options
),
generateQuery
({
options
.
query
,
webhook_id
:
options
.
webhook_id
},
options
.
query
),
{
{
timeout
:
options
.
stream
?
60000
:
10000
,
timeout
:
options
.
stream
?
60000
:
10000
,
username
:
this
.
key
,
username
:
this
.
key
,
...
...
src/company.js
View file @
0716f356
...
@@ -4,19 +4,20 @@ var assert = require('assert');
...
@@ -4,19 +4,20 @@ var assert = require('assert');
var
resource
=
require
(
'./resource'
);
var
resource
=
require
(
'./resource'
);
var
_
=
require
(
'lodash'
);
var
_
=
require
(
'lodash'
);
module
.
exports
=
resource
.
create
(
'Company'
,
{
exports
.
Company
=
resource
.
create
(
'Company'
,
{
api
:
'company'
})
api
:
'company'
,
.
extend
({
path
:
'/companies/domain/<%= domain %>'
find
:
function
(
options
){
options
=
options
||
{};
assert
(
options
.
domain
,
'An domain must be provided'
);
return
this
.
get
(
'/companies/domain/'
+
options
.
domain
,
_
.
omit
(
options
,
'domain'
)
);
}
})
})
.
on
(
'preFind'
,
function
(
options
)
{
.
include
({
assert
(
options
.
domain
,
'A domain must be provided'
);
flag
:
function
(
options
){
}).
include
({
return
this
.
constructor
.
post
(
'/companies/'
+
this
.
id
+
'/flag'
,
options
);
flag
:
function
(
params
,
options
){
return
this
.
client
.
request
(
_
.
extend
({
api
:
this
.
_options
.
api
,
method
:
'post'
,
path
:
_
.
template
(
'/companies/<%= id %>/flag'
,
this
),
query
:
params
||
{}
},
options
));
}
}
});
});
src/person.js
View file @
0716f356
...
@@ -4,30 +4,33 @@ var assert = require('assert');
...
@@ -4,30 +4,33 @@ var assert = require('assert');
var
resource
=
require
(
'./resource'
);
var
resource
=
require
(
'./resource'
);
var
_
=
require
(
'lodash'
);
var
_
=
require
(
'lodash'
);
function
requireEmail
(
options
)
{
exports
.
Person
=
resource
.
create
(
'Person'
,
{
api
:
'person'
})
assert
(
options
.
email
,
'An email must be provided'
);
.
extend
({
}
find
:
function
(
options
){
options
=
options
||
{};
assert
(
options
.
email
,
'An email must be provided'
);
exports
.
Person
=
resource
.
create
(
'Person'
,
{
return
this
.
get
(
api
:
'person'
,
'/people/email/'
+
options
.
email
,
path
:
'/people/email/<%= email %>'
,
_
.
omit
(
options
,
'email'
)
queryKeys
:
'subscribe'
);
}
})
})
.
on
(
'preFind'
,
requireEmail
)
.
include
({
.
include
({
flag
:
function
(
params
,
options
){
flag
:
function
(
options
){
return
this
.
client
.
request
(
_
.
extend
({
return
this
.
constructor
.
post
(
'/people/'
+
this
.
id
+
'/flag'
,
options
);
api
:
this
.
_options
.
api
,
method
:
'post'
,
path
:
_
.
template
(
'/people/<%= id %>/flag'
,
this
),
query
:
params
||
{}
},
options
));
}
}
});
});
exports
.
PersonCompany
=
resource
.
create
(
'PersonCompany'
,
{
exports
.
PersonCompany
=
resource
.
create
(
'PersonCompany'
,
{
api
:
'person'
})
api
:
'person'
,
.
extend
({
path
:
'/combined/email/<%= email %>'
,
find
:
function
(
options
){
queryKeys
:
'subscribe'
options
=
options
||
{};
assert
(
options
.
email
,
'An email must be provided'
);
return
this
.
get
(
'/combined/email/'
+
options
.
email
,
_
.
omit
(
options
,
'email'
)
);
}
})
})
.
on
(
'preFind'
,
requireEmail
);
src/resource.js
View file @
0716f356
...
@@ -17,29 +17,42 @@ function ClearbitResource (data) {
...
@@ -17,29 +17,42 @@ function ClearbitResource (data) {
_
.
extend
(
this
,
data
);
_
.
extend
(
this
,
data
);
}
}
ClearbitResource
.
find
=
Promise
.
method
(
function
(
options
)
{
ClearbitResource
.
extractParams
=
function
(
params
)
{
options
=
options
||
/* istanbul ignore next */
{};
return
_
.
omit
(
params
||
{},
'path'
,
'method'
,
'params'
,
'client'
,
'api'
,
'stream'
);
this
.
emit
(
'preFind'
,
options
);
};
return
this
.
client
.
request
(
_
.
extend
({
api
:
this
.
_options
.
api
,
ClearbitResource
.
get
=
Promise
.
method
(
function
(
path
,
options
)
{
path
:
this
.
_options
.
template
(
options
),
options
=
_
.
extend
({
query
:
_
.
pick
(
options
,
this
.
_options
.
queryKeys
)
path
:
path
,
},
options
))
method
:
'get'
,
.
bind
(
this
)
params
:
this
.
extractParams
(
options
)
.
then
(
function
(
data
)
{
},
this
.
options
,
options
||
{});
return
new
this
(
_
.
extend
({},
data
,
{
return
this
.
client
.
request
(
options
)
_options
:
this
.
_options
,
.
bind
(
this
)
client
:
this
.
client
.
then
(
function
(
data
)
{
})
return
new
this
(
data
);
);
})
})
.
catch
(
isQueued
,
function
()
{
.
catch
(
isQueued
,
function
()
{
throw
new
this
.
QueuedError
(
this
.
name
+
' lookup queued'
);
throw
new
this
.
QueuedError
(
this
.
_name
+
' lookup queued'
);
})
})
.
catch
(
isUnknownRecord
,
function
()
{
.
catch
(
isUnknownRecord
,
function
()
{
throw
new
this
.
NotFoundError
(
this
.
name
+
' not found'
);
throw
new
this
.
NotFoundError
(
this
.
_name
+
' not found'
);
});
});
});
ClearbitResource
.
post
=
Promise
.
method
(
function
(
path
,
options
)
{
options
=
_
.
extend
({
path
:
path
,
method
:
'post'
,
query
:
this
.
extractParams
(
options
)
},
this
.
options
,
options
||
{});
return
this
.
client
.
request
(
options
)
.
bind
(
this
)
.
catch
(
isUnknownRecord
,
function
()
{
throw
new
this
.
NotFoundError
(
this
.
name
+
' not found'
);
});
});
});
function
createErrors
(
name
)
{
function
createErrors
(
name
)
{
...
@@ -54,11 +67,13 @@ exports.create = function (name, options) {
...
@@ -54,11 +67,13 @@ exports.create = function (name, options) {
ClearbitResource
.
apply
(
this
,
arguments
);
ClearbitResource
.
apply
(
this
,
arguments
);
};
};
_
.
extend
(
Resource
,
new
EventEmitter
(),
EventEmitter
.
prototype
,
ClearbitResource
,
createErrors
(
name
),
{
_
.
extend
(
Resource
,
_name
:
name
,
new
EventEmitter
(),
_options
:
_
.
extend
({},
options
,
{
EventEmitter
.
prototype
,
template
:
_
.
template
(
options
.
path
)
ClearbitResource
,
})
createErrors
(
name
),
{
name
:
name
,
options
:
options
});
});
return
_
.
extend
(
function
(
client
)
{
return
_
.
extend
(
function
(
client
)
{
...
@@ -75,6 +90,11 @@ exports.create = function (name, options) {
...
@@ -75,6 +90,11 @@ exports.create = function (name, options) {
include
:
function
(
props
)
{
include
:
function
(
props
)
{
_
.
extend
(
Resource
.
prototype
,
props
);
_
.
extend
(
Resource
.
prototype
,
props
);
return
this
;
return
this
;
},
extend
:
function
(
props
)
{
_
.
extend
(
Resource
,
props
);
return
this
;
}
}
});
});
};
};
src/watchlist.js
0 → 100644
View file @
0716f356
'use strict'
;
var
assert
=
require
(
'assert'
);
var
resource
=
require
(
'./resource'
);
var
_
=
require
(
'lodash'
);
exports
.
Watchlist
=
resource
.
create
(
'Watchlist'
,
{
api
:
'watchlist'
}).
extend
({
search
:
function
(
options
)
{
return
this
.
post
(
'/search/all'
,
options
);
}
})
exports
.
WatchlistIndividual
=
resource
.
create
(
'WatchlistIndividual'
,
{
api
:
'watchlist'
}).
extend
({
search
:
function
(
options
)
{
return
this
.
post
(
'/search/individuals'
,
options
);
}
});
exports
.
WatchlistEntity
=
resource
.
create
(
'WatchlistEntity'
,
{
api
:
'watchlist'
}).
extend
({
search
:
function
(
options
)
{
return
this
.
post
(
'/search/entities'
,
options
);
}
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment