2024-04-15 16:00:49 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace WoWPress\Api;
|
|
|
|
|
|
|
|
class BattleNet extends Api{
|
|
|
|
|
|
|
|
|
|
|
|
protected $api_url = "https://eu.api.blizzard.com";
|
|
|
|
|
|
|
|
|
|
|
|
public function getCharacter($name,$realm,int $timeout=360){
|
|
|
|
$name = urlencode(strtolower($name));
|
|
|
|
$realm = urlencode(strtolower($realm));
|
|
|
|
|
|
|
|
$data = $this->get("/profile/wow/character/$realm/$name", [
|
|
|
|
'namespace' => 'profile-eu',
|
|
|
|
'locale' => 'en_US',
|
|
|
|
'access_token' => $this->bearer()
|
|
|
|
], false, $timeout);
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getGuildRank($name,$realm){
|
|
|
|
$char = $this->getCharacter($name,$realm);
|
|
|
|
$guild = $char['guild']['key']['href'];
|
2024-04-22 15:38:22 +02:00
|
|
|
$rank = 99;
|
2024-04-15 16:00:49 +02:00
|
|
|
|
2024-04-15 23:07:29 +02:00
|
|
|
if($char['guild']['name'] != "Nebelkrieger" || $char['guild']['realm']['name'] != "Alexstrasza"){
|
|
|
|
$guild = $char['guild']['name'];
|
|
|
|
$rank = 99;
|
|
|
|
return compact('guild','rank');
|
|
|
|
}
|
|
|
|
|
2024-04-15 16:00:49 +02:00
|
|
|
$data = $this->get($guild, [
|
|
|
|
'namespace' => 'profile-eu',
|
|
|
|
'locale' => 'en_US',
|
|
|
|
'access_token' => $this->bearer()
|
|
|
|
], false, -1);
|
|
|
|
$data = $this->get($data['roster']['href'], [
|
|
|
|
'namespace' => 'profile-eu',
|
|
|
|
'locale' => 'en_US',
|
|
|
|
'access_token' => $this->bearer()
|
|
|
|
], false, -1);
|
|
|
|
foreach($data['members'] as $member){
|
|
|
|
if($member['character']['name'] == $name && $member['character']['realm']['slug'] == $char['realm']['slug']){
|
2024-04-15 23:07:29 +02:00
|
|
|
$guild = $char['guild']['name'];
|
|
|
|
$rank = intval($member['rank']);
|
2024-04-22 15:38:22 +02:00
|
|
|
return compact('guild','rank');
|
2024-04-15 16:00:49 +02:00
|
|
|
}
|
|
|
|
}
|
2024-04-15 23:07:29 +02:00
|
|
|
|
2024-04-22 15:38:22 +02:00
|
|
|
$guild = "-";
|
|
|
|
|
2024-04-15 23:07:29 +02:00
|
|
|
return compact('guild','rank');
|
2024-04-15 16:00:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function getMedia($name,$realm,int $timeout=360){
|
|
|
|
$name = urlencode(strtolower($name));
|
|
|
|
$realm = urlencode(strtolower($realm));
|
|
|
|
$data = $this->get("/profile/wow/character/$realm/$name/character-media", [
|
|
|
|
'namespace' => 'profile-eu',
|
|
|
|
'locale' => 'en_US',
|
|
|
|
'access_token' => $this->bearer()
|
|
|
|
], false, $timeout);
|
|
|
|
|
2024-04-16 15:25:22 +02:00
|
|
|
if(!empty($data['code']) && $data['code'] == 403){
|
|
|
|
# var_dump($data);
|
|
|
|
# exit;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-04-15 23:07:29 +02:00
|
|
|
|
2024-04-15 16:00:49 +02:00
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|