Skip to content

Commit

Permalink
AmericanAncestors.org; closes rootsdev#11
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin York committed Mar 4, 2015
1 parent 0b782a3 commit aa7edf6
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 24 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ var genSearch = require('gen-search');

## Sites

* [americanancestors](#americanancestors)
* [ancestry](#ancestry)
* [archives](#archives)
* [billiongraves](#billiongraves)
Expand All @@ -102,6 +103,14 @@ var genSearch = require('gen-search');
* [werelate](#werelate)
* [worldvitalrecords](#worldvitalrecords)

### americanancestors

http://www.americanancestors.org/

```javascript
var url = gensearch('americanancestors', data);
```

### ancestry

http://ancestry.com
Expand Down
94 changes: 70 additions & 24 deletions gensearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var utils = _dereq_('./utils.js'),
// We have to explicitly list the sites, instead of
// dynamically loading, so that browserify can see them
var sites = {
'americanancestors': _dereq_('./sites/americanancestors.js'),
'ancestry': _dereq_('./sites/ancestry.js'),
'archives': _dereq_('./sites/archives.js'),
'billiongraves': _dereq_('./sites/billiongraves.js'),
Expand Down Expand Up @@ -61,7 +62,39 @@ search.config = function(site, siteConfig){
}
};

},{"./sites/ancestry.js":2,"./sites/archives.js":3,"./sites/billiongraves.js":4,"./sites/chroniclingamerica.js":5,"./sites/familysearch.js":6,"./sites/findagrave.js":7,"./sites/findmypast.co.uk.js":8,"./sites/findmypast.com.js":9,"./sites/fold3.js":11,"./sites/genealogieonline.js":12,"./sites/genealogybank.js":13,"./sites/geneanet.en.js":14,"./sites/geni.js":15,"./sites/google.js":16,"./sites/mocavo.js":17,"./sites/myheritage.js":18,"./sites/newspapers.js":19,"./sites/nlatrove.js":20,"./sites/openarchives.js":21,"./sites/usgenweb.js":22,"./sites/werelate.js":23,"./sites/worldvitalrecords.js":24,"./utils.js":25}],2:[function(_dereq_,module,exports){
},{"./sites/americanancestors.js":2,"./sites/ancestry.js":3,"./sites/archives.js":4,"./sites/billiongraves.js":5,"./sites/chroniclingamerica.js":6,"./sites/familysearch.js":7,"./sites/findagrave.js":8,"./sites/findmypast.co.uk.js":9,"./sites/findmypast.com.js":10,"./sites/fold3.js":12,"./sites/genealogieonline.js":13,"./sites/genealogybank.js":14,"./sites/geneanet.en.js":15,"./sites/geni.js":16,"./sites/google.js":17,"./sites/mocavo.js":18,"./sites/myheritage.js":19,"./sites/newspapers.js":20,"./sites/nlatrove.js":21,"./sites/openarchives.js":22,"./sites/usgenweb.js":23,"./sites/werelate.js":24,"./sites/worldvitalrecords.js":25,"./utils.js":26}],2:[function(_dereq_,module,exports){
var utils = _dereq_('../utils.js');

module.exports = function(config, data){

var url = 'http://www.americanancestors.org/search/database-search?';
var params = {};

if(data.givenName){
params.firstname = data.givenName;
}

if(data.familyName){
params.lastname = data.familyName;
}

if(data.birthDate){
params.fromyear = utils.getYear(data.birthDate);
}

if(data.deathDate){
params.toyear = utils.getYear(data.deathDate);
}

if(data.birthPlace){
params.location = data.birthPlace;
} else if(data.deathPlace){
params.location = data.deathPlace;
}

return url + utils.queryString(params);
};
},{"../utils.js":26}],3:[function(_dereq_,module,exports){
var utils = _dereq_('../utils.js');

module.exports = function(config, data){
Expand Down Expand Up @@ -106,7 +139,7 @@ module.exports = function(config, data){

};

},{"../utils.js":25}],3:[function(_dereq_,module,exports){
},{"../utils.js":26}],4:[function(_dereq_,module,exports){
var utils = _dereq_('../utils.js');

var defaultConfig = {
Expand Down Expand Up @@ -140,7 +173,7 @@ module.exports = function(config, data){

};

},{"../utils.js":25}],4:[function(_dereq_,module,exports){
},{"../utils.js":26}],5:[function(_dereq_,module,exports){
var utils = _dereq_('../utils.js');

var defaultConfig = {
Expand Down Expand Up @@ -173,7 +206,7 @@ module.exports = function(config, data){

};

},{"../utils.js":25}],5:[function(_dereq_,module,exports){
},{"../utils.js":26}],6:[function(_dereq_,module,exports){
var utils = _dereq_('../utils.js');

module.exports = function(config, data){
Expand Down Expand Up @@ -203,7 +236,7 @@ module.exports = function(config, data){

};

},{"../utils.js":25}],6:[function(_dereq_,module,exports){
},{"../utils.js":26}],7:[function(_dereq_,module,exports){
var utils = _dereq_('../utils.js');

var defaultConfig = {
Expand Down Expand Up @@ -292,7 +325,7 @@ function addQueryParam(query, queryParam, paramValue) {
}
return query;
};
},{"../utils.js":25}],7:[function(_dereq_,module,exports){
},{"../utils.js":26}],8:[function(_dereq_,module,exports){
var utils = _dereq_('../utils.js');

module.exports = function(config, data){
Expand Down Expand Up @@ -321,7 +354,7 @@ module.exports = function(config, data){

};

},{"../utils.js":25}],8:[function(_dereq_,module,exports){
},{"../utils.js":26}],9:[function(_dereq_,module,exports){
var utils = _dereq_('../utils.js'),
fmp = _dereq_('./findmypast.js');

Expand All @@ -335,7 +368,7 @@ module.exports = function(config, data){
config = utils.defaults(config, defaultConfig);
return fmp(config, data, 'co.uk');
};
},{"../utils.js":25,"./findmypast.js":10}],9:[function(_dereq_,module,exports){
},{"../utils.js":26,"./findmypast.js":11}],10:[function(_dereq_,module,exports){
var utils = _dereq_('../utils.js'),
fmp = _dereq_('./findmypast.js');

Expand All @@ -349,7 +382,7 @@ module.exports = function(config, data){
config = utils.defaults(config, defaultConfig);
return fmp(config, data, 'com');
};
},{"../utils.js":25,"./findmypast.js":10}],10:[function(_dereq_,module,exports){
},{"../utils.js":26,"./findmypast.js":11}],11:[function(_dereq_,module,exports){
/**
* This is not a site config. It is a common util for
* the findmypast sites that only differ in the TLD.
Expand Down Expand Up @@ -421,7 +454,7 @@ module.exports = function(config, data, tld){
return baseUrl + query;

};
},{"../utils.js":25}],11:[function(_dereq_,module,exports){
},{"../utils.js":26}],12:[function(_dereq_,module,exports){
var utils = _dereq_('../utils.js');

module.exports = function(config, data){
Expand All @@ -447,7 +480,7 @@ module.exports = function(config, data){

};

},{"../utils.js":25}],12:[function(_dereq_,module,exports){
},{"../utils.js":26}],13:[function(_dereq_,module,exports){
var utils = _dereq_('../utils.js');

var defaultConfig = {
Expand Down Expand Up @@ -504,7 +537,7 @@ module.exports = function(config, data){

};

},{"../utils.js":25}],13:[function(_dereq_,module,exports){
},{"../utils.js":26}],14:[function(_dereq_,module,exports){
var utils = _dereq_('../utils.js');

var defaultConfig = {
Expand Down Expand Up @@ -567,7 +600,7 @@ module.exports = function(config, data){

};

},{"../utils.js":25}],14:[function(_dereq_,module,exports){
},{"../utils.js":26}],15:[function(_dereq_,module,exports){
var utils = _dereq_('../utils.js');

var defaultConfig = {
Expand Down Expand Up @@ -608,7 +641,7 @@ module.exports = function(config, data){
return url + query;

};
},{"../utils.js":25}],15:[function(_dereq_,module,exports){
},{"../utils.js":26}],16:[function(_dereq_,module,exports){
var utils = _dereq_('../utils.js');

module.exports = function(config, data){
Expand All @@ -634,7 +667,7 @@ module.exports = function(config, data){

};

},{"../utils.js":25}],16:[function(_dereq_,module,exports){
},{"../utils.js":26}],17:[function(_dereq_,module,exports){
var utils = _dereq_('../utils.js');

module.exports = function(config, data){
Expand All @@ -655,7 +688,7 @@ module.exports = function(config, data){

return url += encodeURIComponent(searchWords.join(' '));
};
},{"../utils.js":25}],17:[function(_dereq_,module,exports){
},{"../utils.js":26}],18:[function(_dereq_,module,exports){
var utils = _dereq_('../utils.js');

module.exports = function(config, data){
Expand All @@ -671,7 +704,7 @@ module.exports = function(config, data){

return url;
};
},{"../utils.js":25}],18:[function(_dereq_,module,exports){
},{"../utils.js":26}],19:[function(_dereq_,module,exports){
var utils = _dereq_('../utils.js');

module.exports = function(config, data){
Expand Down Expand Up @@ -770,7 +803,7 @@ function fixSpace(str){
return str.replace(/ /g, '%2F3');
}

},{"../utils.js":25}],19:[function(_dereq_,module,exports){
},{"../utils.js":26}],20:[function(_dereq_,module,exports){
var utils = _dereq_('../utils.js');

var defaultConfig = {
Expand Down Expand Up @@ -840,7 +873,7 @@ module.exports = function(config, data){

};

},{"../utils.js":25}],20:[function(_dereq_,module,exports){
},{"../utils.js":26}],21:[function(_dereq_,module,exports){
var utils = _dereq_('../utils.js');

module.exports = function(config, data){
Expand All @@ -857,7 +890,7 @@ module.exports = function(config, data){

return url + encodeURIComponent(parts.join(' '));
};
},{"../utils.js":25}],21:[function(_dereq_,module,exports){
},{"../utils.js":26}],22:[function(_dereq_,module,exports){
var utils = _dereq_('../utils.js');

module.exports = function(config, data){
Expand All @@ -882,7 +915,7 @@ module.exports = function(config, data){
return url + query;

};
},{"../utils.js":25}],22:[function(_dereq_,module,exports){
},{"../utils.js":26}],23:[function(_dereq_,module,exports){
var utils = _dereq_('../utils.js');

module.exports = function(config, data){
Expand All @@ -904,7 +937,7 @@ module.exports = function(config, data){
return url + query;

};
},{"../utils.js":25}],23:[function(_dereq_,module,exports){
},{"../utils.js":26}],24:[function(_dereq_,module,exports){
var utils = _dereq_('../utils.js');

var defaultConfig = {
Expand Down Expand Up @@ -953,7 +986,7 @@ module.exports = function(config, data){

};

},{"../utils.js":25}],24:[function(_dereq_,module,exports){
},{"../utils.js":26}],25:[function(_dereq_,module,exports){
var utils = _dereq_('../utils.js');

var defaultConfig = {
Expand Down Expand Up @@ -993,7 +1026,7 @@ module.exports = function(config, data){

};

},{"../utils.js":25}],25:[function(_dereq_,module,exports){
},{"../utils.js":26}],26:[function(_dereq_,module,exports){
var utils = {};

/**
Expand Down Expand Up @@ -1024,6 +1057,19 @@ utils.addQueryParam = function(query, name, value){
return query;
};

/**
* Take in a map of param names and values
* and return an encoded query string
* without the leading '?'
*/
utils.queryString = function(params){
var parts = [];
utils.each(params, function(val, key){
parts.push(key + '=' + encodeURIComponent(val));
});
return parts.join('&');
};

/**
* Functions lifted from underscore.js
* http://underscorejs.org/
Expand Down
1 change: 1 addition & 0 deletions src/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var utils = require('./utils.js'),
// We have to explicitly list the sites, instead of
// dynamically loading, so that browserify can see them
var sites = {
'americanancestors': require('./sites/americanancestors.js'),
'ancestry': require('./sites/ancestry.js'),
'archives': require('./sites/archives.js'),
'billiongraves': require('./sites/billiongraves.js'),
Expand Down
31 changes: 31 additions & 0 deletions src/sites/americanancestors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
var utils = require('../utils.js');

module.exports = function(config, data){

var url = 'http://www.americanancestors.org/search/database-search?';
var params = {};

if(data.givenName){
params.firstname = data.givenName;
}

if(data.familyName){
params.lastname = data.familyName;
}

if(data.birthDate){
params.fromyear = utils.getYear(data.birthDate);
}

if(data.deathDate){
params.toyear = utils.getYear(data.deathDate);
}

if(data.birthPlace){
params.location = data.birthPlace;
} else if(data.deathPlace){
params.location = data.deathPlace;
}

return url + utils.queryString(params);
};
13 changes: 13 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ utils.addQueryParam = function(query, name, value){
return query;
};

/**
* Take in a map of param names and values
* and return an encoded query string
* without the leading '?'
*/
utils.queryString = function(params){
var parts = [];
utils.each(params, function(val, key){
parts.push(key + '=' + encodeURIComponent(val));
});
return parts.join('&');
};

/**
* Functions lifted from underscore.js
* http://underscorejs.org/
Expand Down
20 changes: 20 additions & 0 deletions test/sites/americanancestors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var test = require('../tester.js')('americanancestors'),
utils = require(require('path').join(__dirname, '..', '..', 'src', 'utils.js'));

describe('americanancestors', function(){

it('1', function(){
test(test.data[0], 'http://www.americanancestors.org/search/database-search?firstname=Joe%20William&lastname=Clark');
});

it('2', function(){
test(test.data[1], 'http://www.americanancestors.org/search/database-search?firstname=Joe%20William&lastname=Clark&fromyear=1835&toyear=1889&location=Texas');
});

it('use death place when birth place is not available', function(){
var data = utils.extend({}, test.data[1]);
delete data.birthPlace;
test(data, 'http://www.americanancestors.org/search/database-search?firstname=Joe%20William&lastname=Clark&fromyear=1835&toyear=1889&location=Springfield%2C%20Illinois');
});

});
7 changes: 7 additions & 0 deletions test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,11 @@ describe('utils', function(){
assert.deepEqual(utils.extend({}, {one:1},{two:2},{one:3}), {one:3,two:2});
});

it('queryString', function(){
assert.equal(utils.queryString({
'some': 'vals,',
'more': 'we-rd'
}), 'some=vals%2C&more=we-rd');
});

});

0 comments on commit aa7edf6

Please sign in to comment.