JS API wrapper for the WattzOn API
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
example
lib
src
README.txt

README.txt

WattzOn JavaScript API wrappers
Raffi Krikorian <raffi.krikorian@synthesisstudios.com>
27 April 2009

A first pass at the JavaScript wrappers for the WattzOn API -- this is 
supporting API version 2009-01-27/2.  In order to use these JS wrappers,
both jQuery and JS-Class must also be included first.  These wrappers do
not (yet) support 2009-01-27/3 which includes power-meter upload and 
download, however it will soon.

All calls to the API are performed through the wattzon.API object.  First
instantiate that object with your API key (retrieved through the
http://www.wattzon.com/account page when you're logged in).

    var api = new wattzon.API( 'apw6v977dl204wrcojdoyyykr' );

The functions that can be called on this API all use callbacks to return
the wrapper object.  For example, to get an array of all the countries that
are in the WattzOn database, use a call like

    api.listCountries( function( cs ) {
        // an array of wattzon.countryHolder objects are passed in
    }, function( errorMessage, statusCode ) {
        // an error message is returned if something goes wrong
    } );
    
The wattzon.countryHolder objects are just proxy-objects that can be used
to get more information.  The wattzon.holder object is the base class of all
the proxy objects, and it simply contains the "key" and the "name" of the
real object.  If you have a wattzon.countryHolder object, then you can retrieve
the full object with a (this is assuming cs is an array of wattzon.countryHolder
objects in the last call)

    cs[0].getCountry( function( c ) {
        // c will contain the wattzon.country object that the countryHolder pointed to
    }, function( errorMessage, statusCode ) {
        // an error message is returned if something goes wrong
    } );

The wattzon.API has the following functions available

    getItemSummary - return a wattzon.itemSummary object from an item's key
    getItem - return a wattzon.item object from an item's key
    getCategory - return a wattzon.category object from a category's key
    getTopCategory - return a wattzon.category object for the top of the tree
    listCountries - return an array of wattzon.countryHolders for all the countries
    getCountry - return a wattzon.country object for a specific country