complete implementation of appmetadata + images
This commit is contained in:
@@ -7,6 +7,8 @@ using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
using System.Linq;
|
||||
using System.Globalization;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace OnePeek.Api
|
||||
{
|
||||
@@ -23,20 +25,36 @@ namespace OnePeek.Api
|
||||
EndpointUris.GetWindowsPhoneMetadataUri(appId, storeCulture.ToString())
|
||||
);
|
||||
|
||||
try
|
||||
{
|
||||
//string entryXml = XDocument.Parse(xml).Descendants().FirstOrDefault(x => x.Name.LocalName == "entry").ToString();
|
||||
IEnumerable<XElement> xel = XDocument.Parse(xml).Elements().First().Descendants();
|
||||
|
||||
AppMetadata result = Deserialize.Xml<AppMetadata>(xml);
|
||||
result.Id = appId;
|
||||
return result;
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Debug.WriteLine(exc.Message);
|
||||
}
|
||||
// create metadatas
|
||||
AppMetadata result = Deserialize.Xml<AppMetadata>(xml);
|
||||
result.Id = appId;
|
||||
result.StoreType = store;
|
||||
result.StoreCultureType = storeCulture;
|
||||
|
||||
return null;
|
||||
// create publisher
|
||||
result.Publisher = Deserialize.Xml<AppPublisher>(xml);
|
||||
result.Publisher.Id = result.Publisher.Urn.Split(':').LastOrDefault();
|
||||
|
||||
// create rating
|
||||
result.Rating = Deserialize.Xml<AppRating>(xml);
|
||||
result.Rating.AverageRating = xel.GetFloat("averageUserRating");
|
||||
|
||||
// create images
|
||||
result.Images = Deserialize.Xml<AppMetadataImages>(xml);
|
||||
result.Images.Cleanup();
|
||||
result.Images.Screenshots = xel.Where(x => x.Name.LocalName == "screenshot").Select(x =>
|
||||
{
|
||||
IEnumerable<XElement> childs = x.Descendants();
|
||||
return new AppImage()
|
||||
{
|
||||
Urn = childs.Get("id"),
|
||||
Rotation = childs.GetShort("orientation")
|
||||
};
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace OnePeek.Api.Extensions
|
||||
{
|
||||
internal static class XmlExtensions
|
||||
{
|
||||
public static string Get(this IEnumerable<XElement> elements, string name)
|
||||
{
|
||||
XElement element = elements.FirstOrDefault(x => x.Name.LocalName == name);
|
||||
return element != null ? element.Value : String.Empty;
|
||||
}
|
||||
|
||||
public static float GetFloat(this IEnumerable<XElement> elements, string name)
|
||||
{
|
||||
string value = elements.Get(name);
|
||||
return !String.IsNullOrEmpty(value) ? float.Parse(value, CultureInfo.InvariantCulture) : 0;
|
||||
}
|
||||
|
||||
public static short GetShort(this IEnumerable<XElement> elements, string name)
|
||||
{
|
||||
string value = elements.Get(name);
|
||||
return !String.IsNullOrEmpty(value) ? Int16.Parse(value) : (short)0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -47,6 +47,7 @@
|
||||
<Compile Include="AppRatingEndpoint.cs" />
|
||||
<Compile Include="EndpointUris.cs" />
|
||||
<Compile Include="Extensions\EnumExtensions.cs" />
|
||||
<Compile Include="Extensions\XmlExtensions.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Xml.Serialization;
|
||||
using System.Linq;
|
||||
|
||||
namespace OnePeek.Entities
|
||||
{
|
||||
public class AppImage
|
||||
{
|
||||
public string Id { get { return !String.IsNullOrWhiteSpace(Urn) ? Urn.Split(':').LastOrDefault() : null; } }
|
||||
|
||||
[XmlElement("id")]
|
||||
public string Urn { get; set; }
|
||||
|
||||
public short Rotation { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,19 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace OnePeek.Entities
|
||||
{
|
||||
[XmlRoot("feed")]
|
||||
public class AppMetadata
|
||||
public partial class AppMetadata
|
||||
{
|
||||
public string Id { get; set; }
|
||||
|
||||
public StoreType StoreType { get; set; }
|
||||
|
||||
public StoreCultureType StoreCultureType { get; set; }
|
||||
|
||||
[XmlElement("updated")]
|
||||
public DateTime? StoreDataModifiedDate { get; set; }
|
||||
|
||||
@@ -15,28 +23,61 @@ namespace OnePeek.Entities
|
||||
[XmlElement("id")]
|
||||
public string Urn { get; set; }
|
||||
|
||||
public string Id { get; set; }
|
||||
|
||||
[XmlElement("releaseDate")]
|
||||
public DateTime ReleaseDate { get; set; }
|
||||
|
||||
[XmlElement("content")]
|
||||
public string Summary { get; set; }
|
||||
public string Text { get; set; }
|
||||
|
||||
[XmlElement("whatsNew")]
|
||||
public string UpdateSummary { get; set; }
|
||||
public string UpdateText { get; set; }
|
||||
|
||||
[XmlElement("iapCount")]
|
||||
public int IAPCount { get; set; }
|
||||
|
||||
[XmlElement("visibilityStatus")]
|
||||
public AppVisibilityStatus VisibilityStatus { get; set; }
|
||||
|
||||
[XmlElement("privacyPolicyUrl")]
|
||||
public string PrivacyPolicyUri { get; set; }
|
||||
|
||||
[XmlElement("isUniversal")]
|
||||
public bool IsUniversal { get; set; }
|
||||
|
||||
public AppMetadataImages Images { get; set; }
|
||||
|
||||
public AppPublisher Publisher { get; set; }
|
||||
|
||||
public AppRating Rating { get; set; }
|
||||
|
||||
[XmlElement("isuniversal")]
|
||||
public bool IsUniversal { get; set; }
|
||||
}
|
||||
|
||||
[XmlRoot("feed")]
|
||||
public class AppMetadataImages
|
||||
{
|
||||
[XmlElement("image")]
|
||||
public AppImage Logo { get; set; }
|
||||
|
||||
public IEnumerable<AppImage> Screenshots { get; set; }
|
||||
|
||||
[XmlElement("squareImage")]
|
||||
public AppImage LogoSquare { get; set; }
|
||||
|
||||
[XmlElement("doubleWideImage")]
|
||||
public AppImage LogoWide { get; set; }
|
||||
|
||||
[XmlElement("backgroundImage")]
|
||||
public AppImage Background { get; set; }
|
||||
|
||||
public void Cleanup()
|
||||
{
|
||||
if (Logo != null && String.IsNullOrEmpty(Logo.Urn)) Logo = null;
|
||||
if (LogoSquare != null && String.IsNullOrEmpty(LogoSquare.Urn)) LogoSquare = null;
|
||||
if (LogoWide != null && String.IsNullOrEmpty(LogoWide.Urn)) LogoWide = null;
|
||||
if (Background != null && String.IsNullOrEmpty(Background.Urn)) Background = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public enum AppVisibilityStatus
|
||||
{
|
||||
Unknown,
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
using System;
|
||||
using System.Xml.Serialization;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace OnePeek.Entities
|
||||
{
|
||||
[XmlRoot("feed")]
|
||||
public class AppPublisher
|
||||
{
|
||||
[XmlElement("publisherid")]
|
||||
public string Id { get; set; }
|
||||
|
||||
[XmlElement("publisherguid")]
|
||||
public string Uid { get; set; }
|
||||
[XmlElement("publisherGuid")]
|
||||
public string Urn { get; set; }
|
||||
|
||||
[XmlElement("publisher")]
|
||||
public string Name { get; set; }
|
||||
|
||||
[XmlElement("publisherurl")]
|
||||
public Uri Url { get; set; }
|
||||
[XmlElement("publisherUrl")]
|
||||
public string Uri { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Serialization;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace OnePeek.Entities
|
||||
{
|
||||
[XmlRoot("feed")]
|
||||
public class AppRating
|
||||
{
|
||||
[XmlElement("averageuserrating")]
|
||||
public float AverageRating { get; set; }
|
||||
|
||||
[XmlElement("userratingcount")]
|
||||
[XmlElement("userRatingCount")]
|
||||
public int RatingCount { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ using System.Xml.Serialization;
|
||||
namespace OnePeek.Entities
|
||||
{
|
||||
[XmlRoot("feed")]
|
||||
public class AppReviews
|
||||
public partial class AppReviews
|
||||
{
|
||||
public string Id { get; set; }
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace OnePeek.Entities
|
||||
}
|
||||
|
||||
|
||||
public class AppReview
|
||||
public partial class AppReview
|
||||
{
|
||||
public DateTime CreatedDate { get; set; }
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
<!-- A reference to the entire .NET Framework is automatically included -->
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AppImage.cs" />
|
||||
<Compile Include="AppMetadata.cs" />
|
||||
<Compile Include="AppPublisher.cs" />
|
||||
<Compile Include="AppRating.cs" />
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Nancy;
|
||||
using OnePeek.Api;
|
||||
using OnePeek.Entities;
|
||||
using System.IO;
|
||||
|
||||
@@ -8,8 +9,8 @@ namespace OnePeek.WebConsole
|
||||
{
|
||||
public HomeModule()
|
||||
{
|
||||
var ratingEndpoint = new Api.AppRatingEndpoint();
|
||||
var metaEndpoint = new Api.AppMetadataEndpoint();
|
||||
AppRatingEndpoint ratingEndpoint = new AppRatingEndpoint();
|
||||
AppMetadataEndpoint metaEndpoint = new AppMetadataEndpoint();
|
||||
|
||||
|
||||
Get["/meta/{id?2532ff45-aa3f-4aba-a266-ed7ec71d47bd}", true] = async (ctx, token) =>
|
||||
|
||||
Reference in New Issue
Block a user