1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace SetBased\ClubCollect\Endpoint; |
5
|
|
|
|
6
|
|
|
use SetBased\ClubCollect\Exception\ClubCollectApiException; |
7
|
|
|
use SetBased\ClubCollect\Resource\BaseResource; |
8
|
|
|
use SetBased\ClubCollect\Resource\Company; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Endpoint for companies. |
12
|
|
|
*/ |
13
|
|
|
class CompanyEndpoint extends Endpoint |
14
|
|
|
{ |
15
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
16
|
|
|
/** |
17
|
|
|
* Fetches the company from ClubCollect. |
18
|
|
|
* |
19
|
|
|
* @return Company |
20
|
|
|
* |
21
|
|
|
* @throws ClubCollectApiException |
22
|
|
|
*/ |
23
|
|
|
public function fetch(): Company |
24
|
|
|
{ |
25
|
|
|
/** @var Company $resource */ |
26
|
|
|
$resource = parent::restGet(['companies', $this->client->getCompanyId()], |
27
|
|
|
['api_key' => $this->client->getApiKey()]); |
28
|
|
|
if (!is_a($resource, Company::class)) |
29
|
|
|
{ |
30
|
|
|
throw new ClubCollectApiException('Expected a Company object, got a %s', get_class($resource)); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
return $resource; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
37
|
|
|
/** |
38
|
|
|
* Returns an instance of this class. |
39
|
|
|
* |
40
|
|
|
* @param array $response The API response. |
41
|
|
|
* |
42
|
|
|
* @return Company |
43
|
|
|
* |
44
|
|
|
* @throws ClubCollectApiException |
45
|
|
|
*/ |
46
|
|
|
protected function createResourceObject(array $response): BaseResource |
47
|
|
|
{ |
48
|
|
|
return new Company($this->client, $response); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
//---------------------------------------------------------------------------------------------------------------------- |
55
|
|
|
|