File: D:/HostingSpaces/farmfun/reserveren.farmfun.be/app/Komma/Teamleader/Endpoints/ContactEndpoint.php
<?php
namespace App\Komma\Teamleader\Endpoints;
use App\Komma\Teamleader\Base\ApiException;
use App\Komma\Teamleader\Base\ApiResponse;
use App\Komma\Teamleader\Base\Endpoint;
use App\Komma\Teamleader\Resources\Contact;
use App\Komma\Teamleader\TeamleaderApi;
use GuzzleHttp\Psr7\Request;
final class ContactEndpoint extends Endpoint
{
protected string $resourceClass = Contact::class;
/**
* Get a list of the recipes
*
* @param array $params
* @return ApiResponse
* @throws ApiException
*/
public function list(array $params = []): ApiResponse
{
$apiResponse = new ApiResponse($this->resourceClass, 'list');
$apiResponse->setApiPath('contacts.list');
return $apiResponse->fill(
$this->apiClient->send(
new Request(
TeamleaderApi::HTTP_GET,
$apiResponse->getApiPath(),
$this->buildHttpHeaders(),
json_encode($params)
)
)
);
}
/**
* @param array $contactData
* @return ApiResponse
* @throws ApiException
*/
public function add(array $contactData): ApiResponse
{
$apiResponse = new ApiResponse($this->resourceClass, 'detail');
$apiResponse->setApiPath('contacts.add');
return $apiResponse->fill(
$this->apiClient->send(
new Request(
TeamleaderApi::HTTP_POST,
$apiResponse->getApiPath(),
$this->buildHttpHeaders(),
json_encode($contactData)
)
)
);
}
/**
* @param string $contactId
* @param string $companyId
* @throws ApiException
*/
public function linkToCompany(string $contactId, string $companyId): void
{
$apiResponse = new ApiResponse($this->resourceClass, 'detail');
$apiResponse->setApiPath('contacts.add');
$this->apiClient->sendSimple(
new Request(
TeamleaderApi::HTTP_POST,
'contacts.linkToCompany',
$this->buildHttpHeaders(),
json_encode([
'id' => $contactId,
'company_id' => $companyId,
])
)
);
}
/**
* Get a contact by its id
*
* @param string $id
* @return ApiResponse
* @throws ApiException
*/
public function info(string $id): ApiResponse
{
$apiResponse = new ApiResponse($this->resourceClass, 'detail');
$apiResponse->setApiPath('contacts.info');
return $apiResponse->fill(
$this->apiClient->send(
new Request(
TeamleaderApi::HTTP_GET,
$apiResponse->getApiPath(),
$this->buildHttpHeaders(),
json_encode(['id' => $id])
)
)
);
}
}