Test Failed
Branch development (5babc9)
by Jonathan
04:47
created

PutTrait::uri()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 1
c 0
b 0
f 0
nc 1
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
    abstract protected function uri($uri);
23
24
    abstract protected function request($method, $uri, $options);
25
26
    abstract protected function buildPropertyMapArray(array $array, PropertyMap $propertyMap);
27
28
    /**
29
     * Create an API key
30
     *
31
     * @return null|string
32
     */
33
    public function createApiKey()
34
    {
35
        $ret = null;
36
37
        $response = $this->request('PUT', $this->uri('/account/apikey'), []);
38
39
        if ($response instanceof Response && 201 === $response->getStatusCode()) {
40
            $ret = (string) json_decode($response->getBody(), true);
41
            StaticValidator::execute($ret, 'ApiKey');
42
        }
43
44
        return $ret;
45
    }
46
}
47