Socket
Socket
Sign inDemoInstall

searchitunes

Package Overview
Dependencies
0
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 2.0.0

.travis.yml

13

package.json

@@ -5,7 +5,7 @@ {

"email": "fr@nkl.in",
"url": "http://frankl.in"
"url": "https://frankl.in"
},
"name": "searchitunes",
"description": "Light module to quickly search Apple's iTunes Store for music and apps.",
"version": "1.0.0",
"description": "Light module to search the Apple iTunes Store and App Store",
"version": "2.0.0",
"repository": {

@@ -23,9 +23,12 @@ "type": "git",

"engines": {
"node": "*"
"node": ">=0.8.0"
},
"keywords": ["itunes", "apps", "apple", "middleware", "api"],
"keywords": ["itunes", "apps", "appstore", "apple", "api"],
"license": {
"type": "Public Domain",
"url": "https://github.com/fvdm/nodejs-searchitunes/raw/master/UNLICENSE"
},
"scripts": {
"test": "node test.js"
}
}

@@ -1,73 +0,74 @@

nodejs-searchitunes
===================
searchitunes
============
Light Node.js module to quickly search Apple's iTunes Store for music and apps.
Light node.js module to quickly search the Apple iTunes Store and App Store for music, apps, etc.
Basically this performs a GET request to the iTunes API and validates the returned data to make sure the process doesn't die by remote failures.
[![Build Status](https://travis-ci.org/fvdm/nodejs-searchitunes.svg?branch=master)](https://travis-ci.org/fvdm/nodejs-searchitunes)
# Installation
Installation
------------
Installation and connecting is simple:
Stable: `npm install searchitunes`
Source: `npm install fvdm/nodejs-searchitunes`
### From NPM
```
npm install searchitunes
```
Usage
-----
```js
var itunes = require('searchitunes')
```
### ( params, callback )
parameter | type | required | description
--------- | -------- | -------- | -----------------------------
params | object | yes | object with search parameters
callback | function | yes | function to process results
### From Github
```
git clone https://github.com/fvdm/nodejs-searchitunes
```
Params: [API documentation](http://www.apple.com/itunes/affiliates/resources/documentation/itunes-store-web-service-search-api.html)
```js
var itunes = require('./nodejs-searchitunes')
```
### Callback
# Usage
The `callback` function receives two parameters: `err` and `data`.
On success `err` is _null_ and `data` is the result object.
On error `err` is an instance of _Error_ and `data` is not set, see *Errors* below.
### ( paramsObject, callback )
* **paramsObject** -- object with search parameters.
* **callback** -- function that receives results.
### Example
You can find all the parameters in the API documentation: http://www.apple.com/itunes/affiliates/resources/documentation/itunes-store-web-service-search-api.html
```js
var searchitunes = require('searchitunes')
// Find free Github app for iPhone in Dutch App Store
searchitunes(
{
entity: 'software',
country: 'NL',
term: 'github',
limit: 1,
price: 0
},
function( err, data ) {
if( err ) {
## callback
// Error
console.log( 'Search failed: '+ err.message )
**Success**: callbackFunction ( resultObject )
} else {
**Faillure**: callbackFunction ( result, errorObject )
// All good
console.log( app )
**Result** is always the response body, in case of JSON the parsed object. In case of faillure **errorObject** is provided with *reason* and *headers*.
}
}
)
```
## Example
#### Output
```js
var searchitunes = require('searchitunes')
// Find free Github app for iPhone in Dutch App Store
searchitunes({
entity: 'software',
country: 'NL',
term: 'github',
limit: 1,
price: 0
}, console.log )
```
```js
{ resultCount: 1,
results:
results:
[ { kind: 'software',

@@ -112,7 +113,18 @@ features: [],

*(console.log goes only 3 levels deep, combined with [util.inspect](http://nodejs.org/api/util.html#util_util_inspect_object_showhidden_depth_colors) would be more useful)*
Errors
------
# Unlicense
message | description
---------------- | --------------------------------------------
request failed | Request can not be made, see `err.error`
request closed | Request was closed too early
invalid response | API returned unreadable data, see `err.body`
invalid params | Client provided no or invalid parameters
no results | No results received
Unlicense
---------
This is free and unencumbered software released into the public domain.

@@ -141,2 +153,10 @@

For more information, please refer to <http://unlicense.org/>
For more information, please refer to <http://unlicense.org/>
Author
------
Franklin van de Meent
| [Website](https://frankl.in)
| [Github](https://github.com/fvdm)
/*
Name: nodejs-searchitunes
Source: https://github.com/fvdm/nodejs-searchitunes
Feedback: https://github.com/fvdm/nodejs-searchitunes/issues
License: unlicense / public domains
Name: searchitunes
Description: Search the Apple iTunes Store and App Store.
Author: Franklin van de Meent (https://frankl.in)
Source: https://github.com/fvdm/nodejs-searchitunes
Feedback: https://github.com/fvdm/nodejs-searchitunes/issues
API docs: http://www.apple.com/itunes/affiliates/resources/documentation/itunes-store-web-service-search-api.html
License: Unlicense / Public Domain, see UNLICENSE file
(https://github.com/fvdm/nodejs-searchitunes/raw/master/UNLICENSE)
*/
API docs: http://www.apple.com/itunes/affiliates/resources/documentation/itunes-store-web-service-search-api.html
var http = require('http')
var querystring = require('querystring')
This is free and unencumbered software released into the public domain.
module.exports = function( params, cb ) {
// prevent multiple callbacks
var complete = false
function doCallback( err, res ) {
if( !complete ) {
complete = true
cb( err, res || null )
}
}
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
// check input
if( !params || !(params instanceof Object) ) {
doCallback( new Error('invalid params') )
return
}
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
// build request
params.version = params.version || 2
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
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'
}
}
For more information, please refer to <http://unlicense.org/>
*/
var request = http.request( options )
var http = require('http'),
querystring = require('querystring'),
api = {
host: 'itunes.apple.com',
port: 80,
path: '/WebObjects/MZStoreServices.woa/ws/wsSearch'
}
// response
request.on( 'response', function( response ) {
var data = []
var size = 0
response.on( 'data', function( ch ) {
data.push( ch )
size += ch.length
})
module.exports = function( params, cb ) {
params.version = params.version || 2
var req = http.request(
{
host: api.host,
port: api.port,
path: api.path +'?'+ querystring.stringify( params ),
method: 'GET',
headers: {
'Accept': 'application/json',
'User-Agent': 'appstoresearch.js'
}
},
function( response ) {
var data = ''
response.on( 'data', function( chunk ) { data += chunk })
response.on( 'end', function() {
// process response
data = data.toString().trim()
if( data.length >= 2 && data.substr(0,1) == '{' && data.substr( data.length -1, 1 ) == '}' ) {
data = JSON.parse( data )
if( data.resultCount !== undefined ) {
cb( data )
} else {
cb( false, {reason: 'incomplete json', headers: response.headers, data: data} )
}
} else {
// not json
cb( false, {reason: 'not json', headers: response.headers, data: data} )
}
})
}
).end()
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 ) {
var error = new Error('http error')
error.code = response.statusCode
error.body = data
doCallback( error )
return
}
try {
data = JSON.parse( data )
if( !(data.results instanceof Array) || data.results.length === 0 ) {
doCallback( new Error('no results') )
} else {
doCallback( null, data )
}
}
catch(e) {
var error = new Error('invalid response')
error.error = e
doCallback( error )
}
})
})
// request failed
request.on( 'error', function( err ) {
var error = new Error('request failed')
error.error = err
doCallback( error )
})
// run it
request.end()
}
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