Skip to content

Instantly share code, notes, and snippets.

@nambrot
Created January 5, 2012 21:38
Show Gist options
  • Save nambrot/1567460 to your computer and use it in GitHub Desktop.
Save nambrot/1567460 to your computer and use it in GitHub Desktop.
parse: function(resp, xhr){
// create scope
var that = this;
// proper parsing of the response paging fields
if (resp.paging && resp.paging.next)
{
this.next = resp.paging.next;
}
else
{
this.isDone = true;
this.trigger('load:finished', this);
}
this.isLoading = false;
this.trigger('load:end', this);
// filter the items we support, currently only photos
var items = _.filter(resp.data, function (obj) {
return obj.type == 'photo'
});
// create the batch array to get the actual items
FB.api('/','POST', {
batch: _.map(items, function (obj) {
return {
'method': 'GET',
'relative_url': obj.object_id
}
})
}, function (response) {
// we got the actual objects
var models = _.map(response, function (obj) {
return JSON.parse(obj.body)
});
// zip the objects to insert the correct types so that we can get the model from the model map
var objects = _.zip(models, items);
_.each(objects, function (obj) {
obj[0].to = obj[1].to;
obj[0].type = obj[1].type;
var model = new a.modelmap[obj[1].type].model(obj[0]);
that.add(model);
});
});
return [];
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment