Example #1
0
 /**
  * @param Contact $contact
  * @return bool
  * @throws APIException
  * @throws \Exception
  */
 public function persist(Contact $contact)
 {
     $data = $contact->toGandiArray();
     if ($contact->isNew()) {
         $response = $this->gandi->create($this->api_key, $data);
         if (is_array($response)) {
             return $response['handle'];
         } else {
             throw new APIException("Cannot create contact.");
         }
     } else {
         $handle = $contact->getHandle();
         $response = $this->gandi->update($this->api_key, $handle, $data);
         if (is_array($response)) {
             return true;
         } else {
             throw new \Exception("Cannot update contact.");
         }
     }
 }