Example #1
0
        public async Task FetchTokenIfNeeded()
        {
            if (_tvdbInfo.TokenIsInvalid)
            {
                Log.Information("Token is expired. Fetching new one....");
                try {
                    string newToken = await _retrieverService.FetchNewToken(_tvdbInfo.ToAuthenticator());

                    SetNewTokenAndSaveToFile(newToken);
                }
                catch (Exception e) {
                    Log.Error(e, "Could not fetch new token.");
                }
            }
            else if (_tvdbInfo.TokenIsAlmostExpired)
            {
                // refresh the token
                Log.Information("Token will expire soon. Will refresh it");
                string newToken = await _retrieverService.FetchRefreshToken(_tvdbInfo.Token);

                SetNewTokenAndSaveToFile(newToken);
            }
            else
            {
                Log.Information("Token is still good");
            }
        }
Example #2
0
        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);
        }