/// <summary> /// Funckja obslugujaca zapytania do API Twittera o liste ostatnich 15 twittow. /// Funckja nie zwraca bezposrednio zadnej wartosci. /// Modyfukuje wartosci zmiennych w klasie. /// </summary> public async Task GetUserTwitts() { string url = makeTwittUrl(User.Data.Id); var request = new HttpRequestMessage(HttpMethod.Get, url); Client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", _config["Twitter:BearerToken"]); var response = await Client.SendAsync(request); _logger.LogInformation("response status code: {status_code}", response.StatusCode); if (response.IsSuccessStatusCode) { string data = await response.Content.ReadAsStringAsync(); _logger.LogInformation("response:{data}", data); var responseStream = await response.Content.ReadAsStreamAsync(); Twitts = await JsonSerializer.DeserializeAsync <TwitterTwitts>(responseStream, options); } else { throw new Exception(response.ReasonPhrase); } }
public void UserHasNoTwittsTwitterTwittSerializerTest() { JsonSerializerOptions options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; string data = "{\"data\":[]}"; TwitterTwitts Twitt = JsonSerializer.Deserialize <TwitterTwitts>(data, options); Assert.Empty(Twitt.Data); }
public void UserHasTwittsTwitterTwittSerializerTest() { JsonSerializerOptions options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; string data = "{\"data\":[{\"id\":\"1377428415716950023\",\"possibly_sensitive\":false,\"created_at\":\"2021-04-01T01:11:40.000Z\",\"text\":\"Two years ago, I began my campaign in Pittsburgh, saying I was running to rebuild the backbone of America.Today, I returned as president to lay out a vision for how we do that.We're going to rebuild the middle class - and this time, we're going to bring everyone along. https://t.co/hSNbI08mDF\"},{\"id\":\"1377402906157084681\",\"possibly_sensitive\":false,\"created_at\":\"2021-03-31T23:30:18.000Z\",\"text\":\"Let me be clear: We're going to ensure corporations finally pay their fair share. https://t.co/k5Kz1NaLdi\"},{\"id\":\"1377389132775743488\",\"possibly_sensitive\":false,\"created_at\":\"2021-03-31T22:35:34.000Z\",\"text\":\"The American Jobs Plan will create millions of good paying jobs, grow our economy, make us more competitive, promote our national security interests, and put us in a position to win the global competition with China. https://t.co/yaVX6MDB3M\"},{\"id\":\"1377367570831921152\",\"possibly_sensitive\":false,\"created_at\":\"2021-03-31T21:09:53.000Z\",\"text\":\"Historically, infrastructure has been bipartisan. There is no reason it can't be bipartisan again.The divisions of the moment shouldn't stop us from doing right by the future.\"}]}"; TwitterTwitts Twitt = JsonSerializer.Deserialize <TwitterTwitts>(data, options); Assert.NotEmpty(Twitt.Data); }
public async Task OnGet() { _logger.LogInformation("List:OnGet()::TwitterUserName: {TwitterUserName}", TwitterUserName); var Obj = new TwitterApiProcessor(_loggerTwitterApiProcessor, _config, TwitterUserName); await Obj.GetUserID(); if (Obj.Contex == null && Obj.User.Data.Id != null) { await Obj.GetUserTwitts(); Twitts = Obj.Twitts; User = Obj.User; } else { Contex = Obj.Contex; } ListOfTwittIdInDB = _context.Twitt.Select(c => c.Id).ToList(); _logger.LogInformation("List:OnGet()::ListOfTwittIdInDB: {ListOfTwittIdInDB}", ListOfTwittIdInDB); }