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