1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SchulzeFelix\Stat; |
4
|
|
|
|
5
|
|
|
use Carbon\Carbon; |
6
|
|
|
use GuzzleHttp\Exception\ClientException; |
7
|
|
|
use SchulzeFelix\Stat\Api\StatBilling; |
8
|
|
|
use SchulzeFelix\Stat\Api\StatBulk; |
9
|
|
|
use SchulzeFelix\Stat\Api\StatKeywords; |
10
|
|
|
use SchulzeFelix\Stat\Api\StatProjects; |
11
|
|
|
use SchulzeFelix\Stat\Api\StatRankings; |
12
|
|
|
use SchulzeFelix\Stat\Api\StatSerps; |
13
|
|
|
use SchulzeFelix\Stat\Api\StatSites; |
14
|
|
|
use SchulzeFelix\Stat\Api\StatSubAccounts; |
15
|
|
|
use SchulzeFelix\Stat\Api\StatTags; |
16
|
|
|
|
17
|
|
|
class Stat |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var StatClient |
21
|
|
|
*/ |
22
|
|
|
private $statClient; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Stat constructor. |
26
|
|
|
*/ |
27
|
|
|
public function __construct(StatClient $statClient) |
28
|
|
|
{ |
29
|
|
|
$this->statClient = $statClient; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function projects() |
33
|
|
|
{ |
34
|
|
|
return new StatProjects($this->statClient); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function sites() |
38
|
|
|
{ |
39
|
|
|
return new StatSites($this->statClient); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function tags() |
43
|
|
|
{ |
44
|
|
|
return new StatTags($this->statClient); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function keywords() |
48
|
|
|
{ |
49
|
|
|
return new StatKeywords($this->statClient); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function rankings() |
53
|
|
|
{ |
54
|
|
|
return new StatRankings($this->statClient); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function serps() |
58
|
|
|
{ |
59
|
|
|
return new StatSerps($this->statClient); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function bulk() |
63
|
|
|
{ |
64
|
|
|
return new StatBulk($this->statClient); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function subaccounts() |
68
|
|
|
{ |
69
|
|
|
return new StatSubAccounts($this->statClient); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function billing() |
73
|
|
|
{ |
74
|
|
|
return new StatBilling($this->statClient); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function blockedUntil() |
78
|
|
|
{ |
79
|
|
|
try { |
80
|
|
|
$this->statClient->performQuery('projects/list', []); |
81
|
|
|
} catch (ClientException $e) { |
82
|
|
|
$now = Carbon::now(); |
83
|
|
|
try { |
84
|
|
|
if ($e->getCode() == 403) { |
85
|
|
|
preg_match("/(\d{1,2}) hours and (\d{1,2}) minutes/", $e->getResponse()->getBody()->getContents(), $matches); |
86
|
|
|
|
87
|
|
|
return $now->addHours($matches[1])->addMinutes($matches[2]); |
88
|
|
|
} |
89
|
|
|
} catch (\Exception $e) { |
90
|
|
|
// |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
return Carbon::now(); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|