Skip to content

Instantly share code, notes, and snippets.

@dericcrago
Forked from bhang/KinveyCollection.js
Created March 15, 2012 05:31
Show Gist options
  • Save dericcrago/2042167 to your computer and use it in GitHub Desktop.
Save dericcrago/2042167 to your computer and use it in GitHub Desktop.
KinveyCollection
// Credentials for use with Kinvey
// NOTE: This example shows passing in the master secret.
// In a production environment, these credentials should be protected i.e.
// they should be requested from the user or secured via a login screen
var kinvey_app_key = 'kidxxxx';
var kinvey_secret = 'master secret';
// Define .ajax Defaults
$.ajaxSetup({
beforeSend: function(jqXHR) {
jqXHR.setRequestHeader(
'Authorization',
'Basic ' + $.base64.encode(
kinvey_app_key + ':' + kinvey_secret
)
);
}
});
// User submission model
var UserSubmissionModel = Backbone.Model.extend({
// Backbone looks for 'id' by default
// However, MongoDB uses '_id' so we need to override it
idAttribute: '_id'
});
// An example of a Kinvey collection that we want to interact with
var UserSubmissionsCollection = Backbone.Collection.extend({
model: UserSubmissionModel,
// URL is a function of the app_key and the name of the collection
url: function() {
return 'https://baas.kinvey.com/appdata/' + kinvey_app_key + '/user_submissions/';
}
});
// Create an instance of our collection...
var UserSubmissions = new UserSubmissionsCollection();
// ... and fetch some data !!!
UserSubmissions.fetch();
/// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment