Esempio n. 1
0
 /// <summary>
 /// Creates a new request object for making API calls.
 /// </summary>
 /// <param name="apiKey">API key to use for requests.</param>
 /// <param name="tvdbCacheProvider">The cache provider to use for persistent API requests.</param>
 public TvdbApiRequest(string apiKey, TvdbCacheProvider tvdbCacheProvider)
 {
     Debug.WriteLine("-> TvdbApiRequest::_cstr tvdbCacheProvider=\"" + tvdbCacheProvider + "\" Called");
     _cookieContainer = new CookieContainer();
     ApiKey           = apiKey;
     CacheProvider    = tvdbCacheProvider;
     PerformCacheUpdate();
 }
Esempio n. 2
0
        /// <summary>
        /// Instantiates a new copy of the TVDB API helper class
        /// </summary>
        /// <param name="apiKey">API Key to use for lookups</param>
        /// <param name="cacheType">Type of cache to use. Defaults to memory and persistent.</param>
        /// <param name="persistentCacheLocation">Location of persistent cache (if one is to be used).</param>
        public Tvdb(string apiKey, TvdbCacheType cacheType = TvdbCacheType.PersistentMemory, string persistentCacheLocation = null)
        {
            Debug.WriteLine("-> Tvdb::_cstr apiKey=\"" + apiKey + "\" cacheType=\"" + cacheType + "\" persistentCacheLocation=\"" + persistentCacheLocation + "\" Called");
            // Create the cache
            var tvdbCacheProvider = new TvdbCacheProvider(cacheType, persistentCacheLocation);

            // Create request object
            TvdbApiRequest = new TvdbApiRequest(apiKey, tvdbCacheProvider);
        }
Esempio n. 3
0
        /// <summary>
        /// Performs an API update request if appropriate. This is controlled by the API timeout key.
        /// </summary>
        /// <returns>If updates were made.</returns>
        public bool PerformCacheUpdate()
        {
            Debug.WriteLine("-> TvdbApiRequest::PerformCacheUpdate Called");
            var sec = (DateTime.Now - TvdbCacheProvider.EpochToDateTime(CacheProvider.LastApiTime)).TotalSeconds;

            if (sec < _cacheTimeout && CacheProvider.LastApiTime != 0)
            {
                return(false);
            }
            var time = TvdbApiTime.TvdbServerTime(this, CacheProvider.LastApiTime);

            CacheProvider.SetApiTime(time);
            return(true);
        }