Skip to content

Commit

Permalink
Add get me albums
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcio Cesar Corrêa authored and Marcio Cesar Corrêa committed Feb 17, 2017
1 parent 916fd6e commit d92272e
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion lib/imgur.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,16 @@ imgur._imgurRequest = function (operation, payload, extraFormParams) {
json: true
};

if (!operation || typeof operation !== 'string' || (!payload && operation !== 'credits')) {
if (!operation || typeof operation !== 'string' || (!payload && operation !== 'credits' && operation !== 'albums')) {
deferred.reject(new Error('Invalid argument'));
return deferred.promise;
}

switch(operation) {
case 'albums':
options.method = 'GET';
options.uri += 'account/me/albums';
break;
case 'upload':
options.method = 'POST';
options.uri += 'image';
Expand Down Expand Up @@ -419,6 +423,23 @@ imgur.getAlbumInfo = function (id) {
return deferred.promise;
}

/**
* Get albums metadata
* @returns {promise}
*/
imgur.getAlbums = function () {
var deferred = Q.defer();
var url = 'albums';
imgur._imgurRequest(url)
.then(function (json) {
deferred.resolve(json);
})
.catch(function (err) {
deferred.reject(err);
});

return deferred.promise;
}

/**
* Upload an image file
Expand Down

0 comments on commit d92272e

Please sign in to comment.