Verified Commit 712e1864 authored by Connor Tumbleson's avatar Connor Tumbleson

Merge branch 'master' into production

parents 2a58028e bfd9fc0f
Pipeline #1425 passed with stages
in 4 minutes and 43 seconds
......@@ -31,6 +31,26 @@ class Text
return Str::lower(str_replace(' ', '-', str_replace('"', null, str_replace("'", null, $gamertag))));
}
/**
* @param string $gamertag
*
* @return string
*/
public static function blizzard(string $gamertag): string
{
return str_replace('#', '-', $gamertag);
}
/**
* @param string $gamertag
*
* @return string
*/
public static function blizzardSeo(string $gamertag): string
{
return self::seoGamertag(self::blizzard($gamertag));
}
/**
* Returns value greatest used.
*
......
......@@ -4,6 +4,7 @@ namespace Onyx\Overwatch;
use Carbon\Carbon;
use Onyx\Account;
use Onyx\Destiny\Helpers\String\Text;
use Onyx\Destiny\Helpers\String\Text as DestinyText;
use Onyx\Overwatch\Constants as OverwatchConstants;
use Onyx\Overwatch\Helpers\Game\Season;
......@@ -34,12 +35,15 @@ class Client extends Http
public function fetchBlobStat($account, $platform = Console::Xbox)
{
// xbl/pc/psn
$url = sprintf(OverwatchConstants::$getBlobStats, $account->gamertag, Console::getOverwatchTag($platform));
$url = sprintf(OverwatchConstants::$getBlobStats, Text::blizzard($account->gamertag), Console::getOverwatchTag($platform));
$data = $this->getJson($url);
if (isset($data['any']) && isset($data['any']['stats']['competitive'])) {
return $data['any'];
$types = ['any', 'us', 'eu'];
foreach ($types as $type) {
if (isset($data[$type]) && isset($data[$type]['stats']['competitive'])) {
return $data[$type];
}
}
throw new OWApiNetworkException('Could not find account (Either no competitive data or does not exist).');
......@@ -75,13 +79,12 @@ class Client extends Http
// Account does not exist. Make it.
if ($account === null) {
$account = Account::firstOrCreate([
'gamertag' => $gamertag,
'gamertag' => Text::blizzardSeo($gamertag),
'accountType' => $platform,
]);
} else {
$account->gamertag = $gamertag;
}
$account->gamertag = Text::blizzard($gamertag);
$data = $this->fetchBlobStat($account, $platform);
// Insert data
......@@ -104,7 +107,7 @@ class Client extends Http
*/
public function checkCacheForTag($account, $platform = Console::Xbox)
{
$seo = DestinyText::seoGamertag($account);
$seo = DestinyText::blizzardSeo($account);
if (isset($this->account_cached[$seo])) {
return $this->account_cached[$seo];
......
......@@ -3,7 +3,7 @@
namespace Onyx\XboxLive;
use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\Promise as GuzzlePromise;
use GuzzleHttp\Psr7\Response;
use Illuminate\Support\Facades\Cache;
use Onyx\Account;
use Onyx\XboxLive\Constants as XboxConstants;
......@@ -46,7 +46,8 @@ class Client extends XboxAPI
]);
// Set up getCommands
$requests = [];
$results = [];
foreach ($accounts as $account) {
if ($account->xuid == null) {
if ($this->getXuid($account) == null) {
......@@ -55,13 +56,12 @@ class Client extends XboxAPI
}
$url = sprintf(XboxConstants::$getPresenceUrl, $account->xuid);
$requests[$account->seo] = $client->getAsync($url, [
$results[$account->seo] = $client->get($url, [
'headers' => ['X-AUTH' => env('XBOXAPI_KEY')],
]);
}
$results = GuzzlePromise\settle($requests)->wait();
return $results;
}
......@@ -86,7 +86,7 @@ class Client extends XboxAPI
}
/**
* @param $presence
* @param Response[] $presence
* @param $accounts Account[]
*
* @return string
......@@ -102,10 +102,10 @@ class Client extends XboxAPI
$found = false;
foreach ($presence as $seo => $response) {
if ($response['state'] === 'rejected') {
if ($response->getReasonPhrase() !== 'OK') {
continue;
}
$data = json_decode($response['value']->getBody(), true);
$data = json_decode($response->getBody()->getContents(), true);
if (isset($data['state']) && $data['state'] == 'Online') {
foreach ($data['devices'] as $device) {
......
......@@ -27,7 +27,7 @@ class AddOverwatchRequest extends Request
return [
'gamertag' => 'required|min:3|overwatch-real',
'platform' => 'required|in:0,1,2',
'platform' => 'required|in:1,2,3',
];
}
}
......@@ -26,7 +26,7 @@ var paths = {
elixir(function(mix) {
mix
.copy(paths.jquery + 'cdn/jquery.min.js', 'public/js/jquery.min.js')
.copy(paths.jquery + 'jquery.min.js', 'public/js/jquery.min.js')
.copy(paths.chartsjs + 'Chart.bundle.min.js', 'public/js/chart.js')
.copy(paths.fontawesome + 'css/font-awesome.min.css', 'public/css/font-awesome.min.css')
.copy(paths.fontawesome + 'fonts', 'public/fonts/')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment