add default params for requests and accessors for authentification codes

This commit is contained in:
2013-06-13 16:06:28 +02:00
parent 81d3e7e172
commit a92d5a1e1f
6 changed files with 65 additions and 9 deletions
@@ -50,6 +50,9 @@
<Name>PocketSharp</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<WCFMetadata Include="Service References\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
+4 -1
View File
@@ -1,4 +1,5 @@
using System;
using PocketSharp;
namespace PocketSharp.Console
{
@@ -11,7 +12,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();
PocketClient client = new PocketClient("15396-f6f92101d72c8e270a6c9bb3");
client.Test();
System.Console.ReadKey();
}
+12 -2
View File
@@ -3,7 +3,7 @@ using System;
namespace PocketSharp
{
class IPocketClient
public interface IPocketClient
{
/// <summary>
/// base URL for the API
@@ -16,6 +16,16 @@ namespace PocketSharp
/// </summary>
string ConsumerKey { get; set; }
/// <summary>
/// Code retrieved on authentification
/// </summary>
string AuthCode { get; set; }
/// <summary>
/// Code retrieved on authentification-success
/// </summary>
string AccessCode { get; set; }
/// <summary>
/// Makes a HTTP REST request to the API
/// </summary>
@@ -29,6 +39,6 @@ namespace PocketSharp
/// <typeparam name="T"></typeparam>
/// <param name="request">The request.</param>
/// <returns></returns>
T Request<T>(RestRequest request) where T : class, new();
T Request<T>(RestRequest request) where T : new();
}
}
@@ -0,0 +1,13 @@
using RestSharp.Serializers;
using System.Collections.Generic;
using System.Runtime.Serialization;
namespace PocketSharp.Models.Authentification
{
class RequestCode
{
public string Code { get; set; }
public string State { get; set; }
}
}
+30 -5
View File
@@ -1,8 +1,6 @@
using RestSharp;
using PocketSharp.Models.Authentification;
using RestSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PocketSharp
{
@@ -29,6 +27,18 @@ namespace PocketSharp
/// </summary>
public string ConsumerKey { get; set; }
/// <summary>
/// Code retrieved on authentification
/// </summary>
protected string AuthCode { get; set; }
/// <summary>
/// Code retrieved on authentification-success
/// </summary>
protected string AccessCode { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="PocketClient"/> class.
/// </summary>
@@ -55,6 +65,9 @@ namespace PocketSharp
// add default parameters to each request
_restClient.AddDefaultParameter("consumer_key", ConsumerKey);
// Pocket needs this specific Accept header :-S
_restClient.AddDefaultHeader("Accept", "*/*");
// defines the response format (according to the Pocket docs)
_restClient.AddDefaultHeader("X-Accept", "application/json");
@@ -74,7 +87,6 @@ namespace PocketSharp
return _restClient.Execute(request);
}
/// <summary>
/// Makes a typed HTTP REST request to the API
/// </summary>
@@ -87,5 +99,18 @@ namespace PocketSharp
return response.Data;
}
public bool Test()
{
var request = new RestRequest("oauth/request", Method.POST);
request.AddParameter("redirect_uri", "http://ceecore.com");
RequestCode rawResponse = Request<RequestCode>(request);
return true;
}
}
}
+3 -1
View File
@@ -46,12 +46,14 @@
</ItemGroup>
<ItemGroup>
<Compile Include="APIException.cs" />
<Compile Include="IPocketClient.cs" />
<Compile Include="JsonDeserializer.cs" />
<Compile Include="Models\Authentification\RequestCode.cs" />
<Compile Include="PocketClient.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Components\" />
<Folder Include="Models\" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />