Skip to content

Commit

Permalink
resolve merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Tidwell committed Feb 18, 2019
2 parents d519201 + 4a84c9b commit a6fe910
Show file tree
Hide file tree
Showing 24 changed files with 184 additions and 17 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<<<<<<< HEAD
=======
### 2.2.0
- Add timeout support (#39)

>>>>>>> master
### 2.1.2
- Force escaping of all url params (#34)

Expand Down
35 changes: 34 additions & 1 deletion docs/Client.html
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,39 @@ <h6>Properties</h6>



<tr>

<td class="name"><code>timeout</code></td>


<td class="type">


<span class="param-type">number</span>



</td>


<td class="attributes">

&lt;optional><br>





</td>




<td class="description last">Duration in ms to wait for a timeout, passed to https request as timeout option</td>
</tr>



<tr>

<td class="name"><code>massageProperties</code></td>
Expand Down Expand Up @@ -383,7 +416,7 @@ <h6>Properties</h6>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Jul 09 2018 17:18:03 GMT-0400 (EDT) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Feb 18 2019 15:34:43 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
2 changes: 1 addition & 1 deletion docs/Matches.html
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ <h6>Properties</h6>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Jul 09 2018 17:18:03 GMT-0400 (EDT) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Feb 18 2019 15:34:43 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
2 changes: 1 addition & 1 deletion docs/Participants.html
Original file line number Diff line number Diff line change
Expand Up @@ -1645,7 +1645,7 @@ <h6>Properties</h6>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Jul 09 2018 17:18:03 GMT-0400 (EDT) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Feb 18 2019 15:34:43 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
2 changes: 1 addition & 1 deletion docs/Tournaments.html
Original file line number Diff line number Diff line change
Expand Up @@ -2356,7 +2356,7 @@ <h6>Properties</h6>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Jul 09 2018 17:18:03 GMT-0400 (EDT) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Feb 18 2019 15:34:43 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
15 changes: 14 additions & 1 deletion docs/api_client.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ <h1 class="page-title">api/client.js</h1>
* @param {string} options.apiKey Your challonge API Key
* @param {string} [options.subdomain] - Sets the subdomain and automatically passes tournament[subdomain] and prefixes the subdomain to tournament urls. If you don't want to pass a subdomain to the constructor, and want to use an organization (or multiple organizations), you must use client.setSubdomain('subdomain') before making api calls.
* @param {string} [options.format] The format of the response data. Defaults to 'json'. If set to 'json', will return javascript objects. Anything else (including 'xml') will return the raw text string.
* @param {number} [options.timeout] Duration in ms to wait for a timeout, passed to https request as timeout option
* @param {boolean} [options.massageProperties] If the response object should be massaged into camelCase properties when using json format. Defaults to true.
* @description
* Constructor function for the Client base responsible for communicating with Challonge API
Expand Down Expand Up @@ -141,6 +142,11 @@ <h1 class="page-title">api/client.js</h1>
}
};

const timeout = this.options.get('timeout');
if (timeout) {
options.timeout = timeout;
}

const req = https.request(options, (res) => {
// store the chunked data as it comes back
let resData = '';
Expand All @@ -165,6 +171,13 @@ <h1 class="page-title">api/client.js</h1>
});
});

req.on('timeout', () => {
errorHandler.handle({
timeout: true
}, '', callback, self.options.get('format'));
req.destroy();
});

req.end();
};
</code></pre>
Expand All @@ -179,7 +192,7 @@ <h1 class="page-title">api/client.js</h1>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Jul 09 2018 17:18:03 GMT-0400 (EDT) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Feb 18 2019 15:34:43 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
13 changes: 12 additions & 1 deletion docs/api_error-handler.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,17 @@ <h1 class="page-title">api/error-handler.js</h1>
return;
}

if (res.timeout) {
err = {
error: true,
errors: [],
statusCode: 'timeout',
text: ''
};
callback(err, res);
return;
}

// not an api-documented error
err = {
error: true,
Expand All @@ -120,7 +131,7 @@ <h1 class="page-title">api/error-handler.js</h1>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Jul 09 2018 17:18:03 GMT-0400 (EDT) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Feb 18 2019 15:34:43 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
2 changes: 1 addition & 1 deletion docs/api_matches.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ <h1 class="page-title">api/matches.js</h1>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Jul 09 2018 17:18:03 GMT-0400 (EDT) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Feb 18 2019 15:34:43 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
2 changes: 1 addition & 1 deletion docs/api_participants.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ <h1 class="page-title">api/participants.js</h1>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Jul 09 2018 17:18:03 GMT-0400 (EDT) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Feb 18 2019 15:34:43 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
2 changes: 1 addition & 1 deletion docs/api_tournaments.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ <h1 class="page-title">api/tournaments.js</h1>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Jul 09 2018 17:18:03 GMT-0400 (EDT) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Feb 18 2019 15:34:43 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
3 changes: 2 additions & 1 deletion docs/challonge.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ <h1 class="page-title">challonge.js</h1>
* @param {string} options.apiKey Your challonge API Key
* @param {string} [options.subdomain] - Sets the subdomain and automatically passes tournament[subdomain] and prefixes the subdomain to tournament urls. If you don't want to pass a subdomain to the constructor, and want to use an organization (or multiple organizations), you must use client.setSubdomain('subdomain') before making api calls.
* @param {string} [options.format] The format of the response data. Defaults to 'json'. If set to 'json', will return javascript objects. Anything else (including 'xml') will return the raw text string.
* @param {number} [options.timeout] Duration in ms to wait for a timeout, passed to https request as timeout option
* @param {boolean} [options.massageProperties] If the response object should be massaged into camelCase properties when using json format. Defaults to true.
* @returns {object} new api client instance
* @description
Expand Down Expand Up @@ -89,7 +90,7 @@ <h1 class="page-title">challonge.js</h1>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Jul 09 2018 17:18:03 GMT-0400 (EDT) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Feb 18 2019 15:34:43 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
35 changes: 34 additions & 1 deletion docs/global.html
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,39 @@ <h6>Properties</h6>



<tr>

<td class="name"><code>timeout</code></td>


<td class="type">


<span class="param-type">number</span>



</td>


<td class="attributes">

&lt;optional><br>





</td>




<td class="description last">Duration in ms to wait for a timeout, passed to https request as timeout option</td>
</tr>



<tr>

<td class="name"><code>massageProperties</code></td>
Expand Down Expand Up @@ -450,7 +483,7 @@ <h5>Returns:</h5>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Jul 09 2018 17:18:03 GMT-0400 (EDT) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Feb 18 2019 15:34:43 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ <h3>Branching</h3><p><code>master</code> is the active development branch</p>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Jul 09 2018 17:18:03 GMT-0400 (EDT) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Feb 18 2019 15:34:43 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
2 changes: 1 addition & 1 deletion docs/module-ErrorHandler.html
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ <h5>Parameters:</h5>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Jul 09 2018 17:18:03 GMT-0400 (EDT) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Feb 18 2019 15:34:43 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
2 changes: 1 addition & 1 deletion docs/module-Util.html
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ <h5>Returns:</h5>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Jul 09 2018 17:18:03 GMT-0400 (EDT) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Feb 18 2019 15:34:43 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
2 changes: 1 addition & 1 deletion docs/param-serializer.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ <h1 class="page-title">param-serializer.js</h1>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Jul 09 2018 17:18:03 GMT-0400 (EDT) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Feb 18 2019 15:34:43 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
2 changes: 1 addition & 1 deletion docs/util.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ <h1 class="page-title">util.js</h1>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Jul 09 2018 17:18:03 GMT-0400 (EDT) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Feb 18 2019 15:34:43 GMT-0500 (EST) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
13 changes: 13 additions & 0 deletions lib/api/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const util = require('../util');
* @param {string} options.apiKey Your challonge API Key
* @param {string} [options.subdomain] - Sets the subdomain and automatically passes tournament[subdomain] and prefixes the subdomain to tournament urls. If you don't want to pass a subdomain to the constructor, and want to use an organization (or multiple organizations), you must use client.setSubdomain('subdomain') before making api calls.
* @param {string} [options.format] The format of the response data. Defaults to 'json'. If set to 'json', will return javascript objects. Anything else (including 'xml') will return the raw text string.
* @param {number} [options.timeout] Duration in ms to wait for a timeout, passed to https request as timeout option
* @param {boolean} [options.massageProperties] If the response object should be massaged into camelCase properties when using json format. Defaults to true.
* @description
* Constructor function for the Client base responsible for communicating with Challonge API
Expand Down Expand Up @@ -102,6 +103,11 @@ Client.prototype.makeRequest = function(obj) {
}
};

const timeout = this.options.get('timeout');
if (timeout) {
options.timeout = timeout;
}

const req = https.request(options, (res) => {
// store the chunked data as it comes back
let resData = '';
Expand All @@ -126,5 +132,12 @@ Client.prototype.makeRequest = function(obj) {
});
});

req.on('timeout', () => {
errorHandler.handle({
timeout: true
}, '', callback, self.options.get('format'));
req.destroy();
});

req.end();
};
18 changes: 18 additions & 0 deletions lib/api/client.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ describe('Client Class', () => {
expect(opts.cache_bust).toBeDefined();
});

it('should add a timeout if one is passed', () => {
client.options.timeout = 20000;
client.makeRequest({});

expect(httpsMock.opts.timeout).toEqual(20000);
});

it('should delete the callback, path, and method from the object', () => {
client.makeRequest({
callback: '',
Expand Down Expand Up @@ -242,6 +249,17 @@ describe('Client Class', () => {
});
});

it('should call the error handler on a timeout', () => {
spyOn(errorHandler, 'handle');

client.makeRequest({});

httpsMock.reqListeners.timeout[0]();
expect(errorHandler.handle).toHaveBeenCalledWith({
timeout: true
}, '', undefined, 'json');
});

it('should call the error handler on anything but a 200 response', () => {
spyOn(errorHandler, 'handle');

Expand Down
11 changes: 11 additions & 0 deletions lib/api/error-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ exports.handle = function(res, resData, callback, format) {
return;
}

if (res.timeout) {
err = {
error: true,
errors: [],
statusCode: 'timeout',
text: ''
};
callback(err, res);
return;
}

// not an api-documented error
err = {
error: true,
Expand Down
Loading

0 comments on commit a6fe910

Please sign in to comment.