From 767cdc1f6f6a63ce997fc9476911e2c361f9d402 Mon Sep 17 00:00:00 2001 From: LukePulverenti Date: Wed, 20 Feb 2013 20:33:05 -0500 Subject: Pushing missing changes --- MediaBrowser.Api/LocalizationService.cs | 112 ++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 MediaBrowser.Api/LocalizationService.cs (limited to 'MediaBrowser.Api/LocalizationService.cs') diff --git a/MediaBrowser.Api/LocalizationService.cs b/MediaBrowser.Api/LocalizationService.cs new file mode 100644 index 0000000000..ce9f175e3d --- /dev/null +++ b/MediaBrowser.Api/LocalizationService.cs @@ -0,0 +1,112 @@ +using MediaBrowser.Common.Net; +using MediaBrowser.Controller.Localization; +using MediaBrowser.Model.Entities; +using MediaBrowser.Model.Globalization; +using MoreLinq; +using ServiceStack.ServiceHost; +using System.Collections.Generic; +using System.ComponentModel.Composition; +using System.Globalization; +using System.Linq; + +namespace MediaBrowser.Api +{ + /// + /// Class GetCultures + /// + [Route("/Localization/Cultures", "GET")] + public class GetCultures : IReturn> + { + } + + /// + /// Class GetCountries + /// + [Route("/Localization/Countries", "GET")] + public class GetCountries : IReturn> + { + } + + /// + /// Class ParentalRatings + /// + [Route("/Localization/ParentalRatings", "GET")] + public class GetParentalRatings : IReturn> + { + } + + /// + /// Class CulturesService + /// + [Export(typeof(IRestfulService))] + public class LocalizationService : BaseRestService + { + /// + /// Gets the specified request. + /// + /// The request. + /// System.Object. + public object Get(GetParentalRatings request) + { + var ratings = + Ratings.RatingsDict.Select(k => new ParentalRating { Name = k.Key, Value = k.Value }); + + var result = ratings.OrderBy(p => p.Value).Where(p => p.Value > 0).ToList(); + + return ToOptimizedResult(result); + } + + /// + /// Gets the specified request. + /// + /// The request. + /// System.Object. + public object Get(GetCountries request) + { + var result = CultureInfo.GetCultures(CultureTypes.SpecificCultures) + + .Select(c => new RegionInfo(c.LCID)) + .OrderBy(c => c.DisplayName) + + // Try to eliminate dupes + .DistinctBy(c => c.TwoLetterISORegionName) + + .Select(c => new CountryInfo + { + Name = c.Name, + DisplayName = c.DisplayName, + TwoLetterISORegionName = c.TwoLetterISORegionName, + ThreeLetterISORegionName = c.ThreeLetterISORegionName + }) + .ToList(); + + return ToOptimizedResult(result); + } + + /// + /// Gets the specified request. + /// + /// The request. + /// System.Object. + public object Get(GetCultures request) + { + var result = CultureInfo.GetCultures(CultureTypes.AllCultures) + .OrderBy(c => c.DisplayName) + + // Try to eliminate dupes + .DistinctBy(c => c.TwoLetterISOLanguageName + c.ThreeLetterISOLanguageName) + + .Select(c => new CultureDto + { + Name = c.Name, + DisplayName = c.DisplayName, + ThreeLetterISOLanguageName = c.ThreeLetterISOLanguageName, + TwoLetterISOLanguageName = c.TwoLetterISOLanguageName + }) + .ToList(); + + return ToOptimizedResult(result); + } + } + +} -- cgit v1.2.3