Created
September 27, 2012 01:21
-
-
Save elijahmanor/3791644 to your computer and use it in GitHub Desktop.
AmplifyJS Request Twitter Example
This file contains 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... url, dataType, etc | |
amplify.request.define( "getTweets", "ajax", { | |
url: "http://twitter.com/status/user_timeline/{userName}.json", | |
dataType: "jsonp", | |
type: "GET" | |
}); |
This file contains 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
// 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 ) | |
} | |
}); |
This file contains 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
// 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" } | |
]); | |
}); |
This file contains 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
// 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