public async Task <IEnumerable <TSchema> > SearchAsync <TSchema>(string hashTag, int maxRecords, IParser <TSchema> parser) where TSchema : SchemaBase { try { var uri = new Uri($"{BaseUrl}/search/tweets.json?q={Uri.EscapeDataString(hashTag)}&count={maxRecords}"); TwitterOAuthRequest request = new TwitterOAuthRequest(); var rawResult = await request.EjecutarGetAsync(uri, _tokens); var result = parser.Parse(rawResult); return(result .Take(maxRecords) .ToList()); } catch (WebException wex) { if (wex.Response is HttpWebResponse response) { if ((int)response.StatusCode == 429) { throw new TooManyRequestsException(); } if (response.StatusCode == HttpStatusCode.Unauthorized) { throw new OAuthKeysRevokedException(); } } throw; } }
private async Task <IEnumerable <TSchema> > GetCustomSearch <TSchema>(string query, IParser <TSchema> parser) where TSchema : SchemaBase { try { var uri = new Uri($"{BaseUrl}/{query}"); TwitterOAuthRequest request = new TwitterOAuthRequest(); var rawResult = await request.EjecutarGetAsync(uri, _tokens); return(parser.Parse(rawResult)); } catch (WebException wex) { if (wex.Response is HttpWebResponse response) { if ((int)response.StatusCode == 429) { throw new TooManyRequestsException(); } if (response.StatusCode == HttpStatusCode.Unauthorized) { throw new OAuthKeysRevokedException(); } } throw; } }