Completed
Push — master ( b3f24e...84a5c5 )
by Tobias
03:15
created

Unsubscribe::deleteAll()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 8
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 8
loc 8
ccs 0
cts 4
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
crap 2
1
<?php
2
3
/*
4
 * Copyright (C) 2013-2016 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\Supression;
11
12
use Mailgun\Api\HttpApi;
13
use Mailgun\Api\Pagination;
14
use Mailgun\Assert;
15
use Mailgun\Model\Suppression\Unsubscribe\CreateResponse;
16
use Mailgun\Model\Suppression\Unsubscribe\DeleteResponse;
17
use Mailgun\Model\Suppression\Unsubscribe\IndexResponse;
18
use Mailgun\Model\Suppression\Unsubscribe\ShowResponse;
19
20
/**
21
 * @see https://documentation.mailgun.com/api-suppressions.html#unsubscribes
22
 *
23
 * @author Sean Johnson <[email protected]>
24
 */
25 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...
26
{
27
    use Pagination;
28
29
    /**
30
     * @param string $domain Domain to get unsubscribes for
31
     * @param int    $limit  optional
32
     *
33
     * @return IndexResponse
34
     */
35
    public function index($domain, $limit = 100)
36
    {
37
        Assert::stringNotEmpty($domain);
38
        Assert::range($limit, 1, 10000, 'Limit parameter must be between 1 and 10000');
39
40
        $params = [
41
            'limit' => $limit,
42
        ];
43
44
        $response = $this->httpGet(sprintf('/v3/%s/unsubscribes', $domain), $params);
45
46
        return $this->safeHydrate($response, IndexResponse::class);
47
    }
48
49
    /**
50
     * @param string $domain  Domain to show unsubscribe for
51
     * @param string $address Unsubscribe address
52
     *
53
     * @return ShowResponse
54
     */
55
    public function show($domain, $address)
56
    {
57
        Assert::stringNotEmpty($domain);
58
        Assert::stringNotEmpty($address);
59
60
        $response = $this->httpGet(sprintf('/v3/%s/unsubscribes/%s', $domain, $address));
61
62
        return $this->safeHydrate($response, ShowResponse::class);
63
    }
64
65
    /**
66
     * @param string $domain  Domain to create unsubscribe for
67
     * @param string $address Unsubscribe address
68
     * @param array  $params  optional
69
     *
70
     * @return CreateResponse
71
     */
72
    public function create($domain, $address, array $params = [])
73
    {
74
        Assert::stringNotEmpty($domain);
75
        Assert::stringNotEmpty($address);
76
77
        $params['address'] = $address;
78
79
        $response = $this->httpPost(sprintf('/v3/%s/unsubscribes', $domain), $params);
80
81
        return $this->safeHydrate($response, CreateResponse::class);
82
    }
83
84
    /**
85
     * @param string $domain  Domain to delete unsubscribe for
86
     * @param string $address Unsubscribe address
87
     *
88
     * @return DeleteResponse
89
     */
90
    public function delete($domain, $address)
91
    {
92
        Assert::stringNotEmpty($domain);
93
        Assert::stringNotEmpty($address);
94
95
        $response = $this->httpDelete(sprintf('/v3/%s/unsubscribes/%s', $domain, $address));
96
97
        return $this->safeHydrate($response, DeleteResponse::class);
98
    }
99
100
    /**
101
     * @param string $domain Domain to delete all unsubscribes for
102
     *
103
     * @return DeleteResponse
104
     */
105
    public function deleteAll($domain)
106
    {
107
        Assert::stringNotEmpty($domain);
108
109
        $response = $this->httpDelete(sprintf('/v3/%s/unsubscribes', $domain));
110
111
        return $this->safeHydrate($response, DeleteResponse::class);
112
    }
113
}
114