Skip to content

Instantly share code, notes, and snippets.

@Rhincodon
Created November 12, 2018 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rhincodon/335bec5a3612afc89fa8cad3ca5ce42e to your computer and use it in GitHub Desktop.
Save Rhincodon/335bec5a3612afc89fa8cad3ca5ce42e to your computer and use it in GitHub Desktop.
act.php
<?php
namespace App\Services;
use GuzzleHttp\Client;
class BungieApiService
{
private $client;
public function __construct($apiUrl, $apiKey)
{
$this->client = new Client([
'base_uri' => $apiUrl,
'headers' => [
'X-API-Key' => $apiKey,
],
]);
}
public function getClient()
{
return $this->client;
}
/**
* @param $membershipType
* @param $membershipId
* @param $destinyId
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function getCharacterActivities($membershipType, $membershipId, $destinyId)
{
return $this->client->requestAsync('GET', sprintf(
"Destiny2/%s/Account/%s/Character/%s/Stats/Activities?count=%s",
$membershipType,
$membershipId,
$destinyId,
150
));
}
/**
* @param $activityId
* @return mixed|\Psr\Http\Message\ResponseInterface
*/
public function getActivityExtraData($activityId)
{
return $this->client->requestAsync('GET', sprintf(
"Destiny2/Stats/PostGameCarnageReport/%s",
$activityId
));
}
/**
* @param $clanId
* @return bool
*/
public function getClanInfo($clanId)
{
try {
$response = $this->client->get(sprintf('GroupV2/%s', $clanId));
} catch (\Exception $e) {
return false;
}
return $this->transformResponse($response->getBody()->getContents());
}
/**
* @param $clanId
* @return bool
*/
public function getClanPlayers($clanId)
{
try {
$response = $this->client->get(sprintf('GroupV2/%s/Members', $clanId));
} catch (\Exception $e) {
return false;
}
return $this->transformResponse($response->getBody()->getContents());
}
/**
* @param $membershipType
* @param $membershipId
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function getPlayerCharacters($membershipType, $membershipId)
{
return $this->client->requestAsync('GET', sprintf("Destiny2/%s/Profile/%s?components=Profiles,Characters,Records", $membershipType, $membershipId));
}
private function transformResponse($json)
{
return json_decode($json, true)['Response'];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment