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
ed0c7b6e
Commit
ed0c7b6e
authored
Nov 08, 2016
by
Daniel Cadenas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add timeout
https://trello.com/c/Re6iuMRj/1899-add-timeout-to-the-node-library
parent
f53e0c16
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
50 additions
and
9 deletions
+50
-9
README.md
README.md
+2
-0
package.json
package.json
+1
-1
client.js
src/client.js
+7
-1
client.js
test/client.js
+40
-7
No files found.
README.md
View file @
ed0c7b6e
...
@@ -27,6 +27,7 @@ var clearbit = new Client({key: 'api_key'});
...
@@ -27,6 +27,7 @@ var clearbit = new Client({key: 'api_key'});
*
`webhook_id`
*String*
: Custom identifier for the webhook request
*
`webhook_id`
*String*
: Custom identifier for the webhook request
*
`subscribe`
*Boolean*
: Set to
`true`
to subscribe to the changes
*
`subscribe`
*Boolean*
: Set to
`true`
to subscribe to the changes
*
`stream`
*Boolean*
: Set to
`true`
to use the
[
streaming API
](
https://clearbit.com/docs?shell#streaming
)
instead of webhooks
*
`stream`
*Boolean*
: Set to
`true`
to use the
[
streaming API
](
https://clearbit.com/docs?shell#streaming
)
instead of webhooks
*
`timeout`
*Integer*
: The timeout in milliseconds after which a socket closed error will be thrown.
```
js
```
js
var
Person
=
clearbit
.
Person
;
var
Person
=
clearbit
.
Person
;
...
@@ -51,6 +52,7 @@ Person.find({email: 'email@domain.com'})
...
@@ -51,6 +52,7 @@ Person.find({email: 'email@domain.com'})
*
`domain`
*String*
: The company domain to look up
**(required)**
*
`domain`
*String*
: The company domain to look up
**(required)**
*
`webhook_id`
*String*
: Custom identifier for the webhook request
*
`webhook_id`
*String*
: Custom identifier for the webhook request
*
`stream`
*Boolean*
: Set to
`true`
to use the
[
streaming API
](
https://clearbit.com/docs?shell#streaming
)
instead of webhooks
*
`stream`
*Boolean*
: Set to
`true`
to use the
[
streaming API
](
https://clearbit.com/docs?shell#streaming
)
instead of webhooks
*
`timeout`
*Integer*
: The timeout in milliseconds after which a socket closed error will be thrown.
```
js
```
js
var
Company
=
clearbit
.
Company
;
var
Company
=
clearbit
.
Company
;
...
...
package.json
View file @
ed0c7b6e
{
{
"name"
:
"
clearbit
"
,
"name"
:
"
clearbit
"
,
"version"
:
"1.
2.3
"
,
"version"
:
"1.
3.0
"
,
"description"
:
"Client for Clearbit.co business intelligence APIs"
,
"description"
:
"Client for Clearbit.co business intelligence APIs"
,
"main"
:
"./src"
,
"main"
:
"./src"
,
"scripts"
:
{
"scripts"
:
{
...
...
src/client.js
View file @
ed0c7b6e
...
@@ -59,6 +59,12 @@ ClearbitClient.prototype.request = function (options) {
...
@@ -59,6 +59,12 @@ ClearbitClient.prototype.request = function (options) {
method
:
'get'
method
:
'get'
});
});
if
(
options
.
timeout
)
{
var
timeout
=
options
.
timeout
;
}
else
{
var
timeout
=
options
.
stream
?
60000
:
10000
;
}
return
needle
.
requestAsync
(
return
needle
.
requestAsync
(
options
.
method
,
options
.
method
,
this
.
url
(
options
),
this
.
url
(
options
),
...
@@ -66,7 +72,7 @@ ClearbitClient.prototype.request = function (options) {
...
@@ -66,7 +72,7 @@ ClearbitClient.prototype.request = function (options) {
{
{
json
:
options
.
json
,
json
:
options
.
json
,
headers
:
options
.
headers
,
headers
:
options
.
headers
,
timeout
:
options
.
stream
?
60000
:
10000
,
timeout
:
timeout
,
username
:
this
.
key
,
username
:
this
.
key
,
password
:
''
,
password
:
''
,
user_agent
:
'ClearbitNode/v'
+
pkg
.
version
user_agent
:
'ClearbitNode/v'
+
pkg
.
version
...
...
test/client.js
View file @
ed0c7b6e
...
@@ -100,18 +100,51 @@ describe('Client', function () {
...
@@ -100,18 +100,51 @@ describe('Client', function () {
});
});
});
});
it
(
'uses a timeout of 60 seconds for streaming requests'
,
function
(
)
{
function
requestWithOptions
(
clientRequestOptions
)
{
sinon
.
stub
(
needle
,
'request'
).
yieldsAsync
(
null
,
{},
undefined
);
sinon
.
stub
(
needle
,
'request'
).
yieldsAsync
(
null
,
{},
undefined
);
return
client
.
request
({
return
client
.
request
(
clientRequestOptions
)
.
then
(()
=>
needle
.
request
.
firstCall
.
args
[
3
])
.
finally
(()
=>
needle
.
request
.
restore
());
}
it
(
'can specify a custom timeout for a request'
,
function
()
{
return
requestWithOptions
({
api
:
'person'
,
timeout
:
30000
})
.
then
((
needleOptions
)
=>
{
expect
(
needleOptions
).
to
.
have
.
property
(
'timeout'
,
30000
);
});
});
it
(
'sets the default timeout to 10 seconds'
,
function
()
{
return
requestWithOptions
({
api
:
'person'
})
.
then
((
needleOptions
)
=>
{
expect
(
needleOptions
).
to
.
have
.
property
(
'timeout'
,
10000
);
});
});
it
(
'uses a default timeout of 60 seconds for streaming requests'
,
function
()
{
return
requestWithOptions
({
api
:
'person'
,
api
:
'person'
,
stream
:
true
stream
:
true
})
})
.
then
(
function
()
{
.
then
((
needleOptions
)
=>
{
expect
(
needle
.
request
.
firstCall
.
args
[
3
])
expect
(
needleOptions
).
to
.
have
.
property
(
'timeout'
,
60000
);
.
to
.
have
.
property
(
'timeout'
,
60000
);
});
});
it
(
'can specify a custom timeout for streaming requests'
,
function
()
{
return
requestWithOptions
({
api
:
'person'
,
stream
:
true
,
timeout
:
30000
})
})
.
finally
(
function
()
{
.
then
((
needleOptions
)
=>
{
needle
.
request
.
restore
(
);
expect
(
needleOptions
).
to
.
have
.
property
(
'timeout'
,
30000
);
});
});
});
});
...
...
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