This helper kit allows you to use the Rapleaf Address Book API through direct PHP function calls. It fetches the XML response from the Rapleaf server and returns a corresponding PHP object.
Step 1: Include the library
require_once 'rapleaf_abook.php';
Step 2: Initialize an address book object. You can find your API key here.
$abook = new RapleafAbook($api_key);
Step 3: Query the API for the contact list. You need to get the user's email address and password through a form; see sample.php for an example.
$result = $abook->getData($email, $password);
The returned result has the following structure:
$result = ( 'status' => '200', # HTTP status code returned by the server 'error' => '', # error message if there are any 'contacts' => ( # contact list ([name]=>'dummy', [email]=>'dummy@rapleaf.com'), ([name]=>'dummy2', [email]=>'dummy2@rapleaf.com'), ... ) );
You should check the status before attempting to process the contact list. The following example lists the contacts on success, prints the error message otherwise.
$html = '';
if ($result['status']=='200') { # OK
$contacts = $result['contacts'];
foreach ($contacts as $contact) {
$html.= htmlentities($contact['name'].' <'.$contact['email'].'>');
$html.='<br />';
}
} else {
$html = $result['status'].': '.$result['error'];
}
echo $html;