PluginProbe
Metricool – Social media and site statistics / 2.1.1
Metricool – Social media and site statistics v2.1.1
2.1.1 2.1.0 2.0.2 2.0.1 2.0.0 1.27 trunk
metricool / app / Http / Metricool / Entities / Brands.php

Brands.php in Metricool – Social media and site statistics 2.1.1, at app/Http/Metricool/Entities/Brands.php

52 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 }
52