Skip to content

Instantly share code, notes, and snippets.

@elijahmanor
Created September 27, 2012 01:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elijahmanor/3791644 to your computer and use it in GitHub Desktop.
Save elijahmanor/3791644 to your computer and use it in GitHub Desktop.
AmplifyJS Request Twitter Example
// Define what a getTweets request looks like... url, dataType, etc
amplify.request.define( "getTweets", "ajax", {
url: "http://twitter.com/status/user_timeline/{userName}.json",
dataType: "jsonp",
type: "GET"
});
// Request "getTweets" passing in necessary data used in URL substitution
amplify.request({
resourceId: "getTweets",
data: { userName: "elijahmanor", count: 25 },
success: function( data, status ) {
console.log( data, status );
},
error: function( data, status) {
console.log( data, status )
}
});
// Redefine the getTweets request with hard-coded data
amplify.request.define( "getTweets", function ( settings ) {
settings.success([
{ id: 0, text: "Test Tweet 1", user: { name: "User 1" }, favorited: false, retweet_count: 0, created_at: "Mon Apr 11 8:00:00 +0000 2012" },
{ id: 1, text: "Test Tweet 2", user: { name: "User 2" }, favorited: true, retweet_count: 1, created_at: "Mon Apr 11 9:00:00 +0000 2012" },
{ id: 2, text: "Test Tweet 3", user: { name: "User 3" }, favorited: false, retweet_count: 2, created_at: "Mon Apr 11 10:00:00 +0000 2012" },
{ id: 3, text: "Test Tweet 4", user: { name: "User 4" }, favorited: true, retweet_count: 3, created_at: "Mon Apr 11 11:00:00 +0000 2012" },
{ id: 4, text: "Test Tweet 5", user: { name: "User 5" }, favorited: true, retweet_count: 4, created_at: "Mon Apr 11 12:00:00 +0000 2012" }
]);
});
// Redefine getTweets request with semi-random prototype data using the mockJSON library
amplify.request.define( "getTweets", function ( settings ) {
var mockData = $.mockJSON.generateFromTemplate({
"tweets|20-30": [{
"id|+1": 0,
"text": "@LOREM_IPSUM",
"user": { "name": "@MALE_FIRST_NAME @LAST_NAME" },
"favorited|0-1": false,
"retweet_count|0-10": 0,
"created_at": "Mon Apr 11 @TIME_HH:@TIME_MM:@TIME_SS +0000 2012"
}]
});
settings.success( mockData.tweets );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment