Completed
Push — master ( cab6a9...753b78 )
by Robin
02:45
created

LaravelGoogleIndexingClass::googleClientSetup()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Famdirksen\LaravelGoogleIndexing;
4
5
use Google_Client;
6
use Google_Service_Indexing;
7
use Google_Service_Indexing_UrlNotification;
8
9
class LaravelGoogleIndexingClass
10
{
11
    /** @var Google_Client $googleClient */
12
    private $googleClient;
13
14
    /** @var Google_Service_Indexing $indexingService */
15
    private $indexingService;
16
17
    public function __construct(Google_Client $googleClient)
18
    {
19
        $this->googleClient = $googleClient;
20
21
        $this->googleClientSetup();
22
    }
23
24
    private function googleClientSetup() {
25
        $this->googleClient->setAuthConfig(config('laravel-google-indexing.google.auth_config'));
26
        $this->indexingService = new Google_Service_Indexing($this->googleClient);
27
    }
28
29
    public function status(string $url) {
30
        return $this->indexingService
31
            ->urlNotifications
32
            ->getMetadata([
33
                "url" => urlencode($url)
34
            ]);
35
    }
36
37
    public function update(string $url)
38
    {
39
        return $this->publish($url, "URL_UPDATED");
40
    }
41
42
    public function remove(string $url)
43
    {
44
        return $this->publish($url, "URL_DELETED");
45
    }
46
47
    private function publish(string $url, string $action)
48
    {
49
        $urlNotification = new Google_Service_Indexing_UrlNotification();
50
51
        $urlNotification->setUrl($url);
52
        $urlNotification->setType($action);
53
54
        return $this->indexingService
55
            ->urlNotifications
56
            ->publish($urlNotification);
57
    }
58
}
59