STEW: presenting content on screens

Implement functions to display the data that you retrieve from Twitter in the STEW views.

The UpdateScreen object in the UpdateScreen.js file sets the onSuccess and onError callback functions to be handled by the onTwitterUserResponse and onTwitterServiceError functions. These functions are triggered when the request is completed, either successfully or with an error. The last line of the following code makes the actual request to Twitter:

UpdateScreen.prototype.onActivated = function() {
	// Add event listeners.
	var self = this;
	twitterService.onSuccess = function( response ) {
self.onTwitterUserResponse( response )
}
	twitterService.onError = function( status ) {
self.onTwitterServiceError( status )
}

	// Start the request.
	twitterService.getTweetsForUser( null, 1 );
}

The onTwitterUserResponse function illustrates how the response is handled as a JavaScript object:

UpdateScreen.prototype.onTwitterUserResponse = function( response ) {
	// Set my latest status update.
	var tweet = response[0];
	this.setMyLatestStatus( tweet.text,
new Date( tweet.created_at ).toLocaleString() );
}
UpdateScreen.prototype.onTwitterServiceError = function( status ) {
	alert("Error: (" + status + ")" );
}

The TwitterService performs the necessary conversions. For more information, see STEW: implementing a Twitter service. The data can be accessed by calling various properties on the object retrieved, such as .text or .created. For more information about the responses and requests that you can make, see the Twitter API documentation.