Skip to content

Commit

Permalink
Merge pull request #3 from brozeph/v0.1.4
Browse files Browse the repository at this point in the history
V0.1.4
  • Loading branch information
brozeph committed Dec 30, 2014
2 parents 687c348 + b4e2855 commit 36a696e
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 19 deletions.
3 changes: 0 additions & 3 deletions .jshintrc
Expand Up @@ -26,9 +26,6 @@
"beforeEach" : true,
"describe" : true,
"it" : true,
"req" : true,
"requestError" : true,
"requireWithCoverage" : true,
"should" : true
}
}
7 changes: 7 additions & 0 deletions 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
Expand Down
19 changes: 16 additions & 3 deletions lib/index.js
Expand Up @@ -4,8 +4,6 @@ var request = require('request');
var threeTaps = (function (self) {
'use strict';

self = self || {};

var defaultOptions = {
apikey : '',
pollingUrl : 'https://polling.3taps.com',
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions 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": {
Expand All @@ -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",
Expand Down
22 changes: 12 additions & 10 deletions readme.md
Expand Up @@ -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
Expand All @@ -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
Expand Down
105 changes: 104 additions & 1 deletion test/lib/index.js
Expand Up @@ -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 () {

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 36a696e

Please sign in to comment.