Skip to content

Instantly share code, notes, and snippets.

@elijahmanor
Created July 25, 2011 05:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elijahmanor/1103608 to your computer and use it in GitHub Desktop.
Save elijahmanor/1103608 to your computer and use it in GitHub Desktop.
Simple Twitter Example Using AmplifyJS
// Define what a getTweets request looks like...
amplify.request.define( "getTweets", "ajax", {
url: "http://twitter.com/status/" +
"user_timeline/{userName}.json" +
"?count={count}&callback=?",
dataType: "json",
type: "GET"
});
// You can redefine the request to mock out the response
amplify.request.define( "getTweets", function (settings) {
settings.success([
{ text: "Test Tweet 1" },
{ text: "Test Tweet 2" },
{ text: "Test Tweet 3" },
{ text: "Test Tweet 4" },
{ text: "Test Tweet 5" }
]);
});
// Subscribe to "applciation.started" topic published later
amplify.subscribe( "application.started", function (data) {
// Writes out message that was passed in the Publish
console.log( data.message );
// Request "getTweets" passing in necessary data which
// is used in URL substitution
amplify.request( "getTweets",
{ userName: "AmplifyJS", count: "5" },
function ( tweets ) {
// Store tweets array to persistent storage
amplify.store( "tweets", tweets );
// Retreive tweets array from storage and write
console.log( amplify.store("tweets") );
});
});
// Kick off whole process by publishing message with data
amplify.publish( "application.started", {
message: "Hello World!"
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment