Completed
Push — master ( b33aa2...131cc8 )
by Sean
13s queued 11s
created

SitesApi::status()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
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
     * @param string $siteId
34
     *
35
     * @return array
36
     */
37
    public function status($siteId)
38
    {
39
        return $this->client->send(sprintf('%s/status', $this->apiUri), [
40
            'site_id' => $siteId,
41
        ]);
42
    }
43
    /**
44
     * @param string $siteId
45
     *
46
     * @return array
47
     */
48
    public function delete($siteId)
49
    {
50
        return $this->client->send(sprintf('%s/delete', $this->apiUri), [
51
            'site_id' => $siteId,
52
        ]);
53
    }
54
55
    /**
56
     * @param string $siteId
57
     * @param string $certificate
58
     * @param string $privateKey
59
     *
60
     * @return array
61
     */
62
    public function uploadCustomCertificate($siteId, $certificate, $privateKey)
63
    {
64
        return $this->client->send(sprintf('%s/customCertificate/upload', $this->apiUri), [
65
            'site_id' => $siteId,
66
            'certificate' => base64_encode($certificate),
67
            'private_key' => base64_encode($privateKey),
68
        ]);
69
    }
70
71
    /**
72
     * @param string $siteId
73
     *
74
     * @return array
75
     */
76
    public function removeCustomCertificate($siteId)
77
    {
78
        return $this->client->send(sprintf('%s/removeCustomCertificate', $this->apiUri), [
79
            'site_id' => $siteId,
80
        ]);
81
    }
82
83
    /**
84
     * @param string $siteId       site to purge
85
     * @param string $purgePattern is optional but to purge specific resources the format is as follows
86
     *                             purge all urls that contain text requires no additional formatting, e.g. image.jpg,
87
     *                             or to purge URLs starting with a pattern use  '^' e.g. "^maps/" ,
88
     *                             or to purge all URLs that end with a pattern use '$' e.g. ".jpg$"
89
     *                             See incapsula docs for details
90
     *                             https://docs.incapsula.com/Content/API/sites-api.htm#Purge
91
     *
92
     * @return array
93
     */
94
    public function purgeCache($siteId, $purgePattern = '')
95
    {
96
        return $this->client->send(sprintf('%s/cache/purge', $this->apiUri), [
97
            'site_id' => $siteId,
98
            'purge_pattern' => $purgePattern,
99
        ]);
100
    }
101
102
    /**
103
     * @param string $siteId        site to move
104
     * @param string $destAccountId account id to move the site to
105
     *
106
     * @return array containing response from incapsula with new dns details
107
     */
108
    public function moveSite($siteId, $destAccountId)
109
    {
110
        return $this->client->send(sprintf('%s/moveSite', $this->apiUri), [
111
            'site_id' => $siteId,
112
            'destination_account_id' => $destAccountId,
113
        ]);
114
    }
115
116
    /**
117
     * @param int $siteId   The site ID to retrieve all cache rules for
118
     * @param int $pageSize The number of rules to return per page
119
     * @param int $pageNum  The page number to return (if more than one page of results)
120
     *
121
     * @throws \Exception
122
     *
123
     * @return array
124
     */
125
    public function listCacheRules($siteId, $pageSize = 50, $pageNum = 0)
126
    {
127
        return $this->client->sendRaw(sprintf('%s/performance/caching-rules/list', $this->apiUri), [
128
            'site_id' => $siteId,
129
            'page_size' => $pageSize,
130
            'page_num' => $pageNum,
131
        ]);
132
    }
133
134
        /**
135
     * @param array $params
136
     *
137
     * @return array
138
     */
139
    public function setStaticCacheMode($siteId)
140
    {
141
        return $this->client->send(sprintf('%s/performance/cache-mode', $this->apiUri), [
142
            'site_id' => $siteId,
143
            'cache_mode' => 'static_only',
144
        ]);
145
    }
146
}
147