npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

reviews-collector-ios

v0.1.5

Published

Collect reviews for iOS apps from the Apple App Store

Downloads

6

Readme

reviews-collector-ios

Build Status Code Climate Test Coverage


Getting Started

// Create our Collector
const Collector = require('reviews-collector-ios');
// Create an instance of Collector to get reviews of Google Maps and MapQuest and only parse 2 pages max
const collector = new Collector(['585027354', '316126557'], { maxPages: 2 });

// Do something when we parse a review
collector.on('review', (result) => {
	console.log(`Found a ${result.review.rating} star review`);
});

// Do something when we finish parsing a page of reviews
collector.on('page complete', (result) => {
	console.log(`Finished page ${result.pageNum} of ${result.appId} and found ${result.reviews.length} reviews`);
});

// Do something when we are done parsing an app
collector.on('done collecting', (result) => {
	if (result.error) {
		console.error('Stopped collecting because something went wrong');
	} else {
		console.log(`Finished collecting reviews for ${result.appId}`);
	}
});

// Exit once we are done with all of the apps
collector.on('done with apps', () => {
	console.log('Finished collecting reviews for all of the apps');
	process.exit();
});

// Start collecting reviews
collector.collect();

Instantiating

First, create a Collector prototype by requiring reviews-collector-ios

var Collector = require('reviews-collector-ios');

Next, create an Collector instance using the new keyword and passing an app ID (or an array of app IDs) and an options object

// The app Id argument can be a single app ID string...
var singleAppCollector = new Collector('585027354', { maxPages: 2 });
// ...or an array of app ID strings
var multiAppCollector = new Collector(['585027354', '316126557'], { maxPages: 2 });

Where the arguments are:

  • App ID (string|string[]): The app ID is the portion after the /id in the iTunes URL (e.g. the app ID for this URL - https://itunes.apple.com/us/app/google-maps-real-time-navigation/id585027354?mt=8 - would be 585027354). You can pass a single app ID as a string, or multiple app IDs as an array of strings
  • Options (Object): An object with any (or none) of the following properties:
    • maxPages (Default 5): The maximum number of pages of reviews to parse. Use 0 for unlimited
    • checkBeforeContinue (Default false): When true, the page complete event will have both a continue and a stop function as properties of the object emitted on the event (details below). One of these must be called before the collector will proceed. This is useful when you want to, for example, check to see if the reviews already exist in your database or if they were created in the last X days, etc. Note: When this is set to true, maxPages will be ignored
      • continue() - Keep processing this app if possible
      • stop() - Stop processing this app and move onto the next one, if applicable
    • userAgent (Default iTunes/12.1.2 (Macintosh; OS X 10.10.3) AppleWebKit/0600.5.17): The user agent string to use when making requests
    • delay (Default 1000): The delay (in milliseconds) between page requests
    • maxRetries (Default 3): The maximum number of times to retry a page that could not be parsed before giving up

Listening for Events

Several events are triggered as the Collector parses reviews. You can setup event listeners for these using:

collector.on('<EVENT NAME>', function (result) {
	// Do something with the result every time the event is fired
});

Where the event name is one of:

  • 'review'
    • Fires when: A review is parsed from the page

    • Emits:

      {
      	os: 'iOS', // The OS of the app
      	appId: '585027354', // The ID of the app
      	pageNum: 3, // The page that the review was pulled from
      	review: {
      		id: '1383547048', // The unique review ID
      		date: 'Wed May 25 2016 04:00:00 GMT-0400 (EDT)', // The date of the review (as a Date object)
      		rating: 5, // The star rating given in the review
      		title: 'Great app', // The (optional) title of the review
      		text: 'This app is my most favorite' // The (optional) body of the review
      	}
      }
  • 'page complete'
    • Fires when: A page of reviews has been parsed

    • Emits:

      {
      	os: 'iOS', // The OS of the app
      	appId: '585027354', // The ID of the app
      	pageNum: 3, // The page that the review was pulled from
      	reviews: [ /* Review objects */ ],
      	firstReviewTime: 'Wed May 23 2016 04:00:00 GMT-0400 (EDT)', // The timestamp of the oldest review on the page (as a Date object)
      	lastReviewTime: 'Wed May 25 2016 04:00:00 GMT-0400 (EDT)', // The timestamp of the newest review on the page (as a Date object)
      	// If the 'checkBeforeContinue' option is set to true:
      	continue: function() {}, // Continue processing reviews for the app
      	stop: function() {} // Stop processing the app
      }
  • 'done collecting'
    • Fires when: The collector has finished collecting reviews for a particular app for one of the following reasons:

      • The collector's maxPages limit is reached for an app
      • The collector reaches the last page of reviews for the app
      • The collector's maxRetries limit is reached for an app
    • Emits:

      {
      	os: 'iOS', // The OS of the app
      	appId: '585027354', // The ID of the app
      	pageNum: 3, // The page that the review was pulled from
      	appsRemaining: 0, // # of apps left in queue
      	error: undefined || { /* Error object */ }
      }
  • 'done with apps'
    • Fires when: Processing has completed for all of the apps

    • Emits:

      {
      	os: 'iOS' // The OS of the app
      }

Starting the Collector

Once you have created an instance of Collector and setup your event listeners, you can begin the collection process using:

collector.collect();

The Collector will then collect reviews until it reaches one of the stop points described in the done collecting event (see above)

Examples

You can find a few examples of using the module within the /examples folder:

  • single_app.js - A basic example of how to collect reviews for a single app using maxPages to determine page depth
  • multi_app.js - An example of collecting reviews for multiple apps using maxPages to determine page depth
  • check_before_continue.js - An example of collecting reviews for multiple apps using checkBeforeContinue to determine page depth (based on review date)