Class OfferList

An OfferList contains a list of offer objects (AbebooksOffer or AmazonOffer). There are methods for selecting one of the offers from the list, as well as methods for additional filtering to make a smaller list.

The OfferList isn't created directly, but is returned by the offers() method on a Source module.

Class Summary

Using length()

var amazon = FILLZ.SOURCE.AMAZONUS.v1;
var o = amazon.offers();
debug('got '+o.length()+' offers');

Using first()

var amazon = FILLZ.SOURCE.AMAZONUS.v1;
var o = amazon.offers().sort_by_price();
debug('the lowest price is '+o.first().price);

Using last()

var amazon = FILLZ.SOURCE.AMAZONUS.v1;
var o = amazon.offers().sort_by_price();
debug('the highest price is '+o.last().price);

Using take()

var amazon = FILLZ.SOURCE.AMAZONUS.v1;
var o = amazon.offers().sort_by_price();
debug('the average of the 3 lowest prices is '+o.take(3).average_price());

Using reverse()

var amazon = FILLZ.SOURCE.AMAZONUS.v1;
var o = amazon.offers().sort_by_price();
debug('the lowest price is '+o.first().price);
debug('the highest price is '+o.reverse().first().price);

Using sort_by_price()

var amazon = FILLZ.SOURCE.AMAZONUS.v1;
var o = amazon.offers().sort_by_price();
debug('the lowest price is '+o.first().price);

Using sort_by_total()

var amazon = FILLZ.SOURCE.AMAZONUS.v1;
var o = amazon.offers().sort_by_total();
debug('the lowest total price is '+o.first().price);

Using filter([filters...])

var amazon = FILLZ.SOURCE.AMAZONUS.v1;
var filter = FILLZ.FILTERS.v1;
var o1 = amazon.offers();
debug('there are '+o1.length()+' offers total');
var o2 = o1.filter(filter.price.greater_than(10));
debug('there are '+o2.length()+' offers with price > 10');

Using lowest_price_offer()

var amazon = FILLZ.SOURCE.AMAZONUS.v1;
var lowest = amazon.offers().lowest_price_offer();
if (lowest) {
  debug('lowest offer by price is ' + lowest.price);
}

Using lowest_total_offer()

var amazon = FILLZ.SOURCE.AMAZONUS.v1;
var lowest = amazon.offers().lowest_total_offer();
if (lowest) {
  debug('lowest offer by total is ' + lowest.price);
}

Using average_price()

var abebooks = FILLZ.SOURCE.ABEBOOKS.v2;
var average  = abebooks.offers().average_price();
if (average) {
  debug('average price is ' + average);
}

Using average_total()

var amazon  = FILLZ.SOURCE.AMAZONUS.v1;
var average = amazon.offers().average_total();
if (average) {
  debug('average total is ' + average);
}

Methods

  • length()

    Returns

    • The number of offers in the OfferList.
  • first()

    Returns

    • The first offer in the OfferList.
  • last()

    Returns

    • The last offer in the OfferList.
  • take(how_many)

    Returns

    • A most how_many offers from the beginning of OfferList.
  • reverse()

    Returns

    • An OfferList in reverse order.
  • sort_by_price()

    Returns

    • An OfferList sorted by price from lowest to highest.
  • sort_by_total()

    Returns

    • An OfferList sorted by total price (price + shipping) from lowest to highest.
  • filter(filters..)

    Takes a list of filter objects, and returns a new OfferList containing only the Offers that the filters are true for.

    Parameters

    • One or more filter objects. The filter objects that are valid for this OfferList depend on which Source was used to create the OfferList.

    Returns

    • An OfferList containing only offers that meet the criteria of all filter arguments.
  • lowest_price_offer()

    Finds offer with lowest price (excluding shipping) in list of offers.

    The offer returned will be one of: AbebooksOffer or AmazonOffer

    Returns

    • Offer with lowest price, or undefined if there are no offers in the offer list.
  • lowest_total_offer()

    Finds offer with lowest total price (including shipping) in list of offers.

    The offer returned will be one of: AbebooksOffer or AmazonOffer

    Returns

    Offer with lowest total (price + shipping), or undefined if there are no offers in the offer list.

  • average_price()

    Averages the prices in the OfferList (excluding shipping). This method will not return a meaningful result when used on Amazon grouped data.

    Returns

    • Number representing the average price of all offers in the list, or undefined if there are no offers.
  • average_total()

    Averages the total (price + shipping for domestic buyer) for all offers in the OfferList. This method will not return a meaningful result when used on Amazon grouped data.

    Returns

    • Number representing the average total of all offers in the list, or undefined if there are no offers.