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