99class FriendService extends TokenRefreshingService
1010{
1111 const BASE = '/friends ' ;
12+ const DEFAULT_PAGINATION_LIMIT = 10 ;
1213
1314 /**
1415 * This returns all the friends of the current authenticated user.
@@ -19,10 +20,10 @@ class FriendService extends TokenRefreshingService
1920 * @return array
2021 * @see UserService::getFriends()
2122 */
22- public function getFriends ($ offset = 0 , $ limit = 10 )
23+ public function getFriends ($ offset = 0 , $ limit = self :: DEFAULT_PAGINATION_LIMIT )
2324 {
2425 $ offset = intval ($ offset ) === 0 ? 0 : intval ($ offset );
25- $ limit = intval ($ limit ) === 0 ? 10 : intval ($ limit );
26+ $ limit = intval ($ limit ) === 0 ? self :: DEFAULT_PAGINATION_LIMIT : intval ($ limit );
2627
2728 return $ this ->createResponse ($ this ->get (self ::BASE . "/?offset= {$ offset }&limit= {$ limit }" ));
2829 }
@@ -126,4 +127,29 @@ public function removeFriend($friendUserId)
126127 {
127128 return $ this ->createResponse ($ this ->delete ("/friend/ {$ friendUserId }" ));
128129 }
130+
131+ /**
132+ * Use this to search for friends in the current authenticated user's (your) friend list.
133+ *
134+ * @param string $searchKeyword The search term to search for friends in your friend list.
135+ * This can be part of a name or an email address.
136+ * @param int $offset [optional] offset for pagination
137+ * @param int $limit [optional] limit for pagination
138+ *
139+ * @return array
140+ */
141+ public function searchFriends ($ searchKeyword , $ offset = 0 , $ limit = self ::DEFAULT_PAGINATION_LIMIT )
142+ {
143+ if (empty ($ searchKeyword )) {
144+ return [];
145+ }
146+
147+ $ offset = intval ($ offset ) === 0 ? 0 : intval ($ offset );
148+ $ limit = intval ($ limit ) === 0 ? self ::DEFAULT_PAGINATION_LIMIT : intval ($ limit );
149+ $ searchKeyword = urlencode ($ searchKeyword );
150+
151+ return $ this ->createResponse (
152+ $ this ->get ("/v2/friends/search?search= {$ searchKeyword }&offset= {$ offset }&limit= {$ limit }" )
153+ );
154+ }
129155}
0 commit comments