Skip to content

Commit

Permalink
Merge pull request #8 from orhnsnmz/patch-1
Browse files Browse the repository at this point in the history
Getting a user's data by supplying a username
  • Loading branch information
mikefowler committed Feb 23, 2015
2 parents b79a26e + ee9b712 commit 6d3d300
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/instajam.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
throw new InstajamError("Client ID and Redirect URI are required.");
}

// If the app is requesting additional
// If the app is requesting additional p
// scopes, build a string to append to
// the auth URL.
if (options.scope && typeof options.scope === 'object') {
Expand Down Expand Up @@ -213,11 +213,19 @@
// Make a request to the API
User.prototype.search.call(this, id, {}, function(result) {

// If the initial user search yields any
// results, then just return the first, but
// Go through the results and check for
// a perfect match, then query again with that user's ID
// otherwise return nothing.
if (result.data && result.data.length === 1) {
result = result.data[0];
if (result.data) {
var userIds = result.data;
result = false;

for (var i = 0; i < userIds.length; i++) {
if (userIds[i].username === id) {
User.prototype.get(parseInt(userIds[i].id, 10), callback);
return;
}
}
} else {
result = false;
}
Expand Down Expand Up @@ -668,4 +676,4 @@
Instajam.location = new Location();
// Instajam.geography = new Geography();

}(window.Instajam = window.Instajam || {}));
}(window.Instajam = window.Instajam || {}));

0 comments on commit 6d3d300

Please sign in to comment.