Skip to content

Instantly share code, notes, and snippets.

@elijahmanor
Created September 26, 2012 04:41
Show Gist options
  • Save elijahmanor/3786089 to your computer and use it in GitHub Desktop.
Save elijahmanor/3786089 to your computer and use it in GitHub Desktop.
AmplifyJS Request Netflix Example
amplify.request.define( "getMovies", "ajax", {
url: "http://odata.netflix.com/Catalog/Titles?$filter=substringof('{criteria}',Name)&$callback=?&$format=json",
dataType: "jsonp",
cache: 1000,
decoder: function ( data, status, xhr, success, error ) {
if ( status === "success" ) {
success( data.d.results );
} else if ( status === "fail" || status === "error" ) {
error( data.message, data.status );
} else {
error( data.message , "fatal" );
}
}
});
amplify.request({
resourceId: "getMovies",
data: {
criteria: "Star Trek"
},
success: function( data ) {
console.log( data );
},
error: function( message, status ) {
console.log( message, status );
}
});
amplify.request.define( "getMovies", function( settings ) {
settings.success([
{ Id: "1", Name: settings.data.criteria + " A", Rating: "PG", ReleaseYear: "1976", Runtime: 4354, ShortName: "", ShortSynopsis: "", Synopsis: "", TinyUrl: "", Url: "" },
{ Id: "2", Name: settings.data.criteria + " B", Rating: "PG", ReleaseYear: "1989", Runtime: 3344, ShortName: "", ShortSynopsis: "", Synopsis: "", TinyUrl: "", Url: "" }
]);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment