| @@ 482-499 (lines=18) @@ | ||
| 479 | * @return View |
|
| 480 | * @throws LPTrackerSDKException |
|
| 481 | */ |
|
| 482 | public function saveView(View $view) |
|
| 483 | { |
|
| 484 | if ( ! $view->validate()) { |
|
| 485 | throw new LPTrackerSDKException('Invalid view'); |
|
| 486 | } |
|
| 487 | ||
| 488 | if ($view->getId() > 0) { |
|
| 489 | $url = '/view/'.$view->getId(); |
|
| 490 | ||
| 491 | $response = LPTrackerRequest::sendRequest($url, $view->toArray(), 'PUT', $this->token, $this->address); |
|
| 492 | } else { |
|
| 493 | $response = LPTrackerRequest::sendRequest('/view', $view->toArray(), 'POST', $this->token, $this->address); |
|
| 494 | } |
|
| 495 | ||
| 496 | $resultView = new View($response); |
|
| 497 | ||
| 498 | return $resultView; |
|
| 499 | } |
|
| 500 | ||
| 501 | ||
| 502 | /** |
|
| @@ 595-612 (lines=18) @@ | ||
| 592 | * @return Lead |
|
| 593 | * @throws LPTrackerSDKException |
|
| 594 | */ |
|
| 595 | public function saveLead(Lead $lead) |
|
| 596 | { |
|
| 597 | if ( ! $lead->validate()) { |
|
| 598 | throw new LPTrackerSDKException('Invalid lead'); |
|
| 599 | } |
|
| 600 | ||
| 601 | if ($lead->getId() > 0) { |
|
| 602 | $url = '/lead/'.$lead->getId(); |
|
| 603 | ||
| 604 | $response = LPTrackerRequest::sendRequest($url, $lead->toArray(true), 'PUT', $this->token, $this->address); |
|
| 605 | } else { |
|
| 606 | $response = LPTrackerRequest::sendRequest('/lead', $lead->toArray(true), 'POST', $this->token, |
|
| 607 | $this->address); |
|
| 608 | } |
|
| 609 | ||
| 610 | $resultLead = new Lead($response); |
|
| 611 | ||
| 612 | return $resultLead; |
|
| 613 | } |
|
| 614 | ||
| 615 | ||