|
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\Model\Suppression\Unsubscribe; |
|
11
|
|
|
|
|
12
|
|
|
use Mailgun\Model\ApiResponse; |
|
13
|
|
|
use Mailgun\Model\PaginationResponse; |
|
14
|
|
|
use Mailgun\Model\PagingProvider; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @author Sean Johnson <[email protected]> |
|
18
|
|
|
*/ |
|
19
|
|
|
final class IndexResponse implements ApiResponse, PagingProvider |
|
20
|
|
|
{ |
|
21
|
|
|
use PaginationResponse; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Array to store a list of Unsubscribe items from |
|
25
|
|
|
* index response |
|
26
|
|
|
* |
|
27
|
|
|
* @see Mailgun/Model/Suppression/Unsubscribe/Unsubscribe |
|
28
|
|
|
* @var Unsubscribe[] |
|
29
|
|
|
*/ |
|
30
|
|
|
private $items = []; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Store the total number of Unsubscribe items |
|
34
|
|
|
* |
|
35
|
|
|
* @see Mailgun/Model/Suppression/Unsubscribe/Unsubscribe |
|
36
|
|
|
* @var integer |
|
37
|
|
|
*/ |
|
38
|
|
|
private $totalCount; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @see Mailgun/Model/Suppression/Unsubscribe/Unsubscribe |
|
42
|
|
|
* |
|
43
|
|
|
* @param Unsubscribe[] $items |
|
44
|
|
|
* @param array $paging |
|
45
|
|
|
*/ |
|
46
|
|
|
private function __construct(array $items, array $paging) |
|
47
|
|
|
{ |
|
48
|
|
|
$this->items = $items; |
|
49
|
|
|
$this->paging = $paging; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Allow create the unsubscribe items with paging |
|
54
|
|
|
* |
|
55
|
|
|
* @param array $data |
|
56
|
|
|
* |
|
57
|
|
|
* @return IndexResponse |
|
58
|
|
|
*/ |
|
59
|
|
|
public static function create(array $data) |
|
60
|
|
|
{ |
|
61
|
|
|
$unsubscribes = []; |
|
62
|
|
|
if (isset($data['items'])) { |
|
63
|
|
|
foreach ($data['items'] as $item) { |
|
64
|
|
|
$unsubscribes[] = Unsubscribe::create($item); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
return new self($unsubscribes, $data['paging']); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Get the Unsusbscribe item models from the response |
|
73
|
|
|
* |
|
74
|
|
|
* @see Mailgun/Model/Suppression/Unsubscribe/Unsubscribe |
|
75
|
|
|
* |
|
76
|
|
|
* @return Unsubscribe[] |
|
77
|
|
|
*/ |
|
78
|
|
|
public function getItems() |
|
79
|
|
|
{ |
|
80
|
|
|
return $this->items; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Get the total count of Unsusbscribe in index response |
|
85
|
|
|
* |
|
86
|
|
|
* @see Mailgun/Model/Suppression/Unsubscribe/Unsubscribe |
|
87
|
|
|
* |
|
88
|
|
|
* @return integer |
|
89
|
|
|
*/ |
|
90
|
|
|
public function getTotalCount() |
|
91
|
|
|
{ |
|
92
|
|
|
if (null === $this->totalCount) { |
|
93
|
|
|
$this->totalCount = count($this->items); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
return $this->totalCount; |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|