-
Notifications
You must be signed in to change notification settings - Fork 518
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
102 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |