Search iTunes store
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
example
lib
test
.gitignore
.travis.yml Limit CI to 6 and 7 Feb 21, 2017
LICENSE
README.md Use ES6 default parameters and replace default result callback Feb 21, 2017
index.js Use ES6 default parameters and replace default result callback Feb 21, 2017
package.json Use strict Nov 26, 2016
repl.js

README.md

Build Status Coverage Status

fanboy

The fanboy Node.js package implements proxy caching for parts of the iTunes Search API.

Types

void()

null or undefined.

result(obj)

A map or filter callback applied with each JSON result obj.

Returns result or void().

The default callback adds the required guid property to obj and returns it. For production I’d return a classy object.

opts()

The options for the fanboy cache:

  • cacheSize Number The cache size passed to levelup.
  • country String The country code for the search API—defaults to 'us'.
  • highWaterMark Number Passed to stream.Readable constructor.
  • hostname String The host name of the store ('itunes.apple.com').
  • media String The media type to search for ('all').
  • objectMode Boolean Whether this stream should behave as a stream of objects (false).
  • path String The path to the store (/search).
  • port Number The port to access the store (80).
  • result result()
  • ttl Number Time to live in milliseconds (24 * 3600 * 1000).

Exports

The fanboy module exports a single function that returns a new cache object (an instance of the Fanboy class). To access the Fanboy class require('fanboy').

Creating a new cache

fanboy(name, opts)

  • name String The name of the file system directory for the database.
  • opts opts() Optional parameters of the cache.
const fanboy = require('fanboy')

const cache = fanboy('/tmp/fanboy.db', {
  type: 'podcast'
})

Searching the cache

const search = cache.search()
search.end('merlin mann')
search.pipe(process.stdout)

To run this printing only the title(s), do:

$ node example/search | json -ga title

This will search remotely and cache the result, subsequent requests will use the cache.

Looking up a guid

const lookup = cache.lookup()
lookup.end('471418144')
lookup.pipe(process.stdout)

You can run this with:

$ node example/lookup | json

Getting suggestions for search terms

const suggest = cache.suggest()
suggest.end('m')
suggest.pipe(process.stdout)

Try:

$ node example/suggest | json

If you have not searched before doing this, you will not get any results, because the suggestions index is populated as we are caching data.

Overriding stream options

The search, lookup, and suggest functions accept an optional stream options Object that lets you override global stream options—highWaterMark, encoding, and objectMode—of your fanboy instance.

Installation

With npm, do:

$ npm install fanboy

License

MIT License