| @@ 165-183 (lines=19) @@ | ||
| 162 | * @return Contact |
|
| 163 | * @throws LPTrackerSDKException |
|
| 164 | */ |
|
| 165 | public function saveContact(Contact $contact) |
|
| 166 | { |
|
| 167 | if ( ! $contact->validate()) { |
|
| 168 | throw new LPTrackerSDKException('Invalid contact'); |
|
| 169 | } |
|
| 170 | ||
| 171 | if ($contact->getId() > 0) { |
|
| 172 | $url = '/contact/'.$contact->getId(); |
|
| 173 | ||
| 174 | $response = LPTrackerRequest::sendRequest($url, $contact->toArray(), 'PUT', $this->token, $this->address); |
|
| 175 | } else { |
|
| 176 | $response = LPTrackerRequest::sendRequest('/contact', $contact->toArray(), 'POST', $this->token, |
|
| 177 | $this->address); |
|
| 178 | } |
|
| 179 | ||
| 180 | $resultContact = new Contact($response); |
|
| 181 | ||
| 182 | return $resultContact; |
|
| 183 | } |
|
| 184 | ||
| 185 | ||
| 186 | /** |
|
| @@ 253-270 (lines=18) @@ | ||
| 250 | * @return Lead |
|
| 251 | * @throws LPTrackerSDKException |
|
| 252 | */ |
|
| 253 | public function saveLead(Lead $lead) |
|
| 254 | { |
|
| 255 | if ( ! $lead->validate()) { |
|
| 256 | throw new LPTrackerSDKException('Invalid lead'); |
|
| 257 | } |
|
| 258 | ||
| 259 | if ($lead->getId() > 0) { |
|
| 260 | $url = '/lead/'.$lead->getId(); |
|
| 261 | ||
| 262 | $response = LPTrackerRequest::sendRequest($url, $lead->toArray(), 'PUT', $this->token, $this->address); |
|
| 263 | } else { |
|
| 264 | $response = LPTrackerRequest::sendRequest('/lead', $lead->toArray(), 'POST', $this->token, $this->address); |
|
| 265 | } |
|
| 266 | ||
| 267 | $resultLead = new Lead($response); |
|
| 268 | ||
| 269 | return $resultLead; |
|
| 270 | } |
|
| 271 | ||
| 272 | ||
| 273 | /** |
|