Completed
Push — master ( c0a386...56655a )
by Tobias
06:16 queued 03:48
created

Ip::unassign()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 5
cp 0
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 2
1
<?php
2
3
/*
4
 * Copyright (C) 2013 Mailgun
5
 *
6
 * This software may be modified and distributed under the terms
7
 * of the MIT license. See the LICENSE file for details.
8
 */
9
10
namespace Mailgun\Api;
11
12
use Mailgun\Assert;
13
use Mailgun\Model\Ip\IndexResponse;
14
use Mailgun\Model\Ip\ShowResponse;
15
use Mailgun\Model\Ip\UpdateResponse;
16
use Psr\Http\Message\ResponseInterface;
17
18
/**
19
 * {@link https://documentation.mailgun.com/en/latest/api-ips.html#ips}.
20
 *
21
 * @author Tobias Nyholm <[email protected]>
22
 */
23
class Ip extends HttpApi
24
{
25
    /**
26
     * Returns a list of IPs.
27
     *
28
     * @param bool $dedicated
29
     *
30
     * @return IndexResponse|ResponseInterface
31
     */
32
    public function index($dedicated = false)
33
    {
34
        Assert::boolean($dedicated);
35
36
        $params = [
37
            'dedicated' => $dedicated,
38
        ];
39
40
        $response = $this->httpGet('/v3/ips', $params);
41
42
        return $this->hydrateResponse($response, IndexResponse::class);
43
    }
44
45
    /**
46
     * Returns a list of IPs assigned to a domain.
47
     *
48
     * @param string $domain
49
     *
50
     * @return IndexResponse|ResponseInterface
51
     */
52
    public function domainIndex($domain)
53
    {
54
        Assert::stringNotEmpty($domain);
55
56
        $response = $this->httpGet(sprintf('/v3/domains/%s/ip', $domain));
57
58
        return $this->hydrateResponse($response, IndexResponse::class);
59
    }
60
61
    /**
62
     * Returns a single ip.
63
     *
64
     * @param string $ip
65
     *
66
     * @return ShowResponse|ResponseInterface
67
     */
68
    public function show($ip)
69
    {
70
        Assert::ip($ip);
71
72
        $response = $this->httpGet(sprintf('/v3/ips/%s', $ip));
73
74
        return $this->hydrateResponse($response, ShowResponse::class);
75
    }
76
77
    /**
78
     * Assign a dedicated IP to the domain specified.
79
     *
80
     * @param string $domain
81
     * @param string $ip
82
     *
83
     * @return UpdateResponse|ResponseInterface
84
     */
85
    public function assign($domain, $ip)
86
    {
87
        Assert::stringNotEmpty($domain);
88
        Assert::ip($ip);
89
90
        $params = [
91
            'id' => $ip,
92
        ];
93
94
        $response = $this->httpPost(sprintf('/v3/domains/%s/ips', $domain), $params);
95
96
        return $this->hydrateResponse($response, UpdateResponse::class);
97
    }
98
99
    /**
100
     * Unassign an IP from the domain specified.
101
     *
102
     * @param string $domain
103
     * @param string $ip
104
     *
105
     * @return UpdateResponse|ResponseInterface
106
     */
107
    public function unassign($domain, $ip)
108
    {
109
        Assert::stringNotEmpty($domain);
110
        Assert::ip($ip);
111
112
        $response = $this->httpDelete(sprintf('/v3/domains/%s/ips/%s', $domain, $ip));
113
114
        return $this->hydrateResponse($response, UpdateResponse::class);
115
    }
116
}
117