Skip to content
Browse files

Merge branch 'master' into lastfm

  • Loading branch information...
2 parents e426feb + 79fdf13 commit ba96482dda9c677356e33bc0f1c131075baf2cb2 @temas temas committed
View
5 Collections/Photos/dataStore.js
@@ -24,6 +24,9 @@ exports.init = function(mongo, _locker) {
collection = mongo.collections.photo;
collectionDataStore.init(mongo, 'photo', locker);
+ collection.ensureIndex({url:1}, {background:true}, function() {});
+ collection.ensureIndex({name:1}, {background:true}, function() {});
+
db = mongo.dbClient;
logger = require("logger");
}
@@ -63,4 +66,4 @@ exports.get = collectionDataStore.get;
exports.getAll = collectionDataStore.getAll;
exports.getLastObjectID = collectionDataStore.getLastObjectID;
exports.getTotalCount = collectionDataStore.getTotalCount;
-exports.getSince = collectionDataStore.getSince;
+exports.getSince = collectionDataStore.getSince;
View
5 Connectors/Flickr/contacts.js
@@ -12,7 +12,10 @@ var path = require("path");
var PER_PAGE = 1000;
exports.sync = function(processInfo, callback) {
var paging = require(path.join(processInfo.absoluteSrcdir, 'lib', 'paging.js'));
- paging.getPage(processInfo, 'flickr.contacts.getList', 'contact', PER_PAGE, {}, function(config, contactsArray) {
+ paging.getPage(processInfo, 'flickr.contacts.getList', 'contact', PER_PAGE, {}, function(err, config, contactsArray) {
+ if (err) {
+ return callback(err);
+ }
for(var i in contactsArray) {
contactsArray[i] = {obj:contactsArray[i], timestamp:config.lastUpdate, type:'new'};
}
View
11 Connectors/Flickr/lib/paging.js
@@ -24,14 +24,15 @@ exports.getPage = function(processInfo, endpoint, type, perPage, params, callbac
var json = JSON.parse(body);
var page;
var pages;
+ if (json.stat && json.stat == "fail") {
+ return callback(json.message);
+ }
try {
page = parseInt(json[type_s].page);
pages = parseInt(json[type_s].pages);
} catch (E) {
- console.error("Error processing json: " + E);
- // Make sure we do that page again
- page = config.paging[type].lastPage;
- pages = page + 1;
+ console.error("Error processing json: %s from %s", E, body);
+ return callback("Error processing the json");
}
if(page > pages) { //whoa whoa whoa, bad news bears, page should never be greater than pages
// seems like there is a possiblity of pages === 0 if there are no photos
@@ -48,7 +49,7 @@ exports.getPage = function(processInfo, endpoint, type, perPage, params, callbac
config.paging[type].totalPages = pages;
config.nextRun = -1;
}
- callback(config, json[type_s][type]);
+ callback(null, config, json[type_s][type]);
}
});
}
View
6 Connectors/Flickr/photos.js
@@ -64,7 +64,11 @@ exports.sync = function(processInfo, callback) {
if (!processInfo.config) processInfo.config = {};
paging.getPage(processInfo, 'flickr.people.getPhotos', 'photo', PER_PAGE,
- {extras:extras, user_id:processInfo.auth.user.nsid, min_upload_date:(processInfo.config.last_checked_date || 0)}, function(config, photosArray) {
+ {extras:extras, user_id:processInfo.auth.user.nsid, min_upload_date:(processInfo.config.last_checked_date || 0)}, function(err, config, photosArray) {
+ if (err) {
+ return callback(err);
+ }
+
// If we're on the last page of a real result go ahead and update
if (config && config.paging && config.paging["photo"] && config.paging["photo"].totalPages < 0) {
config.last_checked_date = parseInt(Date.now() / 1000);
View
1 tests/fixtures/flickr/bad.json
@@ -0,0 +1 @@
+{"stat":"fail","code":"97","message":"Missing signature"}
View
17 tests/synclet-local-flickr.js
@@ -41,7 +41,6 @@ suite.next().suite.addBatch({
assert.isNull(err);
assert.equal(response.config.paging["contact"].lastPage, 1);
assert.equal(response.config.nextRun, -1);
-
}
}
}).addBatch({
@@ -76,5 +75,19 @@ suite.next().suite.addBatch({
assert.equal(response.data.photo[0].obj.lastupdate, '1282612259');
}
}
-})
+}).addBatch({
+ "Error responses": {
+ topic:function() {
+ pinfo.config = {paging:{contact:{lastPage:50}}};
+ fakeweb.allowNetConnect = false;
+ fakeweb.registerUri({
+ uri : 'http://api.flickr.com:80/services/rest/?api_sig=38a0193a7ae1fd2b2d379fc2a12ffc12&api_key=sdf&auth_token=qwert&format=json&method=flickr.contacts.getList&nojsoncallback=1&page=51&per_page=1000',
+ file:__dirname + "/fixtures/flickr/bad.json" });
+ contacts.sync(pinfo, this.callback) },
+ "are handled properly": function(err, topic) {
+ assert.equal(err, "Missing signature")
+ err = null;
+ }
+ }
+});
suite.export(module);

0 comments on commit ba96482

Please sign in to comment.
Something went wrong with that request. Please try again.