@param string $region
@param int    $gameId

@return string
425134
public function getReplayDirPath($region, $gameId)
    {
        $stringGameId = (string) $gameId;

        return sprintf(
            '%s/%s/%s/%s/%s/%d',
            $this->path,
            $region,
            $stringGameId[0] . $stringGameId[1],
            $stringGameId[2],
            $stringGameId[3],
            $gameId
        );
    }
1285884
public function fetch_profile($gamertag, $region)
    {
        $gamertag = trim($gamertag);
        $url = 'http://live.xbox.com/' . $region . '/Profile?gamertag=' . urlencode($gamertag);
        $key = $this->version . ':profile.' . $gamertag;

        $data = $this->__cache->fetch($key);
        if (!$data) {
            $data      = $this->fetch_url($url);
            $freshness = 'new';
            $this->__cache->store($key, $data, 3600);
        } else {
            $freshness = 'from cache';
        }

        if (stripos($data, '<section class="contextRail custom">')) {
            $user = array();
            $user['gamertag']                   = trim($gamertag);
            $user['tier']                       = (strpos($data, '<div class="goldBadge">') !== false) ? 'gold' : 'silver';
            $user['badges']['xboxlaunchteam']   = false;
            $user['badges']['nxelaunchteam']    = false;
            $user['badges']['kinectlaunchteam'] = false;
            $user['avatar']['full']             = 'http://avatar.xboxlive.com/avatar/' . $gamertag . '/avatar-body.png';
            $user['avatar']['small']            = 'http://avatar.xboxlive.com/avatar/' . $gamertag . '/avatarpic-s.png';
            $user['avatar']['large']            = 'http://avatar.xboxlive.com/avatar/' . $gamertag . '/avatarpic-l.png';
            $user['avatar']['tile']             = trim(str_replace('https://avatar-ssl', 'http://avatar', $this->find($data, '<img class="gamerpic" src="', '" alt="')));
            $user['gamerscore']                 = (int) trim($this->find($data, '<div class="gamerscore">', '</div>'));
            $user['reputation']                 = 0;
            $user['presence']                   = trim(str_replace("\r\n", ' - ', $this->find($data, '<div class="presence">', '</div>')));
            $user['online']                     = (bool)(strpos($user['presence'], 'Online') !== false && strpos($user['presence'], 'Online Status Unavailable') === false);
            $user['gamertag']                   = str_replace(array('&#39;s Profile', '\'s Profile'), '', trim($this->find($data, '<h1 class="pageTitle">', '</h1>')));
            $user['motto']                      = $this->clean(trim(strip_tags($this->find($data, '<div class="motto">', '</div>'))));
            $user['name']                       = trim(strip_tags($this->find($data, '<div class="name" title="', '">')));
            $user['location']                   = trim(strip_tags(str_replace('<label>Location:</label>', '', trim($this->find($data, '<div class="location">', '</div>')))));
            $user['biography']                  = trim(strip_tags(str_replace('<label>Bio:</label>', '', trim($this->find($data, '<div class="bio">', '</div>')))));

            $recentactivity = $this->fetch_games($gamertag, $region);
            if (is_array($recentactivity)) {
                $user['recentactivity'] = array_slice($recentactivity['games'], 0, 5, true);
            } else {
                $user['recentactivity'] = null;
            }

            if (strpos($data, '<div class="badges">') !== false) {
                if (strpos($data, 'xbox360Badge') !== false) {
                    $user['badges']['xboxlaunchteam'] = true;
                }
                if (strpos($data, 'nxeBadge') !== false) {
                    $user['badges']['nxelaunchteam'] = true;
                }
                if (strpos($data, 'kinectBadge') !== false) {
                    $user['badges']['kinectlaunchteam'] = true;
                }
            }

            $starvalue = array(
                'Empty'        => 0,
                'Quarter'      => 1,
                'Half'         => 2,
                'ThreeQuarter' => 3,
                'Full'         => 4,
            );

            preg_match_all('~<div class="Star (.*?)"></div>~si', $data, $reputation);
            foreach ($reputation[1] as $value) {
                $user['reputation'] = $user['reputation'] + $starvalue[$value];
            }

            $user['freshness'] = $freshness;

            return $user;
        } elseif (stripos($data, 'errorCode: \'404\'')) {
            $this->error = 501;

            return false;
        } else {
            $this->error = 500;
            $this->__cache->remove($key);
            $this->force_new_login();

            return false;
        }
    }
150497
private function buildQuery(string $url, string $apiKey, string $locale = null, string $region = null) : string
    {
        if (null !== $apiKey) {
            $url = sprintf('%s&key=%s', $url, $apiKey);
        }
        if (null !== $locale) {
            $url = sprintf('%s&language=%s', $url, $locale);
        }
        if (null !== $region) {
            $url = sprintf('%s&region=%s', $url, $region);
        }

        return $url;
    }
818918
public static AddressInfo of(RegionId regionId, String name) {
    return of(RegionAddressId.of(regionId, name));
  }
652832
public function getLastChunkInfo($region, $gameId, $chunkId, $clientIp)
    {
        // Cache control
        $cacheName = $this->getCacheName($gameId, $clientIp);

        // TODO validate isAuthStrict with a same IP
        if ($this->isAuthStrict && !$this->cache->has($cacheName)) {
            // Log
            $this->log($gameId, sprintf('GET /getLastChunkInfo/%s/%s/%d/token | ERROR: trying to access without cached current chunkId', $region, $gameId, $chunkId));

            return false;
        }

        // TODO at this time, two players with the same IP watching the same game will have some weird issue
        $currentChunkId = $this->cache->get($cacheName) + 1;

        // Saving current chunkId in cache
        $this->cache->set($cacheName, $currentChunkId);

        $keyframeId = null;
        $lastChunkInfo = $this->observerClient->getLastChunkInfo($region, $gameId, $currentChunkId, $keyframeId);

        // Log
        $this->log($gameId, sprintf('GET /getLastChunkInfo/%s/%s/%d/token | currentChunkId: %s | currentKeyframe: %s', $region, $gameId, $chunkId, $currentChunkId, $keyframeId));

        return $lastChunkInfo;
    }
