├── .gitignore ├── .npmignore ├── README.md ├── UNLICENSE ├── lib └── opencnam.js ├── package.json └── tests └── simple-cli-test.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .git* 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | A simple node library for getting caller ID name information. 2 | 3 | This library uses [opencnam](http://www.opencnam.com "opencnam") as a backend. 4 | 5 | 6 | ## Installation 7 | 8 | Install from [npm](http://npmjs.org/ "node package manager"), the node package 9 | manager: 10 | 11 | $ npm install opencnam 12 | 13 | If you'd like to install node-opencnam globally, you can run: 14 | 15 | $ npm install -g opencnam 16 | 17 | NOTE: If you install node-opencnam globally, you may need to run the ``npm`` 18 | command with ``sudo``. 19 | 20 | 21 | ## Usage 22 | 23 | Using ``node-opencnam`` is easy. Below is a sample node program written using 24 | ``node-opencnam``. All it does is lookup a phone number and then output the 25 | caller ID name for the specified phone number and print it out. 26 | 27 | When using ``node-opencnam``, note that you can pass it any US phone number, in 28 | any format. This means that if you enter ``'abc8182223333bcbcbc'``, 29 | ``node-opencnam`` will still resolve it to ``'8182223333'``. 30 | 31 | If you enter a number less than 10-digits in length, you'll get an error. If 32 | you enter a number longer than 10-digits in length, ``node-opencnam`` will only 33 | use the last 10-digits of the number. 34 | 35 | So, here it is: 36 | 37 | ``` javascript 38 | var opencnam = require('opencnam'); 39 | 40 | opencnam.lookup('2024561111', function (err, cnam) { 41 | if (!err) { 42 | console.log(cnam); 43 | } else { 44 | console.log(err); 45 | } 46 | }); 47 | ``` 48 | 49 | If you're using the Professional Tier, you can pass in the account credentials via the `options` parameter: 50 | 51 | ``` javascript 52 | var opencnam = require('opencnam'); 53 | 54 | var options = { 55 | account_sid: '', 56 | auth_token: '' 57 | }; 58 | 59 | opencnam.lookup('2024561111', options, function (err, cnam) { 60 | if (!err) { 61 | console.log(cnam); 62 | } else { 63 | console.log(err); 64 | } 65 | }); 66 | ``` 67 | 68 | 69 | ## Limits 70 | 71 | The [opencnam](http://www.opencnam.com "opencnam") API we use as a backend 72 | limits you to no more than 10 requests per hour (using the Free Tier). 73 | 74 | 75 | ## Changelog 76 | 77 | v0.1.1: 2012/03/26 78 | 79 | - Initial release! 80 | 81 | v0.1.2: 2015/02/26 82 | 83 | - Using v2 of the API 84 | 85 | v0.1.3: 2015/05/06 86 | 87 | - option to use the professional tier 88 | 89 | 90 | -------------------------------------------------------------------------------- /UNLICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /lib/opencnam.js: -------------------------------------------------------------------------------- 1 | // opencnam.js 2 | // 3 | // A simple node library for getting caller ID name information. 4 | 5 | 6 | var exports, request, OPENCNAM_API_URI; 7 | 8 | 9 | // Dependent libraries. 10 | request = require('request'); 11 | 12 | // Public facing OpenCNAM API endpoint. See: http://docs.opencnam.com/ 13 | OPENCNAM_API_URI = 'https://api.opencnam.com/v2/phone/' 14 | 15 | 16 | // Lookup the caller ID for the given phone number. 17 | exports.lookup = function(phone_number, options, callback) { 18 | if (callback === undefined && typeof options === 'function') { 19 | callback = options; 20 | options = undefined; 21 | } 22 | 23 | if (options === null || typeof options !== 'object') { 24 | options = {}; 25 | } 26 | 27 | // Validate phone_number or fail. 28 | if (!phone_number) { 29 | return callback(new Error('phone_number required.')); 30 | } 31 | 32 | phone_number = phone_number.replace(/[^\d.]/g, ''); 33 | phone_number = phone_number.substr(phone_number.length - 10); 34 | 35 | if (phone_number.length != 10) { 36 | return callback(new Error('phone_number must be 10 digits.')); 37 | } 38 | 39 | var uri = OPENCNAM_API_URI + phone_number + '?format=text'; 40 | 41 | if (options.account_sid) { 42 | uri += '&account_sid=' + encodeURIComponent(options.account_sid); 43 | } 44 | 45 | if (options.auth_token) { 46 | uri += '&auth_token=' + encodeURIComponent(options.auth_token); 47 | } 48 | 49 | // Query OpenCNAM, and return the resulting caller ID information. 50 | request(uri, function (error, response, body) { 51 | if (!error && response.statusCode == 200) { 52 | return callback(null, body); 53 | } else { 54 | return callback(new Error('No caller ID found.')); 55 | } 56 | }); 57 | 58 | }; 59 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "opencnam", 3 | "description": "A simple node library for getting caller ID name information.", 4 | "keywords": ["opencnam", "callerid", "api", "tools", "telephony", "simple"], 5 | "author": "Randall Degges ", 6 | "version": "0.1.3", 7 | "licenses": [{ 8 | "type": "UNLICENSE", 9 | "url": "http://github.com/telephonyresearch/node-opencnam/raw/master/UNLICENSE" 10 | }], 11 | "repository": { 12 | "type": "git", 13 | "url": "http://github.com/telephonyresearch/node-opencnam.git" 14 | }, 15 | "engines": { 16 | "node": ">=0.4.0" 17 | }, 18 | "dependencies": { 19 | "request": ">= 2.9.153" 20 | }, 21 | "main" : "./lib/opencnam" 22 | } 23 | -------------------------------------------------------------------------------- /tests/simple-cli-test.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env js 2 | 3 | /* 4 | ********************************************************************** 5 | WARNING: 6 | 7 | * tests for the professional tier will be charged to your account 8 | 9 | * tests for the hobbyist tier will count towards your hourly limit 10 | ********************************************************************** 11 | 12 | The Professional tier will only be tested if OPENCNAM_ACCOUNT_SID and 13 | OPENCNAM_AUTH_TOKEN are defined in your environment. 14 | 15 | */ 16 | 17 | var opencnam = require('opencnam'); 18 | 19 | var phonenumber = process.argv.slice(2)[0]; 20 | if (!phonenumber) { 21 | console.error("\nA phone number is required as an argument."); 22 | console.error("Aborting.\n"); 23 | process.exit(1); 24 | } 25 | 26 | var options = { 27 | account_sid: process.env["OPENCNAM_ACCOUNT_SID"], 28 | auth_token: process.env["OPENCNAM_AUTH_TOKEN"] 29 | }; 30 | 31 | options.set = (options.account_sid && options.auth_token) ? true:false; 32 | console.log('\n'); 33 | 34 | if (options.set) { 35 | opencnam.lookup(phonenumber, options, function (err, cnam) { 36 | console.log("==> Testing professional tier..."); 37 | if (!err){ 38 | console.log(cnam); 39 | } else { 40 | console.log(err); 41 | } 42 | console.log("OPENCNAM_ACCOUNT_SID and OPENCNAM_AUTH_TOKEN not set in the environment."); 43 | console.log("Professional tier will not be tested.\n"); 44 | }); 45 | } else { 46 | console.log("\n"); 47 | } 48 | 49 | opencnam.lookup(phonenumber, opts, function (err, cnam) { 50 | console.log("==> Testing hobbyist tier with new signature..."); 51 | if (!err){ 52 | console.log(cnam); 53 | } else { 54 | console.log(err); 55 | } 56 | console.log('\n'); 57 | }); 58 | 59 | var opts; 60 | opencnam.lookup(phonenumber, function (err, cnam) { 61 | console.log("==> Testing hobbyist tier with old signature..."); 62 | if (!err){ 63 | console.log(cnam); 64 | } else { 65 | console.log(err); 66 | } 67 | console.log('\n'); 68 | }); 69 | 70 | --------------------------------------------------------------------------------