The Javascript API is designed to closely follow the design of the
Newsgator API (note - the newsgator api documentation is required reading to understand this library), it has the same main objects - Locations, Folders, Subscriptions, Feeds, and Posts. It also has a Newsgator object which is the application entry point.
Currently only GET operations are supported i.e. you cannot modify (subscribe, delete, mark as read etc) the aggregator.
The api is designed to be used asynchronously, using
Mochkit's
Signals library. This library has a very simple syntax connect(object, event, handler), handler can be designated as either a function, an object and the name of a method of that object, or an object and a function. With the last two the function is called with the
this pointer set to the object.
API Overview
Each object in the API has a number of retrieveXXX methods, which asynchronously retrieve the desired information, when the information is retrieved the api fires a signal (named onRetrieveXXX to match the method name). The retrieved information can be then accesed through the properties of the api objects.
Example
var apiKey = "5993F57CBACC43DC8B6C9C8310813EDB";
var base = "http://services.newsgator.com/ngws/svc/";
var newsgator = new Newsgator();
connect(newsgator, "onRetrieveLocations", onLocationsReady);
newsgator.retrieve();
function onLocationsReady(){
var locations = newsgator.getLocations();
var onlineLocation = locations["NewsGator Web Edition"];
connect(onlineLocation, "onRetrieveSubscriptionsHeadlines", onHeadlinesReady);
onlineLocation.retrieveSubscriptionsHeadlines();
};
function onHeadlinesReady(){
var heads = onlineLocation.getHeadlines();
drawHeadlines(heads);
};
function drawHeadlines(subs){
var table = TABLE({}, "");
for(var i=0; i<subs.length; i++){
var sub = subs[i];
var title = sub.title;
var link = sub.link;
var descripton = sub.description;
var row = TR({}, TD({}, A({href: link}, title)), TD({}, description) );
table.appendChild(row);
}
document.body.appendChild(table);
}