Ejemplo n.º 1
0
        public async Task <ConnectUser> GetConnectUser(ConnectUserQuery query, string accessToken, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (string.IsNullOrWhiteSpace(accessToken))
            {
                throw new ArgumentNullException("accessToken");
            }

            var dict = new QueryStringDictionary();

            if (!string.IsNullOrWhiteSpace(query.Id))
            {
                dict.Add("id", query.Id);
            }
            else if (!string.IsNullOrWhiteSpace(query.NameOrEmail))
            {
                dict.Add("nameOrEmail", query.NameOrEmail);
            }
            else if (!string.IsNullOrWhiteSpace(query.Name))
            {
                dict.Add("name", query.Name);
            }
            else if (!string.IsNullOrWhiteSpace(query.Email))
            {
                dict.Add("email", query.Email);
            }
            else
            {
                throw new ArgumentException("Empty ConnectUserQuery supplied");
            }

            var url = GetConnectUrl("user") + "?" + dict.GetQueryString();

            var request = new HttpRequest
            {
                Method            = "GET",
                Url               = url,
                CancellationToken = cancellationToken
            };

            AddUserAccessToken(request, accessToken);
            AddAppInfo(request, _appName, _appVersion);

            using (var stream = await _httpClient.SendAsync(request).ConfigureAwait(false))
            {
                return(JsonSerializer.DeserializeFromStream <ConnectUser>(stream));
            }
        }
Ejemplo n.º 2
0
        public async Task <PinStatusResult> GetPinStatus(PinCreationResult pin)
        {
            var dict = new QueryStringDictionary();

            dict.Add("deviceId", pin.DeviceId);
            dict.Add("pin", pin.Pin);

            var url = GetConnectUrl("pin") + "?" + dict.GetQueryString();

            var request = new HttpRequest
            {
                Method = "GET",
                Url    = url
            };

            AddAppInfo(request, _appName, _appVersion);

            using (var stream = await _httpClient.SendAsync(request).ConfigureAwait(false))
            {
                return(JsonSerializer.DeserializeFromStream <PinStatusResult>(stream));
            }
        }
Ejemplo n.º 3
0
        public async Task <ConnectUserServer[]> GetServers(string userId, string accessToken, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (string.IsNullOrWhiteSpace(userId))
            {
                throw new ArgumentNullException("userId");
            }
            if (string.IsNullOrWhiteSpace(accessToken))
            {
                throw new ArgumentNullException("accessToken");
            }

            var dict = new QueryStringDictionary();

            dict.Add("userId", userId);

            var url = GetConnectUrl("servers") + "?" + dict.GetQueryString();

            var request = new HttpRequest
            {
                Method            = "GET",
                Url               = url,
                CancellationToken = cancellationToken
            };

            AddUserAccessToken(request, accessToken);
            AddAppInfo(request, _appName, _appVersion);

            using (var stream = await _httpClient.SendAsync(request).ConfigureAwait(false))
            {
                using (var reader = new StreamReader(stream))
                {
                    var json = await reader.ReadToEndAsync().ConfigureAwait(false);

                    _logger.Debug("Connect servers response: {0}", json);

                    return(JsonSerializer.DeserializeFromString <ConnectUserServer[]>(json));
                }
            }
        }