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
c0d2af94
Commit
c0d2af94
authored
Oct 09, 2014
by
Ben Drucker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Generate the base URL for request using client#base
parent
16127fba
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
72 additions
and
10 deletions
+72
-10
package.json
package.json
+2
-1
client.js
src/client.js
+18
-0
client.js
test/client.js
+52
-9
No files found.
package.json
View file @
c0d2af94
...
...
@@ -24,7 +24,8 @@
"dependencies"
:
{
"
bluebird
"
:
"2"
,
"
create-error
"
:
"0.3"
,
"
needle
"
:
"0.7"
"
needle
"
:
"0.7"
,
"
lodash
"
:
"2"
},
"devDependencies"
:
{
"
chai
"
:
"1"
,
...
...
src/client.js
View file @
c0d2af94
'use strict'
;
var
assert
=
require
(
'assert'
);
var
util
=
require
(
'util'
);
var
_
=
require
(
'lodash'
);
function
ClearbitClient
(
config
)
{
config
=
config
||
{};
...
...
@@ -9,4 +11,19 @@ function ClearbitClient (config) {
this
.
key
=
config
.
key
;
};
var
base
=
'https://%s%s.clearbit.co/v%s'
;
ClearbitClient
.
prototype
.
base
=
function
(
options
)
{
options
=
_
.
defaults
(
options
||
{},
{
version
:
'1'
,
stream
:
false
});
assert
(
options
.
api
,
'An API must be specified'
);
return
util
.
format
.
apply
(
util
,
[
base
,
options
.
api
,
options
.
stream
?
'-stream'
:
''
,
options
.
version
]);
};
module
.
exports
=
ClearbitClient
;
\ No newline at end of file
test/client.js
View file @
c0d2af94
...
...
@@ -5,19 +5,61 @@ var ClearbitClient = require('../src/client');
describe
(
'ClearbitClient'
,
function
()
{
it
(
'must be called with new'
,
function
()
{
expect
(
ClearbitClient
).
to
.
throw
(
/called with new/
);
var
client
;
beforeEach
(
function
()
{
client
=
new
ClearbitClient
({
key
:
'k'
});
});
it
(
'must provide an API key'
,
function
()
{
expect
(
function
()
{
return
new
ClearbitClient
();
})
.
to
.
throw
(
/API key/
);
describe
(
'Constructor'
,
function
()
{
it
(
'must be called with new'
,
function
()
{
expect
(
ClearbitClient
).
to
.
throw
(
/called with new/
);
});
it
(
'must provide an API key'
,
function
()
{
expect
(
function
()
{
return
new
ClearbitClient
();
})
.
to
.
throw
(
/API key/
);
});
it
(
'configures the API key'
,
function
()
{
expect
(
new
ClearbitClient
({
key
:
'k'
})).
to
.
have
.
property
(
'key'
,
'k'
);
});
});
it
(
'configures the API key'
,
function
()
{
expect
(
new
ClearbitClient
({
key
:
'k'
})).
to
.
have
.
property
(
'key'
,
'k'
);
describe
(
'#base'
,
function
()
{
it
(
'requires an API'
,
function
()
{
expect
(
client
.
base
).
to
.
throw
(
/API must be specified/
);
});
it
(
'can generate the default base'
,
function
()
{
expect
(
client
.
base
({
api
:
'person'
}))
.
to
.
equal
(
'https://person.clearbit.co/v1'
);
});
it
(
'can generate a streaming base'
,
function
()
{
expect
(
client
.
base
({
api
:
'person'
,
stream
:
true
}))
.
to
.
equal
(
'https://person-stream.clearbit.co/v1'
);
});
it
(
'can set a custom version'
,
function
()
{
expect
(
client
.
base
({
api
:
'person'
,
version
:
'2'
}))
.
to
.
equal
(
'https://person.clearbit.co/v2'
);
});
});
});
\ No newline at end of file
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