public async Task <string> FetchNewToken(TVDBAuthenticator authenticator) { Log.Information("Fetching new token..."); string myToken = null; string jsonAuth = JsonConvert.SerializeObject(authenticator); var stringContent = new StringContent(jsonAuth, UnicodeEncoding.UTF8, "application/json"); var client = _clientFactory.CreateClient(); try { client.DefaultRequestHeaders.Accept.Clear(); client.BaseAddress = GetLoginUri(); var response = await client.PostAsync(GetLoginUri(), stringContent); response.EnsureSuccessStatusCode(); Log.Information("Successfully fetched new token"); var stringResult = await response.Content.ReadAsStringAsync(); TokenFromTVDBDto TokenObject = JsonConvert.DeserializeObject <TokenFromTVDBDto>(stringResult); myToken = TokenObject.Token; } catch (Exception e) { Log.Error(e, "Error fetching new token"); } return(myToken); }
public void ToAuthenticator_Valid_ReturnsAuthenticator() { string filePath = @"c:\temp\tvdbinfo.json"; string expectedApiKey = "URV9WXPTFX8R9J6A"; string expectedUserKey = "6U0AVI208RGC9EWE"; string expectedUsername = "******"; // Act TVDBInfo tvdbInfo = TVDBInfo.ReadFromFile(filePath); TVDBAuthenticator authenticator = tvdbInfo.ToAuthenticator(); Assert.Equal(expectedApiKey, authenticator.ApiKey); Assert.Equal(expectedUserKey, authenticator.UserKey); Assert.Equal(expectedUsername, authenticator.Username); }