Skip to content

Commit 9cc8a8b

Browse files
committed
Add intial version of the Rickies API
1 parent 02027cb commit 9cc8a8b

5 files changed

Lines changed: 26 additions & 1 deletion

File tree

‎Changelog.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
_Also check out the [roadmap](Roadmap.md) with features I’d like to add in the future._
44

5+
### 4 April 2022
6+
7+
- [Rickies API](https://rickies.co/api) available to fetch the current chairmen in JSON format
8+
59
## 29 March 2022 v2.2
610

711
- New [Trophies](https://rickies.co/trophies) page with explanations about the different Rickies trophies, including:

‎includes/data_controllers/magtricky_data_controller.php‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// MagTricky _data_ controller
44

5-
$magtricky__params = [];
5+
$magtricky__params = $api__array = [];
66
$magtricky__array = [
77
'Myke' => 0,
88
'Federico' => 0,
@@ -18,6 +18,11 @@
1818
// $id = json_decode(json_encode($array), true)["id"];
1919
$fields = json_decode(json_encode($array), true)['fields'];
2020
$magtricky__array[check_key('Title holder', $fields)]++;
21+
22+
$api__array[str_replace(' ', '_', strtolower(check_key('Chairman', $fields)))]['name'] = check_key(
23+
'Title holder',
24+
$fields
25+
);
2126
}
2227
} else {
2328
// Response from Airtable is not countable, so it's probably an error instead of an empty array
@@ -26,3 +31,4 @@
2631
} while ($magtricky__request = $magtricky__response->next());
2732

2833
// echo '<pre>', var_dump($magtricky__array), '</pre>';
34+
// echo '<pre>', var_dump($api__array), '</pre>';

‎includes/view_controllers/rickies_controller.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
include '../includes/view_controllers/rickies_list_controller.php';
1111
$include_subbody = '../includes/views/rickies.php';
1212
break;
13+
case 'api':
14+
// Redirect to the API output (temporary)
15+
header('Location: ' . domain_url() . '/api/chairmen.json');
16+
die();
1317
case '3j-leaderboard':
1418
// Leaderboard of Triple J Pickies
1519
$triple_j = true;

‎public_html/.htaccess‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ RewriteRule ^sitemap\.xml$ /sitemap.php [L]
1111
## Manifest JSON to PHP
1212
RewriteRule ^manifest\.json$ /manifest.php [L]
1313

14+
## API JSON to PHP
15+
RewriteRule ^api/chairmen\.json$ /api/chairmen.php [L]
16+
1417
## From Bill subdomain to directory
1518
RewriteBase /
1619
RewriteCond %{HTTP_HOST} ^thebillof\.(.*)$ [NC]

‎public_html/api/chairmen.php‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
require_once $_SERVER['DOCUMENT_ROOT'] . '/../includes/functions.php';
4+
5+
header('Content-Type: application/json; charset=utf-8');
6+
7+
include $_SERVER['DOCUMENT_ROOT'] . '/../includes/data_controllers/magtricky_data_controller.php';
8+
echo json_encode($api__array);

0 commit comments

Comments
 (0)