Socket
Socket
Sign inDemoInstall

twilio

Package Overview
Dependencies
Maintainers
1
Versions
301
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

twilio - npm Package Compare versions

Comparing version 0.7.1 to 0.8.0

lib/resources/UsageRecords.js

2

config.js

@@ -5,4 +5,4 @@ //Configuration for running tests and examples against the Twilio API

authToken:'1cb7a094ce91af64cc6bcc12a449fb1c',
from:'+16513566397', //The Twilio number you've bought or configured
from:'+16513566323', //The Twilio number you've bought or configured
to:'+16512080532' //The number you would like to send messages to for testing
};

@@ -13,4 +13,4 @@ /**

//Shorthand to automatically create a RestClient
function initializer(sid,tkn) {
return new RestClient(sid, tkn);
function initializer(sid, tkn, options) {
return new RestClient(sid, tkn, options);
}

@@ -17,0 +17,0 @@

@@ -14,3 +14,3 @@ /**

//All other REST resources are based on account - some can simply be generated, others need additonal URL params
//TODO: This can be smarter. Should eventually refactor generator to do subresources too. Shouldn't need to be custom
//TODO: This can probably be smarter. Should eventually refactor generator to do subresources too. Shouldn't need to be custom
//Probably should generate the whole f***ing thing from an object literal describing the resource structure. But this does work.

@@ -59,6 +59,3 @@ var subresources = {

usage:{
records:ListInstanceResource(client,sid,'Usage/Records',
['GET'],
['GET']
),
records:require('./UsageRecords')(client, sid),
triggers:ListInstanceResource(client,sid,'Usage/Triggers',

@@ -86,3 +83,3 @@ ['GET','POST','DELETE',{update:'POST'}],

generate.restFunctions(resourceApi, client, ['GET', 'PUT', 'POST'], '/Accounts/' + accountSid);
resourceApi.update = resourceApi.put;
resourceApi.update = resourceApi.post;
resourceApi.list = resourceApi.get;

@@ -89,0 +86,0 @@

@@ -21,3 +21,5 @@ /**

resourceApi.local.list = resourceApi.local.get;
resourceApi.local.search = resourceApi.local.get;
resourceApi.tollFree.list = resourceApi.tollFree.get;
resourceApi.tollFree.search = resourceApi.tollFree.get;

@@ -24,0 +26,0 @@ return resourceApi;

@@ -17,7 +17,19 @@ /**

//Add in subresources
resourceApi.participants = {
get: generate(client, 'GET', baseResourceUrl + '/' + sid + '/Participants')
resourceApi.participants = function(participantSid) {
var participantResourceApi = {
get:generate(client, 'GET', baseResourceUrl + '/' + sid + '/Participants/' + participantSid),
post:generate(client, 'POST', baseResourceUrl + '/' + sid + '/Participants/' + participantSid),
delete:generate(client, 'DELETE', baseResourceUrl + '/' + sid + '/Participants/' + participantSid)
};
//Aliases
participantResourceApi.update = participantResourceApi.post;
participantResourceApi.kick = participantResourceApi.delete;
return participantResourceApi;
};
resourceApi.list = resourceApi.get;
resourceApi.participants.get = generate(client, 'GET', baseResourceUrl + '/' + sid + '/Participants');
//Aliases
resourceApi.participants.list = resourceApi.participants.get;

@@ -30,4 +42,5 @@

Conferences.get = generate(client, 'GET', baseResourceUrl);
Conferences.list = Conferences.get;
return Conferences;
};

@@ -25,5 +25,7 @@ /**

//There's also a special resource for a call at the front of the queue, not specified by SID
resourceApi.members.front.get = resourceApi.members('Front').get;
resourceApi.members.front.post = resourceApi.members('Front').post;
resourceApi.members.front.update = resourceApi.members('Front').update;
resourceApi.members.front = {
get: resourceApi.members('Front').get,
post: resourceApi.members('Front').post,
update: resourceApi.members('Front').post
};

@@ -30,0 +32,0 @@ return resourceApi;

@@ -30,4 +30,5 @@ /**

Recordings.get = generate(client, 'GET', baseResourceUrl);
Recordings.list = Recordings.get;
return Recordings;
};

@@ -29,5 +29,17 @@ /**

//Required client config
if (!sid && !tkn) throw 'RestClient requires an application SID and auth token';
this.accountSid = sid;
this.authToken = tkn;
if (!sid || !tkn) {
if (process.env.TWILIO_ACCOUNT_SID && process.env.TWILIO_AUTH_TOKEN) {
this.accountSid = process.env.TWILIO_ACCOUNT_SID;
this.authToken = process.env.TWILIO_AUTH_TOKEN;
}
else {
throw 'RestClient requires an application SID and auth token set explicitly ' +
'or via the TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN environment variables';
}
}
else {
//if auth token/SID passed in manually, trim spaces
this.accountSid = sid.replace(/ /g,'');
this.authToken = tkn.replace(/ /g,'');
}

@@ -49,4 +61,4 @@ //Optional client config

this.listSms = this.accounts.sms.messages.get;
this.getSms = function(sid, callback) {
this.accounts.sms.messages(sid).get(callback);
this.getSms = function(messageSid, callback) {
this.accounts.sms.messages(messageSid).get(callback);
};

@@ -57,4 +69,4 @@

this.listCalls = this.accounts.calls.get;
this.getCall = function(sid, callback) {
this.accounts.calls(sid).get(callback);
this.getCall = function(callSid, callback) {
this.accounts.calls(callSid).get(callback);
};

@@ -101,5 +113,40 @@ }

if (!err && (response.statusCode < 200 || response.statusCode > 206)) {
err = data ? data : { status: response.statusCode, message:'HTTP request error, check response for more info'};
err = data ? data : {
status: response.statusCode,
message:'HTTP request error, check response for more info'
};
}
//process data and make available in a more JavaScripty format
function processKeys(source) {
if (_.isObject(source)) {
Object.keys(source).forEach(function(key) {
//Supplement underscore values with camel-case
if (key.indexOf('_') > 0) {
var cc = key.replace(/_([a-z])/g, function (g) {
return g[1].toUpperCase()
});
source[cc] = source[key];
}
//process any nested arrays...
if (Array.isArray(source[key])) {
source[key].forEach(processKeys);
}
else if (_.isObject(source[key])) {
processKeys(source[key]);
}
});
//Look for and convert date strings for specific keys
['startDate', 'endDate', 'dateCreated', 'dateUpdated', 'startTime', 'endTime'].forEach(function(dateKey) {
if (source[dateKey]) {
source[dateKey] = new Date(source[dateKey]);
}
});
}
}
processKeys(data);
//hang response off the JSON-serialized data

@@ -106,0 +153,0 @@ data.nodeClientResponse = response;

{
"name":"twilio",
"description":"A Twilio helper library",
"version":"0.7.1",
"version":"0.8.0",
"author":"Kevin Whinnery <kevin.whinnery@gmail.com>",

@@ -6,0 +6,0 @@ "contributors":[

@@ -9,4 +9,2 @@ # node-twilio

The existing "twilio" node module in npm represents the 0.4.x version, whose last major update came in August 2011. The original repository for this module is [here](https://github.com/sjwalter/node-twilio). This version of the module will remain in a special `0.4.x` branch, for those users and projects still depending on that version of the API.
New development, working toward an eventual 1.0 release, will be on the master branch. Planned feature releases are:

@@ -13,0 +11,0 @@

@@ -28,3 +28,3 @@ var config = require('../config'),

}, function (err2, data2, response2) {
expect(data2.friendly_name).toBe('TestAccountDos');
expect(data2.friendlyName).toBe('TestAccountDos');
newAccountSidTwo = data2.sid;

@@ -31,0 +31,0 @@ done();

@@ -16,3 +16,3 @@ var config = require('../config'),

it('gets a list of available phone numbers for a given country, with an area code filter', function (done) {
client.accounts.availablePhoneNumbers('US').local.list({
client.accounts.availablePhoneNumbers('US').local.search({
areaCode:651

@@ -19,0 +19,0 @@ }, function (err, data) {

@@ -21,2 +21,23 @@ var config = require('../config'),

it('should use environment variables, if defined, for the constructor', function() {
var oldSid = process.env.TWILIO_ACCOUNT_SID,
oldAuthToken = process.env.TWILIO_AUTH_TOKEN;
process.env.TWILIO_ACCOUNT_SID = 'foo';
process.env.TWILIO_AUTH_TOKEN = 'bar';
var c = twilio();
expect(c.accountSid).toBe('foo');
expect(c.authToken).toBe('bar');
delete process.env.TWILIO_ACCOUNT_SID;
delete process.env.TWILIO_AUTH_TOKEN;
expect(twilio).toThrow();
process.env.TWILIO_ACCOUNT_SID = oldSid;
process.env.TWILIO_AUTH_TOKEN = oldAuthToken;
});
//create a client with a valid account SID and authToken for live testing

@@ -49,2 +70,12 @@ var client = new twilio.RestClient(config.accountSid, config.authToken);

});
it('should fail with an unauthorized error if the auth token is wrong and has space', function(done) {
var c = twilio(config.accountSid, 'foo bar');
c.accounts.get(function(err, data) {
expect(err).toBeTruthy();
expect(err.status).toBe(401);
done();
});
});
});

@@ -34,3 +34,4 @@ var config = require('../config'),

}, function(err, data) {
expect(data.sms_messages.length).toBeGreaterThan(0);
//can use either camel-case or underscore values
expect(data.smsMessages.length).toBeGreaterThan(0);
expect(data.sms_messages[0].from).toBe(config.from);

@@ -37,0 +38,0 @@ done();

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc