Skip to content

Commit

Permalink
Merge branch 'master' into pricing
Browse files Browse the repository at this point in the history
  • Loading branch information
Doug Black committed May 6, 2015
2 parents e6c6d31 + da991e3 commit 7900d0d
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 3 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ For detailed usage infomation and API docs, head out here:

[http://twilio.github.io/twilio-node/](http://twilio.github.io/twilio-node/)

## Getting help

If you need help installing or using the library, please contact Twilio Support at help@twilio.com first. Twilio's Support staff are well-versed in all of the Twilio Helper Libraries, and usually reply within 24 hours.

If you've instead found a bug in the library or would like new features added, go ahead and open issues or pull requests against this repo!

## Contributing

Bug fixes, docs, and enhancements welcome! If you're not familiar with the GitHub pull request/contribution process, [this is a nice tutorial](http://gun.io/blog/how-to-github-fork-branch-and-pull-request/).
Expand Down Expand Up @@ -41,3 +47,5 @@ In your fork, create a new feature/bug fix branch, [per the guide listed above](

Right now, the docs are maintained in static HTML in the `gh-pages` branch of this repository. We hope to switch to a more robust documentation system soon, but for the time being, you can make documentation changes by editing [index.html](https://github.com/twilio/twilio-node/blob/gh-pages/index.html) directly.



34 changes: 34 additions & 0 deletions lib/LookupsClient.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
@module LookupsClient
This module presents a higher-level API for interacting with resources
in the Twilio Lookups API. Tries to map very closely to the resource structure
of the actual Twilio API, while still providing a nice JavaScript interface.
*/

//Dependencies
var _ = require('underscore');
var Client = require('./Client');
var util = require('util');

/**
The Twilio Lookups API client
@constructor
@param {string} sid - The application SID, as seen in the Twilio portal
@param {string} tkn - The auth token, as seen in the Twilio portal
@param {object} options (optional) - optional config for the REST client
- @member {string} host - host for the Twilio API (default: lookups.twilio.com)
- @member {string} apiVersion - the Twilio REST API version to use for requests (default: v1)
*/
function LookupsClient(sid, tkn, options) {
//Required client config
options = options || {};
LookupsClient.super_.call(this, sid, tkn, options.host || 'lookups.twilio.com', options.apiVersion || 'v1', options.timeout);

var phoneNumbersResource = require('./resources/lookups/PhoneNumbers')(this);
this.phoneNumbers = phoneNumbersResource;
}

util.inherits(LookupsClient, Client);

module.exports = LookupsClient;
2 changes: 2 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var webhooks = require('./webhooks'),
RestClient = require('./RestClient'),
PricingClient = require('./PricingClient');
TaskRouterClient = require('./TaskRouterClient');
LookupsClient = require('./LookupsClient');

//Shorthand to automatically create a RestClient
function initializer(sid, tkn, options) {
Expand All @@ -20,6 +21,7 @@ function initializer(sid, tkn, options) {
initializer.RestClient = RestClient;
initializer.PricingClient = PricingClient;
initializer.TaskRouterClient = TaskRouterClient;
initializer.LookupsClient = LookupsClient;
initializer.Capability = require('./Capability');
initializer.TaskRouterCapability = require('./TaskRouterCapability');
initializer.TwimlResponse = require('./TwimlResponse');
Expand Down
23 changes: 23 additions & 0 deletions lib/resources/lookups/PhoneNumbers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

/**
@module resources/PhoneNumbers
/**
@module resources/PhoneNumbers
The Twilio Lookups PhoneNumbers Resource.
*/
var generate = require('../generate');

module.exports = function (client, accountSid) {
var baseResourceUrl = '/PhoneNumbers';

//Instance requests
function PhoneNumbers(number) {
var resourceApi = {
get:generate(client, 'GET', baseResourceUrl + '/' + number),
};

return resourceApi;
};

return PhoneNumbers;
};
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "twilio",
"description": "A Twilio helper library",
"version": "2.0.0",
"version": "2.1.0",
"author": "Kevin Whinnery <kevin.whinnery@gmail.com>",
"contributors": [
{
Expand All @@ -14,15 +14,15 @@
"url": "https://github.com/twilio/twilio-node.git"
},
"dependencies": {
"request": "2.27.x",
"request": "2.55.x",
"underscore": "1.x",
"jwt-simple": "0.1.x",
"q": "0.9.7",
"scmp": "0.0.3"
},
"devDependencies": {
"express": "3.x",
"jasmine-node": "*"
"jasmine-node": "^1.14.5"
},
"scripts": {
"test": "jasmine-node spec"
Expand Down
32 changes: 32 additions & 0 deletions spec/lookups.phone_number.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
var twilio = require('../index');

describe('The Twilio Lookups PhoneNumber resource', function () {
var client = new twilio.LookupsClient('AC123', '123');

beforeEach(function () {
spyOn(client, 'request');
});

it('fetches a phone number', function() {
client.phoneNumbers('4153902337').get()
expect(client.request).toHaveBeenCalled();
expect(client.request).toHaveBeenCalledWith({
url: '/PhoneNumbers/4153902337',
method: 'GET',
qs: {}
}, undefined);
});

it('fetches a phone number with country code and type', function() {
client.phoneNumbers('4153902337').get({countryCode: 'US', type: 'carrier'});
expect(client.request).toHaveBeenCalled();
expect(client.request).toHaveBeenCalledWith({
url: '/PhoneNumbers/4153902337',
method: 'GET',
qs: {
CountryCode: 'US',
Type: 'carrier'
}
}, undefined);
});
});

0 comments on commit 7900d0d

Please sign in to comment.