1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OhDear\PhpSdk; |
4
|
|
|
|
5
|
|
|
use Carbon\Carbon; |
6
|
|
|
use GuzzleHttp\Client; |
7
|
|
|
use OhDear\PhpSdk\Actions\ManagesBrokenLinks; |
8
|
|
|
use OhDear\PhpSdk\Actions\ManagesCertificateHealth; |
9
|
|
|
use OhDear\PhpSdk\Actions\ManagesChecks; |
10
|
|
|
use OhDear\PhpSdk\Actions\ManagesDowntime; |
11
|
|
|
use OhDear\PhpSdk\Actions\ManagesMaintenancePeriods; |
12
|
|
|
use OhDear\PhpSdk\Actions\ManagesMixedContent; |
13
|
|
|
use OhDear\PhpSdk\Actions\ManagesPerformance; |
14
|
|
|
use OhDear\PhpSdk\Actions\ManagesSites; |
15
|
|
|
use OhDear\PhpSdk\Actions\ManagesStatusPages; |
16
|
|
|
use OhDear\PhpSdk\Actions\ManagesUptime; |
17
|
|
|
use OhDear\PhpSdk\Actions\ManagesUsers; |
18
|
|
|
|
19
|
|
|
class OhDear |
20
|
|
|
{ |
21
|
|
|
use MakesHttpRequests, |
22
|
|
|
ManagesSites, |
23
|
|
|
ManagesChecks, |
24
|
|
|
ManagesUsers, |
25
|
|
|
ManagesBrokenLinks, |
26
|
|
|
ManagesMaintenancePeriods, |
27
|
|
|
ManagesMixedContent, |
28
|
|
|
ManagesUptime, |
29
|
|
|
ManagesDowntime, |
30
|
|
|
ManagesCertificateHealth, |
31
|
|
|
ManagesStatusPages, |
32
|
|
|
ManagesPerformance; |
33
|
|
|
|
34
|
|
|
/** @var string */ |
35
|
|
|
public $apiToken; |
36
|
|
|
|
37
|
|
|
/** @var \GuzzleHttp\Client */ |
38
|
|
|
public $client; |
39
|
|
|
|
40
|
|
|
public function __construct(string $apiToken, Client $client = null) |
41
|
|
|
{ |
42
|
|
|
$this->apiToken = $apiToken; |
43
|
|
|
|
44
|
|
|
$this->client = $client ?: new Client([ |
45
|
|
|
'base_uri' => 'https://ohdear.app/api/', |
46
|
|
|
'http_errors' => false, |
47
|
|
|
'headers' => [ |
48
|
|
|
'Authorization' => 'Bearer '.$this->apiToken, |
49
|
|
|
'Accept' => 'application/json', |
50
|
|
|
'Content-Type' => 'application/json', |
51
|
|
|
], |
52
|
|
|
]); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
protected function transformCollection(array $collection, string $class): array |
56
|
|
|
{ |
57
|
|
|
return array_map(function ($attributes) use ($class) { |
58
|
|
|
return new $class($attributes, $this); |
59
|
|
|
}, $collection); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function convertDateFormat(string $date, $format = 'YmdHis'): string |
63
|
|
|
{ |
64
|
|
|
return Carbon::parse($date)->format($format); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|