Comparing version 5.0.8 to 5.0.9
@@ -155,22 +155,8 @@ module.exports = | ||
if (items === void 0) { items = []; } | ||
return __awaiter(_this, void 0, void 0, function () { | ||
var error_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
return [4 /*yield*/, doRequest({ | ||
accessToken: accessToken, | ||
method: 'info', | ||
config: config, | ||
data: sortUrlsAndHash(items), | ||
})]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
case 2: | ||
error_1 = _a.sent(); | ||
throw error_1; | ||
case 3: return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, bitlyRequest('info', sortUrlsAndHash(items))]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); }); | ||
}; | ||
@@ -182,17 +168,8 @@ /** | ||
*/ | ||
var shorten = function (longUrl) { return __awaiter(_this, void 0, void 0, function () { | ||
var error_2; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
return [4 /*yield*/, doRequest({ accessToken: accessToken, method: 'shorten', config: config, data: { longUrl: longUrl } })]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
case 2: | ||
error_2 = _a.sent(); | ||
throw error_2; | ||
case 3: return [2 /*return*/]; | ||
} | ||
}); | ||
}); }; | ||
var shorten = function (longUrl) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, bitlyRequest('shorten', { longUrl: longUrl })]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); }); }; | ||
/** | ||
@@ -203,22 +180,8 @@ * Request to expand urls and hashes | ||
*/ | ||
var expand = function (items) { return __awaiter(_this, void 0, void 0, function () { | ||
var error_3; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
return [4 /*yield*/, doRequest({ | ||
accessToken: accessToken, | ||
method: 'expand', | ||
config: config, | ||
data: sortUrlsAndHash(items), | ||
})]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
case 2: | ||
error_3 = _a.sent(); | ||
throw error_3; | ||
case 3: return [2 /*return*/]; | ||
} | ||
}); | ||
}); }; | ||
var expand = function (items) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, bitlyRequest('expand', sortUrlsAndHash(items))]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); }); }; | ||
/** | ||
@@ -229,22 +192,8 @@ * Request to get clicks for urls and hashes | ||
*/ | ||
var clicks = function (items) { return __awaiter(_this, void 0, void 0, function () { | ||
var error_4; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
return [4 /*yield*/, doRequest({ | ||
accessToken: accessToken, | ||
method: 'clicks', | ||
config: config, | ||
data: sortUrlsAndHash(items), | ||
})]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
case 2: | ||
error_4 = _a.sent(); | ||
throw error_4; | ||
case 3: return [2 /*return*/]; | ||
} | ||
}); | ||
}); }; | ||
var clicks = function (items) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, bitlyRequest('clicks', sortUrlsAndHash(items))]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); }); }; | ||
/** | ||
@@ -255,22 +204,8 @@ * Request to get clicks by minute for urls and hashes | ||
*/ | ||
var clicksByMinute = function (items) { return __awaiter(_this, void 0, void 0, function () { | ||
var error_5; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
return [4 /*yield*/, doRequest({ | ||
accessToken: accessToken, | ||
method: 'clicks_by_minute', | ||
config: config, | ||
data: sortUrlsAndHash(items), | ||
})]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
case 2: | ||
error_5 = _a.sent(); | ||
throw error_5; | ||
case 3: return [2 /*return*/]; | ||
} | ||
}); | ||
}); }; | ||
var clicksByMinute = function (items) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, bitlyRequest('clicks_by_minute', sortUrlsAndHash(items))]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); }); }; | ||
/** | ||
@@ -281,22 +216,8 @@ * Request to get clicks by day for urls and hashes | ||
*/ | ||
var clicksByDay = function (items) { return __awaiter(_this, void 0, void 0, function () { | ||
var error_6; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
return [4 /*yield*/, doRequest({ | ||
accessToken: accessToken, | ||
method: 'clicks_by_day', | ||
config: config, | ||
data: sortUrlsAndHash(items), | ||
})]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
case 2: | ||
error_6 = _a.sent(); | ||
throw error_6; | ||
case 3: return [2 /*return*/]; | ||
} | ||
}); | ||
}); }; | ||
var clicksByDay = function (items) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, bitlyRequest('clicks_by_day', sortUrlsAndHash(items))]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); }); }; | ||
/** | ||
@@ -307,22 +228,8 @@ * Lookup a single url | ||
*/ | ||
var lookup = function (url) { return __awaiter(_this, void 0, void 0, function () { | ||
var error_7; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
return [4 /*yield*/, doRequest({ | ||
accessToken: accessToken, | ||
method: 'lookup', | ||
config: config, | ||
data: { url: url }, | ||
})]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
case 2: | ||
error_7 = _a.sent(); | ||
throw error_7; | ||
case 3: return [2 /*return*/]; | ||
} | ||
}); | ||
}); }; | ||
var lookup = function (url) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, bitlyRequest('lookup', { url: url })]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); }); }; | ||
/** | ||
@@ -333,22 +240,8 @@ * Request referrers for a single url | ||
*/ | ||
var referrers = function (item) { return __awaiter(_this, void 0, void 0, function () { | ||
var error_8; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
return [4 /*yield*/, doRequest({ | ||
accessToken: accessToken, | ||
method: 'referrers', | ||
config: config, | ||
data: sortUrlsAndHash([item]), | ||
})]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
case 2: | ||
error_8 = _a.sent(); | ||
throw error_8; | ||
case 3: return [2 /*return*/]; | ||
} | ||
}); | ||
}); }; | ||
var referrers = function (item) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, bitlyRequest('referrers', sortUrlsAndHash([item]))]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); }); }; | ||
/** | ||
@@ -359,22 +252,8 @@ * Request countries for a single url | ||
*/ | ||
var countries = function (item) { return __awaiter(_this, void 0, void 0, function () { | ||
var error_9; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
return [4 /*yield*/, doRequest({ | ||
accessToken: accessToken, | ||
method: 'countries', | ||
config: config, | ||
data: sortUrlsAndHash([item]), | ||
})]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
case 2: | ||
error_9 = _a.sent(); | ||
throw error_9; | ||
case 3: return [2 /*return*/]; | ||
} | ||
}); | ||
}); }; | ||
var countries = function (item) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, bitlyRequest('countries', sortUrlsAndHash([item]))]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); }); }; | ||
/** | ||
@@ -387,3 +266,3 @@ * Perform any bitly API request using a method name and passed data object | ||
var bitlyRequest = function (method, data) { return __awaiter(_this, void 0, void 0, function () { | ||
var error_10; | ||
var result, err, e_1; | ||
return __generator(this, function (_a) { | ||
@@ -399,6 +278,14 @@ switch (_a.label) { | ||
})]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
case 1: | ||
result = _a.sent(); | ||
if (result.status_code >= 200 && result.status_code < 400) { | ||
return [2 /*return*/, result]; | ||
} | ||
err = new Error("[node-bitly] Request returned " + result.status_code + ": " + result.status_txt); | ||
err.statusCode = result.status_code; | ||
err.data = result.data; | ||
throw err; | ||
case 2: | ||
error_10 = _a.sent(); | ||
throw error_10; | ||
e_1 = _a.sent(); | ||
throw e_1; | ||
case 3: return [2 /*return*/]; | ||
@@ -405,0 +292,0 @@ } |
@@ -12,3 +12,3 @@ { | ||
"homepage": "https://github.com/tanepiper/node-bitly", | ||
"version": "5.0.8", | ||
"version": "5.0.9", | ||
"author": { | ||
@@ -15,0 +15,0 @@ "name": "Tane Piper", |
129
src/bitly.js
@@ -34,14 +34,3 @@ const { doRequest, sortUrlsAndHash, generateUrl } = require('./lib'); | ||
*/ | ||
const info = async (items = []) => { | ||
try { | ||
return await doRequest({ | ||
accessToken, | ||
method: 'info', | ||
config, | ||
data: sortUrlsAndHash(items), | ||
}); | ||
} catch (error) { | ||
throw error; | ||
} | ||
}; | ||
const info = async (items = []) => await bitlyRequest('info', sortUrlsAndHash(items)); | ||
@@ -53,9 +42,3 @@ /** | ||
*/ | ||
const shorten = async longUrl => { | ||
try { | ||
return await doRequest({ accessToken, method: 'shorten', config, data: { longUrl } }); | ||
} catch (error) { | ||
throw error; | ||
} | ||
}; | ||
const shorten = async longUrl => await bitlyRequest('shorten', { longUrl }); | ||
@@ -67,14 +50,3 @@ /** | ||
*/ | ||
const expand = async items => { | ||
try { | ||
return await doRequest({ | ||
accessToken, | ||
method: 'expand', | ||
config, | ||
data: sortUrlsAndHash(items), | ||
}); | ||
} catch (error) { | ||
throw error; | ||
} | ||
}; | ||
const expand = async items => await bitlyRequest('expand', sortUrlsAndHash(items)); | ||
@@ -86,14 +58,3 @@ /** | ||
*/ | ||
const clicks = async items => { | ||
try { | ||
return await doRequest({ | ||
accessToken, | ||
method: 'clicks', | ||
config, | ||
data: sortUrlsAndHash(items), | ||
}); | ||
} catch (error) { | ||
throw error; | ||
} | ||
}; | ||
const clicks = async items => await bitlyRequest('clicks', sortUrlsAndHash(items)); | ||
@@ -105,14 +66,4 @@ /** | ||
*/ | ||
const clicksByMinute = async items => { | ||
try { | ||
return await doRequest({ | ||
accessToken, | ||
method: 'clicks_by_minute', | ||
config, | ||
data: sortUrlsAndHash(items), | ||
}); | ||
} catch (error) { | ||
throw error; | ||
} | ||
}; | ||
const clicksByMinute = async items => | ||
await bitlyRequest('clicks_by_minute', sortUrlsAndHash(items)); | ||
@@ -124,14 +75,3 @@ /** | ||
*/ | ||
const clicksByDay = async items => { | ||
try { | ||
return await doRequest({ | ||
accessToken, | ||
method: 'clicks_by_day', | ||
config, | ||
data: sortUrlsAndHash(items), | ||
}); | ||
} catch (error) { | ||
throw error; | ||
} | ||
}; | ||
const clicksByDay = async items => await bitlyRequest('clicks_by_day', sortUrlsAndHash(items)); | ||
@@ -143,14 +83,3 @@ /** | ||
*/ | ||
const lookup = async url => { | ||
try { | ||
return await doRequest({ | ||
accessToken, | ||
method: 'lookup', | ||
config, | ||
data: { url }, | ||
}); | ||
} catch (error) { | ||
throw error; | ||
} | ||
}; | ||
const lookup = async url => await bitlyRequest('lookup', { url }); | ||
@@ -162,14 +91,3 @@ /** | ||
*/ | ||
const referrers = async item => { | ||
try { | ||
return await doRequest({ | ||
accessToken, | ||
method: 'referrers', | ||
config, | ||
data: sortUrlsAndHash([item]), | ||
}); | ||
} catch (error) { | ||
throw error; | ||
} | ||
}; | ||
const referrers = async item => await bitlyRequest('referrers', sortUrlsAndHash([item])); | ||
@@ -181,14 +99,3 @@ /** | ||
*/ | ||
const countries = async item => { | ||
try { | ||
return await doRequest({ | ||
accessToken, | ||
method: 'countries', | ||
config, | ||
data: sortUrlsAndHash([item]), | ||
}); | ||
} catch (error) { | ||
throw error; | ||
} | ||
}; | ||
const countries = async item => await bitlyRequest('countries', sortUrlsAndHash([item])); | ||
@@ -203,3 +110,3 @@ /** | ||
try { | ||
return await doRequest({ | ||
const result = await doRequest({ | ||
accessToken, | ||
@@ -210,4 +117,14 @@ method, | ||
}); | ||
} catch (error) { | ||
throw error; | ||
if (result.status_code >= 200 && result.status_code < 400 ) { | ||
return result; | ||
} | ||
const err = new Error(`[node-bitly] Request returned ${result.status_code}: ${result.status_txt}`); | ||
err.statusCode = result.status_code | ||
err.data = result.data | ||
throw err; | ||
} catch (e) { | ||
throw e; | ||
} | ||
@@ -214,0 +131,0 @@ }; |
@@ -18,2 +18,29 @@ require('sepia'); | ||
describe('should handle invalid requests', () => { | ||
it('it should throw an error', async () => { | ||
let err; | ||
try { | ||
await bitly.shorten(EXAMPLE_URL_BITLY); | ||
} catch (error) { | ||
err = error; | ||
} | ||
return expect(err.statusCode).to.equal(500); | ||
}); | ||
}); | ||
describe('should work with bitly api endpoints with no helper', () => { | ||
it('should accept any valid bitly url and data object', async() => { | ||
try { | ||
const {data} = await bitly.bitlyRequest('link/referrers_by_domain', { | ||
link: EXAMPLE_URL_BITLY, | ||
unit: 'hour', | ||
timezone: 'Europe/Amsterdam' | ||
}); | ||
return expect(data).to.have.property('referrers'); | ||
} catch (error) { | ||
throw error; | ||
} | ||
}) | ||
}) | ||
describe('shorten', () => { | ||
@@ -20,0 +47,0 @@ it('should shorten a url', async () => { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
73631
931