diff options
| -rw-r--r-- | http.php | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/http.php b/http.php new file mode 100644 index 0000000..7c8abe6 --- /dev/null +++ b/http.php @@ -0,0 +1,55 @@ +<?php + +require_once('boston_food_trucks.php'); + + +class Request { + public $parameters; + + public function parse_parameters () { + $parameters = array(); + + if (isset($_SERVER['QUERY_STRING'])) { + parse_str($_SERVER['QUERY_STRING'], $parameters); + } + + $this->parameters = $parameters; + } + +} + + +class Filters { + public $filters; + private $keys; + + public function __construct () { + $this->keys = array('trucks', + 'days_of_week', + 'times_of_day', + 'locations'); + } + + + public function get_filters ($array) { + // If our array includes expected keys, add those to $this->filters + foreach ($this->keys as $value) { + if (isset($array[$value]) and is_array($array[$value])) { + $this->filters[$value] = $array[$value]; + } + } + } +} + + +// Parse GET parameters +$R = new Request; +$R->parse_parameters(); + +// Get filters from GET parameters +$Filters = new Filters; +$Filters->get_filters($R->parameters); + +// Output JSON from food truck API +$BostonFoodTrucks = new BostonFoodTrucks; +echo $BostonFoodTrucks->schedule($Filters->filters); |
