simple PocketItem; GetResource method;
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace PocketSharp
|
||||
{
|
||||
public partial class PocketClient
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using RestSharp;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace PocketSharp
|
||||
{
|
||||
@@ -35,5 +36,15 @@ namespace PocketSharp
|
||||
/// <param name="request">The request.</param>
|
||||
/// <returns></returns>
|
||||
T Request<T>(RestRequest request) where T : new();
|
||||
|
||||
/// <summary>
|
||||
/// Fetches a typed resource
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="method">Requested method (path after /v3/)</param>
|
||||
/// <param name="parameters">Additional POST parameters</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="APIException">No access token available. Use authentification first.</exception>
|
||||
public T GetResource<T>(string method, List<Parameter> parameters) where T : class, new();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
using RestSharp.Serializers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace PocketSharp.Models
|
||||
{
|
||||
[DataContract]
|
||||
class PocketItem
|
||||
{
|
||||
[DataMember(Name = "item_id")]
|
||||
public int ID { get; set; }
|
||||
|
||||
private Uri _uri;
|
||||
[DataMember(Name = "resolved_url")]
|
||||
public Uri Uri
|
||||
{
|
||||
get { return _uri; }
|
||||
set { _uri = new Uri(value.ToString()); }
|
||||
}
|
||||
|
||||
[DataMember(Name = "resolved_title")]
|
||||
public string Title { get; set; }
|
||||
|
||||
[DataMember(Name = "given_title")]
|
||||
public string FullTitle { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public string Excerpt { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using PocketSharp.Models.Authentification;
|
||||
using RestSharp;
|
||||
using RestSharp;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
|
||||
namespace PocketSharp
|
||||
@@ -119,6 +119,9 @@ namespace PocketSharp
|
||||
/// </summary>
|
||||
/// <param name="response">The response.</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="APIException">
|
||||
/// Error retrieving response
|
||||
/// </exception>
|
||||
protected bool ValidateResponse(IRestResponse response)
|
||||
{
|
||||
if (response.StatusCode != HttpStatusCode.OK)
|
||||
@@ -132,5 +135,38 @@ namespace PocketSharp
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Fetches a typed resource
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="method">Requested method (path after /v3/)</param>
|
||||
/// <param name="parameters">Additional POST parameters</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="APIException">No access token available. Use authentification first.</exception>
|
||||
public T GetResource<T>(string method, List<Parameter> parameters) where T : class, new()
|
||||
{
|
||||
// every single Pocket API endpoint requires HTTP POST data
|
||||
var request = new RestRequest(method, Method.POST);
|
||||
|
||||
// check if access token is available
|
||||
if(AccessCode == null)
|
||||
{
|
||||
throw new APIException("No access token available. Use authentification first.");
|
||||
}
|
||||
|
||||
// add access token (necessary for all requests except authentification)
|
||||
request.AddParameter("access_token", AccessCode);
|
||||
|
||||
// enumeration for params
|
||||
parameters.ForEach(delegate(Parameter param)
|
||||
{
|
||||
request.AddParameter(param);
|
||||
});
|
||||
|
||||
// do the request
|
||||
return Request<T>(request);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,16 +47,16 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="APIException.cs" />
|
||||
<Compile Include="Components\Authentification.cs" />
|
||||
<Compile Include="IPocketClient.cs" />
|
||||
<Compile Include="JsonDeserializer.cs" />
|
||||
<Compile Include="Models\Authentification\AcessCode.cs" />
|
||||
<Compile Include="Models\Authentification\AccessCode.cs" />
|
||||
<Compile Include="Models\Authentification\RequestCode.cs" />
|
||||
<Compile Include="Models\PocketItem.cs" />
|
||||
<Compile Include="PocketClient.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Components\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user