1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SchulzeFelix\Stat\Api; |
4
|
|
|
|
5
|
|
|
use Carbon\Carbon; |
6
|
|
|
use Illuminate\Support\Collection; |
7
|
|
|
use SchulzeFelix\Stat\Objects\StatKeywordEngineRanking; |
8
|
|
|
use SchulzeFelix\Stat\Objects\StatKeywordRanking; |
9
|
|
|
|
10
|
|
|
class StatRankings extends BaseStat |
11
|
|
|
{ |
12
|
|
|
public function list($keywordID, Carbon $fromDate, Carbon $toDate): Collection |
13
|
|
|
{ |
14
|
|
|
$start = 0; |
15
|
|
|
$rankings = collect(); |
16
|
|
|
|
17
|
|
|
do { |
18
|
|
|
$response = $this->performQuery('rankings/list', ['keyword_id' => $keywordID, 'from_date' => $fromDate->toDateString(), 'to_date' => $toDate->toDateString(), 'start' => 0]); |
19
|
|
|
$start += 30; |
20
|
|
|
|
21
|
|
|
if ($response['totalresults'] == 0) { |
22
|
|
|
break; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
if ($response['totalresults'] == 1) { |
26
|
|
|
$rankings->push($response['Result']); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
if ($response['totalresults'] > 1) { |
30
|
|
|
$rankings = $rankings->merge($response['Result']); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
if (! isset($response['nextpage'])) { |
34
|
|
|
break; |
35
|
|
|
} |
36
|
|
|
} while ($response['resultsreturned'] < $response['totalresults']); |
37
|
|
|
|
38
|
|
|
$rankings = $rankings->transform(function ($ranking, $key) { |
|
|
|
|
39
|
|
|
return new StatKeywordRanking([ |
40
|
|
|
'date' => $ranking['date'], |
41
|
|
|
'google' => new StatKeywordEngineRanking([ |
42
|
|
|
'rank' => $ranking['Google']['Rank'], |
43
|
|
|
'base_rank' => $ranking['Google']['BaseRank'], |
44
|
|
|
'url' => $ranking['Google']['Url'] ?? '', |
45
|
|
|
]), |
46
|
|
|
'bing' => new StatKeywordEngineRanking([ |
47
|
|
|
'rank' => $ranking['Bing']['Rank'], |
48
|
|
|
'url' => $ranking['Bing']['Url'] ?? '', |
49
|
|
|
'base_rank' => $ranking['Bing']['BaseRank'], |
50
|
|
|
]), |
51
|
|
|
]); |
52
|
|
|
}); |
53
|
|
|
|
54
|
|
|
return $rankings; |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.