| @@ -1,0 +1,51 @@ | ||
| 1 | +<?php | |
| 2 | + | |
| 3 | +declare(strict_types=1); | |
| 4 | + | |
| 5 | +namespace Metricool\Http\Metricool\Entities; | |
| 6 | + | |
| 7 | +use Metricool\Http\Metricool\Exceptions\ApiException; | |
| 8 | +use Metricool\Http\Metricool\MetricoolClient; | |
| 9 | + | |
| 10 | +class Brands | |
| 11 | +{ | |
| 12 | + protected MetricoolClient $client; | |
| 13 | + private string $endpoint = 'v2/settings/brands/'; | |
| 14 | + | |
| 15 | + public function __construct(MetricoolClient $client) | |
| 16 | + { | |
| 17 | + $this->client = $client; | |
| 18 | + } | |
| 19 | + | |
| 20 | + /** | |
| 21 | + * Stub method to get all connected brands | |
| 22 | + * @throws ApiException | |
| 23 | + */ | |
| 24 | + public function all(): array | |
| 25 | + { | |
| 26 | + $result = $this->client->get($this->endpoint); | |
| 27 | + | |
| 28 | + if (!isset($result['data'])) { | |
| 29 | + return []; | |
| 30 | + } | |
| 31 | + | |
| 32 | + return $result['data']; | |
| 33 | + } | |
| 34 | + | |
| 35 | + /** | |
| 36 | + * Stub method to get brand by id | |
| 37 | + * @throws ApiException | |
| 38 | + */ | |
| 39 | + public function get(string $id): array | |
| 40 | + { | |
| 41 | + // append the blogId parameter to the endpoint, to prevent 403 response | |
| 42 | + $url = add_query_arg('blogId', $id, $this->endpoint . $id); | |
| 43 | + $result = $this->client->get($url); | |
| 44 | + | |
| 45 | + if (!isset($result['data'])) { | |
| 46 | + return []; | |
| 47 | + } | |
| 48 | + | |
| 49 | + return $result['data']; | |
| 50 | + } | |
| 51 | +} | |