Completed
Push — master ( fb9892...6dff17 )
by David
02:46
created

Tag::devices()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 5
cp 0
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 2
1
<?php
2
3
/*
4
 * Copyright (C) 2013 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\Model\Tag\CountryResponse;
14
use Mailgun\Model\Tag\DeleteResponse;
15
use Mailgun\Model\Tag\DeviceResponse;
16
use Mailgun\Model\Tag\IndexResponse;
17
use Mailgun\Model\Tag\ProviderResponse;
18
use Mailgun\Model\Tag\ShowResponse;
19
use Mailgun\Model\Tag\StatisticsResponse;
20
use Mailgun\Model\Tag\UpdateResponse;
21
use Psr\Http\Message\ResponseInterface;
22
23
/**
24
 * {@link https://documentation.mailgun.com/api-tags.html#tags}.
25
 *
26
 * @author Tobias Nyholm <[email protected]>
27
 */
28
class Tag extends HttpApi
29
{
30
    /**
31
     * Returns a list of tags.
32
33
     *
34
     * @return IndexResponse|ResponseInterface
35
     */
36 1
    public function index(string $domain, int $limit = 100)
37
    {
38 1
        Assert::stringNotEmpty($domain);
39
        $params = [
40 1
            'limit' => $limit,
41
        ];
42
43 1
        $response = $this->httpGet(sprintf('/v3/%s/tags', $domain), $params);
44
45 1
        return $this->hydrateResponse($response, IndexResponse::class);
46
    }
47
48
    /**
49
     * Returns a single tag.
50
     *
51
     * @return ShowResponse|ResponseInterface
52
     */
53 1
    public function show(string $domain, string $tag)
54
    {
55 1
        Assert::stringNotEmpty($domain);
56 1
        Assert::stringNotEmpty($tag);
57
58 1
        $response = $this->httpGet(sprintf('/v3/%s/tags/%s', $domain, $tag));
59
60 1
        return $this->hydrateResponse($response, ShowResponse::class);
61
    }
62
63
    /**
64
     * Update a tag.
65
     *
66
     *
67
     * @return UpdateResponse|ResponseInterface
68
     */
69 1
    public function update(string $domain, string $tag, string $description)
70
    {
71 1
        Assert::stringNotEmpty($domain);
72 1
        Assert::stringNotEmpty($tag);
73
74
        $params = [
75 1
            'description' => $description,
76
        ];
77
78 1
        $response = $this->httpPut(sprintf('/v3/%s/tags/%s', $domain, $tag), $params);
79
80 1
        return $this->hydrateResponse($response, UpdateResponse::class);
81
    }
82
83
    /**
84
     * Returns statistics for a single tag.
85
     *
86
     *
87
     * @return StatisticsResponse|ResponseInterface
88
     */
89 1
    public function stats(string $domain, string $tag, array $params)
90
    {
91 1
        Assert::stringNotEmpty($domain);
92 1
        Assert::stringNotEmpty($tag);
93
94 1
        $response = $this->httpGet(sprintf('/v3/%s/tags/%s/stats', $domain, $tag), $params);
95
96 1
        return $this->hydrateResponse($response, StatisticsResponse::class);
97
    }
98
99
    /**
100
     * Removes a tag from the account.
101
     *
102
     *
103
     * @return DeleteResponse|ResponseInterface
104
     */
105 1
    public function delete(string $domain, string $tag)
106
    {
107 1
        Assert::stringNotEmpty($domain);
108 1
        Assert::stringNotEmpty($tag);
109
110 1
        $response = $this->httpDelete(sprintf('/v3/%s/tags/%s', $domain, $tag));
111
112 1
        return $this->hydrateResponse($response, DeleteResponse::class);
113
    }
114
115
    /**
116
     * @return CountryResponse|ResponseInterface
117
     */
118
    public function countries(string $domain, string $tag)
119
    {
120
        Assert::stringNotEmpty($domain);
121
        Assert::stringNotEmpty($tag);
122
123
        $response = $this->httpGet(sprintf('/v3/%s/tags/%s/stats/aggregates/countries', $domain, $tag));
124
125
        return $this->hydrateResponse($response, CountryResponse::class);
126
    }
127
128
    /**
129
     * @return ProviderResponse|ResponseInterface
130
     */
131
    public function providers(string $domain, string $tag)
132
    {
133
        Assert::stringNotEmpty($domain);
134
        Assert::stringNotEmpty($tag);
135
136
        $response = $this->httpGet(sprintf('/v3/%s/tags/%s/stats/aggregates/providers', $domain, $tag));
137
138
        return $this->hydrateResponse($response, ProviderResponse::class);
139
    }
140
141
    /**
142
     * @return DeviceResponse|ResponseInterface
143
     */
144
    public function devices(string $domain, string $tag)
145
    {
146
        Assert::stringNotEmpty($domain);
147
        Assert::stringNotEmpty($tag);
148
149
        $response = $this->httpGet(sprintf('/v3/%s/tags/%s/stats/aggregates/devices', $domain, $tag));
150
151
        return $this->hydrateResponse($response, DeviceResponse::class);
152
    }
153
}
154