diff options
author | Christian Cleberg <hello@cleberg.net> | 2023-05-31 21:14:41 -0500 |
---|---|---|
committer | Christian Cleberg <hello@cleberg.net> | 2023-05-31 21:14:41 -0500 |
commit | e530c99eb5bfaacf29b8666ee561b737bf62c023 (patch) | |
tree | 1cb0473601a2e7a431da1ee9c8c3bd7a690474ef | |
parent | 58ee925fe7e32d449f9541cf7e7b2dc409a5b212 (diff) | |
download | hn-e530c99eb5bfaacf29b8666ee561b737bf62c023.tar.gz hn-e530c99eb5bfaacf29b8666ee561b737bf62c023.tar.bz2 hn-e530c99eb5bfaacf29b8666ee561b737bf62c023.zip |
implement remaining API endpoints
-rw-r--r-- | index.php | 63 |
1 files changed, 53 insertions, 10 deletions
@@ -11,7 +11,7 @@ if (empty($elements[0])) { ); echo_html( $GLOBALS['full_domain'] . '/best/', - 'The top 30 stories from Hacker News. Proxied by hn.', + 'The top stories from Hacker News, proxied by hn.', 'hn', $html_output ); @@ -23,31 +23,75 @@ if (empty($elements[0])) { 'Top' ); echo_html( - $GLOBALS['full_domain'] . '/best/', - 'The top 30 stories from Hacker News. Proxied by hn.', + $GLOBALS['full_domain'] . '/top/', 'hn', $html_output ); break; case 'best': - echo 'best'; + $html_output = get_stories( + 'https://hacker-news.firebaseio.com/v0/beststories.json?limitToFirst=30&orderBy="$key"', + 'Best' + ); + echo_html( + $GLOBALS['full_domain'] . '/best/', + 'The best 30 stories from Hacker News, proxied by hn.', + 'hn', + $html_output + ); break; case 'new': - echo 'new'; + $html_output = get_stories( + 'https://hacker-news.firebaseio.com/v0/newstories.json?limitToFirst=30&orderBy="$key"', + 'New' + ); + echo_html( + $GLOBALS['full_domain'] . '/new/', + 'The newest 30 stories from Hacker News, proxied by hn.', + 'hn', + $html_output + ); break; case 'ask': - echo 'ask'; + $html_output = get_stories( + 'https://hacker-news.firebaseio.com/v0/askstories.json?limitToFirst=30&orderBy="$key"', + 'Ask' + ); + echo_html( + $GLOBALS['full_domain'] . '/ask/', + 'The latest 30 asks from Hacker News, proxied by hn.', + 'hn', + $html_output + ); break; case 'show': - echo 'show'; + $html_output = get_stories( + 'https://hacker-news.firebaseio.com/v0/showstories.json?limitToFirst=30&orderBy="$key"', + 'Show' + ); + echo_html( + $GLOBALS['full_domain'] . '/show/', + 'The latest 30 show stories from Hacker News, proxied by hn.', + 'hn', + $html_output + ); break; case 'job': - echo 'job'; + $html_output = get_stories( + 'https://hacker-news.firebaseio.com/v0/jobstories.json?limitToFirst=30&orderBy="$key"', + 'Job' + ); + echo_html( + $GLOBALS['full_domain'] . '/job/', + 'The latest 30 job posts from Hacker News, proxied by hn.', + 'hn', + $html_output + ); break; default: @@ -64,8 +108,7 @@ if (empty($elements[0])) { * @param string $inline_title The <h1> title to use in the HTML * @return string $html_output The formatted HTML result of stories from the API */ -function get_stories($api_url, $inline_title) -{ +function get_stories($api_url, $inline_title) { $response_raw = file_get_contents($api_url); $response = json_decode($response_raw, true); |