/// <summary> /// Gets the life span for cache items based on the extended <see cref="ApiMethodEnum"/> member. /// </summary> /// <param name="method">The API method for which to calculate the cache life span.</param> /// <param name="client">The governing <see cref="IStackClient"/> instance.</param> /// <returns>The life span duration after which a cache item is no longer considered fresh.</returns> public static TimeSpan? GetCacheLifeSpan(this ApiMethodEnum method, IStackClient client) { if (client == null) { throw new ArgumentNullException("client"); } if (client.Default.CacheLifeSpan.ContainsKey(method)) { return client.Default.CacheLifeSpan[method]; } CacheLifeSpanAttribute lifeSpan = method.GetCustomAttribute<CacheLifeSpanAttribute>(); if (lifeSpan != null) { return lifeSpan.Duration; } return null; }
/// <summary> /// Instances the ApiEndpointBuilder. appKey and accessToken aren't actually required parameters. /// </summary> /// <param name="client">The Stack Exchange client that owns this API endpoint builder.</param> /// <param name="method">The API method to target.</param> /// <param name="appKey">The application's key. Grants a higher request quota.</param> /// <param name="accessToken">The user's access token. Grants authentication and access to methods which require that the application be acting on behalf of a user in order to be invoked.</param> public ApiEndpointBuilder(IStackClient client, ApiMethodEnum?method, string appKey = null, string accessToken = null) : this() { if (client == null) { throw new ArgumentNullException("client"); } if (!method.HasValue) { throw new ArgumentNullException("method"); } Client = client; ApiMethod = method.Value; AppKey = appKey; AccessToken = accessToken; _out = new Lazy <string>(Build); }
/// <summary> /// Instances the ApiEndpointBuilder. appKey and accessToken aren't actually required parameters. /// </summary> /// <param name="client">The Stack Exchange client that owns this API endpoint builder.</param> /// <param name="method">The API method to target.</param> /// <param name="appKey">The application's key. Grants a higher request quota.</param> /// <param name="accessToken">The user's access token. Grants authentication and access to methods which require that the application be acting on behalf of a user in order to be invoked.</param> public ApiEndpointBuilder(IStackClient client, ApiMethodEnum? method, string appKey = null, string accessToken = null) : this() { if (client == null) { throw new ArgumentNullException("client"); } if (!method.HasValue) { throw new ArgumentNullException("method"); } Client = client; ApiMethod = method.Value; AppKey = appKey; AccessToken = accessToken; _out = new Lazy<string>(Build); }
/// <summary> /// Gets the life span for cache items based on the extended <see cref="ApiMethodEnum"/> member. /// </summary> /// <param name="method">The API method for which to calculate the cache life span.</param> /// <param name="client">The governing <see cref="IStackClient"/> instance.</param> /// <returns>The life span duration after which a cache item is no longer considered fresh.</returns> public static TimeSpan?GetCacheLifeSpan(this ApiMethodEnum method, IStackClient client) { if (client == null) { throw new ArgumentNullException("client"); } if (client.Default.CacheLifeSpan.ContainsKey(method)) { return(client.Default.CacheLifeSpan[method]); } CacheLifeSpanAttribute lifeSpan = method.GetCustomAttribute <CacheLifeSpanAttribute>(); if (lifeSpan != null) { return(lifeSpan.Duration); } return(null); }