Created
July 25, 2011 05:28
-
-
Save elijahmanor/1103608 to your computer and use it in GitHub Desktop.
Simple Twitter Example Using AmplifyJS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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