Created
June 1, 2024 09:43
-
-
Save marckohlbrugge/c87bf093676c48f900d16afe003496be to your computer and use it in GitHub Desktop.
Simple example of creating a changelog with the WIP API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Get your API key here: https://wip.co/my/api_keys | |
$apiKey = 'wip_sk_FOOBAR'; | |
$baseUrl = 'https://api.wip.co/v1'; | |
$projectSlug = 'nomadlist'; | |
// Get todos for the project with pagination | |
$limit = 10; | |
$startingAfter = isset($_GET['starting_after']) ? $_GET['starting_after'] : null; | |
$todosEndpoint = "/projects/$projectSlug/todos"; | |
$todosUrl = $baseUrl . $todosEndpoint . "?limit=$limit&api_key=$apiKey"; | |
if ($startingAfter) { | |
$todosUrl .= "&starting_after=$startingAfter"; | |
} | |
$todosResponse = json_decode(file_get_contents($todosUrl), true); | |
if (!$todosResponse) { | |
die('Error fetching todos'); | |
} | |
$todos = $todosResponse['data']; | |
$hasMore = $todosResponse['has_more']; | |
?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>NomadList Changelog</title> | |
<style> | |
body { | |
font-family: Arial, sans-serif; | |
margin: 20px; | |
} | |
.changelog { | |
max-width: 600px; | |
margin: auto; | |
} | |
.todo { | |
border-bottom: 1px solid #ccc; | |
padding: 10px 0; | |
} | |
.todo h3 { | |
margin: 0; | |
} | |
.todo .timestamp { | |
color: #888; | |
font-size: 0.9em; | |
} | |
.todo img { | |
max-width: 100%; | |
height: auto; | |
margin-top: 10px; | |
} | |
.pagination { | |
text-align: center; | |
margin-top: 20px; | |
} | |
.pagination a { | |
margin: 0 5px; | |
text-decoration: none; | |
color: #007BFF; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="changelog"> | |
<h1>NomadList Changelog</h1> | |
<?php foreach ($todos as $todo): ?> | |
<div class="todo"> | |
<h3><?php echo htmlspecialchars($todo['body']); ?></h3> | |
<div class="timestamp"><?php echo date('Y-m-d H:i:s', strtotime($todo['created_at'])); ?></div> | |
<?php if (!empty($todo['attachments'])): ?> | |
<?php foreach ($todo['attachments'] as $attachment): ?> | |
<img src="<?php echo htmlspecialchars($attachment['url']); ?>" alt="Attachment"> | |
<?php endforeach; ?> | |
<?php endif; ?> | |
</div> | |
<?php endforeach; ?> | |
<div class="pagination"> | |
<?php if ($startingAfter): ?> | |
<a href="?starting_after=<?php echo htmlspecialchars($todos[0]['id']); ?>">Previous</a> | |
<?php endif; ?> | |
<?php if ($hasMore): ?> | |
<a href="?starting_after=<?php echo htmlspecialchars(end($todos)['id']); ?>">Next</a> | |
<?php endif; ?> | |
</div> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment