From a4bf31f3e81ba9254caf6fc870db7891212977df Mon Sep 17 00:00:00 2001 From: Peter Henderson Date: Fri, 25 Feb 2011 10:13:37 -0700 Subject: [PATCH] Implement and document Person Version Read --- CHANGELOG.rst | 1 + README.rst | 6 ++++++ ROADMAP.rst | 2 +- familysearch/familytree_v2.py | 16 ++++++++++++++++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index befe583..8ec58b0 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -6,6 +6,7 @@ --- * Supports Authorities requests (place, name, date, and culture) +* Supports Person Version Read * Properly sends session ID on first request without needing to call session() * Search and Match return a single object instead of a one-item list * Supports pickling using any protocol (0-2) diff --git a/README.rst b/README.rst index 0bf49a2..cb020f5 100644 --- a/README.rst +++ b/README.rst @@ -106,6 +106,12 @@ pass additional parameters to the API, simply pass them as named arguments:: print fs.person(['ABCD-123', 'EFGH-456'], events='all', children='all') +Print the latest version of a list of persons (this request is more lightweight +than a full person request, so it supports more IDs at once):: + + for person in fs.version(['ABCD-123', 'EFGH-456']): + print person['id'], person['version'] + Print current user's pedigree:: print fs.pedigree() diff --git a/ROADMAP.rst b/ROADMAP.rst index c061432..13683cd 100644 --- a/ROADMAP.rst +++ b/ROADMAP.rst @@ -17,6 +17,7 @@ --- - Authorities Read +- Person Version Read - Unit tests - Convenience methods to access FamilySearch's data model @@ -26,7 +27,6 @@ Future - Use persistent HTTP connections instead of a new connection for each request - Ensure Python 3 compatibility -- Person Version Read - Person Update - Relationship Read - Relationship Update diff --git a/familysearch/familytree_v2.py b/familysearch/familytree_v2.py index 2eda89a..3dfe324 100644 --- a/familysearch/familytree_v2.py +++ b/familysearch/familytree_v2.py @@ -57,6 +57,22 @@ def person(self, person_id=None, options={}, **kw_options): else: return response + def version(self, person_id): + """ + Read the latest version of a person or list of persons from the family tree. + """ + if isinstance(person_id, list): + person_id = ','.join(person_id) + url = self.familytree_base + 'version' + if person_id: + url = self._add_subpath(url, person_id) + response = json.load(self._request(url))['versions'] + response = self._remove_nones(response) + if len(response) == 1: + return response[0] + else: + return response + def pedigree(self, person_id=None, options={}, **kw_options): """ Get a pedigree for the given person or list of persons from the family tree.