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
9f02dbe4
Commit
9f02dbe4
authored
Jan 20, 2015
by
Ben Drucker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use 2 args in #extend in place of #include and handle arrays outside constructor
parent
19b13741
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
98 additions
and
115 deletions
+98
-115
.jshintrc
.jshintrc
+0
-1
client.js
src/client.js
+2
-2
company.js
src/company.js
+15
-15
person.js
src/person.js
+25
-25
resource.js
src/resource.js
+48
-66
watchlist.js
src/watchlist.js
+6
-3
watchlist.js
test/watchlist.js
+2
-3
No files found.
.jshintrc
View file @
9f02dbe4
...
@@ -6,7 +6,6 @@
...
@@ -6,7 +6,6 @@
"eqeqeq": true,
"eqeqeq": true,
"immed": true,
"immed": true,
"indent": 2,
"indent": 2,
"latedef": true,
"newcap": true,
"newcap": true,
"noarg": true,
"noarg": true,
"quotmark": "single",
"quotmark": "single",
...
...
src/client.js
View file @
9f02dbe4
...
@@ -34,12 +34,12 @@ ClearbitClient.prototype.endpoint = function (options) {
...
@@ -34,12 +34,12 @@ ClearbitClient.prototype.endpoint = function (options) {
assert
(
options
.
api
,
'An API must be specified'
);
assert
(
options
.
api
,
'An API must be specified'
);
return
util
.
format
.
apply
(
util
,
[
return
util
.
format
(
ENDPOINT
,
ENDPOINT
,
options
.
api
,
options
.
api
,
options
.
stream
?
'-stream'
:
''
,
options
.
stream
?
'-stream'
:
''
,
options
.
version
options
.
version
]
);
);
};
};
ClearbitClient
.
prototype
.
url
=
function
(
options
)
{
ClearbitClient
.
prototype
.
url
=
function
(
options
)
{
...
...
src/company.js
View file @
9f02dbe4
...
@@ -5,19 +5,19 @@ var resource = require('./resource');
...
@@ -5,19 +5,19 @@ var resource = require('./resource');
var
_
=
require
(
'lodash'
);
var
_
=
require
(
'lodash'
);
exports
.
Company
=
resource
.
create
(
'Company'
,
{
api
:
'company'
})
exports
.
Company
=
resource
.
create
(
'Company'
,
{
api
:
'company'
})
.
extend
({
.
extend
({
find
:
function
(
options
){
flag
:
function
(
options
){
options
=
options
||
{};
return
this
.
constructor
.
post
(
'/companies/'
+
this
.
id
+
'/flag'
,
options
);
assert
(
options
.
domain
,
'An domain must be provided'
);
}
},
{
find
:
function
(
options
)
{
options
=
options
||
{};
assert
(
options
.
domain
,
'A domain must be provided'
);
return
this
.
get
(
return
this
.
get
(
'/companies/domain/'
+
options
.
domain
,
'/companies/domain/'
+
options
.
domain
,
_
.
omit
(
options
,
'domain'
)
_
.
omit
(
options
,
'domain'
)
);
);
}
}
})
});
.
include
({
flag
:
function
(
options
){
return
this
.
constructor
.
post
(
'/companies/'
+
this
.
id
+
'/flag'
,
options
);
}
});
src/person.js
View file @
9f02dbe4
...
@@ -5,32 +5,32 @@ var resource = require('./resource');
...
@@ -5,32 +5,32 @@ var resource = require('./resource');
var
_
=
require
(
'lodash'
);
var
_
=
require
(
'lodash'
);
exports
.
Person
=
resource
.
create
(
'Person'
,
{
api
:
'person'
})
exports
.
Person
=
resource
.
create
(
'Person'
,
{
api
:
'person'
})
.
extend
({
.
extend
({
find
:
function
(
options
){
flag
:
function
(
options
){
options
=
options
||
{};
return
this
.
constructor
.
post
(
'/people/'
+
this
.
id
+
'/flag'
,
options
);
assert
(
options
.
email
,
'An email must be provided'
);
}
},
{
find
:
function
(
options
){
options
=
options
||
{};
assert
(
options
.
email
,
'An email must be provided'
);
return
this
.
get
(
return
this
.
get
(
'/people/email/'
+
options
.
email
,
'/people/email/'
+
options
.
email
,
_
.
omit
(
options
,
'email'
)
_
.
omit
(
options
,
'email'
)
);
);
}
}
})
});
.
include
({
flag
:
function
(
options
){
return
this
.
constructor
.
post
(
'/people/'
+
this
.
id
+
'/flag'
,
options
);
}
});
exports
.
PersonCompany
=
resource
.
create
(
'PersonCompany'
,
{
api
:
'person'
})
exports
.
PersonCompany
=
resource
.
create
(
'PersonCompany'
,
{
api
:
'person'
})
.
extend
(
{
.
extend
(
null
,
{
find
:
function
(
options
){
find
:
function
(
options
){
options
=
options
||
{};
options
=
options
||
{};
assert
(
options
.
email
,
'An email must be provided'
);
assert
(
options
.
email
,
'An email must be provided'
);
return
this
.
get
(
return
this
.
get
(
'/combined/email/'
+
options
.
email
,
'/combined/email/'
+
options
.
email
,
_
.
omit
(
options
,
'email'
)
_
.
omit
(
options
,
'email'
)
);
);
}
}
});
});
src/resource.js
View file @
9f02dbe4
'use strict'
;
'use strict'
;
var
createError
=
require
(
'create-error'
);
var
createError
=
require
(
'create-error'
);
var
EventEmitter
=
require
(
'events'
).
EventEmitter
;
var
_
=
require
(
'lodash'
);
var
_
=
require
(
'lodash'
);
var
Promise
=
require
(
'bluebird'
);
function
isQueued
(
err
)
{
return
err
.
type
===
'queued'
;
}
function
isUnknownRecord
(
err
)
{
return
err
.
type
===
'unknown_record'
;
}
function
ClearbitResource
(
data
)
{
function
ClearbitResource
(
data
)
{
_
.
extend
(
this
,
data
);
_
.
extend
(
this
,
data
);
}
}
ClearbitResource
.
extractParams
=
function
(
options
)
{
ClearbitResource
.
get
=
function
(
path
,
options
)
{
var
params
=
_
.
omit
(
options
||
{},
'path'
,
'method'
,
'params'
,
'client'
,
'api'
,
'stream'
);
return
_
.
isEmpty
(
params
)
?
null
:
params
;
};
ClearbitResource
.
get
=
Promise
.
method
(
function
(
path
,
options
)
{
options
=
_
.
extend
({
options
=
_
.
extend
({
path
:
path
,
path
:
path
,
method
:
'get'
,
method
:
'get'
,
query
:
this
.
extractParams
(
options
)
query
:
extractParams
(
options
)
},
this
.
options
,
options
||
{}
);
},
this
.
options
,
options
);
return
this
.
client
.
request
(
options
)
return
this
.
client
.
request
(
options
)
.
bind
(
this
)
.
bind
(
this
)
.
then
(
function
(
data
)
{
.
then
(
cast
)
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
)
{
ClearbitResource
.
post
=
function
(
path
,
options
)
{
options
=
_
.
extend
({
options
=
_
.
extend
({
path
:
path
,
path
:
path
,
method
:
'post'
,
method
:
'post'
,
query
:
this
.
extractParams
(
options
)
query
:
extractParams
(
options
)
},
this
.
options
,
options
||
{}
);
},
this
.
options
,
options
);
return
this
.
client
.
request
(
options
)
return
this
.
client
.
request
(
options
)
.
bind
(
this
)
.
bind
(
this
)
.
then
(
function
(
data
)
{
.
then
(
cast
)
return
new
this
(
data
);
})
.
catch
(
isUnknownRecord
,
function
()
{
.
catch
(
isUnknownRecord
,
function
()
{
throw
new
this
.
NotFoundError
(
this
.
name
+
' not found'
);
throw
new
this
.
NotFoundError
(
this
.
name
+
' not found'
);
});
});
});
};
function
createErrors
(
name
)
{
return
{
NotFoundError
:
createError
(
name
+
'NotFoundError'
),
QueuedError
:
createError
(
name
+
'QueuedError'
)
};
}
exports
.
create
=
function
(
name
,
options
)
{
exports
.
create
=
function
(
name
,
options
)
{
var
Resource
=
function
(
data
)
{
var
Resource
=
function
()
{
if
(
_
.
isArray
(
data
))
{
return
data
.
map
(
function
(
item
){
return
new
this
.
constructor
(
item
);
}.
bind
(
this
));
}
ClearbitResource
.
apply
(
this
,
arguments
);
ClearbitResource
.
apply
(
this
,
arguments
);
};
};
_
.
extend
(
Resource
,
_
.
extend
(
Resource
,
ClearbitResource
,
createErrors
(
name
),
{
new
EventEmitter
(),
EventEmitter
.
prototype
,
ClearbitResource
,
createErrors
(
name
),
{
name
:
name
,
name
:
name
,
options
:
options
options
:
options
});
});
...
@@ -96,19 +56,41 @@ exports.create = function (name, options) {
...
@@ -96,19 +56,41 @@ exports.create = function (name, options) {
});
});
},
},
{
{
on
:
function
()
{
extend
:
function
(
proto
,
ctor
)
{
Resource
.
on
.
apply
(
Resource
,
arguments
);
_
.
extend
(
Resource
.
prototype
,
proto
);
return
this
;
_
.
extend
(
Resource
,
ctor
);
},
include
:
function
(
props
)
{
_
.
extend
(
Resource
.
prototype
,
props
);
return
this
;
},
extend
:
function
(
props
)
{
_
.
extend
(
Resource
,
props
);
return
this
;
return
this
;
}
}
});
});
};
};
function
cast
(
data
)
{
/* jshint validthis:true */
return
!
Array
.
isArray
(
data
)
?
new
this
(
data
)
:
data
.
map
(
function
(
result
)
{
return
new
this
(
result
);
},
this
);
}
function
isQueued
(
err
)
{
return
err
.
type
===
'queued'
;
}
function
isUnknownRecord
(
err
)
{
return
err
.
type
===
'unknown_record'
;
}
function
createErrors
(
name
)
{
return
{
NotFoundError
:
createError
(
name
+
'NotFoundError'
),
QueuedError
:
createError
(
name
+
'QueuedError'
)
};
}
function
extractParams
(
options
)
{
var
params
=
_
.
omit
(
options
||
{},
'path'
,
'method'
,
'params'
,
'client'
,
'api'
,
'stream'
);
return
_
.
isEmpty
(
params
)
?
null
:
params
;
}
src/watchlist.js
View file @
9f02dbe4
...
@@ -4,7 +4,8 @@ var resource = require('./resource');
...
@@ -4,7 +4,8 @@ var resource = require('./resource');
exports
.
Watchlist
=
resource
.
create
(
'Watchlist'
,
{
exports
.
Watchlist
=
resource
.
create
(
'Watchlist'
,
{
api
:
'watchlist'
api
:
'watchlist'
}).
extend
({
})
.
extend
(
null
,
{
search
:
function
(
options
)
{
search
:
function
(
options
)
{
return
this
.
post
(
'/search/all'
,
options
);
return
this
.
post
(
'/search/all'
,
options
);
}
}
...
@@ -12,7 +13,8 @@ exports.Watchlist = resource.create('Watchlist', {
...
@@ -12,7 +13,8 @@ exports.Watchlist = resource.create('Watchlist', {
exports
.
WatchlistIndividual
=
resource
.
create
(
'WatchlistIndividual'
,
{
exports
.
WatchlistIndividual
=
resource
.
create
(
'WatchlistIndividual'
,
{
api
:
'watchlist'
api
:
'watchlist'
}).
extend
({
})
.
extend
(
null
,
{
search
:
function
(
options
)
{
search
:
function
(
options
)
{
return
this
.
post
(
'/search/individuals'
,
options
);
return
this
.
post
(
'/search/individuals'
,
options
);
}
}
...
@@ -20,7 +22,8 @@ exports.WatchlistIndividual = resource.create('WatchlistIndividual', {
...
@@ -20,7 +22,8 @@ exports.WatchlistIndividual = resource.create('WatchlistIndividual', {
exports
.
WatchlistEntity
=
resource
.
create
(
'WatchlistEntity'
,
{
exports
.
WatchlistEntity
=
resource
.
create
(
'WatchlistEntity'
,
{
api
:
'watchlist'
api
:
'watchlist'
}).
extend
({
})
.
extend
(
null
,
{
search
:
function
(
options
)
{
search
:
function
(
options
)
{
return
this
.
post
(
'/search/entities'
,
options
);
return
this
.
post
(
'/search/entities'
,
options
);
}
}
...
...
test/watchlist.js
View file @
9f02dbe4
'use strict'
;
'use strict'
;
var
expect
=
require
(
'chai'
).
expect
;
var
expect
=
require
(
'chai'
).
expect
;
var
nock
=
require
(
'nock'
);
var
nock
=
require
(
'nock'
);
var
Watchlist
=
require
(
'../'
)(
'k'
).
Watchlist
;
var
Watchlist
=
require
(
'../'
)(
'k'
).
Watchlist
;
describe
(
'Watchlist'
,
function
()
{
describe
(
'Watchlist'
,
function
()
{
...
@@ -25,7 +25,6 @@ describe('Watchlist', function () {
...
@@ -25,7 +25,6 @@ describe('Watchlist', function () {
.
reply
(
200
,
watchlist
);
.
reply
(
200
,
watchlist
);
return
Watchlist
.
search
({
name
:
'Joe'
})
return
Watchlist
.
search
({
name
:
'Joe'
})
.
then
(
function
(
watchlist
)
{
.
then
(
function
(
watchlist
)
{
// console.log(watchlist.constructor)
expect
(
watchlist
[
0
])
expect
(
watchlist
[
0
])
.
to
.
be
.
an
.
instanceOf
(
Watchlist
)
.
to
.
be
.
an
.
instanceOf
(
Watchlist
)
.
and
.
have
.
property
(
'id'
,
watchlist
.
id
);
.
and
.
have
.
property
(
'id'
,
watchlist
.
id
);
...
...
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