Skip to content

Commit

Permalink
Merge pull request #40 from brezelman/newFamilySearchApi
Browse files Browse the repository at this point in the history
New FamilySearch API
  • Loading branch information
Justin authored Aug 10, 2019
2 parents 4f663bd + e0270e9 commit f87880a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 30 deletions.
34 changes: 8 additions & 26 deletions src/sites/familysearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = function(config, data){

config = utils.defaults(config, defaultConfig);

var fsURL = 'https://www.familysearch.org/search/record/results?count=20&query=';
var fsURL = 'https://www.familysearch.org/search/record/results?count=20';
var query = '';

// Simple mappings from the person data object to fs params
Expand All @@ -30,59 +30,41 @@ module.exports = function(config, data){
];
utils.each(simpleMappings, function(map) {
if( data[map[1]] ) {
query = addQueryParam(query, map[0], data[map[1]]);
query = utils.addQueryParam(query, map[0], data[map[1]]);
}
});

// Process the birth year
if(data.birthDate){
var birthYear = utils.getYearInt(data.birthDate);
if( birthYear ) {
query = addQueryParam(query, 'birth_year', (birthYear - config.birthRange)+'-'+(birthYear + config.birthRange));
query = utils.addQueryParam(query, 'birth_year_from', birthYear - config.birthRange);
query = utils.addQueryParam(query, 'birth_year_to', birthYear + config.birthRange)
}
}

// Process the death year
if(data.deathDate){
var deathYear = utils.getYearInt(data.deathDate);
if( deathYear ) {
query = addQueryParam(query, 'death_year', (deathYear - config.deathRange)+'-'+(deathYear + config.deathRange));
query = utils.addQueryParam(query, 'death_year_from', deathYear - config.deathRange);
query = utils.addQueryParam(query, 'death_year_to', deathYear + config.deathRange);
}
}

// Process the marriage year
if(data.marriageDate){
var marriageYear = utils.getYearInt(data.marriageDate);
if( marriageYear ) {
query = addQueryParam(query, 'marriage_year', (marriageYear - config.marriageRange)+'-'+(marriageYear + config.marriageRange));
query = utils.addQueryParam(query, 'marriage_year_from', marriageYear - config.marriageRange);
query = utils.addQueryParam(query, 'marriage_year_to', marriageYear + config.marriageRange);
}
}

query = encodeURIComponent(query);

if(config.collectionId){
query = utils.addQueryParam(query, 'collection_id', config.collectionId);
}

return fsURL + query;

};

/**
* Add a query parameter to the current query
*/
function addQueryParam(query, queryParam, paramValue) {
if(paramValue){
if(query) {
query += ' ';
}
query += '+' + queryParam + ':';
// if the value has a space, wrap it in quotes
if(paramValue.indexOf(' ') >= 0) {
query += '"' + paramValue + '"~';
} else {
query += paramValue + '~';
}
}
return query;
};
8 changes: 4 additions & 4 deletions test/sites/familysearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ var test = require('../tester.js')('familysearch');
describe('familysearch', function(){

it('1', function(){
test(test.data[0], 'https://www.familysearch.org/search/record/results?count=20&query=%2Bgivenname%3A%22Joe%20William%22~%20%2Bsurname%3AClark~');
test(test.data[0], 'https://www.familysearch.org/search/record/results?count=20&givenname=Joe%20William&surname=Clark');
});

it('2', function(){
test(test.data[1], 'https://www.familysearch.org/search/record/results?count=20&query=%2Bgivenname%3A%22Joe%20William%22~%20%2Bsurname%3AClark~%20%2Bbirth_place%3ATexas~%20%2Bdeath_place%3A%22Springfield%2C%20Illinois%22~%20%2Bfather_givenname%3ADale~%20%2Bfather_surname%3AClark~%20%2Bmother_givenname%3ASusan~%20%2Bmother_surname%3AAnthony~%20%2Bspouse_givenname%3AJennifer~%20%2Bspouse_surname%3AThomas~%20%2Bmarriage_place%3A%22St%20Louis%2C%20MO%22~%20%2Bbirth_year%3A1833-1837~%20%2Bdeath_year%3A1887-1891~%20%2Bmarriage_year%3A1856-1860~');
test(test.data[1], 'https://www.familysearch.org/search/record/results?count=20&givenname=Joe%20William&surname=Clark&birth_place=Texas&death_place=Springfield%2C%20Illinois&father_givenname=Dale&father_surname=Clark&mother_givenname=Susan&mother_surname=Anthony&spouse_givenname=Jennifer&spouse_surname=Thomas&marriage_place=St%20Louis%2C%20MO&birth_year_from=1833&birth_year_to=1837&death_year_from=1887&death_year_to=1891&marriage_year_from=1856&marriage_year_to=1860');
});

it('config', function(){
test(test.data[1], 'https://www.familysearch.org/search/record/results?count=20&query=%2Bgivenname%3A%22Joe%20William%22~%20%2Bsurname%3AClark~%20%2Bbirth_place%3ATexas~%20%2Bdeath_place%3A%22Springfield%2C%20Illinois%22~%20%2Bfather_givenname%3ADale~%20%2Bfather_surname%3AClark~%20%2Bmother_givenname%3ASusan~%20%2Bmother_surname%3AAnthony~%20%2Bspouse_givenname%3AJennifer~%20%2Bspouse_surname%3AThomas~%20%2Bmarriage_place%3A%22St%20Louis%2C%20MO%22~%20%2Bbirth_year%3A1832-1838~%20%2Bdeath_year%3A1885-1893~%20%2Bmarriage_year%3A1853-1863~', {
test(test.data[1], 'https://www.familysearch.org/search/record/results?count=20&givenname=Joe%20William&surname=Clark&birth_place=Texas&death_place=Springfield%2C%20Illinois&father_givenname=Dale&father_surname=Clark&mother_givenname=Susan&mother_surname=Anthony&spouse_givenname=Jennifer&spouse_surname=Thomas&marriage_place=St%20Louis%2C%20MO&birth_year_from=1832&birth_year_to=1838&death_year_from=1885&death_year_to=1893&marriage_year_from=1853&marriage_year_to=1863', {
birthRange: 3,
deathRange: 4,
marriageRange: 5
});
});

it('collection', function(){
test(test.data[0], 'https://www.familysearch.org/search/record/results?count=20&query=%2Bgivenname%3A%22Joe%20William%22~%20%2Bsurname%3AClark~&collection_id=1473014', {
test(test.data[0], 'https://www.familysearch.org/search/record/results?count=20&givenname=Joe%20William&surname=Clark&collection_id=1473014', {
collectionId: 1473014
});
});
Expand Down

0 comments on commit f87880a

Please sign in to comment.