Repository navigation
Expand file tree
/
Copy pathUserAPI.php
More file actions
121 lines (112 loc) · 3.43 KB
/
Copy pathUserAPI.php
File metadata and controls
121 lines (112 loc) · 3.43 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
$ds = DIRECTORY_SEPARATOR;
require dirname(__FILE__) . $ds . "UserDB.php";
class UserAPI {
/**
* reference to the user database queries
* @var type
*/
private $_userDb;
/**
* instantiate the User class with a PDO database connection
*
* @author Justen Doherty <phpchap@gmail.com>
*
* @return object $this instance of the User class
*/
public function __construct($id="")
{
$this->_userDb = new UserDB();
return $this;
}
/**
* Add a new friend
* http://www.example.com/api/index.php/userapi/1/requested
*
* @author Justen Doherty <phpchap@gmail.com>
*
* @param int $user_id id of user to fetch
* @param int $friend_id id/array of friends to add
* @return boolean success/failure
*
* @url GET /:userId/getFriend/:friendId
* @url GET /:userId/getFriends/
*/
public function getFriend($userId="", $friendId="")
{
// do we get a specific friend or all friends
if($friendId=="") {
return $this->_userDb->getFriends($userId);
} else {
return $this->_userDb->getFriend($userId, $friendId);
}
}
/**
* Get a list of users
* http://www.example.com/api/index.php/userapi/1/requested
*
* @author Justen Doherty <phpchap@gmail.com>
*
* @param int $user id (optional) fetch a single user or a list of users
* @return array $friends list of friends
*
* @url GET /:userId/requested
*/
function get($userId="")
{
// fetch all users or a single user
if($userId=="") {
return $this->_userDb->getUsers();
} else {
return $this->_userDb->getUser($userId);
}
}
/**
* Get a list of users
* http://www.example.com/api/index.php/userapi/1/requested
*
* @author Justen Doherty <phpchap@gmail.com>
*
* @param int $user id (optional) fetch a single user or a list of users
* @return array $friends list of friends
*
* @url GET /:userId/requested
*/
public function requested($userId="")
{
return $this->_userDb->getRequested($userId);
}
/**
* Accept a friend request
*
* http://www.example.com/api/index.php/userapi/1/requested
*
* @author Justen Dohert <phpchap@gmail.com>
*
* @param int $user_id user_id of the user to fetch
* @param int $friend_id friend_id of friend to accept
* @return boolean successfully accepted friendship
*
* @url POST /:userId/acceptFriend/:friendId
*/
public function acceptFriend($userId, $friendId)
{
return $this->_userDb->acceptFriend($userId, $friendId);
}
/**
* Reject a friend request
* http://www.example.com/api/index.php/userapi/1/requested
*
* @author Justen Dohert <phpchap@gmail.com>
*
* @param int $user_id user_id of the user to fetch
* @param int $friend_id friend_id of friend to accept
* @return boolean successfully rejected friendship
*
* @url POST /:userId/rejectFriend/:friendId
*/
public function rejectFriend($userId, $friendId)
{
return $this->_userDb->rejectFriend($userId, $friendId);
}
}