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
da71b20c
Commit
da71b20c
authored
Oct 24, 2014
by
Ben Drucker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Apply new resource ctor to APIs
parent
186ef9d7
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
70 additions
and
160 deletions
+70
-160
client.js
src/client.js
+3
-3
company.js
src/company.js
+10
-32
person.js
src/person.js
+17
-30
person_company.js
src/person_company.js
+0
-35
person.js
test/person.js
+40
-12
person_company.js
test/person_company.js
+0
-48
No files found.
src/client.js
View file @
da71b20c
...
...
@@ -15,9 +15,9 @@ function ClearbitClient (config) {
assert
(
!!
config
.
key
,
'An API key must be provided'
);
this
.
key
=
config
.
key
;
this
.
Person
=
require
(
'./person'
)(
this
);
this
.
Person
=
require
(
'./person'
).
Person
(
this
);
this
.
PersonCompany
=
require
(
'./person'
).
PersonCompany
(
this
);
this
.
Company
=
require
(
'./company'
)(
this
);
this
.
PersonCompany
=
require
(
'./person_company'
)(
this
);
}
var
base
=
'https://%s%s.clearbit.co/v%s'
;
...
...
@@ -48,7 +48,7 @@ function generateQuery () {
}
ClearbitClient
.
prototype
.
request
=
function
(
options
)
{
options
=
_
.
defaults
(
options
||
/* istanbul ignore next */
{}
,
{
options
=
_
.
defaults
(
options
,
{
method
:
'get'
,
query
:
{}
});
...
...
src/company.js
View file @
da71b20c
'use strict'
;
var
assert
=
require
(
'assert'
);
var
_
=
require
(
'lodash'
);
var
Promise
=
require
(
'bluebird'
);
var
utils
=
require
(
'./utils'
);
module
.
exports
=
function
(
client
)
{
function
Company
(
data
)
{
_
.
extend
(
this
,
data
);
}
Company
.
find
=
Promise
.
method
(
function
(
options
)
{
assert
(
options
&&
options
.
domain
,
'A domain must be provided'
);
return
this
.
client
.
request
(
_
.
extend
({
api
:
'company'
,
path
:
'/companies/domain/'
+
options
.
domain
},
options
))
.
bind
(
this
)
.
then
(
utils
.
cast
)
.
catch
(
utils
.
isQueued
,
function
()
{
throw
new
this
.
QueuedError
(
'Company lookup queued'
);
})
.
catch
(
utils
.
isUnknownRecord
,
function
()
{
throw
new
this
.
NotFoundError
(
'Company not found'
);
});
});
Company
.
prototype
.
client
=
Company
.
client
=
client
;
Company
.
NotFoundError
=
utils
.
NotFoundError
;
Company
.
QueuedError
=
utils
.
QueuedError
;
return
Company
;
};
var
assert
=
require
(
'assert'
);
var
resource
=
require
(
'./resource'
);
module
.
exports
=
resource
.
create
(
'Company'
,
{
api
:
'company'
,
path
:
'/companies/domain/<%= domain %>'
})
.
on
(
'preFind'
,
function
(
options
)
{
assert
(
options
.
domain
,
'A domain must be provided'
);
});
src/person.js
View file @
da71b20c
'use strict'
;
var
assert
=
require
(
'assert'
);
var
_
=
require
(
'lodash'
);
var
Promise
=
require
(
'bluebird'
);
var
utils
=
require
(
'./utils'
);
var
assert
=
require
(
'assert'
);
var
resource
=
require
(
'./resource'
);
module
.
exports
=
function
(
client
)
{
function
Person
(
data
)
{
_
.
extend
(
this
,
data
);
}
function
requireEmail
(
options
)
{
assert
(
options
.
email
,
'An email must be provided'
);
}
Person
.
find
=
Promise
.
method
(
function
(
options
)
{
assert
(
options
&&
options
.
email
,
'An email must be provided'
);
return
this
.
client
.
request
(
_
.
extend
({
api
:
'person'
,
path
:
'/people/email/'
+
options
.
email
,
query
:
_
.
pick
(
options
,
'subscribe'
,
'company'
)
},
options
))
.
bind
(
this
)
.
then
(
utils
.
cast
)
.
catch
(
utils
.
isQueued
,
function
()
{
throw
new
this
.
QueuedError
(
'Person lookup queued'
);
})
.
catch
(
utils
.
isUnknownRecord
,
function
()
{
throw
new
this
.
NotFoundError
(
'Person not found'
);
});
});
exports
.
Person
=
resource
.
create
(
'Person'
,
{
api
:
'person'
,
path
:
'/people/email/<%= email %>'
,
queryKeys
:
'subscribe'
})
.
on
(
'preFind'
,
requireEmail
);
Person
.
prototype
.
client
=
Person
.
client
=
client
;
Person
.
NotFoundError
=
utils
.
NotFoundError
;
Person
.
QueuedError
=
utils
.
QueuedError
;
return
Person
;
}
;
exports
.
PersonCompany
=
resource
.
create
(
'PersonCompany'
,
{
api
:
'person'
,
path
:
'/combined/email/<%= email %>'
,
queryKeys
:
'subscribe'
})
.
on
(
'preFind'
,
requireEmail
)
;
src/person_company.js
deleted
100644 → 0
View file @
186ef9d7
'use strict'
;
var
assert
=
require
(
'assert'
);
var
_
=
require
(
'lodash'
);
var
Promise
=
require
(
'bluebird'
);
var
utils
=
require
(
'./utils'
);
module
.
exports
=
function
(
client
)
{
function
PersonCompany
(
data
)
{
_
.
extend
(
this
,
data
);
}
PersonCompany
.
find
=
Promise
.
method
(
function
(
options
)
{
assert
(
options
&&
options
.
email
,
'An email must be provided'
);
return
this
.
client
.
request
(
_
.
extend
({
api
:
'person'
,
path
:
'/combined/email/'
+
options
.
email
,
query
:
_
.
pick
(
options
,
'subscribe'
,
'webhook_id'
)
},
options
))
.
bind
(
this
)
.
then
(
utils
.
cast
)
.
catch
(
utils
.
isQueued
,
function
()
{
throw
new
this
.
QueuedError
(
'PersonCompany lookup queued'
);
})
.
catch
(
utils
.
isUnknownRecord
,
function
()
{
throw
new
this
.
NotFoundError
(
'PersonCompany not found'
);
});
});
PersonCompany
.
prototype
.
client
=
PersonCompany
.
client
=
client
;
PersonCompany
.
NotFoundError
=
utils
.
NotFoundError
;
PersonCompany
.
QueuedError
=
utils
.
QueuedError
;
return
PersonCompany
;
};
test/person.js
View file @
da71b20c
'use strict'
;
var
expect
=
require
(
'chai'
).
use
(
require
(
'chai-as-promised'
)).
expect
;
var
nock
=
require
(
'nock'
);
var
Person
=
require
(
'../'
)(
'k'
).
Person
;
var
expect
=
require
(
'chai'
).
use
(
require
(
'chai-as-promised'
)).
expect
;
var
nock
=
require
(
'nock'
);
var
Person
=
require
(
'../'
)(
'k'
).
Person
;
var
PersonCompany
=
require
(
'../'
)(
'k'
).
PersonCompany
;
describe
(
'Person'
,
function
()
{
...
...
@@ -15,9 +16,10 @@ describe('Person', function () {
mock
.
done
();
});
describe
(
'Person#find'
,
function
()
{
var
alex
=
require
(
'./fixtures/person'
);
var
company
=
require
(
'./fixtures/company'
);
var
alex
=
require
(
'./fixtures/person'
);
describe
(
'Person#find'
,
function
()
{
it
(
'can find a person by email'
,
function
()
{
mock
...
...
@@ -38,13 +40,6 @@ describe('Person', function () {
return
Person
.
find
({
email
:
'alex@alexmaccaw.com'
,
subscribe
:
true
});
});
it
(
'can override the company setting'
,
function
()
{
mock
.
get
(
'/v1/people/email/alex@alexmaccaw.com?company=false'
)
.
reply
(
200
,
alex
);
return
Person
.
find
({
email
:
'alex@alexmaccaw.com'
,
company
:
false
});
});
it
(
'can handle queued requests'
,
function
()
{
mock
.
get
(
'/v1/people/email/alex@alexmaccaw.com'
)
...
...
@@ -71,4 +66,37 @@ describe('Person', function () {
});
describe
(
'PersonCompany#find'
,
function
()
{
it
(
'can find a person by email'
,
function
()
{
mock
.
get
(
'/v1/combined/email/alex@alexmaccaw.com'
)
.
reply
(
200
,
{
person
:
alex
,
company
:
company
});
return
PersonCompany
.
find
({
email
:
'alex@alexmaccaw.com'
})
.
then
(
function
(
personCompany
)
{
expect
(
personCompany
)
.
to
.
be
.
an
.
instanceOf
(
PersonCompany
)
.
and
.
have
.
have
.
keys
(
'person'
,
'company'
)
.
and
.
have
.
deep
.
property
(
'person.id'
,
alex
.
id
);
});
});
it
(
'can handle queued requests'
,
function
()
{
mock
.
get
(
'/v1/combined/email/alex@alexmaccaw.com'
)
.
reply
(
202
,
{
error
:
{
type
:
'queued'
}
});
return
expect
(
PersonCompany
.
find
({
email
:
'alex@alexmaccaw.com'
}))
.
to
.
be
.
rejectedWith
(
PersonCompany
.
QueuedError
);
});
});
});
test/person_company.js
deleted
100644 → 0
View file @
186ef9d7
'use strict'
;
var
expect
=
require
(
'chai'
).
use
(
require
(
'chai-as-promised'
)).
expect
;
var
nock
=
require
(
'nock'
);
var
PersonCompany
=
require
(
'../'
)(
'k'
).
PersonCompany
;
describe
(
'PersonCompany'
,
function
()
{
var
mock
;
before
(
function
()
{
mock
=
nock
(
'https://person.clearbit.co'
);
});
after
(
nock
.
cleanAll
);
afterEach
(
function
()
{
mock
.
done
();
});
describe
(
'PersonCompany#find'
,
function
()
{
var
alex
=
require
(
'./fixtures/person'
);
it
(
'can find a person by email'
,
function
()
{
mock
.
get
(
'/v1/combined/email/alex@alexmaccaw.com'
)
.
reply
(
200
,
alex
);
return
PersonCompany
.
find
({
email
:
'alex@alexmaccaw.com'
})
.
then
(
function
(
person
)
{
expect
(
person
)
.
to
.
be
.
an
.
instanceOf
(
PersonCompany
)
.
and
.
have
.
property
(
'id'
,
alex
.
id
);
});
});
it
(
'can handle queued requests'
,
function
()
{
mock
.
get
(
'/v1/combined/email/alex@alexmaccaw.com'
)
.
reply
(
202
,
{
error
:
{
type
:
'queued'
}
});
return
expect
(
PersonCompany
.
find
({
email
:
'alex@alexmaccaw.com'
}))
.
to
.
be
.
rejectedWith
(
PersonCompany
.
QueuedError
);
});
});
});
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