As I navigate through the github API's pagination documentation, I am attempting to retrieve event items and extract the Link
header (as recommended) in order to construct the pagination. However, I am facing difficulty in understanding how to work with the headers('Link')
object.
Function:
getEvents: function(page) {
if(cacheService.get('eventos_'+page)) {
return cacheService.get('eventos_'+page);
} else {
var deferred = $q.defer();
$http.get('https://api.github.com/repos/'+owner+'/'+repo+'/events', {params: {per_page: 15, page: page}})
.success(function(events, status, headers) {
console.log(events, status, headers('Link'));
cacheService.put('eventos_'+page, events);
deferred.resolve(events);
}).error(function(err) {
deferred.reject('Error', err);
});
return deferred.promise;
}
}
The resulting data structure (if it can be described as such) is:
"
<https://api.github.com/repositories/XXXXXX/events?page=2&per_page=15>; rel="next",
<https://api.github.com/repositories/XXXXXX/events?page=4&per_page=15>; rel="last"
"
How can I store the page numbers of 'next' and 'last' in $scope variables? Alternatively, how can I traverse this object?
I attempted using headers('Link').rel['last']
without success, unfortunately.