From 748dfe3d03557e47830fbb1e4f76f196f4793193 Mon Sep 17 00:00:00 2001 From: Ryan Date: Wed, 5 Sep 2018 19:20:23 +0000 Subject: [PATCH] chore(release): 1.13.2 [skip ci] ## [1.13.2](https://github.com/node-gh/gh/compare/v1.13.1...v1.13.2) (2018-09-05) ### Performance Improvements * **profiling:** add flame graph generation to npm scripts ([88a9284](https://github.com/node-gh/gh/commit/88a9284)) --- lib/rest-api-client.js | 148 +++++++++++++++++++---------------------- package.json | 2 +- 2 files changed, 69 insertions(+), 81 deletions(-) diff --git a/lib/rest-api-client.js b/lib/rest-api-client.js index 0e0ca74a..4cc5a135 100644 --- a/lib/rest-api-client.js +++ b/lib/rest-api-client.js @@ -7,116 +7,104 @@ * @author Eduardo Lundgren */ -'use strict' +'use strict'; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { - throw new TypeError('Cannot call a class as a function') + throw new TypeError('Cannot call a class as a function'); } } -var _request = require('request') -var http = require('http') -var _url = require('url') -var _ = require('lodash') -var logger = require('./logger') +var _request = require('request'); +var http = require('http'); +var _url = require('url'); +var _ = require('lodash'); +var logger = require('./logger'); -var RestApiClient = (function() { +var RestApiClient = function () { function RestApiClient(options) { - _classCallCheck(this, RestApiClient) + _classCallCheck(this, RestApiClient); - options = _.merge(this.DEFAULT_CONFIG, options) - this.options = options + options = _.merge(this.DEFAULT_CONFIG, options); + this.options = options; } RestApiClient.prototype.encode = function encode() { - return encodeURIComponent.apply(this, arguments) - } + return encodeURIComponent.apply(this, arguments); + }; RestApiClient.prototype.url = function url(pathname, query) { - var options = this.options + var options = this.options; var uri = _url.format({ protocol: options.protocol, hostname: options.host, port: options.port, pathname: options.base + pathname, - query: query, - }) + query: query + }); - return decodeURIComponent(uri) - } + return decodeURIComponent(uri); + }; RestApiClient.prototype.authorize = function authorize(p) { - var options = this.options + var options = this.options; if (p.oauth) { - p.oauth = options.oauth - return + p.oauth = options.oauth; + return; } if (typeof options.user === 'string') { p.auth = { user: options.user, - pass: options.password, - } + pass: options.password + }; } - } + }; RestApiClient.prototype.request = function request(method, path, params) { if (typeof path === 'object') { - var args = Array.from(path) - args.unshift(method) - return this.request.apply(this, args) + var args = Array.from(path); + args.unshift(method); + return this.request.apply(this, args); } - var options = this.options + var options = this.options; var p = { strictSSL: options.strictSSL, method: method, uri: this.url(path), json: true, - followAllRedirects: true, - } + followAllRedirects: true + }; if (params) { - p = _.merge(p, params) + p = _.merge(p, params); } - this.authorize(p) - - var id = Math.floor(Math.random() * 10000000) - var begin = new Date().getTime() - - return new Promise(function(resolve, reject) { - logger.debug( - 'New request #' + id + ' started at ' + begin + ':\n' + method + ' ' + p.uri - ) - logger.insane(p) - _request(p, function(error, response) { - var end = new Date().getTime() - logger.debug( - 'End of request #' + - id + - ' at ' + - end + - ' (' + - (end - begin) + - 'ms)' + - ' with status code: ' + - (response && response.statusCode) - ) + this.authorize(p); + + var id = Math.floor(Math.random() * 10000000); + var begin = new Date().getTime(); + + return new Promise(function (resolve, reject) { + logger.debug('New request #' + id + ' started at ' + begin + ':\n' + method + ' ' + p.uri); + logger.insane(p); + _request(p, function (error, response) { + var end = new Date().getTime(); + logger.debug('End of request #' + id + ' at ' + end + ' (' + (end - begin) + 'ms)' + ' with status code: ' + (response && response.statusCode)); if (response) { - logger.insane('Response headers:') - logger.insane(response.headers) - logger.debug('Response body') - logger.debug(response.body) + logger.insane('Response headers:'); + logger.insane(response.headers); + logger.debug('Response body'); + logger.debug(response.body); } if (error) { - reject(error) - return + reject(error); + return; } if (response.statusCode < 200 || response.statusCode > 399) { @@ -124,34 +112,34 @@ var RestApiClient = (function() { error: response.statusCode + ' ' + http.STATUS_CODES[response.statusCode], code: response.statusCode, msg: http.STATUS_CODES[response.statusCode], - response: response, - }) - return + response: response + }); + return; } - resolve(response) - }) - }) - } + resolve(response); + }); + }); + }; RestApiClient.prototype.get = function get() { - return this.request('GET', arguments) - } + return this.request('GET', arguments); + }; RestApiClient.prototype.post = function post() { - return this.request('POST', arguments) - } + return this.request('POST', arguments); + }; RestApiClient.prototype.put = function put() { - return this.request('PUT', arguments) - } + return this.request('PUT', arguments); + }; RestApiClient.prototype['delete'] = function _delete() { - return this.request('DELETE', arguments) - } + return this.request('DELETE', arguments); + }; - return RestApiClient -})() + return RestApiClient; +}(); RestApiClient.prototype.DEFAULT_CONFIG = { protocol: 'https', @@ -161,7 +149,7 @@ RestApiClient.prototype.DEFAULT_CONFIG = { password: 'password', base: '', // oauth: undefined, - strictSSL: true, -} + strictSSL: true +}; -module.exports = RestApiClient +module.exports = RestApiClient; diff --git a/package.json b/package.json index ad9a6102..8d1a718c 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "gh", "description": "GitHub command line tools.", - "version": "1.13.1", + "version": "1.13.2", "homepage": "http://nodegh.io", "author": { "name": "Eduardo Lundgren",