Socket
Socket
Sign inDemoInstall

searchitunes

Package Overview
Dependencies
1
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.1 to 2.1.1

13

package.json

@@ -8,4 +8,4 @@ {

"name": "searchitunes",
"description": "Light module to search the Apple iTunes Store and App Store",
"version": "2.0.1",
"description": "Search the Apple iTunes Store and App Store with this lightweight module",
"version": "2.1.1",
"repository": {

@@ -19,3 +19,5 @@ "type": "git",

"main": "searchitunes.js",
"dependencies": {},
"dependencies": {
"httpreq": "0.4.x"
},
"devDependencies": {},

@@ -27,6 +29,3 @@ "optionalDependencies": {},

"keywords": ["itunes", "apps", "music", "appstore", "apple", "api"],
"license": {
"type": "Public Domain",
"url": "https://github.com/fvdm/nodejs-searchitunes/raw/master/UNLICENSE"
},
"license": "Unlicense",
"scripts": {

@@ -33,0 +32,0 @@ "test": "node test.js"

@@ -12,69 +12,34 @@ /*

var http = require ('http');
var querystring = require ('querystring');
var http = require ('httpreq');
module.exports = function (params, cb) {
// prevent multiple callbacks
var complete = false;
function doCallback (err, res) {
if (!complete) {
complete = true;
cb (err, res || null);
}
}
// check input
module.exports = function (params, callback) {
if (!params || !(params instanceof Object)) {
doCallback (new Error('invalid params'));
return;
return callback (new Error ('invalid params'));
}
// build request
params.version = params.version || 2;
var options = {
host: 'itunes.apple.com',
path: '/WebObjects/MZStoreServices.woa/ws/wsSearch?'+ querystring.stringify (params),
method: 'GET',
headers: {
'Accept': 'application/json',
'User-Agent': 'searchitunes.js'
}
};
var request = http.request (options);
// response
request.on ('response', function (response) {
var data = [];
var size = 0;
response.on ('data', function (ch) {
data.push(ch);
size += ch.length;
});
response.on ('close', function () {
doCallback (new Error ('request closed'));
});
response.on ('end', function () {
data = new Buffer.concat (data, size).toString ('utf8').trim ();
if( response.statusCode >= 300 ) {
http.get (
'http://itunes.apple.com/WebObjects/MZStoreServices.woa/ws/wsSearch',
{
parameters: params,
headers: {
'Accept': 'application/json',
'User-Agent': 'searchitunes.js'
}
},
function (err, res) {
if (err) {
var error = new Error ('http error');
error.code = response.statusCode;
error.body = data;
doCallback (error);
return;
error.code = res.statusCode;
error.body = res.body;
return callback (error);
}
try {
data = JSON.parse (data);
data = JSON.parse (res.body);
if (!(data.results instanceof Array) || data.results.length === 0) {
doCallback (new Error('no results'));
} else {
doCallback (null, data);
return callback (new Error ('no results'));
}
return callback (null, data);
}

@@ -84,16 +49,6 @@ catch (e) {

error.error = e;
doCallback (error);
callback (error);
}
});
});
// request failed
request.on ('error', function (err) {
var error = new Error ('request failed');
error.error = err;
doCallback (error);
});
// run it
request.end ();
}
);
};

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc