1 | <?php namespace Cornford\Pokenotifier; |
||
8 | class Notifier extends NotifierBase implements NotifyingInterface { |
||
9 | |||
10 | const TYPE_POKEMON = 'pokemon'; |
||
11 | |||
12 | /** |
||
13 | * Process scan request. |
||
14 | * |
||
15 | * @param Position $position |
||
16 | * |
||
17 | * @throws NotifierException |
||
18 | * |
||
19 | * @return boolean |
||
20 | */ |
||
21 | public function processScanRequest(Position $position) |
||
39 | |||
40 | /** |
||
41 | * Process webhook request. |
||
42 | * |
||
43 | * @param array $result |
||
44 | * @param Position $position |
||
45 | * |
||
46 | * @throws NotifierException |
||
47 | * |
||
48 | * @return boolean |
||
49 | */ |
||
50 | public function processWebhookRequest(array $result, Position $position) |
||
64 | |||
65 | /** |
||
66 | * Request PokemonGo-Map scan. |
||
67 | * |
||
68 | * @param Position $position |
||
69 | * |
||
70 | * @return boolean |
||
71 | */ |
||
72 | public function requestPokemonGoMapScan(Position $position) |
||
92 | |||
93 | /** |
||
94 | * Request PokemonGo-Map data array. |
||
95 | * |
||
96 | * @return array|boolean |
||
97 | */ |
||
98 | public function requestPokemonGoMapData() |
||
110 | |||
111 | /** |
||
112 | * Expire cache items. |
||
113 | * |
||
114 | * @param string $timeout |
||
115 | * |
||
116 | * @return boolean |
||
117 | */ |
||
118 | public function expireCachedItems($timeout = '-1 hour') |
||
119 | { |
||
120 | try { |
||
121 | foreach ($this->getDirectoryIterator() as $file) { |
||
122 | if ($file->isDot() || $file->getFilename() == '.gitkeep') { |
||
123 | continue; |
||
124 | } |
||
125 | |||
126 | if ($file->getMTime() <= strtotime($timeout)) { |
||
127 | unlink($file->getPathname()); |
||
128 | } |
||
129 | } |
||
130 | } catch (Exception $exception) { |
||
131 | return false; |
||
132 | } |
||
133 | |||
134 | return true; |
||
135 | } |
||
136 | |||
137 | /** |
||
138 | * Send slack notification. |
||
139 | * |
||
140 | * @param array $pokemon |
||
141 | * @param Position $position |
||
142 | * |
||
143 | * @return boolean |
||
144 | */ |
||
145 | public function sendSlackNotification(array $pokemon, Position $position) |
||
171 | |||
172 | /** |
||
173 | * Process an array of Pokemon. |
||
174 | * |
||
175 | * @param array $array |
||
176 | * @param Position $position |
||
177 | * @param boolean $notification |
||
178 | * |
||
179 | * @return boolean |
||
180 | */ |
||
181 | public function processPokemon(array $array, Position $position, $notification = true) |
||
206 | |||
207 | } |