Comparing version 0.0.4 to 0.0.5
@@ -43,10 +43,11 @@ var request = require('request'); | ||
e.prototype.yo = function(usernames, cb) { | ||
e.prototype.yo = function(options, cb) { | ||
var self = this; | ||
if (self.config.api_token != undefined) { | ||
if (usernames instanceof Array) { | ||
for (var i in usernames) { | ||
if (options.usernames) { | ||
for (var i in options.usernames) { | ||
request.post('http://api.justyo.co/yo/', {form: { | ||
'api_token': self.config.api_token, | ||
'username': usernames[i] | ||
'username': options.usernames[i], | ||
'link': options.link ? options.link : undefined | ||
}}, function(err, response, body) { | ||
@@ -62,3 +63,3 @@ if (err) throw err; | ||
} | ||
if (i == usernames.length - 1) { | ||
if (i == options.usernames.length - 1) { | ||
return cb ? cb({ | ||
@@ -75,6 +76,7 @@ "status": 1, | ||
} | ||
else { | ||
else if (options.username) { | ||
request.post('http://api.justyo.co/yo/', {form: { | ||
'api_token': self.config.api_token, | ||
'username': usernames | ||
'username': options.username, | ||
'link': options.link ? options.link : undefined | ||
}}, function(err, response, body) { | ||
@@ -101,2 +103,9 @@ if (err) throw err; | ||
} | ||
else { | ||
return cb ? cb({ | ||
"status": 0, | ||
"response": null, | ||
"errors": ["No username(s) set to Yo"] | ||
}) : false; | ||
} | ||
} | ||
@@ -112,11 +121,15 @@ else { | ||
e.prototype.yoAll = function(cb) { | ||
e.prototype.yoAll = function(options, cb) { | ||
var self = this; | ||
if (typeof options === 'function'){ | ||
cb = options; | ||
options = undefined; | ||
} | ||
if (self.config.api_token != undefined) { | ||
request.post('http://api.justyo.co/yoall/', {form: { | ||
'api_token': self.config.api_token | ||
'api_token': self.config.api_token, | ||
'link': options.link ? options.link : undefined | ||
}}, function(err, response, body) { | ||
if (err) throw err; | ||
var data = JSON.parse(body); | ||
if (data.result == "OK") { | ||
if (response.statusCode != 200) { | ||
return cb ? cb({ | ||
@@ -123,0 +136,0 @@ "status": 1, |
{ | ||
"name": "yode", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "A Yo api wrapper for Node.js", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
4668
180