Completed
Push — master ( 2d0c9c...1268a4 )
by Jens
10:44
created

CustomerEmailConfirmRequest::ofToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 2
crap 1
1
<?php
2
/**
3
 * @author @jayS-de <[email protected]>
4
 * @created: 12.02.15, 14:18
5
 */
6
7
namespace Commercetools\Core\Request\Customers;
8
9
use Commercetools\Core\Client\HttpMethod;
10
use Commercetools\Core\Client\JsonRequest;
11
use Commercetools\Core\Model\Common\Context;
12
use Commercetools\Core\Request\AbstractApiRequest;
13
use Commercetools\Core\Response\ApiResponseInterface;
14
use Commercetools\Core\Model\Customer\Customer;
15
use Commercetools\Core\Response\ResourceResponse;
16
use Psr\Http\Message\ResponseInterface;
17
18
/**
19
 * @package Commercetools\Core\Request\Customers
20
 * @link https://dev.commercetools.com/http-api-projects-customers.html#verify-customers-email
21
 * @method Customer mapResponse(ApiResponseInterface $response)
22
 */
23
class CustomerEmailConfirmRequest extends AbstractApiRequest
24
{
25
    protected $resultClass = '\Commercetools\Core\Model\Customer\Customer';
26
27
    const TOKEN_VALUE = 'tokenValue';
28
29
    /**
30
     * @var string
31
     */
32
    protected $tokenValue;
33
34
    /**
35
     * @param string $tokenValue
36
     * @param Context $context
37
     */
38 4
    public function __construct($tokenValue, Context $context = null)
39
    {
40 4
        parent::__construct(CustomersEndpoint::endpoint(), $context);
41 4
        $this->tokenValue = $tokenValue;
42 4
    }
43
44
    /**
45
     * @param string $tokenValue
46
     * @param Context $context
47
     * @return static
48
     */
49 4
    public static function ofToken($tokenValue, Context $context = null)
50
    {
51 4
        return new static($tokenValue, $context);
52
    }
53
54
    /**
55
     * @return string
56
     * @internal
57
     */
58 4
    protected function getPath()
59
    {
60 4
        return (string)$this->getEndpoint() . '/email/confirm';
61
    }
62
63
    /**
64
     * @return JsonRequest
65
     * @internal
66
     */
67 4
    public function httpRequest()
68
    {
69
        $payload = [
70 4
            static::TOKEN_VALUE => $this->tokenValue,
71
        ];
72 4
        return new JsonRequest(HttpMethod::POST, $this->getPath(), $payload);
73
    }
74
75 1
    public function buildResponse(ResponseInterface $response)
76
    {
77 1
        return new ResourceResponse($response, $this, $this->getContext());
78
    }
79
}
80