@param string $region
@param int    $gameId

@return string
430221
public function downloadEndStats($region, $gameId)
    {
        try {
            $endStats = $this->buzz->get(sprintf($this->getUrl($region) . self::URL_ENDSTATS, $region, $gameId));
        } catch (TimeoutException $e) {
            return false;
        } catch (RequestException $e) {
            return false;
        }

        // base64_decode to decode endStats file

        return $endStats->getContent();
    }
826215
public function GetPlayerAchievementsV1($steamid, $appid, $l = null)
    {
        return $this->_call(__METHOD__, 'GET', array('steamid' => $steamid, 'appid' => $appid, 'l' => $l));
    }
632560
public function fetchConversationWith($gamertag, $region, $sender)
	{
		$gamertag = trim($gamertag);
		$url = 'https://account.xbox.com/' . $region . '/Messages/UserConversation?senderGamerTag=' . $sender;
		$key = $this->version . ':getMessages.' . $gamertag;
	
		$data      = $this->fetch_url($url);
		$doc = new DOMDocument();
		if(!empty($sender) && !empty($gamertag)) {
			$doc->loadHtml($data);
		    $xpath = new DOMXPath($doc); 
		    $postThumbLinks = $xpath->query("//div[@class='messageContent']");

			$i = 0;
			$array = array();
			$last_sender = "";
		    foreach($postThumbLinks as $link) {

				$body = $this->find($link->ownerDocument->saveHTML($link),'<div class="messageBody">','</div>');
				$time = $this->find($link->ownerDocument->saveHTML($link),'<div class="sentDate localTime">','</div>');
				$sender = $this->find($link->ownerDocument->saveHTML($link),'<div class="senderGamertag">','</div>');

				$array[$i]['message'] = $body;
				$array[$i]['time'] = $time;
				if($sender){
					$array[$i]['sender'] = $sender;
					$last_sender = $sender;
				}else{
					$array[$i]['sender'] = $last_sender;
				}

				$i++;
		    }
		} else {
		    return false;
		}

		return $array;
	}
