implement simple first version of Retrieve component;
This commit is contained in:
@@ -14,6 +14,9 @@ namespace PocketSharp.Console
|
||||
// this apiKey is just for demonstration purposes
|
||||
// please create your own application and retrieve it's key. It's a 1-step process ;-)
|
||||
PocketClient client = new PocketClient("15396-f6f92101d72c8e270a6c9bb3");
|
||||
client.AccessCode = "a85134a7-243c-6656-ab82-97c901";
|
||||
|
||||
client.Get();
|
||||
|
||||
System.Console.ReadKey();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
using PocketSharp.Models;
|
||||
using RestSharp;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace PocketSharp
|
||||
{
|
||||
public partial class PocketClient : IPocketClient
|
||||
{
|
||||
public bool Get()
|
||||
{
|
||||
//var parameters = new List<Parameter>()
|
||||
//{
|
||||
// new Parameter { Name = "favorite", Value = "1", Type = ParameterType.GetOrPost }
|
||||
//};
|
||||
|
||||
Retrieve result = GetResource<Retrieve>("get", parameters);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -45,6 +45,6 @@ namespace PocketSharp
|
||||
/// <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();
|
||||
T GetResource<T>(string method, List<Parameter> parameters) where T : class, new();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using RestSharp.Serializers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace PocketSharp.Models
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace PocketSharp.Models
|
||||
{
|
||||
class ResponseBase
|
||||
{
|
||||
public bool Status { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace PocketSharp.Models
|
||||
{
|
||||
[DataContract]
|
||||
class Retrieve : ResponseBase
|
||||
{
|
||||
[DataMember]
|
||||
public bool Complete { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public int Since { get; set; }
|
||||
|
||||
[DataMember(Name = "list")]
|
||||
public List<PocketItem> Items { get; set; }
|
||||
}
|
||||
}
|
||||
+22
-22
@@ -41,7 +41,7 @@ namespace PocketSharp
|
||||
/// <summary>
|
||||
/// Code retrieved on authentification-success
|
||||
/// </summary>
|
||||
protected string AccessCode { get; set; }
|
||||
public string AccessCode { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
@@ -114,27 +114,6 @@ namespace PocketSharp
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Validates the response.
|
||||
/// </summary>
|
||||
/// <param name="response">The response.</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="APIException">
|
||||
/// Error retrieving response
|
||||
/// </exception>
|
||||
protected void ValidateResponse(IRestResponse response)
|
||||
{
|
||||
if (response.StatusCode != HttpStatusCode.OK)
|
||||
{
|
||||
throw new APIException(response.Content, response.ErrorException);
|
||||
}
|
||||
else if (response.ErrorException != null)
|
||||
{
|
||||
throw new APIException("Error retrieving response", response.ErrorException);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Fetches a typed resource
|
||||
/// </summary>
|
||||
@@ -166,5 +145,26 @@ namespace PocketSharp
|
||||
// do the request
|
||||
return Request<T>(request);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Validates the response.
|
||||
/// </summary>
|
||||
/// <param name="response">The response.</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="APIException">
|
||||
/// Error retrieving response
|
||||
/// </exception>
|
||||
protected void ValidateResponse(IRestResponse response)
|
||||
{
|
||||
if (response.StatusCode != HttpStatusCode.OK)
|
||||
{
|
||||
throw new APIException(response.Content, response.ErrorException);
|
||||
}
|
||||
else if (response.ErrorException != null)
|
||||
{
|
||||
throw new APIException("Error retrieving response", response.ErrorException);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,11 +48,14 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="APIException.cs" />
|
||||
<Compile Include="Components\Authentification.cs" />
|
||||
<Compile Include="Components\Get.cs" />
|
||||
<Compile Include="IPocketClient.cs" />
|
||||
<Compile Include="JsonDeserializer.cs" />
|
||||
<Compile Include="Models\Authentification\AccessCode.cs" />
|
||||
<Compile Include="Models\Authentification\RequestCode.cs" />
|
||||
<Compile Include="Models\PocketItem.cs" />
|
||||
<Compile Include="Models\ResponseBase.cs" />
|
||||
<Compile Include="Models\Retrieve.cs" />
|
||||
<Compile Include="PocketClient.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user