| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Metricool\Http\Metricool; |
| 6 |
|
| 7 |
/** |
| 8 |
* Facade for Metricool API entities. Calls to undefined methods are routed to |
| 9 |
* {@see MetricoolClient} |
| 10 |
* |
| 11 |
* @mixin MetricoolClient |
| 12 |
*/ |
| 13 |
class MetricoolApi |
| 14 |
{ |
| 15 |
protected MetricoolClient $client; |
| 16 |
|
| 17 |
public function __construct(MetricoolClient $client) |
| 18 |
{ |
| 19 |
$this->client = $client; |
| 20 |
} |
| 21 |
|
| 22 |
/** |
| 23 |
* Easy access to the ConnectedBrands entity. |
| 24 |
*/ |
| 25 |
public function connectedBrands(): Entities\ConnectedBrands |
| 26 |
{ |
| 27 |
return new Entities\ConnectedBrands($this->client); |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* Easy access to the statistic entities via the StatisticsFacade. |
| 32 |
*/ |
| 33 |
public function statistics(): Entities\Facades\StatisticsFacade |
| 34 |
{ |
| 35 |
return new Entities\Facades\StatisticsFacade($this->client); |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Easy access to the real time entities via the RealtimeFacade. |
| 40 |
*/ |
| 41 |
public function realtime(): Entities\Facades\RealtimeFacade |
| 42 |
{ |
| 43 |
return new Entities\Facades\RealtimeFacade($this->client); |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Easy access to the UserSettings entity. |
| 48 |
*/ |
| 49 |
public function user(): Entities\User |
| 50 |
{ |
| 51 |
return new Entities\User($this->client); |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Easy access to the UserSettings entity. |
| 56 |
*/ |
| 57 |
public function userSettings(): Entities\UserSettings |
| 58 |
{ |
| 59 |
return new Entities\UserSettings($this->client); |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* Easy access to the UpdatePassword entity. |
| 64 |
*/ |
| 65 |
public function userCredentials(): Entities\UserCredentials |
| 66 |
{ |
| 67 |
return new Entities\UserCredentials($this->client); |
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* Easy access to the ConnectedBrands entity. |
| 72 |
*/ |
| 73 |
public function brands(): Entities\Brands |
| 74 |
{ |
| 75 |
return new Entities\Brands($this->client); |
| 76 |
} |
| 77 |
|
| 78 |
/** |
| 79 |
* This magic method is called when a method is requested that does not |
| 80 |
* exist on this class. It will try to call the method on the |
| 81 |
* MetricoolClient instance, if not found, it will throw an exception. |
| 82 |
* |
| 83 |
* @return mixed |
| 84 |
* @throws \BadMethodCallException |
| 85 |
*/ |
| 86 |
public function __call(string $name, array $arguments) |
| 87 |
{ |
| 88 |
if (method_exists($this->client, $name)) { |
| 89 |
return $this->client->{$name}(...$arguments); |
| 90 |
} |
| 91 |
|
| 92 |
throw new \BadMethodCallException(esc_html("Method {$name} does not exist on MetricoolClient.")); |
| 93 |
} |
| 94 |
} |
| 95 |
|