|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
/** |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright (C) 2018 Ross Mitchell |
|
6
|
|
|
* |
|
7
|
|
|
* This file is part of RossMitchell/UpdateCloudFlare. |
|
8
|
|
|
* |
|
9
|
|
|
* RossMitchell/UpdateCloudFlare is free software: you can redistribute |
|
10
|
|
|
* it and/or modify it under the terms of the GNU General Public License |
|
11
|
|
|
* as published by the Free Software Foundation, either version 3 of the |
|
12
|
|
|
* License, or (at your option) any later version. |
|
13
|
|
|
* |
|
14
|
|
|
* This program is distributed in the hope that it will be useful, |
|
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17
|
|
|
* GNU General Public License for more details. |
|
18
|
|
|
* |
|
19
|
|
|
* You should have received a copy of the GNU General Public License |
|
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
21
|
|
|
*/ |
|
22
|
|
|
|
|
23
|
|
|
namespace RossMitchell\UpdateCloudFlare\Model\Requests; |
|
24
|
|
|
|
|
25
|
|
|
use RossMitchell\UpdateCloudFlare\Exceptions\CloudFlareException; |
|
26
|
|
|
use RossMitchell\UpdateCloudFlare\Factories\Responses\UpdateDnsRecordsFactory; |
|
27
|
|
|
use RossMitchell\UpdateCloudFlare\Interfaces\CurlInterface; |
|
28
|
|
|
use RossMitchell\UpdateCloudFlare\Requests\UpdateDnsRecords; |
|
29
|
|
|
use Symfony\Component\Console\Exception\LogicException; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Class UpdateDnsRecord |
|
33
|
|
|
* @package RossMitchell\UpdateCloudFlare\Data |
|
34
|
|
|
*/ |
|
35
|
|
|
class UpdateDnsRecord |
|
36
|
|
|
{ |
|
37
|
|
|
/** |
|
38
|
|
|
* @var CurlInterface |
|
39
|
|
|
*/ |
|
40
|
|
|
private $curl; |
|
41
|
|
|
/** |
|
42
|
|
|
* @var UpdateDnsRecordsFactory |
|
43
|
|
|
*/ |
|
44
|
|
|
private $responseFactory; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* UpdateDnsRecord constructor. |
|
48
|
|
|
* |
|
49
|
|
|
* @param CurlInterface $curl |
|
50
|
|
|
* @param UpdateDnsRecordsFactory $responseFactory |
|
51
|
|
|
*/ |
|
52
|
3 |
|
public function __construct(CurlInterface $curl, UpdateDnsRecordsFactory $responseFactory) |
|
53
|
|
|
{ |
|
54
|
3 |
|
$this->curl = $curl; |
|
55
|
3 |
|
$this->responseFactory = $responseFactory; |
|
56
|
3 |
|
} |
|
57
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @param UpdateDnsRecords $request |
|
61
|
|
|
* |
|
62
|
|
|
* @return bool |
|
63
|
|
|
* @throws CloudFlareException |
|
64
|
|
|
*/ |
|
65
|
3 |
|
public function changeIpAddress(UpdateDnsRecords $request): bool |
|
66
|
|
|
{ |
|
67
|
3 |
|
$rawResult = \json_decode($this->curl->makeRequest($request)); |
|
68
|
3 |
|
$result = $this->responseFactory->create($rawResult); |
|
69
|
2 |
|
$expectedIpAddress = $request->getSubDomainInfo()->getIpAddress(); |
|
70
|
2 |
|
$newIpAddress = $result->getResult()->getContent(); |
|
71
|
2 |
|
if ($newIpAddress !== $expectedIpAddress) { |
|
72
|
1 |
|
throw new LogicException('Ip Address has not been Updated'); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
1 |
|
return true; |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|