From e375daf268ecfd13d2a4559fb93fa70b71bb5948 Mon Sep 17 00:00:00 2001 From: Brad Beebe Date: Wed, 20 Aug 2014 10:57:03 -0700 Subject: [PATCH 1/2] Issue teleportd/instagram-node#30 --- lib/instagram.js | 169 ++++++++++++++++++++++++----------------------- 1 file changed, 87 insertions(+), 82 deletions(-) diff --git a/lib/instagram.js b/lib/instagram.js index 8f71426..5f95924 100644 --- a/lib/instagram.js +++ b/lib/instagram.js @@ -39,6 +39,7 @@ var instagram = function(spec, my) { spec = spec || {}; my.limit = null; + my.remaining = null; my.agent = spec.agent; // public @@ -108,7 +109,7 @@ var instagram = function(spec, my) { * @param method string the request method * @param path string the path * @param params object the params - * @param cb function (err, result, limit); + * @param cb function (err, result, remaining, limit); * @param retry function a retry function */ call = function(method, path, params, cb, retry) { @@ -160,8 +161,10 @@ var instagram = function(spec, my) { res.on('end', function() { var result; - var limit = parseInt(res.headers['x-ratelimit-remaining'], 10) || 0; + var limit = parseInt(res.headers['x-ratelimit-limit'], 10) || 0; + var remaining = parseInt(res.headers['x-ratelimit-remaining'], 10) || 0; my.limit = limit; + my.remaining = remaining; try { result = JSON.parse(body); @@ -169,7 +172,7 @@ var instagram = function(spec, my) { return handle_error(err, cb, retry, res.statusCode, body); } - return cb(null, result, limit); + return cb(null, result, remaining, limit); }); }); @@ -277,11 +280,13 @@ var instagram = function(spec, my) { if(typeof options === 'object') { if(options.access_token) { my.limit = null; + my.remaining = null; my.auth = { access_token: options.access_token }; } else if(options.client_id && options.client_secret) { my.limit = null; + my.remaining = null; my.auth = { client_id: options.client_id, client_secret: options.client_secret, @@ -297,7 +302,7 @@ var instagram = function(spec, my) { /** * Retrieves information about the given user * @param id string the user id - * @param cb function (err, user, limit); + * @param cb function (err, user, remaining, limit); */ user = function(id, cb) { var retry = function() { @@ -308,11 +313,11 @@ var instagram = function(spec, my) { return handle_error(new Error('Wrong param "id"'), cb, retry); } - call('GET', '/users/' + id, {}, function(err, result, limit) { + call('GET', '/users/' + id, {}, function(err, result, remaining, limit) { if(err) { return handle_error(err, cb, retry); } else if(result && result.meta && result.meta.code === 200) { - return cb(null, result.data, limit); + return cb(null, result.data, remaining, limit); } else { return handle_error(result, cb, retry); } @@ -324,7 +329,7 @@ var instagram = function(spec, my) { * @param options object { count, [opt] * min_id, [opt] * max_id [opt] } - * @param cb function (err, feed, pagination, limit); + * @param cb function (err, feed, pagination, remaining, limit); */ user_self_feed = function(options, cb) { var retry = function() { @@ -347,7 +352,7 @@ var instagram = function(spec, my) { params.max_id = options.max_id; } - call('GET', '/users/self/feed', params, function(err, result, limit) { + call('GET', '/users/self/feed', params, function(err, result, remaining, limit) { if(err) { return handle_error(err, cb, retry); } else if(result && result.meta && result.meta.code === 200) { @@ -360,7 +365,7 @@ var instagram = function(spec, my) { result.pagination.next = next; } - return cb(null, result.data, result.pagination || {}, limit); + return cb(null, result.data, result.pagination || {}, remaining, limit); } else { return handle_error(result, cb, retry); } @@ -371,7 +376,7 @@ var instagram = function(spec, my) { * Retrieves the current user likes * @param options object { count, [opt] * max_like_id [opt] } - * @param cb function (err, likes, pagination, limit); + * @param cb function (err, likes, pagination, remaining, limit); */ user_self_liked = function(options, cb) { var retry = function() { @@ -391,7 +396,7 @@ var instagram = function(spec, my) { params.max_like_id = options.max_like_id; } - call('GET', '/users/self/media/liked', params, function(err, result, limit) { + call('GET', '/users/self/media/liked', params, function(err, result, remaining, limit) { if(err) { return handle_error(err, cb, retry); } else if(result && result.meta && result.meta.code === 200) { @@ -405,7 +410,7 @@ var instagram = function(spec, my) { delete result.pagination.next_url; } - return cb(null, result.data, result.pagination || {}, limit); + return cb(null, result.data, result.pagination || {}, remaining, limit); } else { return handle_error(result, cb, retry); } @@ -421,7 +426,7 @@ var instagram = function(spec, my) { * min_timestamp, [opt] * max_id, [opt] * min_id [opt] } - * @param cb(err, results, pagination, limit); + * @param cb(err, results, pagination, remaining, limit); */ user_media_recent = function(user_id, options, cb) { var retry = function() { @@ -454,7 +459,7 @@ var instagram = function(spec, my) { params.min_id = options.min_id; } - call('GET', '/users/' + user_id + '/media/recent', params, function(err, result, limit) { + call('GET', '/users/' + user_id + '/media/recent', params, function(err, result, remaining, limit) { if(err) { return handle_error(err, cb, retry); } else if(result && result.meta && result.meta.code === 200) { @@ -468,7 +473,7 @@ var instagram = function(spec, my) { delete result.pagination.next_url; } - return cb(null, result.data, result.pagination || {}, limit); + return cb(null, result.data, result.pagination || {}, remaining, limit); } else { return handle_error(result, cb, retry); } @@ -482,7 +487,7 @@ var instagram = function(spec, my) { * min_timestamp, [opt] * max_id, [opt] * min_id [opt] } - * @param cb(err, results, pagination, limit); + * @param cb(err, results, pagination, remaining, limit); */ user_self_media_recent = function(options, cb) { var retry = function() { @@ -528,11 +533,11 @@ var instagram = function(spec, my) { params.count = options.count; } - call('GET', '/users/search', params, function(err, result, limit) { + call('GET', '/users/search', params, function(err, result, remaining, limit) { if(err) { return handle_error(err, cb, retry); } else if(result && result.meta && result.meta.code === 200) { - return cb(null, result.data, limit); + return cb(null, result.data, remaining, limit); } else { return handle_error(result, cb, retry); } @@ -544,7 +549,7 @@ var instagram = function(spec, my) { * @param user_id string the user to check * @param options object { count, [opt] * cursor [opt] } - * @param cb function (err, users, pagination, limit); + * @param cb function (err, users, pagination, remaining, limit); */ user_follows = function(user_id, options, cb) { var retry = function() { @@ -568,7 +573,7 @@ var instagram = function(spec, my) { params.cursor = options.cursor; } - call('GET', '/users/' + user_id + '/follows', params, function(err, result, limit) { + call('GET', '/users/' + user_id + '/follows', params, function(err, result, remaining, limit) { if(err) { return handle_error(err, cb, retry); } else if(result && result.meta && result.meta.code === 200) { @@ -582,7 +587,7 @@ var instagram = function(spec, my) { delete result.pagination.next_url; } - return cb(null, result.data, result.pagination || {}, limit); + return cb(null, result.data, result.pagination || {}, remaining, limit); } else { return handle_error(result, cb, retry); } @@ -594,7 +599,7 @@ var instagram = function(spec, my) { * @param user_id string the user to check * @param options object { count, [opt] * cursor [opt] } - * @param cb function (err, users, pagination, limit); + * @param cb function (err, users, pagination, remaining, limit); */ user_followers = function(user_id, options, cb) { var retry = function() { @@ -618,7 +623,7 @@ var instagram = function(spec, my) { params.cursor = options.cursor; } - call('GET', '/users/' + user_id + '/followed-by', params, function(err, result, limit) { + call('GET', '/users/' + user_id + '/followed-by', params, function(err, result, remaining, limit) { if(err) { return handle_error(err, cb, retry); } else if(result && result.meta && result.meta.code === 200) { @@ -632,7 +637,7 @@ var instagram = function(spec, my) { delete result.pagination.next_url; } - return cb(null, result.data, result.pagination || {}, limit); + return cb(null, result.data, result.pagination || {}, remaining, limit); } else { return handle_error(result, cb, retry); } @@ -649,11 +654,11 @@ var instagram = function(spec, my) { user_self_requested_by(cb); }; - call('GET', '/users/self/requested-by', {}, function(err, result, limit) { + call('GET', '/users/self/requested-by', {}, function(err, result, remaining, limit) { if(err) { return handle_error(err, cb, retry); } else if(result && result.meta && result.meta.code === 200) { - return cb(null, result.data, limit); + return cb(null, result.data, remaining, limit); } else { return handle_error(result, cb, retry); } @@ -674,11 +679,11 @@ var instagram = function(spec, my) { return handle_error(new Error('Wrong param "user_id"'), cb, retry); } - call('GET', '/users/' + user_id + '/relationship', {}, function(err, result, limit) { + call('GET', '/users/' + user_id + '/relationship', {}, function(err, result, remaining, limit) { if(err) { return handle_error(err, cb, retry); } else if(result && result.meta && result.meta.code === 200) { - return cb(null, result.data, limit); + return cb(null, result.data, remaining, limit); } else { return handle_error(result, cb, retry); } @@ -719,11 +724,11 @@ var instagram = function(spec, my) { params.sign_request = options.sign_request; } - call('POST', '/users/' + user_id + '/relationship', params, function(err, result, limit) { + call('POST', '/users/' + user_id + '/relationship', params, function(err, result, remaining, limit) { if(err) { return handle_error(err, cb, retry); } else if(result && result.meta && result.meta.code === 200) { - return cb(null, result.data, limit); + return cb(null, result.data, remaining, limit); } else { return handle_error(result, cb, retry); } @@ -744,11 +749,11 @@ var instagram = function(spec, my) { return handle_error(new Error('Wrong param "media_id"'), cb, retry); } - call('GET', '/media/' + media_id, {}, function(err, result, limit) { + call('GET', '/media/' + media_id, {}, function(err, result, remaining, limit) { if(err) { return handle_error(err, cb, retry); } else if(result && result.meta && result.meta.code === 200) { - return cb(null, result.data, limit); + return cb(null, result.data, remaining, limit); } else { return handle_error(result, cb, retry); } @@ -770,11 +775,11 @@ var instagram = function(spec, my) { return handle_error(new Error('Wrong param "media_shortcode"'), cb, retry); } - call('GET', '/media/shortcode/' + media_shortcode, {}, function(err, result, limit) { + call('GET', '/media/shortcode/' + media_shortcode, {}, function(err, result, remaining, limit) { if(err) { return handle_error(err, cb, retry); } else if(result && result.meta && result.meta.code === 200) { - return cb(null, result.data, limit); + return cb(null, result.data, remaining, remaining, limit); } else { return handle_error(result, cb, retry); } @@ -827,11 +832,11 @@ var instagram = function(spec, my) { params.count = options.count; } - call('GET', '/media/search', params, function(err, result, limit) { + call('GET', '/media/search', params, function(err, result, remaining, limit) { if(err) { return handle_error(err, cb, retry); } else if(result && result.meta && result.meta.code === 200) { - return cb(null, result.data, limit); + return cb(null, result.data, remaining, remaining, limit); } else { return handle_error(result, cb, retry); } @@ -847,11 +852,11 @@ var instagram = function(spec, my) { media_popular(cb); }; - call('GET', '/media/popular', {}, function(err, result, limit) { + call('GET', '/media/popular', {}, function(err, result, remaining, limit) { if(err) { return handle_error(err, cb, retry); } else if(result && result.meta && result.meta.code === 200) { - return cb(null, result.data, limit); + return cb(null, result.data, remaining, remaining, limit); } else { return handle_error(result, cb, retry); } @@ -872,11 +877,11 @@ var instagram = function(spec, my) { return handle_error(new Error('Wrong param "media_id"'), cb, retry); } - call('GET', '/media/' + media_id + '/comments', {}, function(err, result, limit) { + call('GET', '/media/' + media_id + '/comments', {}, function(err, result, remaining, limit) { if(err) { return handle_error(err, cb, retry); } else if(result && result.meta && result.meta.code === 200) { - return cb(null, result.data, limit); + return cb(null, result.data, remaining, remaining, limit); } else { return handle_error(result, cb, retry); } @@ -914,11 +919,11 @@ var instagram = function(spec, my) { params.sign_request = options.sign_request; } - call('POST', '/media/' + media_id + '/comments', params, function(err, result, limit) { + call('POST', '/media/' + media_id + '/comments', params, function(err, result, remaining, limit) { if(err) { return handle_error(err, cb, retry); } else if(result && result.meta && result.meta.code === 200) { - return cb(null, result.data, limit); + return cb(null, result.data, remaining, remaining, limit); } else { return handle_error(result, cb, retry); } @@ -955,11 +960,11 @@ var instagram = function(spec, my) { params.sign_request = options.sign_request; } - call('DELETE', '/media/' + media_id + '/comments/' + comment_id, params, function(err, result, limit) { + call('DELETE', '/media/' + media_id + '/comments/' + comment_id, params, function(err, result, remaining, limit) { if(err) { return handle_error(err, cb, retry); } else if(result && result.meta && result.meta.code === 200) { - return cb(null, limit); + return cb(null, remaining, remaining, limit); } else { return handle_error(result, cb, retry); } @@ -980,11 +985,11 @@ var instagram = function(spec, my) { return handle_error(new Error('Wrong param "media_id"'), cb, retry); } - call('GET', '/media/' + media_id + '/likes', {}, function(err, result, limit) { + call('GET', '/media/' + media_id + '/likes', {}, function(err, result, remaining, limit) { if(err) { return handle_error(err, cb, retry); } else if(result && result.meta && result.meta.code === 200) { - return cb(null, result.data, limit); + return cb(null, result.data, remaining, remaining, limit); } else { return handle_error(result, cb, retry); } @@ -1019,11 +1024,11 @@ var instagram = function(spec, my) { params.sign_request = options.sign_request; } - call('POST', '/media/' + media_id + '/likes', params, function(err, result, limit) { + call('POST', '/media/' + media_id + '/likes', params, function(err, result, remaining, limit) { if(err) { return handle_error(err, cb, retry); } else if(result && result.meta && result.meta.code === 200) { - return cb(null, limit); + return cb(null, remaining, limit); } else { return handle_error(result, cb, retry); } @@ -1058,11 +1063,11 @@ var instagram = function(spec, my) { params.sign_request = options.sign_request } - call('DELETE', '/media/' + media_id + '/likes', params, function(err, result, limit) { + call('DELETE', '/media/' + media_id + '/likes', params, function(err, result, remaining, limit) { if(err) { return handle_error(err, cb, retry); } else if(result && result.meta && result.meta.code === 200) { - return cb(null, limit); + return cb(null, remaining, limit); } else { return handle_error(result, cb, retry); } @@ -1083,11 +1088,11 @@ var instagram = function(spec, my) { return handle_error(new Error('Wrong param "tag"'), cb, retry); } - call('GET', '/tags/' + _tag, {}, function(err, result, limit) { + call('GET', '/tags/' + _tag, {}, function(err, result, remaining, limit) { if(err) { return handle_error(err, cb, retry); } else if(result && result.meta && result.meta.code === 200) { - return cb(null, result.data, limit); + return cb(null, result.data, remaining, limit); } else { return handle_error(result, cb, retry); } @@ -1099,7 +1104,7 @@ var instagram = function(spec, my) { * @param tag string the tag * @param options object { min_id, [opt] * max_id [opt] } - * @param cb function (err, result, pagination, limit); + * @param cb function (err, result, pagination, remaining, limit); */ tag_media_recent = function(tag, options, cb) { var retry = function() { @@ -1126,7 +1131,7 @@ var instagram = function(spec, my) { params.count = options.count; } - call('GET', '/tags/' + tag + '/media/recent', params, function(err, result, limit) { + call('GET', '/tags/' + tag + '/media/recent', params, function(err, result, remaining, limit) { if(err) { return handle_error(err, cb, retry); } else if(result && result.meta && result.meta.code === 200) { @@ -1142,7 +1147,7 @@ var instagram = function(spec, my) { delete result.pagination.next_url; } - return cb(null, result.data, result.pagination || {}, limit); + return cb(null, result.data, result.pagination || {}, remaining, limit); } else { return handle_error(result, cb, retry); } @@ -1163,11 +1168,11 @@ var instagram = function(spec, my) { return handle_error(new Error('Wrong param "query"'), cb, retry); } - call('GET', '/tags/search', { q: query }, function(err, result, limit) { + call('GET', '/tags/search', { q: query }, function(err, result, remaining, limit) { if(err) { return handle_error(err, cb, retry); } else if(result && result.meta && result.meta.code === 200) { - return cb(null, result.data, limit); + return cb(null, result.data, remaining, limit); } else { return handle_error(result, cb, retry); } @@ -1189,11 +1194,11 @@ var instagram = function(spec, my) { return handle_error(new Error('Wrong param "location_id"'), cb, retry); } - call('GET', '/locations/' + location_id, {}, function(err, result, limit) { + call('GET', '/locations/' + location_id, {}, function(err, result, remaining, limit) { if(err) { return handle_error(err, cb, retry); } else if(result && result.meta && result.meta.code === 200) { - return cb(null, result.data, limit); + return cb(null, result.data, remaining, limit); } else { return handle_error(result, cb, retry); } @@ -1207,7 +1212,7 @@ var instagram = function(spec, my) { * max_id, [opt] * min_timestamp, [opt] * max_timestamp [opt] } - * @param cb function (err, result, pagination, limit); + * @param cb function (err, result, pagination, remaining, limit); */ location_media_recent = function(location_id, options, cb) { var retry = function() { @@ -1237,7 +1242,7 @@ var instagram = function(spec, my) { params.max_timestamp = options.max_timestamp; } - call('GET', '/locations/' + location_id + '/media/recent', params, function(err, result, limit) { + call('GET', '/locations/' + location_id + '/media/recent', params, function(err, result, remaining, limit) { if(err) { return handle_error(err, cb, retry); } else if(result && result.meta && result.meta.code === 200) { @@ -1251,7 +1256,7 @@ var instagram = function(spec, my) { delete result.pagination.next_url; } - return cb(null, result.data, result.pagination || {}, limit); + return cb(null, result.data, result.pagination || {}, remaining, limit); } else { return handle_error(result, cb, retry); } @@ -1295,11 +1300,11 @@ var instagram = function(spec, my) { return handle_error(new Error('Wrong param "lat/lng" or "foursquare(_v2)_id" or "facebook_places_id"'), cb, retry); } - call('GET', '/locations/search', params, function(err, result, limit) { + call('GET', '/locations/search', params, function(err, result, remaining, limit) { if(err) { return handle_error(err, cb, retry); } else if(result && result.meta && result.meta.code === 200) { - return cb(null, result.data, limit); + return cb(null, result.data, remaining, limit); } else { return handle_error(result, cb, retry); } @@ -1311,7 +1316,7 @@ var instagram = function(spec, my) { * @param geo_id string the instagram geography id * @param options object { min_id, [opt] * count [opt] } - * @param cb function (err, result, pagination, limit); + * @param cb function (err, result, pagination, remaining, limit); */ geography_media_recent = function(geography_id, options, cb) { var retry = function() { @@ -1335,7 +1340,7 @@ var instagram = function(spec, my) { params.count = options.count; } - call('GET', '/geographies/' + geography_id + '/media/recent', params, function(err, result, limit) { + call('GET', '/geographies/' + geography_id + '/media/recent', params, function(err, result, remaining, limit) { if(err) { return handle_error(err, cb, retry); } else if(result && result.meta && result.meta.code === 200) { @@ -1349,7 +1354,7 @@ var instagram = function(spec, my) { delete result.pagination.next_url; } - return cb(null, result.data, result.pagination || {}, limit); + return cb(null, result.data, result.pagination || {}, remaining, limit); } else { return handle_error(result, cb, retry); } @@ -1419,7 +1424,7 @@ var instagram = function(spec, my) { code: code }; - call('POST', '/oauth/access_token', params, function(err, result, limit) { + call('POST', '/oauth/access_token', params, function(err, result, remaining, limit) { if(err) { return handle_error(err, cb, retry); } @@ -1446,11 +1451,11 @@ var instagram = function(spec, my) { return handle_error(new Error('Wrong param "url"'), cb, retry); } - call('GET', '/oembed/', { 'url': url }, function(err, result, limit) { + call('GET', '/oembed/', { 'url': url }, function(err, result, remaining, limit) { if(err) { return handle_error(err, cb, retry); } else if(result) { - return cb(null, result, limit); + return cb(null, result, remaining, limit); } else { return handle_error(result, cb, retry); } @@ -1466,11 +1471,11 @@ var instagram = function(spec, my) { subscriptions(cb); }; - call('GET', '/subscriptions/', {}, function(err, result, limit) { + call('GET', '/subscriptions/', {}, function(err, result, remaining, limit) { if(err) { return handle_error(err, cb, retry); } else if(result && result.meta && result.meta.code === 200) { - return cb(null, result.data, limit); + return cb(null, result.data, remaining, limit); } else { return handle_error(result, cb, retry); } @@ -1495,11 +1500,11 @@ var instagram = function(spec, my) { object_id: tag }; - call('POST', '/subscriptions/', params, function(err, result, limit) { + call('POST', '/subscriptions/', params, function(err, result, remaining, limit) { if(err) { return handle_error(err, cb, retry); } else if(result && result.meta && result.meta.code === 200) { - return cb(null, result.data, limit); + return cb(null, result.data, remaining, limit); } else { return handle_error(result, cb, retry); } @@ -1528,11 +1533,11 @@ var instagram = function(spec, my) { aspect: 'media' }; - call('POST', '/subscriptions/', params, function(err, result, limit) { + call('POST', '/subscriptions/', params, function(err, result, remaining, limit) { if(err) { return handle_error(err, cb, retry); } else if(result && result.meta && result.meta.code === 200) { - return cb(null, result.data, limit); + return cb(null, result.data, remaining, limit); } else { return handle_error(result, cb, retry); } @@ -1555,11 +1560,11 @@ var instagram = function(spec, my) { aspect: 'media' }; - call('POST', '/subscriptions/', params, function(err, result, limit) { + call('POST', '/subscriptions/', params, function(err, result, remaining, limit) { if(err) { return handle_error(err, cb, retry); } else if(result && result.meta && result.meta.code === 200) { - return cb(null, result.data, limit); + return cb(null, result.data, remaining, limit); } else { return handle_error(result, cb, retry); } @@ -1585,11 +1590,11 @@ var instagram = function(spec, my) { aspect: 'media' }; - call('POST', '/subscriptions/', params, function(err, result, limit) { + call('POST', '/subscriptions/', params, function(err, result, remaining, limit) { if(err) { return handle_error(err, cb, retry); } else if(result && result.meta && result.meta.code === 200) { - return cb(null, result.data, limit); + return cb(null, result.data, remaining, limit); } else { return handle_error(result, cb, retry); } @@ -1614,11 +1619,11 @@ var instagram = function(spec, my) { params.object = 'all'; } - call('DELETE', '/subscriptions/', params, function(err, result, limit) { + call('DELETE', '/subscriptions/', params, function(err, result, remaining, limit) { if(err) { return handle_error(err, cb, retry); } else if(result && result.meta && result.meta.code === 200) { - return cb(null, result.data, limit); + return cb(null, result.data, remaining, limit); } else { return handle_error(result, cb, retry); } From 8a30130a415446e0d603603d6e223be072fdfed5 Mon Sep 17 00:00:00 2001 From: Brad Beebe Date: Thu, 21 Aug 2014 09:43:24 -0700 Subject: [PATCH 2/2] Issue teleportd/instagram-node#30 Updated test scripts with new variables --- CHANGELOG.md | 7 +++- README.md | 72 ++++++++++++++++++------------------ lib/instagram.js | 15 ++++---- package.json | 2 +- test/scripts/comments.js | 4 +- test/scripts/likes.js | 14 +++---- test/scripts/locations.js | 12 +++--- test/scripts/media.js | 12 +++--- test/scripts/relationship.js | 16 ++++---- test/scripts/tag.js | 12 +++--- test/scripts/users.js | 20 +++++----- 11 files changed, 96 insertions(+), 90 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f96037..d3cc488 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## v0.4.4 + - Renamed the `limit` variable/property to `remaining` since it was using the `x-ratelimit-remaining` value. + - Assigned the `limit` variable/property to the `x-ratelimit-limit` API call response header value ([#30](https://github.com/teleportd/instagram-node/issues/30)). + - Adjusted the necessary functions to account for the new/renamed variables. + ## v0.4.0 - Add support for new Instagram API security with `sign_request` @@ -6,4 +11,4 @@ automatically set anymore. ([#23](https://github.com/teleportd/instagram-node/issues/23)) - Add `user_self_media_recent(options, cb)` to retrieve the medias posted by the user related to the `access_token` being used. This is just an alias of - `user_media_recent(user_id, options, cb_)`. + `user_media_recent(user_id, options, cb_)`. \ No newline at end of file diff --git a/README.md b/README.md index fcf6899..ea5087a 100644 --- a/README.md +++ b/README.md @@ -117,108 +117,108 @@ Once you've setup the API and/or authenticated, here is the full list of what yo /********************************/ /* USERS */ /********************************/ -ig.user('user_id', function(err, result, limit) {}); +ig.user('user_id', function(err, result, remaining, limit) {}); /* OPTIONS: { [count], [min_id], [max_id] }; */ -ig.user_self_feed([options,] function(err, medias, pagination, limit) {}); +ig.user_self_feed([options,] function(err, medias, pagination, remaining, limit) {}); /* OPTIONS: { [count], [min_timestamp], [max_timestamp], [min_id], [max_id] }; */ -ig.user_media_recent('user_id', [options,] function(err, medias, pagination, limit) {}); +ig.user_media_recent('user_id', [options,] function(err, medias, pagination, remaining, limit) {}); /* OPTIONS: { [count], [min_timestamp], [max_timestamp], [min_id], [max_id] }; */ -ig.user_self_media_recent([options,] function(err, medias, pagination, limit) {}); +ig.user_self_media_recent([options,] function(err, medias, pagination, remaining, limit) {}); /* OPTIONS: { [count], [max_like_id] }; */ -ig.user_self_liked([options,] function(err, medias, pagination, limit) {}); +ig.user_self_liked([options,] function(err, medias, pagination, remaining, limit) {}); /* OPTIONS: { [count] }; */ -ig.user_search('username', [options,] function(err, users, limit) {}); +ig.user_search('username', [options,] function(err, users, remaining, limit) {}); /********************************/ /* RELATIONSHIP */ /********************************/ /* OPTIONS: { [count], [cursor] }; */ -ig.user_follows('user_id', function(err, users, pagination, limit) {}); +ig.user_follows('user_id', function(err, users, pagination, remaining, limit) {}); /* OPTIONS: { [count], [cursor] }; */ -ig.user_followers('user_id', function(err, users, pagination, limit) {}); +ig.user_followers('user_id', function(err, users, pagination, remaining, limit) {}); -ig.user_self_requested_by(function(err, users, limit) {}); +ig.user_self_requested_by(function(err, users, remaining, limit) {}); -ig.user_relationship('user_id', function(err, result, limit) {}); +ig.user_relationship('user_id', function(err, result, remaining, limit) {}); -ig.set_user_relationship('user_id', 'follow', function(err, result, limit) {}); +ig.set_user_relationship('user_id', 'follow', function(err, result, remaining, limit) {}); /********************************/ /* MEDIAS */ /********************************/ -ig.media('media_id', function(err, media, limit) {}); +ig.media('media_id', function(err, media, remaining, limit) {}); /* OPTIONS: { [min_timestamp], [max_timestamp], [distance] }; */ -ig.media_search(48.4335645654, 2.345645645, [options,] function(err, medias, limit) {}); +ig.media_search(48.4335645654, 2.345645645, [options,] function(err, medias, remaining, limit) {}); -ig.media_popular(function(err, medias, limit) {}); +ig.media_popular(function(err, medias, remaining, limit) {}); /********************************/ /* COMMENTS */ /********************************/ -ig.comments('media_id', function(err, result, limit) {}); +ig.comments('media_id', function(err, result, remaining, limit) {}); -ig.add_comment('media_id', 'your comment', function(err, result, limit) {}); +ig.add_comment('media_id', 'your comment', function(err, result, remaining, limit) {}); -ig.del_comment('media_id', 'comment_id', function(err, limit) {}); +ig.del_comment('media_id', 'comment_id', function(err, remaining, limit) {}); /********************************/ /* LIKES */ /********************************/ -ig.likes('media_id', function(err, result, limit) {}); +ig.likes('media_id', function(err, result, remaining, limit) {}); -ig.add_like('media_id', function(err, limit) {}); +ig.add_like('media_id', function(err, remaining, limit) {}); -ig.del_like('media_id', function(err, limit) {}); +ig.del_like('media_id', function(err, remaining, limit) {}); /********************************/ /* TAGS */ /********************************/ -ig.tag('tag', function(err, result, limit) {}); +ig.tag('tag', function(err, result, remaining, limit) {}); /* OPTIONS: { [min_tag_id], [max_tag_id] }; */ -ig.tag_media_recent('tag', [options,] function(err, medias, pagination, limit) {}); +ig.tag_media_recent('tag', [options,] function(err, medias, pagination, remaining, limit) {}); -ig.tag_search('query', function(err, result, limit) {}); +ig.tag_search('query', function(err, result, remaining, limit) {}); /********************************/ /* LOCATIONS */ /********************************/ -ig.location('location_id', function(err, result, limit) {}); +ig.location('location_id', function(err, result, remaining, limit) {}); /* OPTIONS: { [min_id], [max_id], [min_timestamp], [max_timestamp] }; */ -ig.location_media_recent('location_id', [options,] function(err, result, pagination, limit) {}); +ig.location_media_recent('location_id', [options,] function(err, result, pagination, remaining, limit) {}); /* SPECS: { lat, lng, [foursquare_v2_id], [foursquare_id] }; */ /* OPTIONS: { [distance] }; */ -ig.location_search({ lat: 48.565464564, lng: 2.34656589 }, [options,] function(err, result, limit) {}); +ig.location_search({ lat: 48.565464564, lng: 2.34656589 }, [options,] function(err, result, remaining, limit) {}); /********************************/ /* GEOGRAPHIES */ /********************************/ /* OPTIONS: { [min_id], [count] } */ -ig.geography_media_recent(geography_id, [options,] function(err, result, pagination, limit) {}); +ig.geography_media_recent(geography_id, [options,] function(err, result, pagination, remaining, limit) {}); /********************************/ /* SUBSCRIPTIONS */ /********************************/ -ig.subscriptions(function(err, result, limit){}); +ig.subscriptions(function(err, result, remaining, limit){}); ig.del_subscription({id:1}, function(err,subscriptions,limit){}) -ig.add_tag_subscription('funny', 'http://MYHOST/tag/funny', function(err, result, limit){}); +ig.add_tag_subscription('funny', 'http://MYHOST/tag/funny', function(err, result, remaining, limit){}); -ig.add_geography_subscription(48.565464564, 2.34656589, 100, 'http://MYHOST/geography', function(err, result, limit){}); +ig.add_geography_subscription(48.565464564, 2.34656589, 100, 'http://MYHOST/geography', function(err, result, remaining, limit){}); -ig.add_user_subscription('http://MYHOST/user', function(err, result, limit){}); +ig.add_user_subscription('http://MYHOST/user', function(err, result, remaining, limit){}); -ig.add_location_subscription(1257285, 'http://MYHOST/location/1257285', function(err, result, limit){}); +ig.add_location_subscription(1257285, 'http://MYHOST/location/1257285', function(err, result, remaining, limit){}); ``` ## Subscriptions @@ -228,7 +228,7 @@ Subscriptions are callbacks from Instagram to your app when new things happen. T You can get your subscriptions with this: ```javascript -ig.subscriptions(function(err, subscriptions, limit){ +ig.subscriptions(function(err, subscriptions, remaining, limit){ console.log(subscriptions); }); ``` @@ -236,13 +236,13 @@ ig.subscriptions(function(err, subscriptions, limit){ You can delete all your subscriptions with this: ```javascript -ig.del_subscription({ all: true }, function(err, subscriptions, limit){}); +ig.del_subscription({ all: true }, function(err, subscriptions, remaining, limit){}); ``` or just one with this: ```javascript -ig.del_subscription({ id: 1 }, function(err, subscriptions, limit){}); +ig.del_subscription({ id: 1 }, function(err, subscriptions, remaining, limit){}); ``` @@ -272,7 +272,7 @@ is basically the same that Instagram would give you but there will be a `next()` ```javascript var ig = require('instagram-node').instagram(); -var hdl = function(err, result, pagination, limit) { +var hdl = function(err, result, pagination, remaining, limit) { // Your implementation here if(pagination.next) { pagination.next(hdl); // Will get second page results diff --git a/lib/instagram.js b/lib/instagram.js index 5f95924..d8f1225 100644 --- a/lib/instagram.js +++ b/lib/instagram.js @@ -779,7 +779,7 @@ var instagram = function(spec, my) { if(err) { return handle_error(err, cb, retry); } else if(result && result.meta && result.meta.code === 200) { - return cb(null, result.data, remaining, remaining, limit); + return cb(null, result.data, remaining, limit); } else { return handle_error(result, cb, retry); } @@ -836,7 +836,7 @@ var instagram = function(spec, my) { if(err) { return handle_error(err, cb, retry); } else if(result && result.meta && result.meta.code === 200) { - return cb(null, result.data, remaining, remaining, limit); + return cb(null, result.data, remaining, limit); } else { return handle_error(result, cb, retry); } @@ -856,7 +856,7 @@ var instagram = function(spec, my) { if(err) { return handle_error(err, cb, retry); } else if(result && result.meta && result.meta.code === 200) { - return cb(null, result.data, remaining, remaining, limit); + return cb(null, result.data, remaining, limit); } else { return handle_error(result, cb, retry); } @@ -881,7 +881,7 @@ var instagram = function(spec, my) { if(err) { return handle_error(err, cb, retry); } else if(result && result.meta && result.meta.code === 200) { - return cb(null, result.data, remaining, remaining, limit); + return cb(null, result.data, remaining, limit); } else { return handle_error(result, cb, retry); } @@ -923,7 +923,7 @@ var instagram = function(spec, my) { if(err) { return handle_error(err, cb, retry); } else if(result && result.meta && result.meta.code === 200) { - return cb(null, result.data, remaining, remaining, limit); + return cb(null, result.data, remaining, limit); } else { return handle_error(result, cb, retry); } @@ -964,7 +964,7 @@ var instagram = function(spec, my) { if(err) { return handle_error(err, cb, retry); } else if(result && result.meta && result.meta.code === 200) { - return cb(null, remaining, remaining, limit); + return cb(null, remaining, limit); } else { return handle_error(result, cb, retry); } @@ -989,7 +989,7 @@ var instagram = function(spec, my) { if(err) { return handle_error(err, cb, retry); } else if(result && result.meta && result.meta.code === 200) { - return cb(null, result.data, remaining, remaining, limit); + return cb(null, result.data, remaining, limit); } else { return handle_error(result, cb, retry); } @@ -1681,6 +1681,7 @@ var instagram = function(spec, my) { fwk.method(that, 'add_location_subscription', add_location_subscription, _super); fwk.getter(that, 'limit', my, 'limit'); + fwk.getter(that, 'remaining', my, 'remaining'); return that; }; diff --git a/package.json b/package.json index d2db8e4..da38481 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "instagram-node", - "version": "0.4.3", + "version": "0.4.4", "description": "Simple Instagram driver for Node.js", "keywords": ["instagram", "node", "ig", "driver"], "homepage": "https://github.com/teleportd/instagram-node", diff --git a/test/scripts/comments.js b/test/scripts/comments.js index bd1c914..02557ca 100644 --- a/test/scripts/comments.js +++ b/test/scripts/comments.js @@ -24,13 +24,13 @@ var comments = (function(spec, my) { var tests = { 'comments': function(cb_) { var retry = 0; - instagram.comments('318869204166248215_33082304', function(err, result, limit) { + instagram.comments('318869204166248215_33082304', function(err, result, remaining, limit) { var res = { ok: true, description: 'Retrieves comments' }; - if(result && limit) { + if(result && remaining) { return cb_(null, res); } else { if(retry < 2) { diff --git a/test/scripts/likes.js b/test/scripts/likes.js index 5ba4358..36b6b63 100644 --- a/test/scripts/likes.js +++ b/test/scripts/likes.js @@ -24,13 +24,13 @@ var likes = (function(spec, my) { var tests = { 'likes': function(cb_) { var retry = 0; - instagram.likes('318869204166248215_33082304', function(err, result, limit) { + instagram.likes('318869204166248215_33082304', function(err, result, remaining, limit) { var res = { ok: true, description: 'Retrieves likes' }; - if(result && limit) { + if(result && remaining) { return cb_(null, res); } else { if(retry < 2) { @@ -45,13 +45,13 @@ var likes = (function(spec, my) { }, 'add like': function(cb_) { var retry = 0; - instagram.add_like('318869204166248215_33082304', function(err, limit) { + instagram.add_like('318869204166248215_33082304', function(err, remaining, limit) { var res = { ok: true, description: 'Add a like' }; - - if(!err && limit) { + + if(!err && remaining) { return cb_(null, res); } else { if(retry < 2) { @@ -66,13 +66,13 @@ var likes = (function(spec, my) { }, 'del like': function(cb_) { var retry = 0; - instagram.del_like('318869204166248215_33082304', function(err, limit) { + instagram.del_like('318869204166248215_33082304', function(err, remaining, limit) { var res = { ok: true, description: 'Delete a like' }; - if(!err && limit) { + if(!err && remaining) { return cb_(null, res); } else { if(retry < 2) { diff --git a/test/scripts/locations.js b/test/scripts/locations.js index 39eb4c2..f9fe5fa 100644 --- a/test/scripts/locations.js +++ b/test/scripts/locations.js @@ -24,13 +24,13 @@ var locations = (function(spec, my) { var tests = { 'location': function(cb_) { var retry = 0; - instagram.location('7351364', function(err, result, limit) { + instagram.location('7351364', function(err, result, remaining, limit) { var res = { ok: true, description: 'Retrieves a location' }; - if(result && limit) { + if(result && remaining) { return cb_(null, res); } else { if(retry < 2) { @@ -45,13 +45,13 @@ var locations = (function(spec, my) { }, 'location search': function(cb_) { var retry = 0; - instagram.location_search({ lat: 48.858831776042265, lng: 2.3470598999999766, distance: 5000 }, function(err, result, limit) { + instagram.location_search({ lat: 48.858831776042265, lng: 2.3470598999999766, distance: 5000 }, function(err, result, remaining, limit) { var res = { ok: true, description: 'Search a location' }; - if(result && limit) { + if(result && remaining) { return cb_(null, res); } else { if(retry < 2) { @@ -66,13 +66,13 @@ var locations = (function(spec, my) { }, 'location media recent': function(cb_) { var retry = 0; - instagram.location_media_recent('7351364', function(err, result, limit) { + instagram.location_media_recent('7351364', function(err, result, remaining, limit) { var res = { ok: true, description: 'Retrieves location recent medias' }; - if(result && limit) { + if(result && remaining) { return cb_(null, res); } else { if(retry < 2) { diff --git a/test/scripts/media.js b/test/scripts/media.js index e881b1e..defa8f8 100644 --- a/test/scripts/media.js +++ b/test/scripts/media.js @@ -24,13 +24,13 @@ var medias = (function(spec, my) { var tests = { 'media': function(cb_) { var retry = 0; - instagram.media('314584059748370098_2104944', function(err, result, limit) { + instagram.media('314584059748370098_2104944', function(err, result, remaining, limit) { var res = { ok: true, description: 'Retrieves a media' }; - if(result && limit) { + if(result && remaining) { return cb_(null, res); } else { if(retry < 2) { @@ -45,13 +45,13 @@ var medias = (function(spec, my) { }, 'media search': function(cb_) { var retry = 0; - instagram.media_search(48.858831776042265, 2.3470598999999766, { distance: 5000 }, function(err, result, limit) { + instagram.media_search(48.858831776042265, 2.3470598999999766, { distance: 5000 }, function(err, result, remaining, limit) { var res = { ok: true, description: 'Search medias' }; - if(result && limit) { + if(result && remaining) { return cb_(null, res); } else { if(retry < 2) { @@ -66,13 +66,13 @@ var medias = (function(spec, my) { }, 'media popular': function(cb_) { var retry = 0; - instagram.media_popular(function(err, result, limit) { + instagram.media_popular(function(err, result, remaining, limit) { var res = { ok: true, description: 'Retrieves popular medias' }; - if(result && limit) { + if(result && remaining) { return cb_(null, res); } else { if(retry < 2) { diff --git a/test/scripts/relationship.js b/test/scripts/relationship.js index 1ac4df1..7f43fdb 100644 --- a/test/scripts/relationship.js +++ b/test/scripts/relationship.js @@ -24,13 +24,13 @@ var relationships = (function(spec, my) { var tests = { 'follows': function(cb_) { var retry = 0; - instagram.user_follows('33082304', function(err, result, limit) { + instagram.user_follows('33082304', function(err, result, remaining, limit) { var res = { ok: true, description: 'Retrieves follows' }; - if(result && limit) { + if(result && remaining) { return cb_(null, res); } else { if(retry < 2) { @@ -45,13 +45,13 @@ var relationships = (function(spec, my) { }, 'followers': function(cb_) { var retry = 0; - instagram.user_followers('33082304', function(err, result, limit) { + instagram.user_followers('33082304', function(err, result, remaining, limit) { var res = { ok: true, description: 'Retrieves followers' }; - if(result && limit) { + if(result && remaining) { return cb_(null, res); } else { if(retry < 2) { @@ -66,13 +66,13 @@ var relationships = (function(spec, my) { }, 'request': function(cb_) { var retry = 0; - instagram.user_self_requested_by(function(err, result, limit) { + instagram.user_self_requested_by(function(err, result, remaining, limit) { var res = { ok: true, description: 'Retrieves requested-by' }; - if(result && limit) { + if(result && remaining) { return cb_(null, res); } else { if(retry < 2) { @@ -87,13 +87,13 @@ var relationships = (function(spec, my) { }, 'relationship': function(cb_) { var retry = 0; - instagram.user_relationship('33082302', function(err, result, limit) { + instagram.user_relationship('33082302', function(err, result, remaining, limit) { var res = { ok: true, description: 'Retrieves relationship' }; - if(result && limit) { + if(result && remaining) { return cb_(null, res); } else { if(retry < 2) { diff --git a/test/scripts/tag.js b/test/scripts/tag.js index edbac53..f3ddabe 100644 --- a/test/scripts/tag.js +++ b/test/scripts/tag.js @@ -24,13 +24,13 @@ var tags = (function(spec, my) { var tests = { 'tag info': function(cb_) { var retry = 0; - instagram.tag('test', function(err, result, limit) { + instagram.tag('test', function(err, result, remaining, limit) { var res = { ok: true, description: 'Retrieves informations about a tag' }; - if(result && limit) { + if(result && remaining) { return cb_(null, res); } else { if(retry < 2) { @@ -45,13 +45,13 @@ var tags = (function(spec, my) { }, 'tag search': function(cb_) { var retry = 0; - instagram.tag_search('test', function(err, result, limit) { + instagram.tag_search('test', function(err, result, remaining, limit) { var res = { ok: true, description: 'Search a tag' }; - if(result && limit) { + if(result && remaining) { return cb_(null, res); } else { if(retry < 2) { @@ -66,13 +66,13 @@ var tags = (function(spec, my) { }, 'tag media recent': function(cb_) { var retry = 0; - instagram.tag_media_recent('test', function(err, result, limit) { + instagram.tag_media_recent('test', function(err, result, remaining, limit) { var res = { ok: true, description: 'Retrieves recent medias' }; - if(result && limit) { + if(result && remaining) { return cb_(null, res); } else { if(retry < 2) { diff --git a/test/scripts/users.js b/test/scripts/users.js index d1c0746..65d78d6 100644 --- a/test/scripts/users.js +++ b/test/scripts/users.js @@ -24,13 +24,13 @@ var users = (function(spec, my) { var tests = { 'user': function(cb_) { var retry = 0; - instagram.user('33082304', function(err, result, limit) { + instagram.user('33082304', function(err, result, remaining, limit) { var res = { ok: true, description: 'Retrieves informations about a user' }; - if(result && limit) { + if(result && remaining) { return cb_(null, res); } else { if(retry < 2) { @@ -45,13 +45,13 @@ var users = (function(spec, my) { }, 'user feed': function(cb_) { var retry = 0; - instagram.user_self_feed({ count: 3 }, function(err, result, pagination, limit) { + instagram.user_self_feed({ count: 3 }, function(err, result, pagination, remaining, limit) { var res = { ok: true, description: 'Retrieves the feed' }; - if(result && limit) { + if(result && remaining) { return cb_(null, res); } else { if(retry < 2) { @@ -66,13 +66,13 @@ var users = (function(spec, my) { }, 'user media recent': function(cb_) { var retry = 0; - instagram.user_media_recent('33082304', { count: 3 }, function(err, result, pagination, limit) { + instagram.user_media_recent('33082304', { count: 3 }, function(err, result, pagination, remaining, limit) { var res = { ok: true, description: 'Retrieves recent medias' }; - if(result && limit) { + if(result && remaining) { return cb_(null, res); } else { if(retry < 2) { @@ -87,13 +87,13 @@ var users = (function(spec, my) { }, 'user self liked': function(cb_) { var retry = 0; - instagram.user_self_liked({ count: 3 }, function(err, result, limit) { + instagram.user_self_liked({ count: 3 }, function(err, result, remaining, limit) { var res = { ok: true, description: 'Retrieves liked medias' }; - if(result && limit) { + if(result && remaining) { return cb_(null, res); } else { if(retry < 2) { @@ -108,13 +108,13 @@ var users = (function(spec, my) { }, 'user search': function(cb_) { var retry = 0; - instagram.user_search('xn1t0x', function(err, result, limit) { + instagram.user_search('xn1t0x', function(err, result, remaining, limit) { var res = { ok: true, description: 'Search a user' }; - if(result && limit) { + if(result && remaining) { return cb_(null, res); } else { if(retry < 2) {