2012-09-08 14:52:13 +00:00
|
|
|
|
using MediaBrowser.Common.Net.Handlers;
|
2012-09-02 05:30:25 +00:00
|
|
|
|
using MediaBrowser.Controller;
|
|
|
|
|
using MediaBrowser.Model.Weather;
|
2012-09-08 14:52:13 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.ComponentModel.Composition;
|
2012-09-18 19:33:57 +00:00
|
|
|
|
using System.Linq;
|
2012-09-08 14:52:13 +00:00
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Threading.Tasks;
|
2012-09-02 05:30:25 +00:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Api.HttpHandlers
|
|
|
|
|
{
|
2012-09-08 14:52:13 +00:00
|
|
|
|
[Export(typeof(BaseHandler))]
|
2012-09-02 05:30:25 +00:00
|
|
|
|
class WeatherHandler : BaseSerializationHandler<WeatherInfo>
|
|
|
|
|
{
|
2012-09-08 14:52:13 +00:00
|
|
|
|
public override bool HandlesRequest(HttpListenerRequest request)
|
|
|
|
|
{
|
|
|
|
|
return ApiService.IsApiUrlMatch("weather", request);
|
|
|
|
|
}
|
2012-09-19 16:51:37 +00:00
|
|
|
|
|
2012-09-02 05:30:25 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-18 19:33:57 +00:00
|
|
|
|
return Kernel.Instance.WeatherProviders.First().GetWeatherInfoAsync(zipCode);
|
2012-09-02 05:30:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-09-19 16:51:37 +00:00
|
|
|
|
protected override async Task<ResponseInfo> GetResponseInfo()
|
2012-09-02 05:30:25 +00:00
|
|
|
|
{
|
2012-09-19 16:51:37 +00:00
|
|
|
|
var info = await base.GetResponseInfo().ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
info.CacheDuration = TimeSpan.FromMinutes(15);
|
|
|
|
|
|
|
|
|
|
return info;
|
2012-09-02 05:30:25 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|