| @@ 203-221 (lines=19) @@ | ||
| 200 | * @return Contact |
|
| 201 | * @throws LPTrackerSDKException |
|
| 202 | */ |
|
| 203 | public function saveContact(Contact $contact) |
|
| 204 | { |
|
| 205 | if ( ! $contact->validate()) { |
|
| 206 | throw new LPTrackerSDKException('Invalid contact'); |
|
| 207 | } |
|
| 208 | ||
| 209 | if ($contact->getId() > 0) { |
|
| 210 | $url = '/contact/'.$contact->getId(); |
|
| 211 | ||
| 212 | $response = LPTrackerRequest::sendRequest($url, $contact->toArray(), 'PUT', $this->token, $this->address); |
|
| 213 | } else { |
|
| 214 | $response = LPTrackerRequest::sendRequest('/contact', $contact->toArray(), 'POST', $this->token, |
|
| 215 | $this->address); |
|
| 216 | } |
|
| 217 | ||
| 218 | $resultContact = new Contact($response); |
|
| 219 | ||
| 220 | return $resultContact; |
|
| 221 | } |
|
| 222 | ||
| 223 | ||
| 224 | /** |
|
| @@ 403-420 (lines=18) @@ | ||
| 400 | * @return Lead |
|
| 401 | * @throws LPTrackerSDKException |
|
| 402 | */ |
|
| 403 | public function saveLead(Lead $lead) |
|
| 404 | { |
|
| 405 | if ( ! $lead->validate()) { |
|
| 406 | throw new LPTrackerSDKException('Invalid lead'); |
|
| 407 | } |
|
| 408 | ||
| 409 | if ($lead->getId() > 0) { |
|
| 410 | $url = '/lead/'.$lead->getId(); |
|
| 411 | ||
| 412 | $response = LPTrackerRequest::sendRequest($url, $lead->toArray(), 'PUT', $this->token, $this->address); |
|
| 413 | } else { |
|
| 414 | $response = LPTrackerRequest::sendRequest('/lead', $lead->toArray(), 'POST', $this->token, $this->address); |
|
| 415 | } |
|
| 416 | ||
| 417 | $resultLead = new Lead($response); |
|
| 418 | ||
| 419 | return $resultLead; |
|
| 420 | } |
|
| 421 | ||
| 422 | ||
| 423 | /** |
|