Code Monkey home page Code Monkey logo

ireviews's Introduction

iReviews

NPM version Build Status Dependency Status

iTunes store customer reviews fetcher.

Dependencies

  • async : Higher-order functions and common patterns for asynchronous code.
  • request : Simplified HTTP request client.
  • moment : Parse, manipulate, and display dates.
  • jsonschema : A fast and easy to use JSON schema validator.
  • debug : Small debugging utility.
  • xml2js : Simple XML to JavaScript object converter.
  • temporal : Non-blocking, temporal task sequencing.

Features

  • Use of events.
  • Automatic validation of all parameters.
  • Asynchronous reviews download.
  • Parse XML to JSON.
  • Choose a delay before each request.
  • Choose between XML or JSON for the response format (there is an update date for all reviews in XML format).
  • Return an enhance version of the structure (array of reviews).

Installation

$ npm install [--save] ireviews

Usage

var iReviews = require("ireviews");

var parameters = {
	store_id: "APPLICATION_ITUNES_STORE_ID",
	countries_code: [ "ALPHA_2_ISO_COUNTRY_CODE" ],
	delay: 100, // millisecond
	format: "json" // JSON format by default
};

var ireviews = new iReviews.Processor(parameters);

ireviews.storeId = "APPLICATION_ITUNES_STORE_ID";
ireviews.countriesCode = [ "ALPHA_2_ISO_COUNTRY_CODE" ];
ireviews.delay = 100;
ireviews.format = "xml";

// ============= WITHOUT EVENTS

ireviews.listAll(
	parameters, // not needed if already set before calling this method
	function (err, reviews) {
		if (err) return console.log(err);
			console.log(reviews);
	}
);

// ============= WITH EVENTS

ireviews.on("error", function (err) {
	console.log(err);
});

ireviews.on("end", function (reviews) {
	console.log(reviews);
});

ireviews.on("review", function (review) {
	console.log(review);
});

ireviews.parse(function (err) {
	if (err) console.log(err);
});

IMPORTANT :

  • You can have an INVALID_PARAMETERS_ERROR when there is an issue with the parameters JSON.

Structure

  • All reviews
[
	{
    	"count": 1,
        "countryCode": "US",
        "items": [
            {
                "id": "533332669",
                "title": "Help",
                "author": "DanBenedit1",
                "content": "I can't see my playlist after the update...",
                "rating": 1,
                "helpful_vote_count": 3,
                "total_vote_count": 3,
                "application_version": "1.1",
                "updated": 1330129380, // Only with response in XML format
                "country_code": "US"
            }
        ]
    }
]
  • A review
{
	"id": "533332669",
    "title": "Help",
    "author": "DanBenedit1",
    "content": "I can't see my playlist after the update...",
    "rating": 1,
    "helpful_vote_count": 3,
    "total_vote_count": 3,
    "application_version": "1.1",
    "updated": 1330129380, // Only with response in XML format
    "country_code": "US"
}

Examples

I use the application The Beatblaster with 7 countries as example. You can run one of these commands :

  • npm run-script ex-beatblaster-xml-stream
  • npm run-script ex-beatblaster-delay-xml-stream
  • npm run-script ex-beatblaster-xml
  • npm run-script ex-beatblaster-delay-xml
  • npm run-script ex-beatblaster-json-stream
  • npm run-script ex-beatblaster-delay-json-stream
  • npm run-script ex-beatblaster-json
  • npm run-script ex-beatblaster-delay-json

API

Class

Class: Processor([options])
  • options : object with following parameters
{
	"store_id": "",
    "countries_code": [],
    "delay": 1000,
    "format": "json"
}
Class: InvalidParametersError([message, parameters])

Useful when you need to verify if the returned error have an InvalidParametersError type.

  • message : error message
  • parameters : add data to the error instance

Methods

Method: listAll([parameters,] callback)

Start downloading and processing all reviews.

  • parameters : object with following parameters
{
	"store_id": "",
    "countries_code": []
}
  • callback : function called if an error occured or all reviews have been downloaded and processed
ireviews.listAll(function (err, reviews) {
	if (err) return console.log(err);
    console.log(reviews);
});
Method: parse([callback])

Start downloading and processing all reviews and emit following events.

  • callback : function called if an error occured or not
ireviews.parse();

ireviews.parse(function (err) {
	if (err) console.log(err);
});

Events

Event: error

Emitted if an error occured.

ireviews.on("error", function (err) {
	console.log(err);
});
Event: end

Emitted when all reviews have been downloaded and processed.

ireviews.on("end", function (reviews) {
	console.log(reviews);
});
Event: review

Emitted on every review processed.

ireviews.on("review", function (review) {
	console.log(review);
});

ireviews's People

Contributors

igorissen avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.