Created
July 2, 2015 17:40
-
-
Save acwio/796ea15bf933dd5b1ff0 to your computer and use it in GitHub Desktop.
Simple Panoptes API Consumption Example
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
sendAuthentication = function (xhr) { | |
xhr.setRequestHeader('Accept', "application/vnd.api+json; version=1"); | |
}; | |
SubjectModel = Backbone.Model.extend({ | |
initialize:function(opts) { | |
console.log("init subject : "+opts.id); | |
} | |
}); | |
Subjects = Backbone.Collection.extend({ | |
model: SubjectModel, | |
sync: function(method, model, options) { | |
var params = _.extend({ | |
type: 'GET', | |
dataType: 'jsonp', | |
url: model.url(), | |
processData: false | |
}, options); | |
return $.ajax(params); | |
}, | |
parse: function(response) { | |
console.log(response); | |
return response; | |
}, | |
url: function() { | |
return "https://panoptes-staging.zooniverse.org/api/projects/183?display_name=AncientTextualLives&approved=true&beta=true&live=true"; | |
} | |
}); | |
// Create the Collection | |
s=new Subjects(); | |
// Fetch | |
s.fetch({ | |
contentType: "application/json", | |
beforeSend: sendAuthentication | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment