function add(fs_record $record) { switch (get_class($record)) { case 'fs_client': $data = harvest::get_client_xml($record); $path = 'clients'; $result = $this->post($path, $data); if ($result['status']['code'] != 201) { return false; } $ret = new fs_client($this); $ret->fields = $record->fields; $ret->id = preg_replace('`^[^\\d]+`', '', $result['headers']['Location']); return $ret; case 'fs_contact': list(, $parent) = func_get_args(); $path = 'contacts'; $data = harvest::get_contact_xml($record); $data->addChild('client-id', $parent); $data->{'client-id'}->addAttribute('type', 'integer'); $result = $this->post($path, $data); if (!$result) { return false; } if ($result['status']['code'] != 201) { return false; } $ret = new fs_contact($this); $ret->fields = $record->fields; $ret->id = preg_replace('`^[^\\d]+`', '', $result['headers']['Location']); return $ret; } }