/** * Post Person * * @param Batchblue_Service_BatchBook_Person $person * @return Batchblue_Service_BatchBook_PersonService Provides a fluent interface */ public function postPerson(Batchblue_Service_BatchBook_Person $person) { $httpClient = new Zend_Http_Client('https://' . $this->_accountName . '.batchbook.com/service/people.xml'); $httpClient->setParameterPost('person[first_name]', $person->getFirstName()); $httpClient->setParameterPost('person[last_name]', $person->getLastName()); $httpClient->setParameterPost('person[title]', $person->getTitle()); $httpClient->setParameterPost('person[company]', $person->getCompany()); $httpClient->setParameterPost('person[notes]', $person->getNotes()); $personLocations = $person->getLocations(); $httpClient->setAuth($this->_token, 'x'); $response = $httpClient->request(Zend_Http_Client::POST); if (201 != $response->getStatus()) { //TODO: throw more specific exception throw new Exception('Person not created.'); } $location = $response->getHeader('location'); $httpClient = new Zend_Http_Client($location); $httpClient->setAuth($this->_token, 'x'); $response = $httpClient->request(Zend_Http_Client::GET); $xmlResponse = simplexml_load_string($response->getBody()); $this->_populatePersonFromXmlElement($xmlResponse, $person); if ($personLocations != null) { $this->postLocationsOnPerson($person, $personLocations); } return $this; }