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