Created
February 11, 2015 17:30
-
-
Save DinoChiesa/8f5958f735104a647842 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* ugCollectionForEach | |
* | |
* Iterates through all items IN A SINGLE PAGE of a collection within | |
* Apigee Edge BaaS. Uses the Usergrid client object from the usergrid | |
* module. Notice - this logic does not call {has,get}NextPage(). | |
* | |
* @param ugClient - the authenticated client object | |
* @param options - the options for a collection. Pass type and qs. | |
* @param f - function called with each UG entity. Accepts a single argument. | |
* @param doneCb - called in case of error or success. | |
* | |
*********************************************/ | |
function ugCollectionForEach (ugClient, options, f, doneCb) { | |
var results = {count: 0, failCount: 0}; | |
if ( ! options.qs) { | |
doneCb(new Error('missing qs property in the options argument'), null); | |
} | |
if ( ! options.type) { | |
doneCb(new Error('missing type property in the options argument'), null); | |
} | |
ugClient.createCollection(options, function (e, collection) { | |
var e2; | |
if (e) { | |
e2 = new Error('could not make or get collection'); | |
e2.wrappedError = e; | |
doneCb(e2, null); | |
} | |
else { | |
// we got the collection, now examine each of the Entities: | |
while(collection.hasNextEntity()) { | |
f(collection.getNextEntity(), results); | |
results.count++; | |
} | |
doneCb(null, results); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment