1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* ReportingCloud PHP Wrapper |
5
|
|
|
* |
6
|
|
|
* PHP wrapper for ReportingCloud Web API. Authored and supported by Text Control GmbH. |
7
|
|
|
* |
8
|
|
|
* @link http://www.reporting.cloud to learn more about ReportingCloud |
9
|
|
|
* @link https://github.com/TextControl/txtextcontrol-reportingcloud-php for the canonical source repository |
10
|
|
|
* @license https://raw.githubusercontent.com/TextControl/txtextcontrol-reportingcloud-php/master/LICENSE.md |
11
|
|
|
* @copyright © 2018 Text Control GmbH |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace TxTextControl\ReportingCloud; |
15
|
|
|
|
16
|
|
|
use GuzzleHttp\Psr7\Response; |
17
|
|
|
use GuzzleHttp\RequestOptions; |
18
|
|
|
use TxTextControl\ReportingCloud\Exception\InvalidArgumentException; |
19
|
|
|
use TxTextControl\ReportingCloud\Validator\StaticValidator; |
20
|
|
|
|
21
|
|
|
trait DeleteTrait |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* Abstract Methods |
25
|
|
|
* ----------------------------------------------------------------------------------------------------------------- |
26
|
|
|
*/ |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Construct URI with version number |
30
|
|
|
* |
31
|
|
|
* @param string $uri URI |
32
|
|
|
* |
33
|
|
|
* @return string |
34
|
|
|
*/ |
35
|
|
|
abstract protected function uri($uri); |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Request the URI with options |
39
|
|
|
* |
40
|
|
|
* @param string $method HTTP method |
41
|
|
|
* @param string $uri URI |
42
|
|
|
* @param array $options Options |
43
|
|
|
* |
44
|
|
|
* @return mixed|null|\Psr\Http\Message\ResponseInterface |
45
|
|
|
* |
46
|
|
|
* @throws RuntimeException |
47
|
|
|
*/ |
48
|
|
|
abstract protected function request($method, $uri, $options); |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* DELETE Methods |
52
|
|
|
* ----------------------------------------------------------------------------------------------------------------- |
53
|
|
|
*/ |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Delete an API key |
57
|
|
|
* |
58
|
|
|
* @param string $key API key |
59
|
|
|
* |
60
|
|
|
* @return bool |
61
|
|
|
*/ |
62
|
4 |
|
public function deleteApiKey($key) |
63
|
|
|
{ |
64
|
4 |
|
$ret = false; |
65
|
|
|
|
66
|
4 |
|
StaticValidator::execute($key, 'ApiKey'); |
67
|
|
|
|
68
|
|
|
$options = [ |
69
|
4 |
|
RequestOptions::QUERY => [ |
70
|
4 |
|
'key' => $key, |
71
|
2 |
|
], |
72
|
2 |
|
]; |
73
|
|
|
|
74
|
4 |
|
$response = $this->request('DELETE', $this->uri('/account/apikey'), $options); |
75
|
|
|
|
76
|
4 |
|
if ($response instanceof Response && 200 === $response->getStatusCode()) { |
77
|
4 |
|
$ret = true; |
78
|
2 |
|
} |
79
|
|
|
|
80
|
4 |
|
return $ret; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Delete a template in template storage |
85
|
|
|
* |
86
|
|
|
* @param string $templateName Template name |
87
|
|
|
* |
88
|
|
|
* @throws InvalidArgumentException |
89
|
|
|
* |
90
|
|
|
* @return bool |
91
|
|
|
*/ |
92
|
22 |
|
public function deleteTemplate($templateName) |
93
|
|
|
{ |
94
|
22 |
|
$ret = false; |
95
|
|
|
|
96
|
22 |
|
StaticValidator::execute($templateName, 'TemplateName'); |
97
|
|
|
|
98
|
|
|
$options = [ |
99
|
20 |
|
RequestOptions::QUERY => [ |
100
|
20 |
|
'templateName' => $templateName, |
101
|
10 |
|
], |
102
|
10 |
|
]; |
103
|
|
|
|
104
|
20 |
|
$response = $this->request('DELETE', $this->uri('/templates/delete'), $options); |
105
|
|
|
|
106
|
18 |
|
if ($response instanceof Response && 204 === $response->getStatusCode()) { |
107
|
18 |
|
$ret = true; |
108
|
9 |
|
} |
109
|
|
|
|
110
|
18 |
|
return $ret; |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|