From 62bb7dbafe81ce0784a5452c870d6584431ac0a6 Mon Sep 17 00:00:00 2001 From: Tane Piper Date: Wed, 28 Oct 2015 09:29:08 +0000 Subject: [PATCH] Refactor some internal code and bump version --- package.json | 10 ++++----- src/bitly.js | 63 ++++++++++++++++++++-------------------------------- 2 files changed, 28 insertions(+), 45 deletions(-) diff --git a/package.json b/package.json index 6a93b2a..90e7ed6 100644 --- a/package.json +++ b/package.json @@ -1,17 +1,15 @@ { "name": "bitly", "description": "A Bit.ly API library for Node.JS", - "license": { - "type": "MIT", - "url": "http://www.opensource.org/licenses/mit-license.php" - }, - "tags": [ + "license": "MIT", + "keywords": [ "url", "bitly", "shortner", "util" ], - "version": "4.0.1", + "homepage": "https://github.com/tanepiper/node-bitly", + "version": "4.1.0", "author": { "name": "Tane Piper", "email": "piper.tane@gmail.com", diff --git a/src/bitly.js b/src/bitly.js index 3077261..b509458 100644 --- a/src/bitly.js +++ b/src/bitly.js @@ -70,8 +70,13 @@ class Bitly { * @return {void} */ sortUrlsAndHash (items, query) { - var shortUrl = []; - var hash = []; + let shortUrl = []; + let hash = []; + + // If only passed one item, put in array for url checking + if (typeof items === 'string') { + items = [items]; + } items.forEach((item) => { isUri(item) ? shortUrl.push(item) : hash.push(item); }); @@ -88,7 +93,7 @@ class Bitly { * Request to shorten one long url * @param {String} longUrl The URL to be shortened * @param {String=} domain The domain to use (optional) - * @return {Promise|void} + * @return {Promise} */ shorten (longUrl, domain) { var query = { @@ -103,7 +108,7 @@ class Bitly { /** * Request to expand a single short url, short hash or mixed array or items * @param {String|Array} items The string or array of short urls and/or hashes to expand - * @return {Promise|void} + * @return {Promise} */ expand (items) { var query = { @@ -111,11 +116,7 @@ class Bitly { domain: this.config.domain }; - if (typeof items === 'string') { - query[isUri(items) ? 'shortUrl' : 'hash'] = items; - } else { - this.sortUrlsAndHash(items, query); - } + this.sortUrlsAndHash(items, query); return this.doRequest(this.generateNiceUrl(query, 'expand')); } @@ -123,7 +124,7 @@ class Bitly { /** * Request to get clicks for a single short url, short hash or mixed array or items * @param {String|Array} items The string or array of short urls and/or hashes to expand - * @return {Promise|void} + * @return {Promise} */ clicks (items) { var query = { @@ -131,11 +132,7 @@ class Bitly { domain: this.config.domain }; - if (typeof items === 'string') { - query[isUri(items) ? 'shortUrl' : 'hash'] = items; - } else { - this.sortUrlsAndHash(items, query); - } + this.sortUrlsAndHash(items, query); return this.doRequest(this.generateNiceUrl(query, 'clicks')); } @@ -143,7 +140,7 @@ class Bitly { /** * Request to get clicks by minute for a single short url, short hash or mixed array or items * @param {String|Array} items The string or array of short urls and/or hashes to expand - * @return {Promise|void} + * @return {Promise} */ clicksByMinute (items) { var query = { @@ -151,11 +148,7 @@ class Bitly { domain: this.config.domain }; - if (typeof items === 'string') { - query[isUri(items) ? 'shortUrl' : 'hash'] = items; - } else { - this.sortUrlsAndHash(items, query); - } + this.sortUrlsAndHash(items, query); return this.doRequest(this.generateNiceUrl(query, 'clicks_by_minute')); @@ -164,7 +157,7 @@ class Bitly { /** * Request to get clicks by day for a single short url, short hash or mixed array or items * @param {String|Array} items The string or array of short urls and/or hashes to expand - * @return {Promise|void} + * @return {Promise} */ clicksByDay (items) { var query = { @@ -172,11 +165,7 @@ class Bitly { domain: this.config.domain }; - if (typeof items === 'string') { - query[isUri(items) ? 'shortUrl' : 'hash'] = items; - } else { - this.sortUrlsAndHash(items, query); - } + this.sortUrlsAndHash(items, query); return this.doRequest(this.generateNiceUrl(query, 'clicks_by_day')); } @@ -184,7 +173,7 @@ class Bitly { /** * Request to get look up an existing bitly link for a long url or array of urls * @param {String|Array} links The string or array of long urls - * @return {Promise|void} + * @return {Promise} */ lookup (links) { var query = { @@ -200,7 +189,7 @@ class Bitly { /** * Request to get clicks by day for a single short url, short hash or mixed array or items * @param {String|Array} items The string or array of short urls and/or hashes to expand - * @return {Promise|void} + * @return {Promise} */ info (items) { var query = { @@ -208,11 +197,7 @@ class Bitly { domain: this.config.domain }; - if (typeof items === 'string') { - query[isUri(items) ? 'shortUrl' : 'hash'] = items; - } else { - this.sortUrlsAndHash(items, query); - } + this.sortUrlsAndHash(items, query); return this.doRequest(this.generateNiceUrl(query, 'info')); } @@ -222,7 +207,7 @@ class Bitly { * Request the informations on all referrers for a short url. This function only * accepts one url (as per the limit of the bitly API) * @param {String} link The link be checked - * @return {Promise|void} + * @return {Promise} */ referrers (link) { var query = { @@ -238,7 +223,7 @@ class Bitly { /** * Request the information on all countries for a short url. This function only * accepts one url (as per the limit of the bitly API) - * @return {Promise|void} + * @return {Promise} */ countries (link) { var query = { @@ -254,7 +239,7 @@ class Bitly { /** * Request to confirm a pro-domain it set up with bitly * @param {String} domain The domain to be checked - * @return {Promise|void} + * @return {Promise} */ bitlyProDomain (domain) { var query = { @@ -267,7 +252,7 @@ class Bitly { /** * Request entries from a user's link history in reverse chronological order - * @return {Promise|void} + * @return {Promise} */ history () { var query = { @@ -288,7 +273,7 @@ class Bitly { * have to pass an array to new_value. The index have to match those in metadata_field, e.g. metadata_field[0] will * be * changed to new_value[0] etc. - * @return {Promise|void} + * @return {Promise} */ linkEdit (metadata_field, link, new_value) { var query = {