diff --git a/.jshintrc b/.jshintrc index 7943d3b..b374524 100644 --- a/.jshintrc +++ b/.jshintrc @@ -26,9 +26,6 @@ "beforeEach" : true, "describe" : true, "it" : true, - "req" : true, - "requestError" : true, - "requireWithCoverage" : true, "should" : true } } diff --git a/history.md b/history.md index 6af4baa..58dafee 100644 --- a/history.md +++ b/history.md @@ -1,3 +1,10 @@ +# v0.1.4 - 2014/12/30 + +* Methods #poll and #search optionally accept retvals parameter as an array +* Methods #poll and #search optionally accept location parameters as an object +* Increasing unit test code coverage +* Updated gulp development dependency and tightened up jshint + # v0.1.3 - 2014/12/09 * Fixing defect in #poll method where location parameters were not properly parsed or sent diff --git a/lib/index.js b/lib/index.js index f01c510..8f12a5e 100644 --- a/lib/index.js +++ b/lib/index.js @@ -4,8 +4,6 @@ var request = require('request'); var threeTaps = (function (self) { 'use strict'; - self = self || {}; - var defaultOptions = { apikey : '', pollingUrl : 'https://polling.3taps.com', @@ -37,7 +35,22 @@ var threeTaps = (function (self) { } function getParam (paramName, options) { - return options[paramName] || self.options[paramName]; + var value = options[paramName] || self.options[paramName]; + + // look for location as child object in options if applicable + if (/^location\./.test(paramName) && + !value && + typeof options.location !== 'undefined') { + value = options.location[ + paramName.substring(paramName.indexOf('.') + 1)]; + } + + // convert retvals from array to comma delim string value if applicable + if (paramName === 'retvals' && Array.isArray(value)) { + value = value.join(','); + } + + return value; } function makeRequest (requestOptions, callback) { diff --git a/package.json b/package.json index 0db709b..52158d6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "3taps", - "version": "0.1.3", + "version": "0.1.4", "description": "Node client for 3taps API", "main": "./lib", "scripts": { @@ -17,7 +17,7 @@ "license": "MIT", "devDependencies": { "chai": "^1.10.0", - "del": "^1.0.0", + "del": "^1.1.0", "gulp": "^3.8.10", "gulp-coveralls": "^0.1.3", "gulp-istanbul": "^0.5.0", diff --git a/readme.md b/readme.md index 1ba0877..a8d0201 100644 --- a/readme.md +++ b/readme.md @@ -126,15 +126,17 @@ var options = { anchor : 12345, // optional category : '', // optional - 3taps category code, supports logical operators 'category_group' : '', // optional - 3taps category_group code, supports logical operators - 'location.city' : '', // optional - desired City, supports logical operators - 'location.country' : '', // optional - desired Country code, supports logical operators - 'location.county' : '', // optional - desired County code, supports logical operators - 'location.locality' : '', // optional - 3taps Locality code, supports logical operators - 'location.metro' : '', // optional - 3taps Metro Area code, supports logical operators - 'location.region' : '', // optional - 3taps Region code, supports logical operators - 'location.state' : '', // optional - 3taps City code, supports logical operators - 'location.zipcode' : '', // optional - desired Zip Code, supports logical operators - retvals : '', // optional - list of fields to return (see below) + 'location' : { + 'city' : '', // optional - desired City, supports logical operators + 'country' : '', // optional - desired Country code, supports logical operators + 'county' : '', // optional - desired County code, supports logical operators + 'locality' : '', // optional - 3taps Locality code, supports logical operators + 'metro' : '', // optional - 3taps Metro Area code, supports logical operators + 'region' : '', // optional - 3taps Region code, supports logical operators + 'state' : '', // optional - 3taps City code, supports logical operators + 'zipcode' : '' // optional - desired Zip Code, supports logical operators + }, + retvals : [''], // optional - list of fields to return (see below) source : '', // optional - 3taps Data Source code, supports logical operators state : '', // optional - state of the posting (see below), supports logical operators status : '' // optional - status of the posting (see below), supports logical operators @@ -147,7 +149,7 @@ threeTapsClient.poll(options, function (err, data) { ###### retvals -The retvals parameter supports a comma separated list of values from the following: +The retvals parameter supports an array or a comma separated list of values from the following: * id * account_id diff --git a/test/lib/index.js b/test/lib/index.js index 4204a08..b947d5f 100644 --- a/test/lib/index.js +++ b/test/lib/index.js @@ -55,6 +55,14 @@ describe('3taps', function () { }; }); + // test constructor + it('should accept null or empty options', function() { + client = threeTaps(); + + should.exist(client); + should.exist(client.options); + }); + // tests for the polling API describe('polling', function () { @@ -201,6 +209,49 @@ describe('3taps', function () { }); }); + it('should accept retvals param as an array', function (done) { + client.poll({ + retvals : ['one', 'two', 'three'] + }, function (err, data) { + should.not.exist(err); + should.exist(data); + + should.exist(requestQuery.query.retvals); + requestQuery.query.retvals.should.equal('one,two,three'); + + return done(); + }); + }); + + it('should support location as sub-object', function (done) { + client.poll({ + location : { + city : 'test city', + country : 'test country', + county : 'test county', + locality : 'test locality', + metro : 'test metro', + region : 'test region', + state : 'test state', + zipcode : 'test zip' + } + }, function (err, data) { + should.not.exist(err); + should.exist(data); + + should.exist(requestQuery.query['location.city']); + should.exist(requestQuery.query['location.country']); + should.exist(requestQuery.query['location.county']); + should.exist(requestQuery.query['location.locality']); + should.exist(requestQuery.query['location.metro']); + should.exist(requestQuery.query['location.region']); + should.exist(requestQuery.query['location.state']); + should.exist(requestQuery.query['location.zipcode']); + + return done(); + }); + }); + it('should support all params', function (done) { client.poll({ anchor : 12345, @@ -419,6 +470,58 @@ describe('3taps', function () { }); }); + it('should search without options', function (done) { + client.search(function (err, data) { + should.not.exist(err); + should.exist(data); + + return done(); + }); + }); + + it('should accept retvals param as an array', function (done) { + client.search({ + retvals : ['one', 'two', 'three'] + }, function (err, data) { + should.not.exist(err); + should.exist(data); + + should.exist(requestQuery.query.retvals); + requestQuery.query.retvals.should.equal('one,two,three'); + + return done(); + }); + }); + + it('should support location as sub-object', function (done) { + client.search({ + location : { + city : 'test city', + country : 'test country', + county : 'test county', + locality : 'test locality', + metro : 'test metro', + region : 'test region', + state : 'test state', + zipcode : 'test zip' + } + }, function (err, data) { + should.not.exist(err); + should.exist(data); + + should.exist(requestQuery.query['location.city']); + should.exist(requestQuery.query['location.country']); + should.exist(requestQuery.query['location.county']); + should.exist(requestQuery.query['location.locality']); + should.exist(requestQuery.query['location.metro']); + should.exist(requestQuery.query['location.region']); + should.exist(requestQuery.query['location.state']); + should.exist(requestQuery.query['location.zipcode']); + + return done(); + }); + }); + it('should support all params', function (done) { client.search({ category : 'test category', @@ -456,7 +559,7 @@ describe('3taps', function () { anchor : 12345, count : 10, page : 1, - retvals : 'test', + retvals : 'one,two,three', rpp : 50, sort : 'test', tier : 1