Skip to content

Commit 0d6d267

Browse files
authored
Merge pull request #6 from nitrado/WEB-1198-add-changelog-endpoint
WEB-1198: Add the changelog endpoint.
2 parents 03cb9ce + 9d7fb3f commit 0d6d267

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

Diff for: lib/Nitrapi/Services/Service.php

+49
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,55 @@ public function getDDoSHistory() {
147147
return $this->getApi()->dataGet($url);
148148
}
149149

150+
/**
151+
* Lists all changelog items, which are available for the service.
152+
* A changelog item consists of a message with additional information.
153+
* This items will be used to show game updates and other notification
154+
* type messages to the service. A changelog item has the following
155+
* attributes:
156+
*
157+
* category Which category the item will be (default "Game")
158+
* created When the item is created
159+
* status
160+
* name What status the item has (e.g. "Update")
161+
* icon Icon name to use for display purpose
162+
* button_class CSS Class to use for display purpose
163+
* text The actual message to display
164+
* game The full game name
165+
* alert If the message is an alert message
166+
*
167+
* If the first parameter is set to true, changelog items for all
168+
* games will be returned. With the second parameter you can
169+
* suppress all non alert messages.
170+
*
171+
* @param boolean true if you need items from all games
172+
* @param boolean true if only alerts should be shown
173+
*
174+
* @return array a list of changelog items
175+
*/
176+
public function getChangelogItems($allGames = false, $onlyAlerts = false) {
177+
$changelogs = $this->getApi()->dataGet('/changelogs');
178+
if (!isset($changelogs['changelogs'])) return [];
179+
180+
$filteredChangelogs = $changelogs['changelogs'];
181+
182+
// Filter out all non current game related items
183+
if (!$allGames) {
184+
$details = $this->getServiceDetails();
185+
if (!isset($details['game'])) return [];
186+
foreach ($filteredChangelogs as $i => $changelog)
187+
if (!isset($changelog['game']) || $changelog['game'] != $details['game'])
188+
unset($filteredChangelogs[$i]);
189+
}
190+
191+
// Filter out all normal items (only alerts)
192+
if ($onlyAlerts)
193+
foreach ($filteredChangelogs as $i => $changelog)
194+
if (!$changelog['alert']) unset($filteredChangelogs[$i]);
195+
196+
return $filteredChangelogs;
197+
}
198+
150199
/**
151200
* Returns the last log entries. You can optionally
152201
* provide a page number.

0 commit comments

Comments
 (0)