My favorites | Sign in
Project Home Issues Source
Project Information
Members

A client library to help Flash and Flex developers use The Guardian Open Platform.

The SVN repository contains two projects (both set up for Eclipse + Ant + FDT):

  1. openplatform - contains the library source code, a SWC build, ASDoc and an example FLA
  2. openplatform-tests - contains a FlexUnit test suite for the library code

Flash developers

If you use the CS3 / CS4 IDE, have a look at the FLA in openplatform/example

If you use FDT or FlashDevelop, simply adjust your source path to include a copy of the SWC in openplatform/build

Flex developers

Add a copy of the SWC in openplatform/build to your libraries folder.

Documentation

Full ASDoc is available here openplatform/docs/index.html

Dependencies

  • Adobe's Corelib
  • Adobe's FlexUnit

Example Usage

Fetch the first 5 articles written after the 1st Jan 2009 including the word "Obama":

function runSearch() : void
{
	var after : Date = new Date(2009,0, 1);
	var query : SearchQuery = new SearchQuery(1, 5, ContentType.ARTICLE, "Obama", after);
	var searchService : SearchService = new SearchService(YOUR_API_KEY);
	 
	searchService.addEventListener(ApiDataEvent.SEARCH_RESULTS_RECEIVED, handleSearchResults);
	searchService.addEventListener(ApiErrorEvent.SEARCH_ERROR, handleError);
	
	searchService.findContent(query);
}

function handleSearchResults(event : ApiDataEvent) : void
{
	var results : SearchResults = event.data as SearchResults;
	var firstItem : Item = results.getItems().getAll()[0] as Item; 
	
	trace("received " + results.getCount() + " results:");
	
	for each (var item : Item in results.getItems().getAll()) 
	{
		trace(item.getType().getName() + " - " + item.getHeadline());
	}
}

function handleError(event : ApiErrorEvent) : void
{
	trace(event.text);
}

To get a list of the first 10 tags featuring the keyword "politics":

function fetchTags() : void
{
   	var tagService : TagService = new TagService(YOUR_API_KEY);
	
	tagService.addEventListener(ApiDataEvent.TAG_LIST_RECEIVED, handleTagData);
	tagService.addEventListener(ApiErrorEvent.TAG_ERROR, handleError);

	tagService.findTags("politics", 0, 10); 
}   

function handleTagData(event : ApiDataEvent) : void
{
	var data : TagData = event.data as TagData;
	var tags : TagList = data.getItems();
	
	trace("received " + tags.getCount() + " tags:");
	 
	for each (var tag : Tag in tags.getAll()) 
	{
		trace(tag.getType().getName() + " - " + tag.getName());
	}
}

function handleError(event : ApiErrorEvent) : void
{
	trace(event.text);
}

To retrieve an item of content with a specific ID:

function fetchItem(id : String) : void
{
	var contentService:ContentService = new ContentService(YOUR_API_KEY);
	
	contentService.addEventListener(ApiDataEvent.CONTENT_ITEM_RECEIVED, handleContentItem);
	contentService.addEventListener(ApiErrorEvent.CONTENT_ERROR, handleError);
	
	contentService.fetchItem(id);        	
}

function handleContentItem(event : ApiDataEvent) : void
{
	var result : Item = event.data as Item; 
	
	trace("received item # " + result.getHeadline() + " - " + result.getByline());
}

function handleError(event : ApiErrorEvent) : void
{
	trace(event.text);
}
Powered by Google Project Hosting