Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 27 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,24 @@ InstagramClient.prototype.fetch = function (path, params, callback) {
raw += chunk;
});
res.on('end', function () {
var response = JSON.parse(raw);

var pagination = null;
if (typeof(response['pagination']) != 'undefined') {
pagination = response['pagination'];
}

if (response['meta']['code'] == 200) {
callback(response['data'],
null,
pagination);
}else{
callback(response['meta'], response['meta']['code'], pagination);
}
try{
var response = JSON.parse(raw);

var pagination = null;
if (typeof(response['pagination']) != 'undefined') {
pagination = response['pagination'];
}

if (response['meta']['code'] == 200) {
callback(response['data'],
null,
pagination);
}else{
callback(response['meta'], response['meta']['code'], pagination);
}
} catch (e) {
callback({}, {}, {});
}
});
});
}
Expand Down Expand Up @@ -119,8 +123,15 @@ function InstagramUsersClient (parent) {
this.parent = parent;
}

InstagramUsersClient.prototype.id = function (id, callback) {
this.parent.fetch('/v1/users/'+id, callback);
InstagramUsersClient.prototype.id = function (id, params, callback) {
if (typeof params == "function") {
// be compatible with old implementations, where the second parameter was the callback
callback = params;
this.parent.fetch('/v1/users/' + id, callback);

} else {
this.parent.fetch('/v1/users/' + id, params, callback);
}
}

InstagramUsersClient.prototype.media = function (id, params, callback) {
Expand Down