public bool MatchesId(object obj) { TwitchContact other = obj as TwitchContact; if (other == null) { return(false); } return(other.Id == Id); }
public TwitchContact Merge(TwitchContact other) { if (string.IsNullOrEmpty(other.Id) == false) { Id = other.Id; } if (string.IsNullOrEmpty(other.Name) == false) { Name = other.Name; } if (string.IsNullOrEmpty(other.Type) == false) { Type = other.Type; } if (string.IsNullOrEmpty(other.PrimaryEmail) == false) { PrimaryEmail = other.PrimaryEmail; } if (string.IsNullOrEmpty(other.OtherEmails) == false) { OtherEmails = other.OtherEmails; } if (string.IsNullOrEmpty(other.TwitterHandle) == false) { TwitterHandle = other.TwitterHandle; } if (LastContactedDate < other.LastContactedDate) { LastContactedDate = other.LastContactedDate; } DoNotContact |= other.DoNotContact; // keep this sticky. If either has a true value, keep it true. if (string.IsNullOrEmpty(other.Notes) == false) { Notes = other.Notes; } LastUpdated = DateTime.Now; return(this); }
public override bool Equals(object obj) { TwitchContact other = obj as TwitchContact; if (other == null) { return(false); } return(other.Id == Id && other.Name == Name && other.Type == Type && other.PrimaryEmail == PrimaryEmail && other.OtherEmails == OtherEmails && other.TwitterHandle == TwitterHandle && other.LastContactedDate == LastContactedDate && other.LastUpdated == LastUpdated && other.DoNotContact == DoNotContact && other.Notes == Notes); }
public static IEnumerable <TwitchContact> GetLiveChannelData(int viewerThreshold = 10, string[] gameIds = null) { List <TwitchContact> resultSet = new List <TwitchContact>(); bool stopRequests = false; string paginationCursor = ""; while (stopRequests == false) { string url = StreamsEndpoint + "?"; if (string.IsNullOrEmpty(paginationCursor) == false) { url += "after=" + paginationCursor; } if (gameIds != null) { foreach (string gameId in gameIds) { url += "game_id=" + gameId + "&"; } } Console.WriteLine(string.Format("Making request to {0} for live channel information.", url)); HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url); webRequest.Headers.Add(ClientIdHeader, ClientIdValue); WebResponse response = webRequest.GetResponse(); Stream responseStream = response.GetResponseStream(); StreamReader streamReader = new StreamReader(responseStream); string rawResponse = streamReader.ReadToEnd(); Console.WriteLine("Got response, parsing JSON."); JObject json = JObject.Parse(rawResponse); IList <JToken> jsonContacts = json["data"].Children().ToList(); if (jsonContacts.Count <= 0) { Console.WriteLine("No results, assuming this means we've gotten all results."); stopRequests = true; } foreach (JToken token in jsonContacts) { if (token["viewer_count"].ToObject <int>() >= viewerThreshold) { TwitchContact contact = new TwitchContact { Id = token["user_id"].ToString(), LastUpdated = DateTime.Now }; resultSet.Add(contact); } else { stopRequests = true; break; } } string rateLimitValueString = response.Headers["RateLimit-Remaining"]; string rateLimitRefresh = response.Headers["RateLimit-Reset"]; paginationCursor = json["pagination"]["cursor"].ToString(); streamReader.Dispose(); responseStream.Dispose(); response.Dispose(); if (stopRequests) { break; } int rateLimitValue = -1; if (int.TryParse(rateLimitValueString, out rateLimitValue) == false) { Console.WriteLine("Unable to parse the RateLimit-Remaining attribute, quitting."); break; } if (rateLimitValue <= 1) { int sleepSeconds = 70; Console.WriteLine("Rate limit reached, waiting for refresh."); Console.WriteLine(string.Format("Sleeping for {0} seconds.", sleepSeconds)); System.Threading.Thread.Sleep(sleepSeconds * 1000); } } return(resultSet); }