aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Api/HttpHandlers/WeatherHandler.cs
blob: b46473f11967ecae3af85f25a3c710754c3db921 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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);
            }
        }
    }
}