889344
public function player($playerId)
	{
		if ( ! isset($this->info['fellowPlayers']))
		{
			// no players
			return null;
		}
		$players = $this->info['fellowPlayers'];
		if (isset($players[$playerId]))
		{
			return $players[$playerId];
		}

		return null;
	}
841801
public function attach($id, $dropletId, $regionSlug)
    {
        $data = [
            'type' => 'attach',
            'droplet_id' => $dropletId,
            'region' => $regionSlug,
        ];

        $action = $this->adapter->post(sprintf('%s/volumes/%s/actions', $this->endpoint, $id), $data);

        $action = json_decode($action);

        return new ActionEntity($action->action);
    }
554717
public function getByRegionCode($region_code)
    {
        if (\is_scalar($region_code)) {
            // Очищаем входящее значение и приводим к числу
            $region_code = (int) \preg_replace('~\D~', '', $region_code);
            foreach ($this->items as $region) {
                if ($region->getRegionCode() === $region_code) {
                    return $region;
                }
            }
        }
    }
1169388
private function getUrl($region)
    {
        if (!isset($this->servers[$region])) {
            $availableRegions = '';

            foreach ($this->servers as $key => $item) {
                $availableRegions .= $key . ', ';
            }

            $availableRegions = substr($availableRegions, 0, -2);

            throw new UnknownRegionException(
                'The region "' . $region . '" is unknown. Available regions : ' . $availableRegions
            );
        }

        return $this->servers[$region] . self::URL_PREFIX;
    }
882051
private function buildQuery(string $url, string $locale = null, string $region = null): string
    {
        if (null !== $locale) {
            $url = sprintf('%s&language=%s', $url, $locale);
        }

        if (null !== $region) {
            $url = sprintf('%s&region=%s', $url, $region);
        }

        if (null !== $this->apiKey) {
            $url = sprintf('%s&key=%s', $url, $this->apiKey);
        }

        if (null !== $this->clientId) {
            $url = sprintf('%s&client=%s', $url, $this->clientId);

            if (null !== $this->channel) {
                $url = sprintf('%s&channel=%s', $url, $this->channel);
            }

            if (null !== $this->privateKey) {
                $url = $this->signQuery($url);
            }
        }

        return $url;
    }
1175542
public function blocks_for_region($region) {
        $blockcontents = $this->page->blocks->get_content_for_region($region, $this);
        $blocks = $this->page->blocks->get_blocks_for_region($region);
        $lastblock = null;
        $zones = array();
        foreach ($blocks as $block) {
            $zones[] = $block->title;
        }
        $output = '';

        foreach ($blockcontents as $bc) {
            if ($bc instanceof block_contents) {
                $output .= $this->block($bc, $region);
                $lastblock = $bc->title;
            } else if ($bc instanceof block_move_target) {
                $output .= $this->block_move_target($bc, $zones, $lastblock, $region);
            } else {
                throw new coding_exception('Unexpected type of thing (' . get_class($bc) . ') found in list of block contents.');
            }
        }
        return $output;
    }
1161019
private function getRegionTitle($region)
    {
        $region = str_replace('_', ' ', $region);

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

        return $title;
    }
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();
    }
285265
public static function selectLocationListForGame(
        $gameState,
        $gameKey
    ) {
        $gameState = (object) $gameState;
        $gameKey = (string) $gameKey;

        $locationList = [];
        foreach ($gameState->game->$gameKey->location as $locationKey => $hasLocation) {
            if (!$hasLocation) {
                continue;
            }

            $locationItem = $gameState->location->$locationKey;
            $locationList[$locationKey] = $locationItem;
        }

        return $locationList;
    }
853056
public function getTerminalUri(string $transactionId): Uri
    {
        $uri = $this->getUri('terminal', ['merchantId' => $this->merchantId, 'transactionId' => $transactionId]);

        return $uri;
    }
1121694
public function parseRandom($regionId = self::REGION_EUW, OutputInterface $output = null)
    {
        $hasOutput = null != $output;
        if ($hasOutput) {
            $output->write("Parsing homepage...\t\t\t");
        }

        $buzz = new Browser();
        $response = $buzz->get('http://www.lolnexus.com/recent-games?filter-region=' . $regionId . '&filter-sort=1');

        if (!preg_match('/<a class="green-button scouter-button" href="\/' . self::$serverNames[$regionId - 1] . '\/search\?name=(.*)">Live Game<\/a>/', $response->getContent(), $matches)) {
            throw new \RuntimeException('Cannot parse LoL Nexus website, maybe down ?');
        }

        if ($hasOutput) {
            $output->writeln('<info>OK</info>');
        }

        $this->parsePlayer($regionId, $matches[1], $output, $buzz);
    }
656209
public function getGameMetasData($region, $gameId, $token, $clientIp)
    {
        // Setting cache for chunk init
        $cacheName = $this->getCacheName($gameId, $clientIp);
        $this->cache->set($cacheName, 0, 86400); // 1 day

        return $this->observerClient->getMetas($region, $gameId);
    }