Permalink
Browse files

Fix global param bug (sorry for the whitespace cleanup)

  • Loading branch information...
1 parent 2105b01 commit 942971f08427d5bcbcec209e968515f61af9bf10 @jlafitte committed Oct 29, 2013
Showing with 51 additions and 52 deletions.
  1. +51 −52 api.js
View
103 api.js
@@ -1,62 +1,61 @@
+/* jshint node:true */
var spashttp = require("spas-http"),
- _ = require("underscore")._,
- async = require("async");
+ _ = require("underscore")._,
+ async = require("async");
var getVideoDetails = function (credentials) {
- // If this bundle is using oauth2, add in the access token
- var tokenString = _.isObject(credentials) && _.has(credentials, 'access_token') ?
- "&access_token=" + credentials.access_token :
- '';
- return function (obj, cb) {
- spashttp.request({url: "http://gdata.youtube.com/feeds/api/videos/" + obj.media$group.yt$videoid.$t + '?v=2&alt=json' + tokenString }, credentials, function( err, video ) {
- if(video && _.has(video, 'entry')) {
- obj.media$group.media$keywords.$t = video.entry.media$group.media$keywords.$t;
- obj.category = video.entry.category;
- }
+ // If this bundle is using oauth2, add in the access token
+ var tokenString = _.isObject(credentials) && _.has(credentials, 'access_token') ?
+ "&access_token=" + credentials.access_token :
+ '';
+ return function (obj, cb) {
+ spashttp.request({url: "http://gdata.youtube.com/feeds/api/videos/" + obj.media$group.yt$videoid.$t + '?v=2&alt=json' + tokenString }, credentials, function( err, video ) {
+ if(video && _.has(video, 'entry')) {
+ obj.media$group.media$keywords.$t = video.entry.media$group.media$keywords.$t;
+ obj.category = video.entry.category;
+ }
- cb(err);
- });
- }
+ cb(err);
+ });
+ };
};
-
-exports["custom"] = {
- videosWithKeywords: function(params, credentials, cb) {
- params.url = "http://gdata.youtube.com/feeds/api/videos?v=2";
- // Ensure we have a number to perform calculation.
- var maxResults = parseInt(params['max-results']) || 50;
- if (maxResults > 50) params['max-results'] = "50";
- var pages = Math.floor((maxResults-1)/50) + 1;
- var startIndices = [];
- // Prep an array for starting indices to use with `async.concat`
- for (var i = 0; i < pages; i++) { startIndices[i] = i*50 + 1; };
- // In order to concat the video entries only
- var data;
+exports.custom = {
+ videosWithKeywords: function(params, credentials, cb) {
+ params.url = "http://gdata.youtube.com/feeds/api/videos?v=2";
+ // Ensure we have a number to perform calculation.
+ var maxResults = parseInt(params['max-results'],10) || 50;
+ var pages = Math.floor((maxResults-1)/50) + 1;
+ var startIndices = [];
- async.concatSeries(startIndices, function (startIndex, callback) {
- var shadowed = _.clone(params);
- shadowed['start-index'] = startIndex+'';
+ // Prep an array for starting indices to use with `async.concat`
+ for (var i = 0; i < pages; i++) {
+ startIndices[i] = i*50 + 1;
+ }
- spashttp.request(shadowed, credentials, function ( err, videos ) {
- if (_.has(videos, 'feed')) {
- // Save meta data outside.
- if (!data) data = videos;
+ // In order to concat the video entries only
+ var data;
- async.each(videos.feed.entry, getVideoDetails(credentials), function (err) {
- callback(err, videos.feed.entry);
- });
-
- } else {
- callback( err, videos );
- }
-
- });
- }, function(err, results) {
- // After concatenation is done, save the entries back and return.
- data.feed.entry = results;
- cb(err, data);
- });
-
-
- }
+ async.concat(startIndices, function (startIndex, callback) {
+ var shadowed = _.clone(params);
+ shadowed['max-results'] = maxResults >= 50 ? '50' : maxResults+'';
+ shadowed['start-index'] = startIndex+'';
+
+ spashttp.request(shadowed, credentials, function ( err, videos ) {
+ if (_.has(videos, 'feed')) {
+ // Save meta data outside.
+ if (!data) data = videos;
+ async.each(videos.feed.entry, getVideoDetails(credentials), function (err) {
+ callback(err, videos.feed.entry);
+ });
+ } else {
+ callback( err, videos );
+ }
+ });
+ }, function(err, results) {
+ // After concatenation is done, save the entries back and return.
+ data.feed.entry = results;
+ cb(err, data);
+ });
+ }
};

0 comments on commit 942971f

Please sign in to comment.