Comparing version 0.0.1 to 0.0.2
@@ -73,2 +73,6 @@ 'use strict'; | ||
Collection.prototype.map = function(callback){ | ||
return this._models.map(callback); | ||
}; | ||
Collection.prototype.toJSON = function(){ | ||
@@ -75,0 +79,0 @@ var json = []; |
@@ -5,2 +5,3 @@ 'use strict'; | ||
var _ = require('lodash'); | ||
var q = require('q'); | ||
@@ -17,13 +18,13 @@ var DStore = function(options){ | ||
var request = { uri: href, method: 'GET', query: query }; | ||
var deferred = q.defer(); | ||
var self = this; | ||
return this.reqExec.execute(request, function(err, body){ | ||
if(!callback) { return; } | ||
if(err){ return callback(err); } | ||
var error = self.findError(body); | ||
if(error) { return callback(error); } | ||
this.reqExec.execute(request, function(err, body){ | ||
if(!err) { err = self.findPlatformError(body); } | ||
if(err) { return deferred.reject(err); } | ||
var options = response.options ? _.clone(response.options) : {}; | ||
options.request = query; | ||
var model = new response.Model(body, self, options); | ||
return callback(null, model); | ||
deferred.resolve(model); | ||
}); | ||
return deferred.promise.nodeify(callback); | ||
}; | ||
@@ -37,3 +38,3 @@ | ||
DStore.prototype.findError = function(body){ | ||
DStore.prototype.findPlatformError = function(body){ | ||
return body ? body.error : undefined; | ||
@@ -40,0 +41,0 @@ }; |
{ | ||
"name": "newscred", | ||
"version": "0.0.1", | ||
"description": "NewsCred Node.js API", | ||
"scripts": { | ||
"test": "./node_modules/.bin/mocha -r ./test/support/env -R dot --recursive ./test", | ||
"test-travis": "./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -r ./test/support/env -R spec --recursive ./test" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/alexcurtis/node-newscred.git" | ||
}, | ||
"author": { | ||
"name": "Alex Curtis", | ||
"email": "alx.curtis@gmail.com" | ||
}, | ||
"license": "MIT", | ||
"keywords": [ | ||
"newscred", | ||
"api", | ||
"platform", | ||
"news" | ||
], | ||
"bugs": { | ||
"url": "https://github.com/alexcurtis/node-newscred/issues" | ||
}, | ||
"homepage": "https://github.com/alexcurtis/node-newscred", | ||
"devDependencies": { | ||
"gulp": "^3.8.0", | ||
"gulp-autoprefixer": "^0.0.6", | ||
"gulp-jshint": "^1.8.0", | ||
"gulp-load-plugins": "^0.7.1", | ||
"require-dir": "^0.1.0", | ||
"chai": "^1.9.2", | ||
"gulp-mocha": "^1.1.1", | ||
"istanbul": "^0.3.2", | ||
"mocha": "^1.21.4", | ||
"sinon": "^1.10.3", | ||
"sinon-chai": "^2.6.0" | ||
}, | ||
"dependencies": { | ||
"extract-opts": "^2.2.0", | ||
"lodash": "^2.4.1", | ||
"node-uuid": "^1.4.1", | ||
"request": "^2.47.0" | ||
} | ||
"name": "newscred", | ||
"version": "0.0.2", | ||
"description": "NewsCred Node.js API", | ||
"scripts": { | ||
"test": "./node_modules/.bin/mocha -r ./test/support/env -R dot --recursive ./test", | ||
"test-travis": "./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -r ./test/support/env -R spec --recursive ./test" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/alexcurtis/node-newscred.git" | ||
}, | ||
"author": { | ||
"name": "Alex Curtis", | ||
"email": "alx.curtis@gmail.com" | ||
}, | ||
"license": "MIT", | ||
"keywords": [ | ||
"newscred", | ||
"api", | ||
"platform", | ||
"news" | ||
], | ||
"bugs": { | ||
"url": "https://github.com/alexcurtis/node-newscred/issues" | ||
}, | ||
"homepage": "https://github.com/alexcurtis/node-newscred", | ||
"devDependencies": { | ||
"gulp": "^3.8.0", | ||
"gulp-autoprefixer": "^0.0.6", | ||
"gulp-jshint": "^1.8.0", | ||
"gulp-load-plugins": "^0.7.1", | ||
"require-dir": "^0.1.0", | ||
"chai": "^1.9.2", | ||
"gulp-mocha": "^1.1.1", | ||
"istanbul": "^0.3.2", | ||
"mocha": "^1.21.4", | ||
"sinon": "^1.10.3", | ||
"sinon-chai": "^2.6.0" | ||
}, | ||
"dependencies": { | ||
"extract-opts": "^2.2.0", | ||
"lodash": "^2.4.1", | ||
"node-uuid": "^1.4.1", | ||
"q": "^1.1.1", | ||
"request": "^2.47.0" | ||
} | ||
} |
@@ -81,2 +81,3 @@ NewsCred Node.js API | ||
- [Collection](#collection) | ||
- [Promises](#promises) | ||
- [API](#api) | ||
@@ -93,3 +94,2 @@ - [Article](#article-newscred-article) | ||
- [Paging](#paging) | ||
- [Streaming](#streaming) | ||
- [Tests](#tests) | ||
@@ -101,3 +101,3 @@ | ||
### toJSON() | ||
#### toJSON() | ||
@@ -110,19 +110,36 @@ Return a shallow copy of the model's attributes for JSON stringification. This can be used for persistence, serialization, or for augmentation before being sent to the client. | ||
### get(id) | ||
#### get(id) | ||
Returns the first model with the matching id. | ||
### toArray() | ||
#### toArray() | ||
Returns a flat 1D array of the collection's models. | ||
### each(callback(<model>)) | ||
#### each(callback(<model>)) | ||
Iterates through the collection, invoking the callback for each model. | ||
### toJSON() | ||
#### toJSON() | ||
Iterates through the collection, calling toJSON() on each model. Returns an Array. | ||
## Promises | ||
node-newscred works with Node-style callbacks, but also implements promises with | ||
the [Q](https://github.com/kriskowal/q) library. | ||
```javascript | ||
var q = require('q'); | ||
// Fetches images for 'china' articles. | ||
client.article.search('china').then(function(articles){ | ||
return q.all(articles.map(function(article){ | ||
return article.images(); | ||
})); | ||
}).then(function(images){ | ||
console.log(images); | ||
}); | ||
``` | ||
## API | ||
@@ -625,3 +642,3 @@ | ||
``` | ||
<!-- | ||
## Streaming | ||
@@ -644,3 +661,3 @@ | ||
app.listen(process.env.PORT || 3000); | ||
``` | ||
``` --> | ||
@@ -647,0 +664,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
58279
971
667
5