predictionio
Advanced tools
Comparing version 0.0.1 to 0.0.2
var request = require('superagent') | ||
, when = require('when') | ||
@@ -7,2 +8,3 @@ | ||
this._config = obj._config | ||
this._createDeferred = obj._createDeferred | ||
@@ -16,14 +18,17 @@ } | ||
var deferred = this._createDeferred(fn) | ||
params.pio_appkey = this._config.key | ||
request | ||
.post( this._config.baseUrl + '/items.json') | ||
.post(this._config.baseUrl + '/items.json') | ||
.send(params) | ||
.end(function (err, res) { | ||
fn && fn(err, res.body) | ||
if (err || !res) deferred.reject(err) | ||
deferred.resolve(res.body) | ||
}) | ||
return deferred.promise | ||
} | ||
@@ -33,3 +38,4 @@ | ||
var endpoint = this._config.baseUrl + '/items/' + uid + '.json' | ||
var deferred = this._createDeferred(fn) | ||
, endpoint = this._config.baseUrl + '/items/' + uid + '.json' | ||
@@ -41,6 +47,9 @@ request | ||
fn && fn(err, res.body) | ||
if (err || !res) deferred.reject(err) | ||
deferred.resolve(res.body) | ||
}) | ||
return deferred.promise | ||
} | ||
@@ -50,13 +59,17 @@ | ||
var endpoint = this._config.baseUrl + '/items/' + uid + '.json' | ||
var deferred = this._createDeferred(fn) | ||
, endpoint = this._config.baseUrl + '/items/' + uid + '.json' | ||
request | ||
.del(endpoint) | ||
.query({ pio_appkey: this._config.key }) | ||
.send({ pio_appkey: this._config.key }) | ||
.end(function (err, res) { | ||
fn && fn(err, res.body) | ||
if (err || !res) deferred.reject(err) | ||
deferred.resolve(res.body) | ||
}) | ||
return deferred.promise | ||
} | ||
@@ -66,4 +79,7 @@ | ||
if (!params.engine) { | ||
fn && fn('Engine must be supplied', null) | ||
var deferred = this._createDeferred(fn) | ||
if (!params.pio_engine) { | ||
deferred.reject('Engine must be supplied') | ||
return deferred.promise | ||
} | ||
@@ -73,3 +89,3 @@ | ||
var endpoint = this._config.baseUrl + '/engines/itemsim/' + params.engine + '/topn.json' | ||
var endpoint = this._config.baseUrl + '/engines/itemsim/' + params.pio_engine + '/topn.json' | ||
@@ -90,6 +106,9 @@ request | ||
fn && fn(err, res.body) | ||
if (err || !res) deferred.reject(err) | ||
deferred.resolve(res.body) | ||
}) | ||
return deferred.promise | ||
} | ||
@@ -99,4 +118,7 @@ | ||
if (!params.engine) { | ||
fn && fn('Engine must be supplied', null) | ||
var deferred = this._createDeferred(fn) | ||
if (!params.pio_engine) { | ||
deferred.reject('Engine must be supplied') | ||
return deferred.promise | ||
} | ||
@@ -106,3 +128,3 @@ | ||
var endpoint = this._config.baseUrl + '/engines/itemrec/' + params.engine + '/topn.json' | ||
var endpoint = this._config.baseUrl + '/engines/itemrec/' + params.pio_engine + '/topn.json' | ||
@@ -123,6 +145,9 @@ request | ||
fn && fn(err, res.body) | ||
if (err || !res) deferred.reject(err) | ||
deferred.resolve(res.body) | ||
}) | ||
return deferred.promise | ||
} | ||
@@ -129,0 +154,0 @@ |
@@ -1,6 +0,6 @@ | ||
var resources = { | ||
var when = require('when') | ||
, resources = { | ||
users: require('./users') | ||
, items: require('./items') | ||
, users2items: require('./user-to-item') | ||
@@ -12,2 +12,4 @@ } | ||
if (!config || !config.key) return new Error('App Key must be supplied') | ||
if (!(this instanceof PredictionIO)) { | ||
@@ -19,4 +21,4 @@ return new PredictionIO(config, version) | ||
if (this._config.baseUrl === 'localhost') { | ||
this._config.baseUrl = 'http://127.0.0.1:9000' | ||
if (!this._config.baseUrl || this._config.baseUrl === 'localhost') { | ||
this._config.baseUrl = 'http://127.0.0.1:8000' | ||
} | ||
@@ -43,2 +45,18 @@ | ||
, _createDeferred: function(callback) { | ||
var deferred = when.defer() | ||
if (callback) { | ||
deferred.promise.then(function (res) { | ||
setTimeout(function(){ callback(null, res) }, 0) | ||
}, function (err) { | ||
setTimeout(function(){ callback(err, null) }, 0) | ||
}); | ||
} | ||
return deferred | ||
} | ||
} | ||
@@ -45,0 +63,0 @@ |
var request = require('superagent') | ||
, when = require('when') | ||
@@ -7,3 +8,4 @@ | ||
this._config = obj._config | ||
this._createDeferred = obj._createDeferred | ||
} | ||
@@ -16,13 +18,17 @@ | ||
var deferred = this._createDeferred(fn) | ||
params.pio_appkey = this._config.key | ||
request | ||
.post( this._config.baseUrl + '/users.json') | ||
.post(this._config.baseUrl + '/users.json') | ||
.send(params) | ||
.end(function (err, res) { | ||
fn && fn(err, res.body) | ||
if (err || !res) deferred.reject(err) | ||
deferred.resolve(res.body) | ||
}) | ||
return deferred.promise | ||
} | ||
@@ -32,3 +38,4 @@ | ||
var endpoint = this._config.baseUrl + '/users/' + uid + '.json' | ||
var deferred = this._createDeferred(fn) | ||
, endpoint = this._config.baseUrl + '/users/' + uid + '.json' | ||
@@ -40,6 +47,9 @@ request | ||
fn && fn(err, res.body) | ||
if (err || !res) deferred.reject(err) | ||
deferred.resolve(res.body) | ||
}) | ||
return deferred.promise | ||
} | ||
@@ -49,13 +59,37 @@ | ||
var endpoint = this._config.baseUrl + '/users/' + uid + '.json' | ||
var deferred = this._createDeferred(fn) | ||
, endpoint = this._config.baseUrl + '/users/' + uid + '.json' | ||
request | ||
.del(endpoint) | ||
.send({ | ||
pio_appkey: this._config.key | ||
}) | ||
.end(function (err, res) { | ||
if (err || !res) deferred.reject(err) | ||
deferred.resolve(res.body) | ||
}) | ||
return deferred.promise | ||
} | ||
, createAction: function (params, fn) { | ||
var deferred = this._createDeferred(fn) | ||
params.pio_appkey = this._config.key | ||
request | ||
.del(endpoint) | ||
.query({ pio_appkey: this._config.key }) | ||
.post(this._config.baseUrl + '/actions/u2i.json') | ||
.send(params) | ||
.end(function (err, res) { | ||
fn && fn(err, res.body) | ||
if (err || !res) deferred.reject(err) | ||
deferred.resolve(res.body) | ||
}) | ||
return deferred.promise | ||
} | ||
@@ -62,0 +96,0 @@ |
{ | ||
"name": "predictionio", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "PredictionIO Node SDK", | ||
"main": "index.js", | ||
"scripts": {}, | ||
"scripts": { | ||
"test": "mocha --reporter spec" | ||
}, | ||
"repository": { | ||
@@ -21,8 +23,15 @@ "type": "git", | ||
"devDependencies": { | ||
"tap": "~0.4.4" | ||
"mocha": "~1.13.0", | ||
"chai": "~1.8.0", | ||
"chai-as-promised": "~4.0.0", | ||
"mocha-as-promised": "~1.4.0" | ||
}, | ||
"dependencies": { | ||
"superagent": "~0.15.7", | ||
"commander": "~2.0.0" | ||
"commander": "~2.0.0", | ||
"when": "~2.5.1" | ||
}, | ||
"bin": { | ||
"predictionio": "./bin/predictionio" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
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
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
15027
196
3
4
+ Addedwhen@~2.5.1
+ Addedwhen@2.5.1(transitive)