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 TxTextControl\ReportingCloud\PropertyMap\AbstractPropertyMap as PropertyMap; |
18
|
|
|
use TxTextControl\ReportingCloud\Validator\StaticValidator; |
19
|
|
|
|
20
|
|
|
trait PutTrait |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* Abstract Methods |
24
|
|
|
* ----------------------------------------------------------------------------------------------------------------- |
25
|
|
|
*/ |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Construct URI with version number |
29
|
|
|
* |
30
|
|
|
* @param string $uri URI |
31
|
|
|
* |
32
|
|
|
* @return string |
33
|
|
|
*/ |
34
|
|
|
abstract protected function uri($uri); |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Request the URI with options |
38
|
|
|
* |
39
|
|
|
* @param string $method HTTP method |
40
|
|
|
* @param string $uri URI |
41
|
|
|
* @param array $options Options |
42
|
|
|
* |
43
|
|
|
* @return mixed|null|\Psr\Http\Message\ResponseInterface |
44
|
|
|
* |
45
|
|
|
* @throws RuntimeException |
46
|
|
|
*/ |
47
|
|
|
abstract protected function request($method, $uri, $options); |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Using the passed propertyMap, recursively build array |
51
|
|
|
* |
52
|
|
|
* @param array $array Array |
53
|
|
|
* @param PropertyMap $propertyMap PropertyMap |
54
|
|
|
* |
55
|
|
|
* @return array |
56
|
|
|
*/ |
57
|
|
|
abstract protected function buildPropertyMapArray(array $array, PropertyMap $propertyMap); |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* PUT Methods |
61
|
|
|
* ----------------------------------------------------------------------------------------------------------------- |
62
|
|
|
*/ |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Create an API key |
66
|
|
|
* |
67
|
|
|
* @return string|null |
68
|
|
|
*/ |
69
|
6 |
|
public function createApiKey() |
70
|
|
|
{ |
71
|
6 |
|
$ret = null; |
72
|
|
|
|
73
|
6 |
|
$response = $this->request('PUT', $this->uri('/account/apikey'), []); |
74
|
|
|
|
75
|
6 |
|
if ($response instanceof Response && 201 === $response->getStatusCode()) { |
76
|
6 |
|
$ret = (string) json_decode($response->getBody(), true); |
77
|
6 |
|
StaticValidator::execute($ret, 'ApiKey'); |
78
|
3 |
|
} |
79
|
|
|
|
80
|
6 |
|
return $ret; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|