Completed
Push — master ( 280340...8fd247 )
by Sean
11s
created

SitesApi::purgeCache()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Incapsula\Api;
4
5
class SitesApi extends AbstractApi
6
{
7
    private $apiUri = 'https://my.incapsula.com/api/prov/v1/sites';
8
9
    /**
10
     * @param int $pageSize
11
     * @param int $pageNum
12
     *
13
     * @return array
14
     */
15
    public function list($pageSize = 50, $pageNum = 0)
16
    {
17
        return $this->client->send(sprintf('%s/list', $this->apiUri), [
18
            'page_size' => $pageSize,
19
            'page_num' => $pageNum,
20
        ]);
21
    }
22
23
    /**
24
     * @param array $params
25
     *
26
     * @return array
27
     */
28
    public function add($params = [])
29
    {
30
        return $this->client->send(sprintf('%s/add', $this->apiUri), $params);
31
    }
32
33
    /**
34
     * @param string $siteId
35
     *
36
     * @return array
37
     */
38
    public function delete($siteId)
39
    {
40
        return $this->client->send(sprintf('%s/delete', $this->apiUri), [
41
            'site_id' => $siteId,
42
        ]);
43
    }
44
45
    /**
46
     * @param string $siteId
47
     * @param string $certificate
48
     * @param string $privateKey
49
     *
50
     * @return array
51
     */
52
    public function uploadCustomCertificate($siteId, $certificate, $privateKey)
53
    {
54
        return $this->client->send(sprintf('%s/uploadCustomCertificate', $this->apiUri), [
55
            'site_id' => $siteId,
56
            'certificate' => base64_encode($certificate),
57
            'private_key' => base64_encode($privateKey),
58
        ]);
59
    }
60
61
    /**
62
     * @param string $siteId
63
     *
64
     * @return array
65
     */
66
    public function removeCustomCertificate($siteId)
67
    {
68
        return $this->client->send(sprintf('%s/removeCustomCertificate', $this->apiUri), [
69
            'site_id' => $siteId,
70
        ]);
71
    }
72
73
    /**
74
     * @param string $siteId       site to purge
75
     * @param string $purgePattern is optional but to purge specific resources the format is as follows
76
     *                             purge all urls that contain text requires no additional formatting, e.g. image.jpg,
77
     *                             or to purge URLs starting with a pattern use  '^' e.g. "^maps/" ,
78
     *                             or to purge all URLs that end with a pattern use '$' e.g. ".jpg$"
79
     *                             See incapsula docs for details
80
     *                             https://docs.incapsula.com/Content/API/sites-api.htm#Purge
81
     *
82
     * @return array
83
     */
84
    public function purgeCache($siteId, $purgePattern = '')
85
    {
86
        return $this->client->send(sprintf('%s/cache/purge', $this->apiUri), [
87
            'site_id' => $siteId,
88
            'purge_pattern' => $purgePattern,
89
        ]);
90
    }
91
}
92