Пример #1
0
        /// <summary>
        /// Sync the users account properties upstream to the backend upstream.
        /// </summary>
        /// <returns>Was Sync successful</returns>
        public async Task <bool> SyncUpAsync(UpdatedAccountDto dto)
        {
            var requestBody = JsonConvert.SerializeObject(dto);
            var request     = new OAuth2BearerRequest("POST",
                                                      _backendAddress,
                                                      null,
                                                      AuthenticationService.AuthAccount);

            request.SetRequestBody(requestBody);

            try
            {
                var response = await request.GetResponseAsync();

                var result = response.StatusCode == System.Net.HttpStatusCode.OK;
                _userDialogs.Toast(result ? "Updated user account." : "Failed to update user account.");

                return(result);
            }
            catch (Exception)
            {
                _userDialogs.ShowError("Connection to service failed.");

                return(false);
            }
        }
Пример #2
0
        /// <summary>
        /// Check the range of given phonenumbers and returns only those who are members.
        /// </summary>
        /// <param name="phoneNumbers">Targets to check</param>
        /// <returns>Members</returns>
        public async Task <IEnumerable <string> > CheckMembershipRange(IEnumerable <string> phoneNumbers)
        {
            if (phoneNumbers == null)
            {
                throw new ArgumentNullException(nameof(phoneNumbers));
            }

            var request = new OAuth2BearerRequest("POST",
                                                  _isMemberAddress,
                                                  null,
                                                  AuthenticationService.AuthAccount);

            var serialized = JsonConvert.SerializeObject(phoneNumbers);

            request.SetRequestBody(serialized);

            try
            {
                var response = await request.GetResponseAsync();

                var text         = response.GetResponseText();
                var deserialized = JsonConvert.DeserializeObject <IEnumerable <string> >(text);

                return(deserialized);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Пример #3
0
        public void RequestBodyIsNotNull()
        {
            var account = new Account
            {
                Username   = "******",
                Properties = { { "token", "123456789" } }
            };
            var request = new OAuth2BearerRequest("GET", new Uri("http://www.google.com/"), null, account);

            var testData = new Dictionary <string, string>
            {
                { "key", "value" }
            };
            var requestBody = JsonConvert.SerializeObject(testData);

            request.SetRequestBody(requestBody);

            Assert.IsNotNull(request.RequestBodyContent);
        }
Пример #4
0
        /// <summary>
        /// Fetch friends by the given phonenumbers. Non matching phoneNumbers will be ignored.
        /// </summary>
        /// <param name="phoneNumbers">Source phonenumbers.</param>
        /// <returns>Friends matching to given phoneNumbers.</returns>
        public async Task <IEnumerable <Friend> > FetchFriends(IEnumerable <string> phoneNumbers)
        {
            if (phoneNumbers == null)
            {
                throw new ArgumentNullException(nameof(phoneNumbers));
            }

            var request = new OAuth2BearerRequest("POST",
                                                  _baseAddress,
                                                  null,
                                                  AuthenticationService.AuthAccount);

            var serialized = JsonConvert.SerializeObject(phoneNumbers);

            request.SetRequestBody(serialized);

            try
            {
                var response = await request.GetResponseAsync();

                if (response.StatusCode != HttpStatusCode.OK)
                {
                    return(null);
                }

                var body = await response.GetResponseTextAsync();

                var dtos = JsonConvert.DeserializeObject <IEnumerable <UserDto> >(body);

                var friends = new List <Friend>();
                foreach (var dto in dtos)
                {
                    friends.Add(Friend.CreateFromDto(dto));
                }

                return(friends);
            }
            catch (Exception)
            {
                return(null);
            }
        }