diff options
Diffstat (limited to 'MediaBrowser.Api/HttpHandlers/WeatherHandler.cs')
| -rw-r--r-- | MediaBrowser.Api/HttpHandlers/WeatherHandler.cs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/MediaBrowser.Api/HttpHandlers/WeatherHandler.cs b/MediaBrowser.Api/HttpHandlers/WeatherHandler.cs new file mode 100644 index 000000000..b46473f11 --- /dev/null +++ b/MediaBrowser.Api/HttpHandlers/WeatherHandler.cs @@ -0,0 +1,36 @@ +using System;
+using System.Threading.Tasks;
+using MediaBrowser.Common.Net.Handlers;
+using MediaBrowser.Controller;
+using MediaBrowser.Model.Weather;
+
+namespace MediaBrowser.Api.HttpHandlers
+{
+ class WeatherHandler : BaseSerializationHandler<WeatherInfo>
+ {
+ protected override Task<WeatherInfo> GetObjectToSerialize()
+ {
+ // If a specific zip code was requested on the query string, use that. Otherwise use the value from configuration
+
+ string zipCode = QueryString["zipcode"];
+
+ if (string.IsNullOrWhiteSpace(zipCode))
+ {
+ zipCode = Kernel.Instance.Configuration.WeatherZipCode;
+ }
+
+ return Kernel.Instance.WeatherClient.GetWeatherInfoAsync(zipCode);
+ }
+
+ /// <summary>
+ /// Tell the client to cache the weather info for 15 minutes
+ /// </summary>
+ public override TimeSpan CacheDuration
+ {
+ get
+ {
+ return TimeSpan.FromMinutes(15);
+ }
+ }
+ }
+}
|
