Comparing version 0.0.5 to 0.0.7
@@ -70,8 +70,106 @@ /*! | ||
Account.prototype.settings = function(options,callback) { | ||
Account.prototype.secret = function(secret,callback) { | ||
return(new Error("Not Yet Implemented")); | ||
var that = this; | ||
if (secret.length > 8) { | ||
callback(new Error('Secret greater than 8 characters')); | ||
return; | ||
} | ||
if (secret === null) { | ||
callback(new Error('Secret is required')); | ||
} | ||
var uri = url.format({ | ||
protocol : 'http:', | ||
host : 'rest.nexmo.com', | ||
pathname : '/account/settings/'+ this.options.key + '/' + this.options.secret, | ||
query : { | ||
newSecret : secret | ||
} | ||
}); | ||
request.post({ | ||
uri : uri, | ||
headers : { | ||
Accept : 'application/json' | ||
} | ||
}, function (error, response, body) { | ||
if (error || response.statusCode !== 200) { | ||
callback(error || new Error()); | ||
} else { | ||
var results = JSON.parse(body); | ||
if (results['api-secret']) { | ||
callback(null,results['api-secret']); | ||
} else { | ||
callback(new Error()); | ||
} | ||
} | ||
}); | ||
}; | ||
Account.prototype.inboundUrl = function(newUrl,callback) { | ||
var uri = url.format({ | ||
protocol : 'http:', | ||
host : 'rest.nexmo.com', | ||
pathname : '/account/settings/'+ this.options.key + '/' + this.options.secret, | ||
query : { | ||
moCallBackUrl: newUrl | ||
} | ||
}); | ||
request.post({ | ||
uri : uri, | ||
headers : { | ||
Accept : 'application/json' | ||
} | ||
}, function (error, response, body) { | ||
if (error || response.statusCode !== 200) { | ||
callback(error || new Error(response.statusCode)); | ||
} else { | ||
var results = JSON.parse(body); | ||
if (results['mo-callback-url']) { | ||
callback(null,results['mo-callback-url']); | ||
} else { | ||
callback(new Error()); | ||
} | ||
} | ||
}); | ||
}; | ||
Account.prototype.receiptsUrl = function(newUrl,callback) { | ||
var uri = url.format({ | ||
protocol : 'http:', | ||
host : 'rest.nexmo.com', | ||
pathname : '/account/settings/'+ this.options.key + '/' + this.options.secret, | ||
query : { | ||
drCallBackUrl: newUrl | ||
} | ||
}); | ||
request.post({ | ||
uri : uri, | ||
headers : { | ||
Accept : 'application/json' | ||
} | ||
}, function (error, response, body) { | ||
if (error || response.statusCode !== 200) { | ||
callback(error || new Error()); | ||
} else { | ||
var results = JSON.parse(body); | ||
if (results['dr-callback-url']) { | ||
callback(null,results['dr-callback-url']); | ||
} else { | ||
callback(new Error()); | ||
} | ||
} | ||
}); | ||
} | ||
module.exports = Account; |
@@ -18,4 +18,10 @@ /*! | ||
Receipts.prototype.start = function(options,callback) { | ||
Receipts.prototype.start = function(opts,callback) { | ||
var opts; | ||
if (!opts) { | ||
opts = {port: 3001} | ||
} | ||
var that = this; | ||
@@ -27,2 +33,3 @@ | ||
res.writeHead(200); | ||
// res.write('OK'); | ||
res.end(); | ||
@@ -37,3 +44,3 @@ that.emit(req.query.status.toLowerCase(), { | ||
}) | ||
.listen(this.options.port || 3001); | ||
.listen(opts.port || 3001); | ||
@@ -40,0 +47,0 @@ }; |
@@ -12,6 +12,6 @@ { | ||
"devDependencies": { | ||
"nodeunit": "0.5.x" | ||
"nodeunit": "0.6.x" | ||
}, | ||
"engine": "node >= 0.4.1", | ||
"version": "0.0.5", | ||
"version": "0.0.7", | ||
"files": [ | ||
@@ -18,0 +18,0 @@ "index.js", |
@@ -48,2 +48,3 @@ # node-nexmo | ||
* [mikeal/request](https://github.com/mikeal/request) | ||
* [senchalabs/connect](https://github.com/senchalabs/connect) | ||
* [caolan/nodeunit](https://github.com/caolan/nodeunit) (for unit tests) |
@@ -28,2 +28,3 @@ /*! | ||
test.notEqual(b,null); | ||
test.equals(b > 0,true) | ||
test.done(); | ||
@@ -42,4 +43,37 @@ }); | ||
}, | ||
setSecret: function (test) { | ||
nexmo.account.secret(testCredentials.secret, function(err, s) { | ||
test.equals(err,null); | ||
test.notEqual(s,null); | ||
test.equal(s,testCredentials.secret); | ||
test.done(); | ||
}); | ||
}, | ||
setInboundUrl: function (test) { | ||
nexmo.account.inboundUrl('http://www.google.com', function(err, url) { | ||
test.equals(err,null); | ||
test.notEqual(url,null); | ||
test.equals(url,'http://www.google.com'); | ||
test.done(); | ||
}); | ||
}, | ||
setReceiptsUrl: function (test) { | ||
nexmo.account.receiptsUrl('http://www.google.com', function(err, url) { | ||
test.equals(err,null); | ||
test.notEqual(url,null); | ||
test.equals(url,'http://www.google.com'); | ||
test.done(); | ||
}); | ||
} | ||
}); |
@@ -60,4 +60,46 @@ /*! | ||
}); | ||
} | ||
}, | ||
/* receiptEmitAltPort: function (test) { | ||
test.expect(9); | ||
nexmo.receipts.on('failed', function(msg) { | ||
test.notEqual(msg,null); | ||
test.equals(msg.to,'0011234567890'); | ||
test.equals(msg['network-code'],'ABC'); | ||
test.equals(msg['message-id'],'ABC123'); | ||
test.equals(msg.msisdn,'XYZ'); | ||
test.equals(msg.scts,'1101181426'); | ||
nexmo.receipts.stop(); | ||
}); | ||
nexmo.receipts.start({port:8080}); | ||
var uri = url.format({ | ||
protocol : 'http:', | ||
hostname : 'localhost', | ||
port : 8080, | ||
pathname : '/receipts', | ||
query : { | ||
status : 'FAILED', | ||
to : '0011234567890', | ||
'network-code' : 'ABC', | ||
messageId : 'ABC123', | ||
msisdn : 'XYZ', | ||
scts : '1101181426' | ||
} | ||
}); | ||
request.get({ | ||
uri : uri, | ||
}, function (error, response, body) { | ||
test.equal(error, null); | ||
test.notEqual(response, null) | ||
test.equal(response.statusCode, 200); | ||
test.done(); | ||
}); | ||
} */ | ||
}); |
Sorry, the diff of this file is not supported yet
14302
452
50