Skip to content

Commit

Permalink
examples and some changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Tustin committed Sep 29, 2018
1 parent 31b9a86 commit 5197f31
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 9 deletions.
26 changes: 26 additions & 0 deletions examples/User.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
require_once "../vendor/autoload.php";

use PlayStation\Client;

$client = new Client(["verify" => false, "proxy" => "127.0.0.1:8888"]);

$client->login(getenv("PSN_PHP_TOKEN"));

$me = $client->user();

echo sprintf("%s\n", $me->onlineId());
echo sprintf("\tAbout me: %s\n", $me->aboutMe());
echo sprintf("\tAvatar: %s\n", $me->avatarUrl());
echo sprintf("\tFriends with? %d\n", $me->friend());
echo sprintf("\tClose friends with? %d\n", $me->closeFriend());
echo sprintf("\tVerified? %d\n", $me->verified());

$you = $client->user("Hakoom");

echo sprintf("%s\n", $you->onlineId());
echo sprintf("\tAbout me: %s\n", $you->aboutMe());
echo sprintf("\tAvatar: %s\n", $you->avatarUrl());
echo sprintf("\tFriends with? %d\n", $you->friend());
echo sprintf("\tClose friends with? %d\n", $you->closeFriend());
echo sprintf("\tVerified? %d\n", $you->verified());
19 changes: 12 additions & 7 deletions src/Api/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,14 @@ public function closeFriend() : bool
/**
* Add the User to friends list.
*
* Will not do anything if called on the logged in user.
*
* @param string $requestMessage Message to send with the request.
* @return void
*/
public function add(string $requestMessage = null) : void
{
if ($this->onlineId() === null) return;
if ($this->onlineIdParameter() === 'me') return;

$data = ($requestMessage === null) ? new \stdClass() : [
"requestMessage" => $requestMessage
Expand All @@ -153,11 +155,13 @@ public function add(string $requestMessage = null) : void
/**
* Remove the User from friends list.
*
* Will not do anything if called on the logged in user.
*
* @return void
*/
public function remove() : void
{
if ($this->onlineId() === null) return;
if ($this->onlineIdParameter() === 'me') return;

$this->delete(sprintf(self::USERS_ENDPOINT . 'friendList/%s', $this->client->onlineId(), $this->onlineId()));
}
Expand All @@ -169,31 +173,32 @@ public function remove() : void
*/
public function block() : void
{
if ($this->onlineId() === null) return;
if ($this->onlineIdParameter() === 'me') return;

$this->post(sprintf(self::USERS_ENDPOINT . 'blockList/%s', $this->client->onlineId(), $this->onlineId()), null);
}

/**
* Unblock the User.
*
* Will not do anything if called on the logged in user.
*
* @return void
*/
public function unblock() : void
{
if ($this->onlineId() === null) return;
if ($this->onlineIdParameter() === 'me') return;

$this->delete(sprintf(self::USERS_ENDPOINT . 'blockList/%s', $this->client->onlineId(), $this->onlineId()));
}

/**
* Get the User's friends.
*
* @param string $filter Online Filter.
* @param integer $limit How many users to return.
* @return array Array of Api\User.
*/
public function friends($filter = 'online', $limit = 36) : array
public function friends($limit = 36) : array
{
$result = [];

Expand Down Expand Up @@ -411,7 +416,7 @@ public function communities() : array
*/
private function messageGroup() : ?MessageThread
{
if ($this->onlineId() === null) return null;
if ($this->onlineIdParameter() === 'me') return null;

$thread = $this->privateMessageThread();

Expand Down
4 changes: 2 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ class Client {
private $refreshToken;
private $expiresIn;

public function __construct(HttpClient $httpClient = null, array $options = [])
public function __construct(array $options = [])
{
$this->options = $options;
$this->httpClient = $httpClient ?? new HttpClient(new \GuzzleHttp\Client($this->options));
$this->httpClient = new HttpClient(new \GuzzleHttp\Client($this->options));
}

/**
Expand Down

0 comments on commit 5197f31

Please sign in to comment.