flag for caching last HTTP response

This commit is contained in:
2014-07-01 17:10:14 +02:00
parent 140e645e86
commit 01c36a047a
3 changed files with 18 additions and 5 deletions
+1 -1
View File
@@ -58,7 +58,7 @@ namespace PocketSharp
Offset = offset
};
return (await Request<Retrieve>("get", cancellationToken, parameters.Convert())).Items;
return (await Request<Retrieve>("get", cancellationToken, parameters.Convert())).Items ?? new List<PocketItem>();
}
+17 -3
View File
@@ -52,6 +52,11 @@ namespace PocketSharp
/// </summary>
protected bool isMobileClient = true;
/// <summary>
/// Indicates, whether the last HTTP response is cached
/// </summary>
protected bool cacheHTTPResponseData;
/// <summary>
/// callback URLi for API calls
/// </summary>
@@ -104,6 +109,7 @@ namespace PocketSharp
/// <param name="timeout">Request timeout (in seconds).</param>
/// <param name="isMobileClient">Indicates, whether this client is used for mobile or desktop</param>
/// <param name="parserUri">Enables the wrapper for the private Text Parser API</param>
/// <param name="cacheHTTPResponseData">Caches the last HTTP response in public properties</param>
public PocketClient(
string consumerKey,
string accessCode = null,
@@ -111,12 +117,14 @@ namespace PocketSharp
HttpMessageHandler handler = null,
int? timeout = null,
bool isMobileClient = true,
Uri parserUri = null)
Uri parserUri = null,
bool cacheHTTPResponseData = true)
{
// assign public properties
ConsumerKey = consumerKey;
this.isMobileClient = isMobileClient;
this.cacheHTTPResponseData = cacheHTTPResponseData;
// assign access code if submitted
if (accessCode != null)
@@ -244,7 +252,10 @@ namespace PocketSharp
ValidateResponse(response);
// cache headers
lastHeaders = response.Headers;
if (cacheHTTPResponseData)
{
lastHeaders = response.Headers;
}
// read response
responseString = await response.Content.ReadAsStringAsync();
@@ -268,7 +279,10 @@ namespace PocketSharp
}
// cache response
lastResponseData = responseString;
if (cacheHTTPResponseData)
{
lastResponseData = responseString;
}
return DeserializeJson<T>(responseString);
}
-1
View File
@@ -187,7 +187,6 @@ namespace PocketSharp
public override object ReadJson(Newtonsoft.Json.JsonReader reader, Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer)
{
var jObject = JObject.ReadFrom(reader);
var pocketItem = new PocketItem();
serializer.Populate(jObject.CreateReader(), pocketItem);