-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrest.php
More file actions
69 lines (61 loc) · 1.63 KB
/
rest.php
File metadata and controls
69 lines (61 loc) · 1.63 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
<?php
require_once("rest-model.php");
$method = strtolower($_SERVER['REQUEST_METHOD']);
if (isset($_SERVER['PATH_INFO']))
$path = $_SERVER['PATH_INFO'];
else
$path = "";
$pathParts = explode("/", $path);
if(count($pathParts) < 3){
$ret = array('status'=>'FAIL', 'msg'=>'Invalid URL');
retJson($ret);
}
if($pathParts[1] != "v1"){
if($pathParts[1] != "items"){
$ret = array('status'=>'FAIL', 'msg'=>'Invalid URL');
retJson($ret);
}
}
$jsonData = array();
try{
$rawData = file_get_contents("php://input");
$jsonData = json_decode($rawData, true);
if($rawData !== "" && $jsonData==NULL){
$ret = array('status'=>'FAIL','msg'=>'invalid json');
retJson($ret);
}
} catch(Exception $e){
$ret = array('status'=>'FAIL','msg'=>$e);
retJson($ret);
};
if($method === "post" && count($pathParts) == 3){
if($pathParts[2] == "user"){
getToken($jsonData);
$ret = array('status'=>'FAIL','msg'=>'MADE IT PAST THE METHOD CALL');
retJson($ret);
} elseif($pathParts[2] = "items"){
consumeItems($jsonData);
}
} elseif($method === "get" && (count($pathParts) == 3 || count($pathParts) == 4)){
if($pathParts[1] == "items"){
if($pathParts[2] != ""){
userItems($pathParts[2]);
}else{
$ret = array('status'=>'FAIL','msg'=>'Incorrect API call');
retJson($ret);
}
}
if($pathParts[1] == "v1" && $pathParts[2] == "items"){
listItems();
}
if($pathParts[1] == "v1" && $pathParts[2] == "itemsSummary"){
if($pathParts[3] != ""){
userItemSummary($pathParts[3]);
}else{
$ret = array('status'=>'FAIL','msg'=>'Incorrect API call');
retJson($ret);
}
}
}
$ret = array('status'=>'FAIL','msg'=>"Incorrect API call");
retJson($ret);