Completed
Push — master ( de13ff...b1f949 )
by Tobias
03:27
created

Webhook::delete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 9
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 9
loc 9
ccs 0
cts 5
cp 0
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 2
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\Webhook\CreateResponse;
14
use Mailgun\Resource\Api\Webhook\DeleteResponse;
15
use Mailgun\Resource\Api\Webhook\IndexResponse;
16
use Mailgun\Resource\Api\Webhook\ShowResponse;
17
use Mailgun\Resource\Api\Webhook\UpdateResponse;
18
19
/**
20
 * @author Tobias Nyholm <[email protected]>
21
 */
22
class Webhook extends HttpApi
23
{
24
    /**
25
     * @param string $domain
26
     *
27
     * @return IndexResponse
28
     */
29
    public function index($domain)
30
    {
31
        Assert::notEmpty($domain);
32
        $response = $this->httpGet(sprintf('/v3/domains/%s/webhooks', $domain));
33
34
        return $this->deserializer->deserialize($response, IndexResponse::class);
0 ignored issues
show
Bug introduced by
The property deserializer does not seem to exist. Did you mean serializer?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
35
    }
36
37
    /**
38
     * @param string $domain
39
     * @param string $webhook
40
     *
41
     * @return ShowResponse
42
     */
43 View Code Duplication
    public function show($domain, $webhook)
0 ignored issues
show
Duplication introduced by
This method 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...
44
    {
45
        Assert::notEmpty($domain);
46
        Assert::notEmpty($webhook);
47
        $response = $this->httpGet(sprintf('/v3/domains/%s/webhooks/%s', $domain, $webhook));
48
49
        return $this->deserializer->deserialize($response, ShowResponse::class);
0 ignored issues
show
Bug introduced by
The property deserializer does not seem to exist. Did you mean serializer?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
50
    }
51
52
    /**
53
     * @param string $domain
54
     * @param string $id
55
     * @param string $url
56
     *
57
     * @return CreateResponse
58
     */
59 View Code Duplication
    public function create($domain, $id, $url)
0 ignored issues
show
Duplication introduced by
This method 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...
60
    {
61
        Assert::notEmpty($domain);
62
        Assert::notEmpty($id);
63
        Assert::notEmpty($url);
64
65
        $params = [
66
            'id' => $id,
67
            'url' => $url,
68
        ];
69
70
        $response = $this->httpPost(sprintf('/v3/domains/%s/webhooks', $domain), $params);
71
72
        return $this->deserializer->deserialize($response, CreateResponse::class);
0 ignored issues
show
Bug introduced by
The property deserializer does not seem to exist. Did you mean serializer?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
73
    }
74
75
    /**
76
     * @param string $domain
77
     * @param string $id
78
     * @param string $url
79
     *
80
     * @return UpdateResponse
81
     */
82
    public function update($domain, $id, $url)
83
    {
84
        Assert::notEmpty($domain);
85
        Assert::notEmpty($id);
86
        Assert::notEmpty($url);
87
88
        $params = [
89
            'url' => $url,
90
        ];
91
92
        $response = $this->httpPut(sprintf('/v3/domains/%s/webhooks/%s', $domain, $id), $params);
93
94
        return $this->deserializer->deserialize($response, UpdateResponse::class);
0 ignored issues
show
Bug introduced by
The property deserializer does not seem to exist. Did you mean serializer?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
95
    }
96
97
    /**
98
     * @param string $domain
99
     * @param string $id
100
     *
101
     * @return DeleteResponse
102
     */
103 View Code Duplication
    public function delete($domain, $id)
0 ignored issues
show
Duplication introduced by
This method 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...
104
    {
105
        Assert::notEmpty($domain);
106
        Assert::notEmpty($id);
107
108
        $response = $this->httpDelete(sprintf('/v3/domains/%s/webhooks/%s', $domain, $id));
109
110
        return $this->deserializer->deserialize($response, DeleteResponse::class);
0 ignored issues
show
Bug introduced by
The property deserializer does not seem to exist. Did you mean serializer?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
111
    }
112
}
113