diff --git a/PocketWP/ExternalPocketItem.cs b/PocketWP/ExternalPocketItem.cs deleted file mode 100644 index 9ae3763..0000000 --- a/PocketWP/ExternalPocketItem.cs +++ /dev/null @@ -1,107 +0,0 @@ -using System.Collections.Generic; -using System.IO; -using System.Runtime.Serialization; -using System.Runtime.Serialization.Json; -using System.Text; -using PropertyChanged; - -namespace PocketWP -{ - [ImplementPropertyChanged] - [DataContract] - public class ExternalPocketItem - { - /// - /// Gets or sets the URI. - /// - /// - /// The URI. - /// - [DataMember] - public string Uri { get; set; } - - /// - /// Gets or sets the tags. - /// - /// - /// The tags. - /// - [DataMember] - public string Tags { get; set; } - - /// - /// Gets or sets the title. - /// - /// - /// The title. - /// - [DataMember] - public string Title { get; set; } - - /// - /// Gets or sets the tweet identifier. - /// - /// - /// The tweet identifier. - /// - [DataMember] - public string TweetId { get; set; } - - /// - /// Gets or sets the callback URI for your app if you want to be called back after adding. - /// - /// - /// The callback URI. - /// - public string CallbackUri { get; set; } - - /// - /// Gets the type. - /// - /// - /// Single/Multiple items. - /// - [DataMember] - public AddType Type { get; internal set; } - - /// - /// Gets or sets the urls. - /// - /// - /// The urls. - /// - [DataMember] - public List Urls { get; set; } - - /// - /// Gets the tags array. - /// - /// - /// The tags array. - /// - [IgnoreDataMember] - public string[] TagsArray - { - get - { - return string.IsNullOrEmpty(Tags) ? null : Tags.Split(','); - } - } - - /// - /// Converts POCO to JSON. - /// - /// - public string ToEscapedJson() - { - var serialiser = new DataContractJsonSerializer(typeof(ExternalPocketItem)); - using (var stream = new MemoryStream()) - { - serialiser.WriteObject(stream, this); - - var json = Encoding.UTF8.GetString(stream.ToArray(), 0, (int)stream.Length); - return System.Uri.EscapeDataString(json); - } - } - } -} diff --git a/PocketWP/PocketData.cs b/PocketWP/PocketData.cs new file mode 100644 index 0000000..584499c --- /dev/null +++ b/PocketWP/PocketData.cs @@ -0,0 +1,66 @@ +using System.Collections.Generic; +using System.IO; +using System.Runtime.Serialization; +using System.Runtime.Serialization.Json; +using System.Text; +using PropertyChanged; + +namespace PocketWP +{ + [ImplementPropertyChanged] + [DataContract] + public class PocketData + { + /// + /// Gets or sets the item. + /// + /// + /// The item. + /// + [DataMember] + public PocketDataItem Item { get; set; } + + /// + /// Gets or sets the items. + /// + /// + /// The items. + /// + [DataMember] + public List Items { get; set; } + + /// + /// Gets or sets the callback URI for your app if you want to be called back after adding. + /// + /// + /// The callback URI. + /// + [DataMember] + public string CallbackUri { get; set; } + + /// + /// Gets the type. + /// + /// + /// Single/Multiple items. + /// + [DataMember] + public AddType Type { get; internal set; } + + /// + /// Converts POCO to JSON. + /// + /// + public string ToEscapedJson() + { + var serialiser = new DataContractJsonSerializer(typeof(PocketData)); + using (var stream = new MemoryStream()) + { + serialiser.WriteObject(stream, this); + + var json = Encoding.UTF8.GetString(stream.ToArray(), 0, (int)stream.Length); + return System.Uri.EscapeDataString(json); + } + } + } +} diff --git a/PocketWP/PocketDataItem.cs b/PocketWP/PocketDataItem.cs new file mode 100644 index 0000000..2a917bc --- /dev/null +++ b/PocketWP/PocketDataItem.cs @@ -0,0 +1,59 @@ +using System.Runtime.Serialization; + +namespace PocketWP +{ + [DataContract] + public class PocketDataItem + { + /// + /// Gets or sets the URI. + /// + /// + /// The URI. + /// + [DataMember] + public string Uri { get; set; } + + /// + /// Gets or sets the tags. + /// + /// + /// The tags. + /// + [DataMember] + public string Tags { get; set; } + + /// + /// Gets or sets the title. + /// + /// + /// The title. + /// + [DataMember] + public string Title { get; set; } + + /// + /// Gets or sets the tweet identifier. + /// + /// + /// The tweet identifier. + /// + [DataMember] + public string TweetId { get; set; } + + /// + /// Gets the tags array. + /// + /// + /// The tags array. + /// + [IgnoreDataMember] + public string[] TagsArray + { + get + { + return string.IsNullOrEmpty(Tags) ? null : Tags.Split(','); + } + } + } +} \ No newline at end of file diff --git a/PocketWP/PocketHelper.cs b/PocketWP/PocketHelper.cs index 85b786e..d6c2fb3 100644 --- a/PocketWP/PocketHelper.cs +++ b/PocketWP/PocketHelper.cs @@ -35,12 +35,15 @@ namespace PocketWP /// The callback URI for your app if you want to be called back after adding. public static void AddItemToPocket(string uri, string tags = null, string title = null, string tweetId = null, string callbackUri = null) { - AddToPocket(new ExternalPocketItem + AddToPocket(new PocketData { - Uri = uri, - Tags = tags, - Title = title, - TweetId = tweetId, + Item = new PocketDataItem + { + Uri = uri, + Tags = tags, + Title = title, + TweetId = tweetId + }, CallbackUri = callbackUri, Type = AddType.Single }); @@ -49,15 +52,13 @@ namespace PocketWP /// /// Adds multiple items to Pocket /// - /// The URIs. - /// The tags. + /// The items. /// The callback URI for your app if you want to be called back after adding. - public static void AddItemsToPocket(List urls, string tags = null, string callbackUri = null) + public static void AddItemsToPocket(List items, string callbackUri = null) { - AddToPocket(new ExternalPocketItem + AddToPocket(new PocketData { - Urls = urls, - Tags = tags, + Items = items, CallbackUri = callbackUri, Type = AddType.Multiple }); @@ -66,16 +67,16 @@ namespace PocketWP /// /// Buries my nut. /// - /// The item. + /// The item. /// item;Your nut can't be null - private static async void AddToPocket(ExternalPocketItem item) + private static async void AddToPocket(PocketData data) { - if (item == null) + if (data == null) { - throw new ArgumentNullException("item", "Your item can't be null"); + throw new ArgumentNullException("data", "Your item can't be null"); } - var url = PocketUrl + item.ToEscapedJson(); + var url = PocketUrl + data.ToEscapedJson(); await Windows.System.Launcher.LaunchUriAsync(new Uri(url)); } @@ -87,7 +88,6 @@ namespace PocketWP /// True if nut is present public static bool HasPocketItem(Uri uri) { - // /Protocol?encodedLaunchUri=squirrel%3AAddNut%3Fnut%3D return uri.ToString().Contains(Uri.EscapeDataString(PocketUrl)); } @@ -96,7 +96,7 @@ namespace PocketWP /// /// The URI. /// The deserialised nut - public static ExternalPocketItem RetrievePocketItem(Uri uri) + public static PocketData RetrievePocketItem(Uri uri) { var pocketUri = uri.ToString().Replace("/Protocol?encodedLaunchUri=", string.Empty); pocketUri = Uri.UnescapeDataString(pocketUri).Replace(PocketUrl, string.Empty); @@ -105,10 +105,10 @@ namespace PocketWP try { - var serializer = new DataContractJsonSerializer(typeof(ExternalPocketItem)); + var serializer = new DataContractJsonSerializer(typeof(PocketData)); using (var reader = new MemoryStream(Encoding.UTF8.GetBytes(itemJson))) { - return (ExternalPocketItem)serializer.ReadObject(reader); + return (PocketData)serializer.ReadObject(reader); } } catch diff --git a/PocketWP/PocketWP.csproj b/PocketWP/PocketWP.csproj index 00031ea..8e5183c 100644 --- a/PocketWP/PocketWP.csproj +++ b/PocketWP/PocketWP.csproj @@ -88,9 +88,10 @@ + - + diff --git a/PocketWP/Properties/AssemblyInfo.cs b/PocketWP/Properties/AssemblyInfo.cs index 8a56f9a..bec04b5 100644 --- a/PocketWP/Properties/AssemblyInfo.cs +++ b/PocketWP/Properties/AssemblyInfo.cs @@ -32,6 +32,6 @@ using System.Resources; // // You can specify all the values or you can default the Revision and Build Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("1.0.0.1")] -[assembly: AssemblyFileVersion("1.0.0.1")] +[assembly: AssemblyVersion("1.0.0.2")] +[assembly: AssemblyFileVersion("1.0.0.2")] [assembly: NeutralResourcesLanguageAttribute("en-US")]