@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the URI.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The URI.
|
||||
/// </value>
|
||||
[DataMember]
|
||||
public string Uri { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the tags.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The tags.
|
||||
/// </value>
|
||||
[DataMember]
|
||||
public string Tags { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the title.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The title.
|
||||
/// </value>
|
||||
[DataMember]
|
||||
public string Title { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the tweet identifier.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The tweet identifier.
|
||||
/// </value>
|
||||
[DataMember]
|
||||
public string TweetId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the callback URI for your app if you want to be called back after adding.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The callback URI.
|
||||
/// </value>
|
||||
public string CallbackUri { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// Single/Multiple items.
|
||||
/// </value>
|
||||
[DataMember]
|
||||
public AddType Type { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the urls.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The urls.
|
||||
/// </value>
|
||||
[DataMember]
|
||||
public List<string> Urls { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the tags array.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The tags array.
|
||||
/// </value>
|
||||
[IgnoreDataMember]
|
||||
public string[] TagsArray
|
||||
{
|
||||
get
|
||||
{
|
||||
return string.IsNullOrEmpty(Tags) ? null : Tags.Split(',');
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts POCO to JSON.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the item.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The item.
|
||||
/// </value>
|
||||
[DataMember]
|
||||
public PocketDataItem Item { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the items.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The items.
|
||||
/// </value>
|
||||
[DataMember]
|
||||
public List<PocketDataItem> Items { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the callback URI for your app if you want to be called back after adding.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The callback URI.
|
||||
/// </value>
|
||||
[DataMember]
|
||||
public string CallbackUri { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// Single/Multiple items.
|
||||
/// </value>
|
||||
[DataMember]
|
||||
public AddType Type { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Converts POCO to JSON.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace PocketWP
|
||||
{
|
||||
[DataContract]
|
||||
public class PocketDataItem
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the URI.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The URI.
|
||||
/// </value>
|
||||
[DataMember]
|
||||
public string Uri { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the tags.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The tags.
|
||||
/// </value>
|
||||
[DataMember]
|
||||
public string Tags { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the title.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The title.
|
||||
/// </value>
|
||||
[DataMember]
|
||||
public string Title { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the tweet identifier.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The tweet identifier.
|
||||
/// </value>
|
||||
[DataMember]
|
||||
public string TweetId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the tags array.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The tags array.
|
||||
/// </value>
|
||||
[IgnoreDataMember]
|
||||
public string[] TagsArray
|
||||
{
|
||||
get
|
||||
{
|
||||
return string.IsNullOrEmpty(Tags) ? null : Tags.Split(',');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+17
-17
@@ -35,12 +35,15 @@ namespace PocketWP
|
||||
/// <param name="callbackUri">The callback URI for your app if you want to be called back after adding.</param>
|
||||
public static void AddItemToPocket(string uri, string tags = null, string title = null, string tweetId = null, string callbackUri = null)
|
||||
{
|
||||
AddToPocket(new ExternalPocketItem
|
||||
AddToPocket(new PocketData
|
||||
{
|
||||
Item = new PocketDataItem
|
||||
{
|
||||
Uri = uri,
|
||||
Tags = tags,
|
||||
Title = title,
|
||||
TweetId = tweetId,
|
||||
TweetId = tweetId
|
||||
},
|
||||
CallbackUri = callbackUri,
|
||||
Type = AddType.Single
|
||||
});
|
||||
@@ -49,15 +52,13 @@ namespace PocketWP
|
||||
/// <summary>
|
||||
/// Adds multiple items to Pocket
|
||||
/// </summary>
|
||||
/// <param name="urls">The URIs.</param>
|
||||
/// <param name="tags">The tags.</param>
|
||||
/// <param name="items">The items.</param>
|
||||
/// <param name="callbackUri">The callback URI for your app if you want to be called back after adding.</param>
|
||||
public static void AddItemsToPocket(List<string> urls, string tags = null, string callbackUri = null)
|
||||
public static void AddItemsToPocket(List<PocketDataItem> 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
|
||||
/// <summary>
|
||||
/// Buries my nut.
|
||||
/// </summary>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <param name="data">The item.</param>
|
||||
/// <exception cref="System.ArgumentNullException">item;Your nut can't be null</exception>
|
||||
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
|
||||
/// <returns>True if nut is present</returns>
|
||||
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
|
||||
/// </summary>
|
||||
/// <param name="uri">The URI.</param>
|
||||
/// <returns>The deserialised nut</returns>
|
||||
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
|
||||
|
||||
@@ -88,9 +88,10 @@
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AddType.cs" />
|
||||
<Compile Include="PocketDataItem.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="PocketHelper.cs" />
|
||||
<Compile Include="ExternalPocketItem.cs" />
|
||||
<Compile Include="PocketData.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="FodyWeavers.xml" />
|
||||
|
||||
@@ -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")]
|
||||
|
||||
Reference in New Issue
Block a user