Пример #1
0
        public async Task <ApiResponseResult <ServerList> > GetServersAsync(TruncatedLocation location)
        {
            try
            {
                var uri = "vpn/logicals";
                var ip  = location.Value();
                if (!string.IsNullOrEmpty(ip))
                {
                    // The following route is used to retrieve VPN server information,
                    // including scores for the best server to connect to depending on
                    // a user's proximity to a server and its load. To provide relevant
                    // scores even when connected to VPN, we send a truncated version
                    // of the user's public IP address. In keeping with our no-logs policy,
                    // this partial IP address is not stored on the server and is only used
                    // to fulfill this one-off API request.
                    uri += $"?IP={ip}";
                }

                var request = GetAuthorizedRequest(HttpMethod.Get, uri);
                using var response = await _client.SendAsync(request).ConfigureAwait(false);

                var stream = await response.Content.ReadAsStreamAsync();

                return(Logged(GetResponseStreamResult <ServerList>(stream, response.StatusCode), "Get servers"));
            }
            catch (Exception e) when(e.IsApiCommunicationException())
            {
                throw new HttpRequestException(e.Message, e);
            }
        }
Пример #2
0
        public void ValueShouldBeEmptyIfIpIsEmpty()
        {
            var location = new TruncatedLocation(string.Empty);

            location.Value().Should().Be(string.Empty);
        }
Пример #3
0
        public void ValueShouldReturnZeroAsLastIpNumber(string ip)
        {
            var location = new TruncatedLocation(ip);

            location.Value().Split('.')[3].Should().Be("0");
        }