diff options
| author | Teddy Wing | 2013-05-20 21:03:47 -0400 |
|---|---|---|
| committer | Teddy Wing | 2013-05-20 21:03:47 -0400 |
| commit | c3ffa90158ddecea91bc2696c36ff293f5b6e1e0 (patch) | |
| tree | a09406d51752babc23878a26fe16c3ae9678089a /http.php | |
| parent | 074718dc4a87f4d84d94f0a7938d109d3d2e09c9 (diff) | |
| download | Boston-Food-Truck-Schedule-API-c3ffa90158ddecea91bc2696c36ff293f5b6e1e0.tar.bz2 | |
Add HTTP version of API
Diffstat (limited to 'http.php')
| -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); |
