public RateLimitStatus GetRateLimitStatus()
        {
            // goes to twitter comm directly - no limiting
            string xml = twitterComm.ExecuteGet("/account/rate_limit_status.xml");

            var hash = XDocument.Parse(xml).Root;
            var result = new RateLimitStatus
                             {
                                 // ReSharper disable PossibleNullReferenceException
                                 HourlyLimit = int.Parse(hash.Element("hourly-limit").Value),
                                 ResetTime = DateTimeOffset.Parse(hash.Element("reset-time").Value),
                                 RemainingHits = int.Parse(hash.Element("remaining-hits").Value),
                                 // ReSharper restore PossibleNullReferenceException
                             };
            if (!result.IsValid)
            {
                log.WarnFormat("Retrieved RateLimitStatus from Twitter, but it's already not valid! Now: {0} Reset (LocalDateTime): {1} Reset(ToLocalTime): {2}",
                               DateTime.Now,
                               result.ResetTime.LocalDateTime,
                               result.ResetTime.ToLocalTime());
                // problem seems to go away after a little bit (maybe 1 minute? possible bug somewhere..) so forget it,
                // we'll try again in a few minutes.
                result.ResetTime = DateTime.Now.AddMinutes(5);
            }
            return result;
        }
 public void Is_Valid()
 {
     var status = new RateLimitStatus { ResetTime = DateTime.Now.ToUniversalTime().AddHours(1) };
     log.DebugFormat("Reset Time is " + status.ResetTime);
     log.DebugFormat("Current Time is " + DateTime.Now.ToUniversalTime());
     Assert.That(status.IsValid, Is.True);
 }
Exemple #3
0
 private void RefreshStatus()
 {
     if (status.IsValid)
         return;
     log.Info("Refreshing Rate Limit Status");
     status = rateLimitProvider.GetRateLimitStatus();
 }
Exemple #4
0
        public TwitterGovernor(IRateLimitStatusProvider rateLimitProvider, ISettingsProvider settingsProvider)
        {
            this.rateLimitProvider = rateLimitProvider;
            status = rateLimitProvider.GetRateLimitStatus();

            threshold = settingsProvider.Twitter.RateLimitThreshold;
        }