public
Description: OneBody is free, open-source, web-based social networking and online directory software for churches.
Home | Edit | New

HashifyPeople

The “hashify” API method is used to compare local records to remote ones, to determine if changes were made that need to be pushed to the remote end.

POST to /people/hashify.xml

Arguments

  • attrs – list of attributes (separated by comma) to use for hashing
  • legacy-id – list of legacy_ids (separated by comma) of records to hash (note the dash instead of underscore, because when placed in XML, underscore cannot be used)
  • debug (optional) – set to “true” to instruct OneBody to return real data values instead of SHA1 hash (good for debugging, obviously)

Returns

XML containing SHA1 hash of each record. Use this to determine which records to update in the remote system. Compare the returned hash to a hash you perform on the client side.

Hashing Values

See http://github.com/seven1m/onebody-updateagent/blob/master/lib/updateagent/hash_extensions.rb for example Ruby code.

To create the hash on the client side, get the value for each attribute (the same list of “attrs” you pass to the hashify call), concatenate them end-to-end (without any separators), and perform an SHA1 hash on the entire string.

Note that date/time values are written as YYYY-MM-DD HH:MM:SS, true is written as 1, and false is written as 2. All other string values are written as-is.

Note About Server Load

We recommend you do 100 hashes at a time, and sleep 5 seconds after each request to keep the load on the server low.

Example

curl -u superuser@example.com:APIKEYHERE -d="<?xml version='1.0' encoding='UTF-8'?><hash><legacy-id>1806,1807</legacy-id><attrs>first_name,last_name</attrs></hash>" -H "Content-Type: text/xml" http://mysite.com/people/hashify.xml

…returns:

<?xml version="1.0" encoding="UTF-8"?>
<records type="array">
  <record>
    <hash>55e62464f4ad276cb579ab8590e5f66aa0f46667</hash>
    <id>27942</id>
    <legacy-id>1806</legacy-id>
  </record>
  <record>
    <hash>a4109764305dfb51d7ebf295811ada02238bd16d</hash>
    <id>27943</id>
    <legacy-id>1807</legacy-id>
  </record>
</records>

Here we requested two hashes, one for legacy_id 1806, and one for 1807. We asked to hash only the attributes “first_name” and “last_name”.

Now, to get the hash locally, we do something like this:
SHA1("<first_name><last_name>") which would be SHA1("TimMorgan")

To compare more attributes, just tack them on:
attrs=first_name,last_name,birthday
SHA1("TimMorgan1981-04-28 00:00:00")

On the client side, compare the hash you received from the POST and the hash you generated locally. If they are different, then the record needs to be updated remotely.

Last edited by seven1m, Thu Oct 01 15:31:46 -0700 2009
Home | Edit | New
Versions: