Skip to content

Commit 251aab1

Browse files
Added the v2 friend search API
1 parent 557c1a4 commit 251aab1

File tree

8 files changed

+52
-21
lines changed

8 files changed

+52
-21
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ composer require hub/hubid-api-client
1414

1515
## Authentication
1616

17+
Refer to the [https://hubculture.com/developer/home](https://hubculture.com/developer/home) for obtaining the private and public keys.
18+
1719
```php
1820
include '/vendor/autoload.php';
1921

@@ -57,9 +59,9 @@ var_dump($user);
5759
Please run the following command to run a PHP server serving examples.
5860

5961
```bash
60-
make demo
62+
HUBID_PRIVATE_KEY=[your-private-key] HUBID_PUBLIC_KEY=[your-public-key] make demo
6163
```
6264

63-
Browse to [http://localhost:8085/message-service.php](http://localhost:8085/message-service.php).
65+
Browse to [http://localhost:8085/friend-service.php](http://localhost:8085/friend-service.php).
6466

65-
You may look at examples under examples directory.
67+
You may look at examples under `examples` directory.

examples/config.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
$config = array(
88
'base_path' => 'https://id.hubculture.com:466',
99
'verify' => false,
10-
'private_key' => 'private_5d265de1d9204f6235830ce2',
11-
'public_key' => 'public_153222247f4cbe2511208120a',
10+
'private_key' => getenv('HUBID_PRIVATE_KEY'), // __YOUR_KEY__
11+
'public_key' => getenv('HUBID_PUBLIC_KEY'), // __YOUR_KEY__
1212
'client_id' => 10014,
1313
'debug' => true,
1414
);

examples/event-service.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
$redirectUrl = 'http://localhost:8085/event-service.php';
1313
if (empty($_GET['access_token'])) {
14-
$redirectLoginHelper->getAccessToken($redirectUrl);
14+
$redirectLoginHelper->redirectToLoginUrl($redirectUrl);
1515
} else {
1616
$accessToken = $_GET['access_token'];
1717
$refreshedToken = $redirectLoginHelper->getRefreshToken($accessToken);

examples/friend-service.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,19 @@
2525
// example event creation and retrieval
2626
$service = new FriendService($config);
2727

28-
$potentialFriendId = 21025;
2928

30-
try {
31-
$response = $service->addFriend('A friend request via the API SDK', $potentialFriendId);
32-
var_dump($response);
33-
} catch (HubIdApiException $ex) {
34-
$service->removeFriend($potentialFriendId);
35-
$response = $service->addFriend('A friend request via the API SDK', $potentialFriendId);
36-
}
37-
var_dump($service->getPendingFriends());
38-
var_dump($service->removeFriend($potentialFriendId));
29+
var_dump($service->getFriends());
3930
var_dump($service->getPendingFriends());
31+
var_dump($service->getFriendRequests());
32+
var_dump($service->searchFriends('user'));
33+
//
34+
// $potentialFriendId = 123456789;
35+
// try {
36+
// $response = $service->addFriend('A friend request via the API SDK', $potentialFriendId);
37+
// var_dump($response);
38+
// } catch (HubIdApiException $ex) {
39+
// $service->removeFriend($potentialFriendId);
40+
// $response = $service->addFriend('A friend request via the API SDK', $potentialFriendId);
41+
// }
42+
// var_dump($service->removeFriend($potentialFriendId));
4043
}

examples/message-service.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
$redirectUrl = 'http://localhost:8085/message-service.php';
1414

1515
if (empty($_GET['access_token'])) {
16-
$redirectLoginHelper->getAccessToken($redirectUrl);
16+
$redirectLoginHelper->redirectToLoginUrl($redirectUrl);
1717
} else {
1818
$accessToken = $_GET['access_token'];
1919
$refreshedToken = $redirectLoginHelper->getRefreshToken($accessToken);

examples/ultra-service.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
$redirectUrl = 'http://localhost:8085/ultra-service.php';
1212

1313
if (empty($_GET['access_token'])) {
14-
$redirectLoginHelper->getAccessToken($redirectUrl);
14+
$redirectLoginHelper->redirectToLoginUrl($redirectUrl);
1515
} else {
1616
$accessToken = $_GET['access_token'];
1717
$refreshedToken = $redirectLoginHelper->getRefreshToken($accessToken);

examples/user-service.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
$redirectUrl = 'http://localhost:8085/user-service.php';
1313

1414
if (empty($_GET['access_token'])) {
15-
$redirectLoginHelper->getAccessToken($redirectUrl);
15+
$redirectLoginHelper->redirectToLoginUrl($redirectUrl);
1616
} else {
1717
$accessToken = $_GET['access_token'];
1818
$refreshedToken = $redirectLoginHelper->getRefreshToken($accessToken);

src/Service/FriendService.php

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
class 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

Comments
 (0)