Completed
Push — master ( eb518e...509073 )
by Felix
06:40
created

StatSites::rankingDistributions()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 3
1
<?php
2
3
namespace SchulzeFelix\Stat\Api;
4
5
use Illuminate\Support\Collection;
6
7
class StatSites extends BaseStat
8
{
9
10
    public function all() : Collection
11
    {
12
        $start = 0;
13
        $sites = collect();
14
15
        do {
16
            $response = $this->performQuery('sites/all', ['start' => $start, 'results' => 5000]);
17
            $start += 5000;
18
            $sites = $sites->merge($response['Result']);
19
20
            if(!isset($response['nextpage'])) {
21
                break;
22
            }
23
        } while ($response['resultsreturned'] < $response['totalresults']);
24
25
        return $sites;
26
27
    }
28
29
    public function list($project_id) : Collection
30
    {
31
        $response = $this->performQuery('sites/list', ['project_id' => $project_id]);
32
33
        if ($response['resultsreturned'] == 0) {
34
            return collect();
35
        }
36
37
        return collect($response['Result']);
38
    }
39
40
    public function rankingDistributions($siteID, $fromDate, $toDate) : Collection
41
    {
42
        $response = $this->performQuery('sites/ranking_distributions', ['id' => $siteID, 'from_date' => $fromDate, 'to_date' => $toDate]);
43
44
        $rankDistribution = collect($response['RankDistribution']);
45
46
        if(isset($response['RankDistribution']['date'])) {
47
            $rankDistribution = collect([$response['RankDistribution']]);
48
        }
49
50
        return $rankDistribution;
51
52
    }
53
54
    public function create($projectID, $url, $dropWWWprefix = true, $dropDirectories = true)
55
    {
56
        $response = $this->performQuery('sites/create', ['project_id' => $projectID, 'url' => $url, 'drop_www_prefix' => $dropWWWprefix, 'drop_directories' => $dropDirectories]);
57
58
        return $response['Result'];
59
    }
60
61
    public function update($siteID, array $attributes = [])
62
    {
63
        $arguments = ['id' => $siteID] + $attributes;
64
65
        $response = $this->performQuery('sites/update', $arguments);
66
67
        return $response['Result'];
68
69
    }
70
71
    public function delete($siteID)
72
    {
73
        $response = $this->performQuery('sites/delete', ['id' => $siteID]);
74
75
        return (int) $response['Result']['Id'];
76
    }
77
78
}
79