Completed
Push — master ( 1fa199...f73445 )
by Tobias
05:49 queued 03:44
created

Bounce::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 11
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 11
loc 11
ccs 0
cts 6
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 3
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\Suppression;
11
12
use Mailgun\Api\HttpApi;
13
use Mailgun\Api\Pagination;
14
use Mailgun\Assert;
15
use Mailgun\Model\Suppression\Bounce\CreateResponse;
16
use Mailgun\Model\Suppression\Bounce\DeleteResponse;
17
use Mailgun\Model\Suppression\Bounce\IndexResponse;
18
use Mailgun\Model\Suppression\Bounce\ShowResponse;
19
20
/**
21
 * @see https://documentation.mailgun.com/api-suppressions.html#bounces
22
 *
23
 * @author Sean Johnson <[email protected]>
24
 */
25 View Code Duplication
class Bounce 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 list bounces 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/bounces', $domain), $params);
45
46
        return $this->hydrateResponse($response, IndexResponse::class);
47
    }
48
49
    /**
50
     * @param string $domain  Domain to show bounce from
51
     * @param string $address Bounce address to show
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/bounces/%s', $domain, $address));
61
62
        return $this->hydrateResponse($response, ShowResponse::class);
63
    }
64
65
    /**
66
     * @param string $domain  Domain to create a bounce for
67
     * @param string $address Address to create a bounce for
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/bounces', $domain), $params);
80
81
        return $this->hydrateResponse($response, CreateResponse::class);
82
    }
83
84
    /**
85
     * @param string $domain  Domain to delete a bounce for
86
     * @param string $address Bounce address to delete
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/bounces/%s', $domain, $address));
96
97
        return $this->hydrateResponse($response, DeleteResponse::class);
98
    }
99
100
    /**
101
     * @param string $domain Domain to delete all bounces for
102
     *
103
     * @return DeleteResponse
104
     */
105
    public function deleteAll($domain)
106
    {
107
        Assert::stringNotEmpty($domain);
108
109
        $response = $this->httpDelete(sprintf('/v3/%s/bounces', $domain));
110
111
        return $this->hydrateResponse($response, DeleteResponse::class);
112
    }
113
}
114