aboutsummaryrefslogtreecommitdiffstats
path: root/http.php
blob: ddea68f669e24f928e9b1efad258e90325721970 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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 json_encode($BostonFoodTrucks->schedule($Filters->filters));