public TweetController(TweetsApiService tweetsApiService) { _credentials = MyCredentials.GenerateCredentials(); Auth.SetCredentials(_credentials); _tweetsApiService = tweetsApiService; }
private void AssertAreCredentialsEquals(ITwitterCredentials credentials1, ITwitterCredentials credentials2) { Assert.AreEqual(credentials1.AccessToken, credentials2.AccessToken); Assert.AreEqual(credentials1.AccessTokenSecret, credentials2.AccessTokenSecret); Assert.AreEqual(credentials1.ConsumerKey, credentials2.ConsumerKey); Assert.AreEqual(credentials1.ConsumerSecret, credentials2.ConsumerSecret); }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { Console.WriteLine("What topic would you like to get tweets about?"); string subject = Console.ReadLine(); while (!stoppingToken.IsCancellationRequested) { ITwitterCredentials demo = Auth.SetUserCredentials(_options.ConsumerKey, _options.ConsumerSecret, _options.AccessToken, _options.AccessTokenSecret); IFilteredStream stream = Stream.CreateFilteredStream(); stream.AddTrack(subject); stream.AddTweetLanguageFilter(LanguageFilter.Portuguese); _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now); _logger.LogInformation("I'm listening to twitter"); stream.MatchingTweetReceived += async(sender, arguments) => { await SendTweetsByKafka(new Tweet() { TweetedBy = arguments.Tweet.CreatedBy.ScreenName, TweetedAt = arguments.Tweet.CreatedAt, Text = arguments.Tweet.Text }); }; stream.StartStreamMatchingAllConditions(); await Task.Delay(5000, stoppingToken); } }
private ICredentialsRateLimits RefreshCredentialsRateLimits(ITwitterCredentials credentials) { var tokenRateLimits = GetTokenRateLimitsFromTwitter(credentials); _rateLimitCache.RefreshEntry(credentials, tokenRateLimits); return(_rateLimitCache.GetCredentialsRateLimits(credentials)); }
public LinkedIn.Results.IResult<Results.UserIdListResult> GetFollowerIds(ITwitterCredentials credentials, string username) { return this.executer.Execute( credentials, new FollowerIdsCommand { ScreenName = username, }); }
public LinkedIn.Results.IResult <Results.UserIdListResult> GetFollowerIds(ITwitterCredentials credentials, string username) { return(this.executer.Execute( credentials, new FollowerIdsCommand { ScreenName = username, })); }
public IResult <string> UpdateStatus(ITwitterCredentials credentials, string status) { return(this.executer.Execute( credentials, new StatusesUpdateCommand { Status = status, })); }
private static T GetConfiguredStream <T>(T stream, ITwitterCredentials credentials, TweetMode?tweetMode) where T : ITwitterStream { stream.Credentials = credentials ?? ThreadCredentialsAccessor.CurrentThreadCredentials; stream.TweetMode = tweetMode ?? ThreadSettingsAccessor.CurrentThreadSettings.TweetMode; return(stream); }
static void Main(string[] arguments) { ITwitterCredentials credentials = Login.Instance.getCredentials(); if (credentials == null) { credentials = newCredentials(); } ; if (credentials == null) { return; } Auth.SetCredentials(credentials); //AchiveClean.clean(); while (true) { Eraser.CreateEraser(15).StartErase(); Thread.Sleep(1000 * 60 * 10); } //var application = new Application //{ // StartupUri = new Uri("MainWindow.xaml", UriKind.RelativeOrAbsolute) //}; //application.Run(); }
// 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; }
public IResult <Results.Tweet[]> UserTimeline(ITwitterCredentials credentials, string username) { return(this.executer.Execute( credentials, new StatusesUserTimelineCommand { Username = username })); }
public TweetProvider(string consumerKey, string consumerSecret, string accessToken, string accessTokenSecret, bool useFakeLocation = false) { this.credentials = new TwitterCredentials(consumerKey, consumerSecret, accessToken, accessTokenSecret); this.useFakeLocation = useFakeLocation; }
public StreamFactory(ITweetProcessor tweetProcessor, ITwitterCredentials credentials, IFilteredStream stream) { _tweetProcessor = tweetProcessor; _stream = stream ?? Stream.CreateFilteredStream(); Auth.SetUserCredentials(credentials.ConsumerKey, credentials.ConsumerSecret, credentials.AccessToken, credentials.AccessTokenSecret); }
public IResult<string> UpdateStatus(ITwitterCredentials credentials, string status) { return this.executer.Execute( credentials, new StatusesUpdateCommand { Status = status, }); }
// 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); }
public bool InvalidateCredentials(ITwitterCredentials credentials) { var url = "https://api.twitter.com/oauth2/invalidate_token"; var response = _twitterRequestHandler.ExecuteQuery(url, HttpMethod.POST, new InvalidateTokenHttpHandler(), credentials); var jobject = _jObjectStaticWrapper.GetJobjectFromJson(response.Text); JToken unused; if (jobject.TryGetValue("access_token", out unused)) { return(true); } try { var errorsObject = jobject["errors"]; var errors = _jObjectStaticWrapper.ToObject <ITwitterExceptionInfo[]>(errorsObject); _exceptionHandler.TryLogExceptionInfos(errors, url); } catch (Exception) { // Something is definitely wrong! } return(false); }
public ITwitterQuery Create(string queryURL, HttpMethod httpMethod, ITwitterCredentials twitterCredentials) { var twitterQuery = Create(queryURL, httpMethod); twitterQuery.TwitterCredentials = twitterCredentials; return(twitterQuery); }
public static void GetCredentialsFromConfig() { _userCredentials = new TwitterCredentials(ConfigurationManager.AppSettings["twitterConsumerKey"], ConfigurationManager.AppSettings["twitterConsumerSecret"], ConfigurationManager.AppSettings["twitterAccessToken"], ConfigurationManager.AppSettings["twitterAccessTokenSecret"]); }
public bool InitializeApplicationBearer(ITwitterCredentials credentials) { if (credentials == null) { throw new TwitterNullCredentialsException(); } if (string.IsNullOrEmpty(credentials.AccessToken) || string.IsNullOrEmpty(credentials.AccessTokenSecret)) { try { var response = _twitterRequestHandler.ExecuteQuery("https://api.twitter.com/oauth2/token", HttpMethod.POST, new BearerHttpHandler(), credentials); var accessToken = Regex.Match(response.Text, "access_token\":\"(?<value>.*)\"").Groups["value"].Value; credentials.ApplicationOnlyBearerToken = accessToken; return(true); } catch (TwitterException ex) { if (_exceptionHandler.LogExceptions) { _exceptionHandler.AddTwitterException(ex); } if (!_exceptionHandler.SwallowWebExceptions) { throw; } } } return(false); }
public static ITwitterCredentials AuthorizeAndGetCredentials(SecureString consumerKey, SecureString consumerSecret) { string consumerKeyStr = consumerKey.AsString(); string consumerSecretStr = consumerSecret.AsString(); if (consumerKeyStr.Length != 25) { // Consumer key length check Console.WriteLine("Consumer key is not 25 characters long."); return(null); } if (consumerSecretStr.Length != 50) { // Consumer secret key length check Console.WriteLine("Consumer secret is not 50 characters long."); return(null); } Console.WriteLine("Initiating PIN authentiation with given application consumer key/secret..."); var auth = AuthFlow.InitAuthentication(new ConsumerCredentials(consumerKeyStr, consumerSecretStr)); string pinNumber; if (OpenUrl(auth.AuthorizationURL)) { Console.WriteLine("Your web browser will be opened and navigate to Twitter app authentication page."); Console.WriteLine($" If not opened, manually open an web browser and navigate to: {auth.AuthorizationURL}\n"); } else { Console.WriteLine($"Opening URL failed! You can manually open an web browser and navigate to: {auth.AuthorizationURL}\n"); } Console.WriteLine("After logged in, the page will provide 7-character PIN numbers."); do { Console.Write("Please enter the correct PIN numbers here: "); pinNumber = Console.ReadLine(); } while(!(pinNumber.Length == 7 && int.TryParse(pinNumber, out _))); Console.WriteLine("\nGetting credential...\n"); ITwitterCredentials credential = AuthFlow.CreateCredentialsFromVerifierCode(pinNumber, auth); if (credential != null && !string.IsNullOrEmpty(credential.AccessToken) && !string.IsNullOrEmpty(credential.AccessTokenSecret)) { Console.WriteLine("Got credential successfully"); return(credential); } else { Console.WriteLine("Null credential. Something's wrong while getting credential."); return(null); } }
public static async Task SetUserCredentials(long userId, ITwitterCredentials credentials) { await Task.Run(() => { CredentialsByUserId.AddOrUpdate(userId, credentials); }); }
public IResult<Results.Tweet[]> UserTimeline(ITwitterCredentials credentials, string username) { return this.executer.Execute( credentials, new StatusesUserTimelineCommand { Username = username }); }
public string ExecuteQuery( string queryURL, HttpMethod httpMethod, TwitterClientHandler handler = null, ITwitterCredentials credentials = null) { CleanupQueryURL(ref queryURL); var rateLimitTrackerOption = _tweetinviSettingsAccessor.RateLimitTrackerOption; ITwitterQuery twitterQuery; if (!TryPrepareRequest(queryURL, httpMethod, rateLimitTrackerOption, credentials, out twitterQuery)) { return null; } try { var jsonResult = _twitterRequester.ExecuteQuery(twitterQuery, handler); QueryCompleted(twitterQuery, jsonResult, rateLimitTrackerOption); return jsonResult; } catch (TwitterException ex) { HandleException(queryURL, rateLimitTrackerOption, ex.StatusCode, twitterQuery); throw; } }
public string ExecuteQuery( string queryURL, HttpMethod httpMethod, TwitterClientHandler handler = null, ITwitterCredentials credentials = null) { CleanupQueryURL(ref queryURL); var rateLimitTrackerOption = _tweetinviSettingsAccessor.RateLimitTrackerOption; ITwitterQuery twitterQuery; if (!TryPrepareRequest(queryURL, httpMethod, rateLimitTrackerOption, credentials, out twitterQuery)) { return(null); } try { var jsonResult = _twitterRequester.ExecuteQuery(twitterQuery, handler); QueryCompleted(twitterQuery, jsonResult, rateLimitTrackerOption); return(jsonResult); } catch (TwitterException ex) { HandleException(queryURL, rateLimitTrackerOption, ex.StatusCode, twitterQuery); throw; } }
private bool TryPrepareRequest( string query, HttpMethod httpMethod, RateLimitTrackerOptions rateLimitTrackerOption, ITwitterCredentials credentials, out ITwitterQuery twitterQuery) { twitterQuery = _twitterQueryFactory.Create(query, httpMethod, credentials ?? _credentialsAccessor.CurrentThreadCredentials); var beforeQueryExecuteEventArgs = new QueryBeforeExecuteEventArgs(twitterQuery); _tweetinviEvents.RaiseBeforeQueryExecute(beforeQueryExecuteEventArgs); if (beforeQueryExecuteEventArgs.Cancel) { twitterQuery = null; return(false); } if (rateLimitTrackerOption == RateLimitTrackerOptions.TrackAndAwait) { _rateLimitAwaiter.WaitForCurrentCredentialsRateLimit(query); } return(true); }
private ICredentialsRateLimits 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<ICredentialsRateLimits>(jsonResponse); } catch (TwitterException) { return null; } }); _isRetrievingData = false; return result; }
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); }
/// <summary> /// Sets user credentials. /// </summary> private void SetCredentials() { _credentials = Auth.SetUserCredentials( clientConfiguration.ConsumerKey, clientConfiguration.ConsumerSecret, clientConfiguration.AccessToken, clientConfiguration.AccessTokenSecret); }
public static void GetTwitterAuthorizationUrl() { _applicationCredentials = new TwitterCredentials(ConfigurationManager.AppSettings["twitterConsumerKey"], ConfigurationManager.AppSettings["twitterConsumerSecret"]); var url = CredentialsCreator.GetAuthorizationURL(_applicationCredentials); System.Diagnostics.Process.Start(url); }
public TweetinviConnector() { ExceptionHandler.SwallowWebExceptions = false; var conf = ConfigurationManager.AppSettings; _twitterCredentials = Auth.SetApplicationOnlyCredentials(conf["Twitter.ConsumerKey"], conf["Twitter.ConsumerSecret"]); Auth.InitializeApplicationOnlyCredentials(_twitterCredentials); }
// Sign public static ITwitterRequestParameters GenerateTwitterRequestParameters( string query, HttpMethod method, ITwitterCredentials credentials = null, HttpContent content = null) { return(Accessor.GenerateTwitterRequestParameters(query, method, credentials, content)); }
public ITokenRateLimits GetCredentialsRateLimits(ITwitterCredentials credentials) { var savedCredentials = _credentialsAccessor.CurrentThreadCredentials; _credentialsAccessor.CurrentThreadCredentials = credentials; var rateLimits = GetCurrentCredentialsRateLimits(); _credentialsAccessor.CurrentThreadCredentials = savedCredentials; return rateLimits; }
public async Task <ActionResult> ValidateTwitterAuth(string oauth_verifier, string authorization_id) { ITwitterCredentials userCredentials = AuthFlow.CreateCredentialsFromVerifierCode(oauth_verifier, authorization_id); await SetAuthCookie(userCredentials); return(View(_tweetinviService.ValidateTwitterAuth())); }
public static HetzerCredential fromTwitterCredentials(ITwitterCredentials c) { var o = new HetzerCredential(); o.token = c.AccessToken; o.secret = c.AccessTokenSecret; return(o); }
public QueryAwaitingEventArgs( string query, ITokenRateLimit queryRateLimit, ITwitterCredentials twitterCredentials) { _query = query; _queryRateLimit = queryRateLimit; _twitterCredentials = twitterCredentials; }
public void Itinialize() { _fakeBuilder = new FakeClassBuilder<RateLimitCache>(); _credentials = A.Fake<ITwitterCredentials>(); _credentials2 = A.Fake<ITwitterCredentials>(); _credentialsRateLimits = A.Fake<ICredentialsRateLimits>(); _credentialsRateLimits2 = A.Fake<ICredentialsRateLimits>(); }
public static ITwitterCredentials SetApplicationOnlyCredentials(string consumerKey, string consumerSecret, string bearerToken) { Credentials = new TwitterCredentials(consumerKey, consumerSecret) { ApplicationOnlyBearerToken = bearerToken }; return(Credentials); }
public QueryAwaitingEventArgs( string query, IEndpointRateLimit queryRateLimit, ITwitterCredentials twitterCredentials) { _query = query; _queryRateLimit = queryRateLimit; _twitterCredentials = twitterCredentials; }
public void Itinialize() { _fakeBuilder = new FakeClassBuilder <RateLimitCache>(); _credentials = A.Fake <ITwitterCredentials>(); _credentials2 = A.Fake <ITwitterCredentials>(); _credentialsRateLimits = A.Fake <ICredentialsRateLimits>(); _credentialsRateLimits2 = A.Fake <ICredentialsRateLimits>(); }
public ICredentialsRateLimits GetCredentialsRateLimits(ITwitterCredentials credentials) { var rateLimits = _rateLimitCache.GetCredentialsRateLimits(credentials); if (rateLimits == null) { rateLimits = RefreshCredentialsRateLimits(credentials); } return rateLimits; }
public ClientProvider(ITwitterCredentials credentials) { if (credentials == null) throw new ArgumentNullException(nameof(credentials)); _container = new WindsorContainer(); _container.AddFacility<TypedFactoryFacility>(); _container.Register(Component.For<ITwitterCredentials>().Instance(credentials)); _container.Register(Classes.FromAssemblyInThisApplication().Pick().WithServiceAllInterfaces().LifestyleTransient()); }
public void CheckAuthorization() { _credentials = _credentialsStore.Load(); if (string.IsNullOrEmpty(_credentials.ConsumerKey) || string.IsNullOrEmpty(_credentials.ConsumerSecret)) AuthorizationStatus = AuthorizationStatus.InvalidApplication; else CheckCredentials(); }
public void QueryExecuted(string query, ITwitterCredentials credentials, int numberOfRequests = 1) { var rateLimit = _rateLimitCacheManager.GetQueryRateLimit(query, credentials); if (rateLimit != null) { var newRemainingValue = Math.Max(rateLimit.Remaining - numberOfRequests, 0); rateLimit.Remaining = newRemainingValue; } }
public RequestAuthorizer(ITwitterCredentials credentials, IHttpUtils oAuthUtils) { if (credentials == null) throw new ArgumentNullException("credentials"); if (oAuthUtils == null) throw new ArgumentNullException("oAuthUtils"); _credentials = credentials; _oAuthUtils = oAuthUtils; }
public void WaitForCredentialsRateLimit(string query, ITwitterCredentials credentials) { var queryRateLimit = _rateLimitCacheManager.GetQueryRateLimit(query, credentials); var timeToWait = GetTimeToWaitFromQueryRateLimit(queryRateLimit); if (timeToWait > 0) { _queryAwaitingForRateLimitWeakEvent.Raise(this, new QueryAwaitingEventArgs(query, queryRateLimit, credentials)); _threadHelper.Sleep(timeToWait); } }
public ILoggedUser GetLoggedUser(ITwitterCredentials credentials) { var userDTO = _credentialsAccessor.ExecuteOperationWithCredentials(credentials, () => { return _userFactoryQueryExecutor.GetLoggedUser(); }); var loggedUser = GenerateLoggedUserFromDTO(userDTO); loggedUser.SetCredentials(credentials); return loggedUser; }
public ICredentialsRateLimits GetCredentialsRateLimits(ITwitterCredentials credentials) { lock (_lockCredentialsRateLimitsDictionary) { ICredentialsRateLimits credentialsRateLimits; if (credentials != null && _credentialsRateLimits.TryGetValue(credentials, out credentialsRateLimits)) { return credentialsRateLimits; } return null; } }
public IEndpointRateLimit GetQueryRateLimit(string query, ITwitterCredentials credentials) { var rateLimits = _rateLimitCache.GetCredentialsRateLimits(credentials); var queryRateLimit = _rateLimitHelper.GetEndpointRateLimitFromQuery(query, rateLimits); if (rateLimits == null || DoesQueryNeedsToRefreshTheCacheInformation(queryRateLimit)) { rateLimits = RefreshCredentialsRateLimits(credentials); queryRateLimit = _rateLimitHelper.GetEndpointRateLimitFromQuery(query, rateLimits); } return queryRateLimit; }
public void RefreshEntry(ITwitterCredentials credentials, ITokenRateLimits credentialsRateLimits) { lock (_lockTokenRateLimitsDictionary) { if (_tokenRateLimits.ContainsKey(credentials)) { _tokenRateLimits[credentials] = credentialsRateLimits; } else { _tokenRateLimits.Add(credentials, credentialsRateLimits); } } }
public void TestInitialize() { _fakeBuilder = new FakeClassBuilder<RateLimitAwaiter>(); _fakeRateLimitCacheManager = _fakeBuilder.GetFake<IRateLimitCacheManager>(); _fakeCredentialsAccessor = _fakeBuilder.GetFake<ICredentialsAccessor>(); _fakeThreadHelper = _fakeBuilder.GetFake<IThreadHelper>(); _credentials = A.Fake<ITwitterCredentials>(); _endpointRateLimit = A.Fake<IEndpointRateLimit>(); _endpointRateLimit.CallsTo(x => x.Remaining).Returns(0); _endpointRateLimit.CallsTo(x => x.ResetDateTimeInMilliseconds).Returns(TIME_TO_WAIT); _fakeRateLimitCacheManager.CallsTo(x => x.GetQueryRateLimit(TEST_QUERY, _credentials)).Returns(_endpointRateLimit); _fakeCredentialsAccessor.CallsTo(x => x.CurrentThreadCredentials).Returns(_credentials); }
public ITokenRateLimits GetTokenRateLimits(ITwitterCredentials credentials) { lock (_lockTokenRateLimitsDictionary) { ITokenRateLimits credentialsRateLimits; if (_tokenRateLimits.TryGetValue(credentials, out credentialsRateLimits)) { return credentialsRateLimits; } else { return null; } } }
public void Clear(ITwitterCredentials credentials) { // We want to lock both the refresh dictionary access so that we ensure the dictionary // is not cleared during a refresh or when it is being accessed lock (_lockRefresh) { lock (_lockCredentialsRateLimitsDictionary) { if (_credentialsRateLimits.ContainsKey(credentials)) { _credentialsRateLimits.Remove(credentials); } } } }
//Will run in GUI, waits for input. public void authenticateUser(string pin) { // With this pin code it is now possible to get the credentials back from Twitter this.userCredentials = AuthFlow.CreateCredentialsFromVerifierCode(pin, authenticationContext); // Use the user credentials in your application Auth.SetCredentials(this.userCredentials); // Get the AuthenticatedUser from the current thread credentials this.User = Tweetinvi.User.GetAuthenticatedUser(); // Stores the usercredentials for later use this.storeUserCredentials(this.userCredentials.AccessToken, this.userCredentials.AccessTokenSecret); this.twitterUser = new TwitterUser(this.user); }
public IResult<StatusesResult> Tweets( ITwitterCredentials credentials, string query, Results.Language? language, Results.TweetsResultType? resultType, int? count, DateTime? until, string sinceId, string maxId, bool includeEntities) { return this.executer.Execute( credentials, new SearchTweetsCommand { Query = query, Language = language, ResultType = resultType, Count = count, Until = until, SinceId = sinceId, MaxId = maxId, IncludeEntities = includeEntities, }); }
private ITokenRateLimits GetTokenRateLimitsFromTwitter(ITwitterCredentials 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; }
public void RefreshEntry(ITwitterCredentials credentials, ICredentialsRateLimits newCredentialsRateLimits) { lock (_lockCredentialsRateLimitsDictionary) { if (newCredentialsRateLimits == null) { return; } ICredentialsRateLimits currentRateLimits; if (_credentialsRateLimits.TryGetValue(credentials, out currentRateLimits)) { var existingCustomEndpoints = currentRateLimits.OtherEndpointRateLimits; existingCustomEndpoints.ForEach(x => newCredentialsRateLimits.OtherEndpointRateLimits.AddOrUpdate(x)); } _credentialsRateLimits.AddOrUpdate(credentials, newCredentialsRateLimits); } }
public void QueryExecuted(string query, ITwitterCredentials credentials, Dictionary<string, IEnumerable<string>> rateLimitHeaders) { if (rateLimitHeaders != null && rateLimitHeaders.Count > 0) { var rateLimit = _rateLimitCacheManager.GetOrCreateQueryRateLimit(query, credentials); IEnumerable<string> limitHeaders; if (rateLimitHeaders.TryGetValue("x-rate-limit-limit", out limitHeaders)) { var limit = limitHeaders.FirstOrDefault(); if (limit != null) { rateLimit.Limit = int.Parse(limit); } } IEnumerable<string> remainingHeaders; if (rateLimitHeaders.TryGetValue("x-rate-limit-remaining", out remainingHeaders)) { var remaining = remainingHeaders.FirstOrDefault(); if (remaining != null) { rateLimit.Remaining = int.Parse(remaining); } } IEnumerable<string> resetHeaders; if (rateLimitHeaders.TryGetValue("x-rate-limit-reset", out resetHeaders)) { var reset = resetHeaders.FirstOrDefault(); if (reset != null) { rateLimit.Reset = int.Parse(reset); } } } else { QueryExecuted(query, credentials); } }
public static async Task<ITokenRateLimits> GetCredentialsRateLimits(ITwitterCredentials credentials) { return await Sync.ExecuteTaskAsync(() => RateLimit.GetCredentialsRateLimits(credentials)); }
public IResult<Results.Tweet[]> HomeTimeline(ITwitterCredentials credentials) { return this.executer.Execute( credentials, new StatusesHomeTimelineCommand {}); }
public IResult<RateLimitStatusResult> Tweets(ITwitterCredentials credentials) { return this.executer.Execute(credentials, new ApplicationRateLimitStatusCommand()); }