private ITokenRateLimits GetTokenRateLimitsFromTwitter(ITwitterCredentials credentials)
        {
            if (_isRetrievingData)
            {
                return(null);
            }

            var isApplicationOnlyCreds = string.IsNullOrEmpty(credentials.AccessToken) || string.IsNullOrEmpty(credentials.AccessTokenSecret);

            if (isApplicationOnlyCreds && string.IsNullOrEmpty(credentials.ApplicationOnlyBearerToken))
            {
                return(null);
            }

            _isRetrievingData = true;
            var result = _credentialsAccessor.ExecuteOperationWithCredentials(credentials, () =>
            {
                var twitterQuery = _twitterQueryFactory.Create(_helpQueryGenerator.GetCredentialsLimitsQuery(), HttpMethod.GET, credentials);

                try
                {
                    string jsonResponse = _twitterRequester.ExecuteQuery(twitterQuery);
                    return(_jsonObjectConverter.DeserializeObject <ITokenRateLimits>(jsonResponse));
                }
                catch (TwitterException)
                {
                    return(null);
                }
            });

            _isRetrievingData = false;
            return(result);
        }
示例#2
0
        private ICredentialsRateLimits GetTokenRateLimitsFromTwitter(ITwitterCredentials credentials)
        {
            var isApplicationOnlyCreds = string.IsNullOrEmpty(credentials.AccessToken) || string.IsNullOrEmpty(credentials.AccessTokenSecret);

            if (isApplicationOnlyCreds && string.IsNullOrEmpty(credentials.ApplicationOnlyBearerToken))
            {
                return(null);
            }

            var result = _credentialsAccessor.ExecuteOperationWithCredentials(credentials, () =>
            {
                var twitterQuery = _twitterQueryFactory.Create(_helpQueryGenerator.GetCredentialsLimitsQuery(), HttpMethod.GET, credentials);

                try
                {
                    var webRequestResult = _webRequestExecutor.ExecuteQuery(twitterQuery);
                    var json             = webRequestResult.Text;

                    return(_jsonObjectConverter.DeserializeObject <ICredentialsRateLimits>(json));
                }
                catch (TwitterException)
                {
                    return(null);
                }
            });

            return(result);
        }
示例#3
0
        // Get User
        public IAuthenticatedUser GetAuthenticatedUser(ITwitterCredentials credentials = null, IGetAuthenticatedUserParameters parameters = null)
        {
            IUserDTO userDTO;

            if (credentials == null)
            {
                credentials = _credentialsAccessor.CurrentThreadCredentials;
                userDTO     = _userFactoryQueryExecutor.GetAuthenticatedUser(parameters);
            }
            else
            {
                userDTO = _credentialsAccessor.ExecuteOperationWithCredentials(credentials, () =>
                {
                    return(_userFactoryQueryExecutor.GetAuthenticatedUser(parameters));
                });
            }

            var authenticatedUser = GenerateAuthenticatedUserFromDTO(userDTO);

            if (authenticatedUser != null)
            {
                authenticatedUser.SetCredentials(credentials);
            }

            return(authenticatedUser);
        }
示例#4
0
        public ILoggedUser GetLoggedUser(IOAuthCredentials credentials)
        {
            var userDTO = _credentialsAccessor.ExecuteOperationWithCredentials(credentials, () =>
            {
                return(_userFactoryQueryExecutor.GetLoggedUser());
            });

            return(GenerateLoggedUserFromDTO(userDTO));
        }
示例#5
0
        public ILoggedUser GetLoggedUser(ITwitterCredentials credentials)
        {
            var userDTO = _credentialsAccessor.ExecuteOperationWithCredentials(credentials, () =>
            {
                return(_userFactoryQueryExecutor.GetLoggedUser());
            });

            var loggedUser = GenerateLoggedUserFromDTO(userDTO);

            loggedUser.SetCredentials(credentials);

            return(loggedUser);
        }
示例#6
0
        private ITokenRateLimits GetTokenRateLimitsFromTwitter(IOAuthCredentials credentials)
        {
            if (_isRetrievingData)
            {
                return(null);
            }

            _isRetrievingData = true;
            var result = _credentialsAccessor.ExecuteOperationWithCredentials(credentials, () =>
            {
                var twitterQuery    = _twitterQueryFactory.Create(_helpQueryGenerator.GetCredentialsLimitsQuery(), HttpMethod.GET, credentials);
                string jsonResponse = _twitterRequester.ExecuteQuery(twitterQuery);
                return(_jsonObjectConverter.DeserializeObject <ITokenRateLimits>(jsonResponse));
            });

            _isRetrievingData = false;
            return(result);
        }