Completed
Push — master ( 0f5433...3fbd33 )
by David
01:51
created

Unsubscribe::index()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 13
Ratio 100 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 13
loc 13
ccs 6
cts 6
cp 1
rs 9.8333
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * Copyright (C) 2013 Mailgun
7
 *
8
 * This software may be modified and distributed under the terms
9
 * of the MIT license. See the LICENSE file for details.
10
 */
11
12
namespace Mailgun\Api\Suppression;
13
14
use Mailgun\Api\HttpApi;
15
use Mailgun\Api\Pagination;
16
use Mailgun\Assert;
17
use Mailgun\Model\Suppression\Unsubscribe\CreateResponse;
18
use Mailgun\Model\Suppression\Unsubscribe\DeleteResponse;
19
use Mailgun\Model\Suppression\Unsubscribe\IndexResponse;
20
use Mailgun\Model\Suppression\Unsubscribe\ShowResponse;
21
22
/**
23
 * @see https://documentation.mailgun.com/api-suppressions.html#unsubscribes
24
 *
25
 * @author Sean Johnson <[email protected]>
26
 */
27 View Code Duplication
class Unsubscribe extends HttpApi
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
28
{
29
    use Pagination;
30
31
    /**
32
     * @param string $domain Domain to get unsubscribes for
33
     * @param int    $limit  optional
34
     *
35
     * @return IndexResponse
36
     */
37 1
    public function index(string $domain, int $limit = 100)
38
    {
39 1
        Assert::stringNotEmpty($domain);
40 1
        Assert::range($limit, 1, 10000, 'Limit parameter must be between 1 and 10000');
41
42
        $params = [
43 1
            'limit' => $limit,
44
        ];
45
46 1
        $response = $this->httpGet(sprintf('/v3/%s/unsubscribes', $domain), $params);
47
48 1
        return $this->hydrateResponse($response, IndexResponse::class);
49
    }
50
51
    /**
52
     * @param string $domain  Domain to show unsubscribe for
53
     * @param string $address Unsubscribe address
54
     *
55
     * @return ShowResponse
56
     */
57 1
    public function show(string $domain, string $address)
58
    {
59 1
        Assert::stringNotEmpty($domain);
60 1
        Assert::stringNotEmpty($address);
61
62 1
        $response = $this->httpGet(sprintf('/v3/%s/unsubscribes/%s', $domain, $address));
63
64 1
        return $this->hydrateResponse($response, ShowResponse::class);
65
    }
66
67
    /**
68
     * @param string $domain  Domain to create unsubscribe for
69
     * @param string $address Unsubscribe address
70
     * @param array  $params  optional
71
     *
72
     * @return CreateResponse
73
     */
74 1
    public function create(string $domain, string $address, array $params = [])
75
    {
76 1
        Assert::stringNotEmpty($domain);
77 1
        Assert::stringNotEmpty($address);
78
79 1
        $params['address'] = $address;
80
81 1
        $response = $this->httpPost(sprintf('/v3/%s/unsubscribes', $domain), $params);
82
83 1
        return $this->hydrateResponse($response, CreateResponse::class);
84
    }
85
86
    /**
87
     * @param string $domain  Domain to delete unsubscribe for
88
     * @param string $address Unsubscribe address
89
     *
90
     * @return DeleteResponse
91
     */
92 1
    public function delete(string $domain, string $address)
93
    {
94 1
        Assert::stringNotEmpty($domain);
95 1
        Assert::stringNotEmpty($address);
96
97 1
        $response = $this->httpDelete(sprintf('/v3/%s/unsubscribes/%s', $domain, $address));
98
99 1
        return $this->hydrateResponse($response, DeleteResponse::class);
100
    }
101
102
    /**
103
     * @param string $domain Domain to delete all unsubscribes for
104
     *
105
     * @return DeleteResponse
106
     */
107 1
    public function deleteAll(string $domain)
108
    {
109 1
        Assert::stringNotEmpty($domain);
110
111 1
        $response = $this->httpDelete(sprintf('/v3/%s/unsubscribes', $domain));
112
113 1
        return $this->hydrateResponse($response, DeleteResponse::class);
114
    }
115
}
116