355374
public function fetch_games($gamertag, $region)
    {
        $gamertag  = trim($gamertag);
        $url       = 'https://live.xbox.com/' . $region . '/Activity';
        $key       = $this->version . ':games.' . $gamertag;
        $data      = $this->__cache->fetch($key);
        $freshness = 'from cache';

        if (!$data) {
            $data      = $this->fetch_url($url);
            $post_data = '__RequestVerificationToken=' . urlencode(trim($this->find($data, '<input name="__RequestVerificationToken" type="hidden" value="', '" />'))) . '&compareTo=' . urlencode($gamertag);
            $headers   = array('X-Requested-With: XMLHttpRequest', 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8');
            $data      = $this->fetch_url('https://live.xbox.com/' . $region . '/Activity/Summary?compareTo=' . urlencode($gamertag) . '&lc=1033', $url, 10, $post_data, $headers);
            $freshness = 'new';
            $this->__cache->store($key, $data, 3600);
        }

        $json = json_decode($data, true);

        if ($json['Success'] == 'true' && $json['Data']['Players'][0]['Gamertag'] != $this->account_gamertag) {
            $json                             = $json['Data'];
            $games                            = array();
            $games['gamertag']                = $g = $json['Players'][0]['Gamertag'];
            $games['gamerscore']['current']   = $json['Players'][0]['Gamerscore'];
            $games['gamerscore']['total']     = 0;
            $games['achievements']['current'] = 0;
            $games['achievements']['total']   = 0;
            $games['totalgames']              = $json['Players'][0]['GameCount'];
            $games['progress']                = $json['Players'][0]['PercentComplete'];

            $i = 0;
            foreach ($json['Games'] as $game) {
                if ($game['Progress'][$g]['LastPlayed'] !== 'null') {
                    $games['games'][$i]['id']                      = $game['Id'];
                    $games['games'][$i]['hid']                     = dechex($game['Id']);
                    $games['games'][$i]['isapp']                   = (bool)($game['PossibleScore'] == 0);
                    $games['games'][$i]['title']                   = $this->clean($game['Name']);
                    $games['games'][$i]['artwork']['small']        = 'http://download.xbox.com/content/images/66acd000-77fe-1000-9115-d802' . dechex($game['Id']) . '/1033/boxartsm.jpg';
                    $games['games'][$i]['artwork']['large']        = 'http://download.xbox.com/content/images/66acd000-77fe-1000-9115-d802' . dechex($game['Id']) . '/1033/boxartlg.jpg';
                    $games['games'][$i]['gamerscore']['current']   = $game['Progress'][$g]['Score'];
                    $games['games'][$i]['gamerscore']['total']     = $game['PossibleScore'];
                    $games['games'][$i]['achievements']['current'] = $game['Progress'][$g]['Achievements'];
                    $games['games'][$i]['achievements']['total']   = $game['PossibleAchievements'];
                    $games['games'][$i]['progress']                = 0;
                    $games['games'][$i]['lastplayed']              = (int)substr($game['Progress'][$g]['LastPlayed'], 6, 10);
                    $games['gamerscore']['total']                  = $games['gamerscore']['total'] + $games['games'][$i]['gamerscore']['total'];
                    $games['achievements']['current']              = $games['achievements']['current'] + $games['games'][$i]['achievements']['current'];
                    $games['achievements']['total']                = $games['achievements']['total'] + $games['games'][$i]['achievements']['total'];

                    if ($game['Progress'][$g]['Achievements'] !== 0) {
                        $games['games'][$i]['progress'] = round((($game['Progress'][$g]['Achievements'] / $game['PossibleAchievements']) * 100), 1);
                    }

                    $i++;
                }
            }

            $games['freshness'] = $freshness;
            return $games;
        } elseif ($json['Data']['Players'][0]['Gamertag'] == $this->account_gamertag) {
            $this->error = 501;
            return false;
        } else {
            $this->error = 500;
            $this->__cache->remove($key);
            $this->force_new_login();
            return false;
        }
    }
760813
public function isGameExists($region, $gameId)
    {
        $metas = $this->buzz->get(sprintf($this->getUrl($region) . self::URL_META, $region, $gameId));

        // Check if game exists
        if ('HTTP/1.1 500 Internal Server Error' == $metas->getHeaders()[0]) {
            return false;
        }

        return true;
    }
372623
public function getPrizeCategoryGames($categoryid)
    {
        $em = $this->serviceLocator->get('doctrine.entitymanager.orm_default');

        $query = $em->createQuery('SELECT g FROM PlaygroundGame\Entity\Game g
            WHERE (g.prizeCategory = :categoryid AND g.broadcastPlatform = 1)
            ORDER BY g.publicationDate DESC');
        $query->setParameter('categoryid', $categoryid);
        $games = $query->getResult();

        return $games;
    }
75411
public function getCurrencyFor($region)
	{
		$this->_validateRegionIsDefined($region, $this->_currencyCodes);
		return $this->_currencyCodes[$region];
	}
1248432
public function getRegion($region)
    {
        $session = $this->getSession();
        $regionObj = $session->getPage()->find('region', $region);
        if (!$regionObj) {
            throw new \Exception(sprintf('No region "%s" found on the page %s.', $region, $session->getCurrentUrl()));
        }

        return $regionObj;
    }
842134
public function getShardByRegion($region)
	{
		foreach($this->info as $shard) {
			if($shard->slug == $region)
				return $shard;
		}
		return null;
	}
1287138
protected function log($gameId, $message)
    {
        if (null != $this->logger) {
            $this->logger->info('Game #' . $gameId . ': ' . $message);
        }
    }
549227
public function downloadKeyframe($region, $gameId, $keyframeId)
    {
        try {
            $keyframe = $this->buzz->get(sprintf(
                $this->getUrl($region) . self::URL_KEYFRAME_DOWNLOAD,
                $region,
                $gameId,
                $keyframeId
            ));
        } catch (TimeoutException $e) {
            return false;
        } catch (RequestException $e) {
            return false;
        }

        // Check if game exists
        $header = $keyframe->getHeaders()[0];
        if ('HTTP/1.1 500 Internal Server Error' == $header || 'HTTP/1.1 404 Not Found' == $header) {
            return false;
        }

        return $keyframe->getContent();
    }
1360084
public function nodesCountInRegion($region)
    {
        /** @var \Doctrine\ORM\EntityManager $em */
        $em = $this->container->get('doctrine.orm.entity_manager');

        return $em->getRepository(Node::class)->countInRegion($region);
    }
1099128
public function getEndStats($region, $gameId)
    {
        $filePath = $this->getReplayDirPath($region, $gameId) . '/endstats';

        if (!is_file($filePath)) {
            throw new ReplayEndStatsNotFoundException('The endstats for game #' . $gameId . ' is not found');
        }

        return $filePath;
    }
36592
protected function init(PlayerId $playerId, MiniGameId $gameId, $name)
    {
        $this->playerId = $playerId;
        $this->gameId = $gameId;
        $this->name = $name;
    }
1109463
public function getNumberOfPlayers($gameId = null)
    {
        $em = $this->getServiceManager()->get('doctrine.entitymanager.orm_default');
        $rsm = new \Doctrine\ORM\Query\ResultSetMapping;
        $rsm->addScalarResult('c', 'c');
        if ($gameId !== null) {
            $game = $this->getServiceManager()
                ->get('playgroundgame_lottery_service')
                ->getGameMapper()
                ->findById($gameId);

            if ($game && $game->getAnonymousAllowed()) {
                $query = $em->createNativeQuery('
                    SELECT COUNT(distinct e.anonymous_identifier) AS c
                    FROM game_entry e
                    WHERE e.game_id = '.((int) $gameId).'
                ', $rsm);
            } else {
                $query = $em->createNativeQuery('
                    SELECT COUNT(distinct e.user_id) AS c
                    FROM game_entry e
                    WHERE e.game_id = '.((int) $gameId).'
                ', $rsm);
            }
        } else {
            $query = $em->createNativeQuery('
                    SELECT COUNT(distinct e.user_id) AS c
                    FROM game_entry e
                ', $rsm);
        }
        
        $count = $query->getSingleScalarResult();
        return $count;
    }
1161019
private function getRegionTitle($region)
    {
        $region = str_replace('_', ' ', $region);

        $region = explode('/', $region);
        $title = array_shift($region);
        foreach ($region as $part) {
            $title .= ' (' . $part . ')';
        }

        return $title;
    }
650704
public function sendMessage($gamertag, $region, $recipients, $message)
	{
		$gamertag = trim($gamertag);
		$url = 'https://account.xbox.com/' . $region . '/Messages';
		$key = $this->version . ':sendMessage.' . $gamertag;
		
        $data      = $this->fetch_url($url);
        $post_data = '__RequestVerificationToken=' . urlencode(trim($this->find($data, '<input name="__RequestVerificationToken" type="hidden" value="', '" />'))) . '&recipients=' . urlencode($recipients) . '&message=' . urlencode($message);
		
        $headers   = array('X-Requested-With: XMLHttpRequest', 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8');
        $data      = $this->fetch_url('https://account.xbox.com/' . $region . '/Messages/Send', $url, 10, $post_data, $headers);

        return json_decode($data, true);
		
	}