11
11
12
12
namespace Mailgun \Api ;
13
13
14
+ use Exception ;
14
15
use Mailgun \Assert ;
16
+ use Mailgun \Model \Stats \AggregateCountriesResponse ;
17
+ use Mailgun \Model \Stats \AggregateDevicesResponse ;
18
+ use Mailgun \Model \Stats \AggregateResponse ;
15
19
use Mailgun \Model \Stats \TotalResponse ;
16
20
use Psr \Http \Client \ClientExceptionInterface ;
21
+ use Psr \Http \Message \ResponseInterface ;
17
22
18
23
/**
19
24
* @see https://documentation.mailgun.com/en/latest/api-stats.html
20
- *
21
25
* @author Tobias Nyholm <[email protected] >
22
26
*/
23
27
class Stats extends HttpApi
24
28
{
29
+ public const EVENT_ACCEPTED = 'accepted ' ;
30
+ public const EVENT_DELIVERED = 'delivered ' ;
31
+ public const EVENT_FAILED = 'failed ' ;
32
+ public const EVENT_OPENED = 'opened ' ;
33
+ public const EVENT_CLICKED = 'clicked ' ;
34
+ public const EVENT_UNSUBSCRIBED = 'unsubscribed ' ;
35
+ public const EVENT_COMPLAINED = 'complained ' ;
36
+ public const EVENT_STORED = 'stored ' ;
37
+
25
38
/**
26
- * @param string $domain
27
- * @param array $params
28
- * @param array $requestHeaders
39
+ * @param string $domain
40
+ * @param array $params
41
+ * @param array $requestHeaders
29
42
* @return TotalResponse|array
30
43
* @throws ClientExceptionInterface
44
+ * @throws Exception
31
45
*/
32
46
public function total (string $ domain , array $ params = [], array $ requestHeaders = [])
33
47
{
@@ -37,4 +51,62 @@ public function total(string $domain, array $params = [], array $requestHeaders
37
51
38
52
return $ this ->hydrateResponse ($ response , TotalResponse::class);
39
53
}
54
+
55
+ /**
56
+ * @param array $params
57
+ * @param array $requestHeaders
58
+ * @return TotalResponse|array
59
+ * @throws ClientExceptionInterface
60
+ * @throws Exception
61
+ */
62
+ public function totalAccount (array $ params = [], array $ requestHeaders = [])
63
+ {
64
+ Assert::keyExists ($ params , 'event ' , 'You must specify an event ' );
65
+
66
+ $ response = $ this ->httpGet ('/v3/stats/total ' , $ params , $ requestHeaders );
67
+
68
+ return $ this ->hydrateResponse ($ response , TotalResponse::class);
69
+ }
70
+
71
+ /**
72
+ * @param string $domain
73
+ * @param array $requestHeaders
74
+ * @return AggregateResponse
75
+ * @throws ClientExceptionInterface
76
+ * @throws Exception
77
+ */
78
+ public function aggregateCountsByESP (string $ domain , array $ requestHeaders = []): AggregateResponse
79
+ {
80
+ $ response = $ this ->httpGet (sprintf ('/v3/%s/aggregates/providers ' , rawurlencode ($ domain )), [], $ requestHeaders );
81
+
82
+ return $ this ->hydrateResponse ($ response , AggregateResponse::class);
83
+ }
84
+
85
+ /**
86
+ * @param string $domain
87
+ * @param array $requestHeaders
88
+ * @return AggregateDevicesResponse
89
+ * @throws ClientExceptionInterface
90
+ * @throws Exception
91
+ */
92
+ public function aggregateByDevices (string $ domain , array $ requestHeaders = []): AggregateDevicesResponse
93
+ {
94
+ $ response = $ this ->httpGet (sprintf ('/v3/%s/aggregates/devices ' , rawurlencode ($ domain )), [], $ requestHeaders );
95
+
96
+ return $ this ->hydrateResponse ($ response , AggregateDevicesResponse::class);
97
+ }
98
+
99
+ /**
100
+ * @param string $domain
101
+ * @param array $requestHeaders
102
+ * @return AggregateCountriesResponse
103
+ * @throws ClientExceptionInterface
104
+ * @throws Exception
105
+ */
106
+ public function aggregateByCountry (string $ domain , array $ requestHeaders = []): AggregateCountriesResponse
107
+ {
108
+ $ response = $ this ->httpGet (sprintf ('/v3/%s/aggregates/countries ' , rawurlencode ($ domain )), [], $ requestHeaders );
109
+
110
+ return $ this ->hydrateResponse ($ response , AggregateCountriesResponse::class);
111
+ }
40
112
}
0 commit comments