complete PocketItem properties; add PocketImage, PocketVideo, PocketAuthor;
This commit is contained in:
@@ -53,7 +53,7 @@ namespace PocketSharp
|
||||
break;
|
||||
}
|
||||
|
||||
parameters.DetailType = DetailTypeEnum.complete;
|
||||
//parameters.DetailType = DetailTypeEnum.complete;
|
||||
|
||||
return Get<Retrieve>("get", parameters.Convert()).Items;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using RestSharp.Deserializers;
|
||||
using ServiceStack.Text;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace PocketSharp
|
||||
{
|
||||
@@ -23,6 +24,7 @@ namespace PocketSharp
|
||||
return JsonSerializer.DeserializeFromString<T>(response.Content);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Adds custom deserialization for specific types.
|
||||
/// </summary>
|
||||
@@ -30,8 +32,20 @@ namespace PocketSharp
|
||||
{
|
||||
// generate correct Uri format
|
||||
JsConfig<Uri>.DeSerializeFn = value => new Uri(value);
|
||||
|
||||
// create DateTime from UNIX timestamp input
|
||||
JsConfig<DateTime?>.DeSerializeFn = value =>
|
||||
{
|
||||
if(value == "0")
|
||||
{
|
||||
return null;
|
||||
}
|
||||
System.DateTime dateTimeBeginUnixEpoch = new DateTime(1970,1,1,0,0,0,0);
|
||||
return dateTimeBeginUnixEpoch.AddSeconds(Convert.ToDouble(value)).ToLocalTime();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the date format.
|
||||
/// </summary>
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace PocketSharp.Models
|
||||
{
|
||||
[DataContract]
|
||||
public class PocketAuthor
|
||||
{
|
||||
[DataMember(Name = "author_id")]
|
||||
public string ID { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public string Name { get; set; }
|
||||
|
||||
[DataMember(Name = "url")]
|
||||
public Uri Uri { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace PocketSharp.Models
|
||||
{
|
||||
[DataContract]
|
||||
public class PocketImage
|
||||
{
|
||||
[DataMember(Name = "image_id")]
|
||||
public string ID { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public string Caption { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public string Credit { get; set; }
|
||||
|
||||
[DataMember(Name = "src")]
|
||||
public Uri Uri { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace PocketSharp.Models
|
||||
@@ -21,8 +22,88 @@ namespace PocketSharp.Models
|
||||
[DataMember]
|
||||
public string Excerpt { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public int Status { get; set; }
|
||||
|
||||
[DataMember(Name = "favorite")]
|
||||
public bool IsFavorite { get; set; }
|
||||
|
||||
[IgnoreDataMember]
|
||||
public bool IsArchive { get { return Status == 1; } }
|
||||
|
||||
[IgnoreDataMember]
|
||||
public bool IsDeleted { get { return Status == 2; } }
|
||||
|
||||
[DataMember(Name = "is_article")]
|
||||
public bool IsArticle { get; set; }
|
||||
|
||||
[DataMember(Name = "has_image")]
|
||||
public bool HasImage { get; set; }
|
||||
|
||||
[DataMember(Name = "has_video")]
|
||||
public bool HasVideo { get; set; }
|
||||
|
||||
[DataMember(Name = "word_count")]
|
||||
public int WordCount { get; set; }
|
||||
|
||||
[DataMember(Name = "sort_id")]
|
||||
public int Sort { get; set; }
|
||||
|
||||
|
||||
[DataMember(Name = "time_added")]
|
||||
public DateTime? AddTime { get; set; }
|
||||
|
||||
[DataMember(Name = "time_updated")]
|
||||
public DateTime? UpdateTime { get; set; }
|
||||
|
||||
[DataMember(Name = "time_read")]
|
||||
public DateTime? ReadTime { get; set; }
|
||||
|
||||
[DataMember(Name = "time_favorited")]
|
||||
public DateTime? FavoriteTime { get; set; }
|
||||
|
||||
|
||||
[DataMember(Name = "tags")]
|
||||
public Dictionary<string, PocketTag> _TagDictionary { get; set; }
|
||||
|
||||
[DataMember(Name = "images")]
|
||||
public Dictionary<string, PocketImage> _ImageDictionary { get; set; }
|
||||
|
||||
[DataMember(Name = "videos")]
|
||||
public Dictionary<string, PocketVideo> _VideoDictionary { get; set; }
|
||||
|
||||
[DataMember(Name = "authors")]
|
||||
public Dictionary<string, PocketAuthor> _AuthorDictionary { get; set; }
|
||||
|
||||
|
||||
[IgnoreDataMember]
|
||||
public List<PocketTag> Tags
|
||||
{
|
||||
get { return PocketClient.DictionaryToList<PocketTag>(_TagDictionary); }
|
||||
}
|
||||
|
||||
[IgnoreDataMember]
|
||||
public List<PocketImage> Images
|
||||
{
|
||||
get { return PocketClient.DictionaryToList<PocketImage>(_ImageDictionary); }
|
||||
}
|
||||
|
||||
[IgnoreDataMember]
|
||||
public PocketImage LeadImage
|
||||
{
|
||||
get { return Images != null ? Images[0] : null; }
|
||||
}
|
||||
|
||||
[IgnoreDataMember]
|
||||
public List<PocketVideo> Videos
|
||||
{
|
||||
get { return PocketClient.DictionaryToList<PocketVideo>(_VideoDictionary); }
|
||||
}
|
||||
|
||||
[IgnoreDataMember]
|
||||
public List<PocketAuthor> Authors
|
||||
{
|
||||
get { return PocketClient.DictionaryToList<PocketAuthor>(_AuthorDictionary); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace PocketSharp.Models
|
||||
{
|
||||
[DataContract]
|
||||
public class PocketTag
|
||||
{
|
||||
|
||||
[DataMember(Name = "tag")]
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace PocketSharp.Models
|
||||
{
|
||||
[DataContract]
|
||||
public class PocketVideo
|
||||
{
|
||||
[DataMember(Name = "video_id")]
|
||||
public string ID { get; set; }
|
||||
|
||||
[DataMember(Name = "vid")]
|
||||
public string ExternalID { get; set; }
|
||||
|
||||
[DataMember(Name = "src")]
|
||||
public Uri Uri { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -14,24 +14,12 @@ namespace PocketSharp.Models
|
||||
public int Since { get; set; }
|
||||
|
||||
[DataMember(Name = "list")]
|
||||
public Dictionary<string, PocketItem> ItemDictionary { get; set; }
|
||||
public Dictionary<string, PocketItem> _ItemDictionary { get; set; }
|
||||
|
||||
[IgnoreDataMember]
|
||||
public List<PocketItem> Items
|
||||
{
|
||||
get
|
||||
{
|
||||
var itemEnumerator = ItemDictionary.GetEnumerator();
|
||||
List<PocketItem> result = new List<PocketItem>();
|
||||
|
||||
while (itemEnumerator.MoveNext())
|
||||
{
|
||||
result.Add(itemEnumerator.Current.Value);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
private set {}
|
||||
get { return PocketClient.DictionaryToList<PocketItem>(_ItemDictionary); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -266,5 +266,30 @@ namespace PocketSharp
|
||||
throw new APIException("No access token available. Use authentification first.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Convert a dictionary to a list
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="items">The items.</param>
|
||||
/// <returns></returns>
|
||||
internal static List<T> DictionaryToList<T>(Dictionary<string, T> items) where T : new()
|
||||
{
|
||||
if(items == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var itemEnumerator = items.GetEnumerator();
|
||||
List<T> list = new List<T>();
|
||||
|
||||
while (itemEnumerator.MoveNext())
|
||||
{
|
||||
list.Add(itemEnumerator.Current.Value);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,15 +57,18 @@
|
||||
<Compile Include="JsonDeserializer.cs" />
|
||||
<Compile Include="Models\Authentification\AccessCode.cs" />
|
||||
<Compile Include="Models\Authentification\RequestCode.cs" />
|
||||
<Compile Include="Models\Modify.cs" />
|
||||
<Compile Include="Models\PocketAuthor.cs" />
|
||||
<Compile Include="Models\PocketImage.cs" />
|
||||
<Compile Include="Models\PocketVideo.cs" />
|
||||
<Compile Include="Models\Response\Modify.cs" />
|
||||
<Compile Include="Models\Parameters\ActionParameter.cs" />
|
||||
<Compile Include="Models\Parameters\ModifyParameters.cs" />
|
||||
<Compile Include="Models\Parameters\ParameterBase.cs" />
|
||||
<Compile Include="Models\Parameters\RetrieveParameters.cs" />
|
||||
<Compile Include="Models\PocketItem.cs" />
|
||||
<Compile Include="Models\PocketTag.cs" />
|
||||
<Compile Include="Models\ResponseBase.cs" />
|
||||
<Compile Include="Models\Retrieve.cs" />
|
||||
<Compile Include="Models\Response\ResponseBase.cs" />
|
||||
<Compile Include="Models\Response\Retrieve.cs" />
|
||||
<Compile Include="PocketClient.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user