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 / Endpoints / Responses / ConnectedNetworksResponse.php

ConnectedNetworksResponse.php in Metricool – Social media and site statistics 2.1.1, at app/Http/Endpoints/Responses/ConnectedNetworksResponse.php

52 lines 1.2 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\Endpoints\Responses;
6
7 class ConnectedNetworksResponse extends Response
8 {
9 /**
10 * Response from Metricool /v2/settings/brands/{blogId}
11 * @var array $brandSettings
12 */
13 protected array $brandSettings = [];
14
15 public function __construct(array $brandSettings)
16 {
17 $this->brandSettings = $brandSettings;
18 }
19
20 /**
21 * Parse the brandSettings response and extract just the connected networks
22 */
23 protected function parse(): array
24 {
25 $networks = [];
26
27 if (!isset($this->brandSettings['networksData'])) {
28 return $networks;
29 }
30
31 foreach ($this->brandSettings['networksData'] as $network => $networkData) {
32 $networkName = str_replace('Data', '', $network);
33 $networks[$networkName] = $networkData;
34 }
35
36 if (!isset($networks['web']['url'])) {
37 // Hardcode the "web" connection. This prevents an inactive WordPress connection after onboarding.
38 $networks['web']['url'] = home_url();
39 }
40
41 return $networks;
42 }
43
44 /**
45 * @inheritDoc
46 */
47 public function body(): array
48 {
49 return $this->parse();
50 }
51 }
52