diff --git a/api/v1/getfoxes/index.php b/api/v1/getfoxes/index.php new file mode 100644 index 0000000..6f9b499 --- /dev/null +++ b/api/v1/getfoxes/index.php @@ -0,0 +1,51 @@ + 0){ + $foxNums = array(); + $image_paths = array(); + $links = array(); + for ($x = 0; $x < $_GET["count"]; $x++) { + do { + $random_number = rand(1, $FOX_NUM); + } while (in_array( $random_number ,$foxNums )); + array_push($foxNums,$random_number); + array_push($image_paths,'https://randomfox.ca/images/'.$random_number.'.jpg'); + array_push($links,'https://randomfox.ca/?i='.$random_number); + $valid_request = TRUE; + } + } else { + if ($_GET['count'] <= 0){ + header('HTTP/1.1 420 Need to specify COUNT between 0 and '.$MAX_ALLOWED_COUNT.''); + $error_msg = '\'count\' needs to be specified between 0 and '.$MAX_ALLOWED_COUNT.''; + } else { + header('HTTP/1.1 420 Need to specify COUNT within'.$MAX_ALLOWED_COUNT.''); + $error_msg = '\'count\' needs to be specified within '.$MAX_ALLOWED_COUNT.''; + } + } + } else { + header('HTTP/1.1 420 Need to specify COUNT 0 and '.$MAX_ALLOWED_COUNT.''); + $error_msg = '\'count\' needs to be specified 0 and '.$MAX_ALLOWED_COUNT.''; + } +} else { + $foxNums = null; + $image_paths = null; + $links = null; + if (ctype_digit($_GET['count'])){} + header('HTTP/1.1 420 Need to specify COUNT'); + $error_msg = '\'count\' needs to be specified'; +} +if ($valid_request == TRUE){ + $data = array('images' => $image_paths, 'links' => $links); + +} else { + $data = array('error' => $error_msg,'status' => '420'); +} +echo json_encode($data);