africastalking
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -1,2 +0,2 @@ | ||
'use strict' | ||
'use strict'; | ||
@@ -17,12 +17,13 @@ var Promise = require('bluebird'); | ||
Airtime.prototype.send = function (params) { | ||
let options = _.cloneDeep(params); | ||
let _self = this; | ||
let _self = this; | ||
let options = _.cloneDeep(params); | ||
let _recipients = []; | ||
// Validate params | ||
let _validateParams = function () { | ||
var constraints = { | ||
recipients: function (value) { | ||
if (validate.isEmpty(value)) { | ||
@@ -35,3 +36,3 @@ return { | ||
} | ||
if (!validate.isArray(value)) { | ||
@@ -42,11 +43,11 @@ return { | ||
} | ||
for(let i in value){ | ||
for(let i in value) { | ||
let recipient = value[i]; | ||
let phone = recipient.phoneNumber; | ||
let amount = recipient.amount; | ||
if (validate.isEmpty(phone) || | ||
validate.isEmpty(amount)){ | ||
validate.isEmpty(amount)) { | ||
return { | ||
@@ -56,3 +57,3 @@ format: 'must all specify phoneNumber and amount' | ||
} | ||
if (!(/^\+?\d+$/).test(phone)) { | ||
@@ -63,9 +64,3 @@ return { | ||
} | ||
if (!validate.isNumber(amount)) { | ||
return { | ||
format: 'must not containt invalid amounts' | ||
} | ||
} | ||
if (!(amount >= 10 && amount <= 10000)) { | ||
@@ -76,3 +71,3 @@ return { | ||
} | ||
// format amount with currency | ||
@@ -83,10 +78,11 @@ let currency = DEFAULT_CURRENCY; | ||
{ currency: currency, amount: amount } | ||
); | ||
); | ||
_recipients.push( { 'phoneNumber': phone, 'amount': recipient.amount }); | ||
}; | ||
return null; | ||
} | ||
}; | ||
let error = validate(options, constraints); | ||
@@ -98,12 +94,13 @@ if (error) { | ||
} | ||
_validateParams(); | ||
return new Promise(function (resolve, reject) { | ||
let body = { | ||
username: _self.options.username, | ||
recipients: JSON.stringify(options.recipients) | ||
recipients: _recipients | ||
}; | ||
console.log(body); | ||
let rq = unirest.post(Common.AIRTIME_URL); | ||
@@ -114,5 +111,5 @@ rq.headers({ | ||
}); | ||
rq.send(body); | ||
rq.end(function (resp) { | ||
@@ -126,8 +123,7 @@ if (resp.status === 201) { | ||
}); | ||
}); | ||
}; | ||
module.exports = Airtime; |
{ | ||
"name": "africastalking", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "Official AfricasTalking node.js API wrapper", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -195,3 +195,3 @@ # africastalking-node.js | ||
- `recipients`: An array of the following | ||
- `phoneNumber`: Receipient of airtime | ||
- `phoneNumber`: Recipient of airtime | ||
- `amount`: Amount sent. `>= 10 && <= 10K` | ||
@@ -198,0 +198,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
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
65960
731