Beispiel #1
0
        public async Task <CompareUsersResult> CompareUsers(string token, string firstUserName, string secondUserName)
        {
            var cacheResult = Cache.Get(firstUserName, secondUserName);

            if (cacheResult != null)
            {
                return(cacheResult);
            }

            var userInformation = new UserInformation(token);

            User firstUser = await userInformation.Get(firstUserName);

            User secondUser = await userInformation.Get(secondUserName);

            var compareUserFollowers = new CompareUsersFollowers(token);
            var compareUserFriends   = new CompareUsersFriends(token);

            var commonFollowers = await compareUserFollowers.GetCommonFollowersListAsync(firstUserName, secondUserName);

            var commonFriends = await compareUserFriends.GetCommonFriendsListAsync(firstUserName, secondUserName);

            var compareResult = new CompareUsersResult(firstUser, secondUser, commonFollowers, commonFriends);

            Cache.Add(compareResult);

            return(compareResult);
        }
Beispiel #2
0
 public static void Add(CompareUsersResult result)
 {
     if (results.Contains(result))
     {
         var foundResult = results.Find(x => SameUserNames(x.FirstUser.ScreenName, x.SecondUser.ScreenName, result));
         foundResult.Update(result);
     }
     else
     {
         results.Add(result);
     }
 }
        public async Task <IActionResult> Get(string firstUser, string secondUser)
        {
            if (firstUser == null)
            {
                return(StatusCode((int)HttpStatusCode.BadRequest, "You have not include firstUser parameter in the URI."));
            }

            if (secondUser == null)
            {
                return(StatusCode((int)HttpStatusCode.BadRequest, "You have not include secondUser parameter in the URI."));
            }

            var customerKey    = Configuration["TwitterCustomerKey"];
            var customerSecret = Configuration["TwitterCustomerSecret"];

            _token = await _tokenProvider.GetAsync(customerKey, customerSecret);

            CompareUsersResult result = null;

            try
            {
                result = await _compare.CompareUsers(_token, firstUser, secondUser);
            }
            catch (WebException e)
            {
                if (e.Message.Contains("Content not found"))
                {
                    return(StatusCode((int)HttpStatusCode.NotFound, e.Message + " on Twitter."));
                }
                if (e.Status == WebExceptionStatus.ReceiveFailure)
                {
                    return(StatusCode((int)HttpStatusCode.RequestTimeout, e.Message));
                }
            }

            return(Ok(Json(result)));
        }
Beispiel #4
0
 private static bool SameUserNames(string firstUserName, string secondUserName, CompareUsersResult result)
 {
     if (result.FirstUser.ScreenName == firstUserName && result.SecondUser.ScreenName == secondUserName)
     {
         return(true);
     }
     if (result.FirstUser.ScreenName == secondUserName && result.SecondUser.ScreenName == firstUserName)
     {
         return(true);
     }
     return(false);
 }