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

Commit

Permalink
proper profile endpoint and inventory items
Browse files Browse the repository at this point in the history
  • Loading branch information
Tustin committed Feb 22, 2018
1 parent 465c592 commit 7729970
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 6 deletions.
52 changes: 52 additions & 0 deletions src/Model/Items.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
namespace Fortnite\Model;

class Items {
private $items;

public function __construct($items) {
$this->items = $this->parseItems((array)$items);
}

/**
* Returns item by it's item id.
* @param string $id Item id
* @return object The item (null if not found)
*/
public function id($id) {
foreach ($this->items as $item) {
if ($item->itemId == $id) return $item;
}

return null;
}

/**
* Returns all owned items.
* @return array The items
*/
public function all() {
return $this->items;
}

//
// TODO (Tustin): maybe get all items of a certain type? Not really possible for me since I don't own more than like 5 items and they're all dances and gliders.
// You would just need to parse 'templateId' for the first part to get the type.
//

/**
* Parses a list of items and removes any non items (for some reason, quests show up in here)
* @param array $items Items
* @return array Actual items
*/
private function parseItems($items) {
$actual = [];
foreach ($items as $key => $item) {
if (strpos($item->templateId, "Quest:") !== false) continue;
$newItem = $item;
$newItem->itemId = $key; // Add the itemId as a kvp since it only exists as the object identifier initially
$actual[] = $newItem;
}
return $actual;
}
}
15 changes: 9 additions & 6 deletions src/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,32 @@
namespace Fortnite;

use Fortnite\FortniteClient;
use Fortnite\Model\Items;

class Profile {
private $access_token;
private $account_id;

public $stats;
public $items;

public function __construct($access_token, $account_id) {
$this->access_token = $access_token;
$this->account_id = $account_id;
$data = $this->fetch();
$this->items = new Items($data->items);
$this->stats = new Stats($access_token, $account_id);
}

/**
* Fetches current profile data
* @param string $profile_id Profile Id to get data for. Unsure what this is used for.
* @return object The profile's data
* Fetches profile data.
* @return object Profile data
*/
private function fetch($profile_id = "profile0") {
$data = FortniteClient::sendFortnitePostRequest(FortniteClient::FORTNITE_API . 'game/v2/profile/' . $this->account_id . '/client/QueryProfile?profileId=profile0&rvn=-1',
private function fetch() {
$data = FortniteClient::sendFortnitePostRequest(FortniteClient::FORTNITE_API . 'game/v2/profile/' . $this->account_id . '/client/QueryProfile?profileId=athena&rvn=-1',
$this->access_token,
new \StdClass());
return $data;
return $data->profileChanges[0]->profile;
}

/**
Expand Down

0 comments on commit 7729970

Please sign in to comment.