Skip to content
This repository has been archived by the owner on Feb 15, 2020. It is now read-only.

Add support for handling friends requests #57

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/FortniteClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,31 @@ public static function sendUnrealClientPostRequest($endpoint, $params = null, $a
}
}

/**
* Sends a DELETE request as the Unreal Engine Client.
* @param string $endpoint API Endpoint to request
* @param string $authorization Authorization header
* @param boolean $oauth Is $authorization an OAuth2 token
* @return object Decoded JSON response body
*/
public static function sendUnrealClientDeleteRequest($endpoint, $authorization = self::EPIC_LAUNCHER_AUTHORIZATION, $oauth = false) {
$client = new Client(['http_errors' => false]);

try {
$response = $client->delete($endpoint, [
'headers' => [
'User-Agent' => self::UNREAL_CLIENT_USER_AGENT,
'Authorization' => (!$oauth) ? 'basic ' . $authorization : 'bearer ' . $authorization,
'X-Epic-Device-ID' => self::generateDeviceId()
]
]);

return json_decode($response->getBody()->getContents());
} catch (GuzzleException $e) {
throw $e; //Throw exception back up to caller
}
}

/**
* Sends a GET request as the Fortnite client.
* @param string $endpoint API endpoint to request
Expand Down
20 changes: 18 additions & 2 deletions src/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,26 @@ private function fetch() {

/**
* Get current user's friends on Unreal Engine.
* @param boolean Whether to include friend requests and suggestions. False by default.
* @return array Array of friends
*/
public function getFriends() {
$data = FortniteClient::sendUnrealClientGetRequest(FortniteClient::EPIC_FRIENDS_ENDPOINT . $this->account_id, $this->access_token, true);
public function getFriends($includePending = false) {
$data = FortniteClient::sendUnrealClientGetRequest(FortniteClient::EPIC_FRIENDS_ENDPOINT . $this->account_id .
'?includePending=' . ($includePending ? 'true' : 'false'),
$this->access_token,
true);

return $data;
}

/**
* Remove a friend or decline a friend request on Unreal Engine.
* @param string ID of friend to remove
*/
public function removeFriend($id) {
$data = FortniteClient::sendUnrealClientDeleteRequest(FortniteClient::EPIC_FRIENDS_ENDPOINT . $this->account_id . '/' . $id,
$this->access_token,
new \StdClass());

return $data;
}
Expand Down