Skip to content

Commit

Permalink
Version 0.7.2
Browse files Browse the repository at this point in the history
Version 0.7.2
  • Loading branch information
XiaoFaye committed Jul 22, 2017
1 parent 86e8ab2 commit 9f2a724
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 15 deletions.
5 changes: 4 additions & 1 deletion Base/BaseObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ void OnSerializing(StreamingContext ctx)
{
if (pi.PropertyType == typeof(decimal?))
{
objValue.SetValue(this, (pi.GetValue(this) as decimal?).Value.ToString(CultureInfo.InvariantCulture));
if (GetType().FullName.StartsWith("WooCommerceNET.WooCommerce.v1") || GetType().FullName.StartsWith("WooCommerceNET.WooCommerce.v2"))
objValue.SetValue(this, (pi.GetValue(this) as decimal?).Value.ToString(CultureInfo.InvariantCulture));
else
objValue.SetValue(this, decimal.Parse(pi.GetValue(this).ToString(), CultureInfo.InvariantCulture));
}
else if (pi.PropertyType == typeof(int?))
{
Expand Down
6 changes: 6 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@

Version History
-------------------
* v0.7.2 update
1. Add webResponseFilter in RestAPI, which allows you to get information from the HttpWebResponse object, e.g.:X-WP-Total and X-WP-TotalPages.
2. Fix decimal values do not be serialized as string issue.
3. Avoid Deadlocking on the UI Thread on non-async calls.
4. Fix Variation weight not deserialising issue.
5. Allow calling third party Plugins restful apis.
* v0.7.1 Major update
1. Able to override the process of SerializeJSon and DeserializeJSon.
2. Allow to handle meta value for different return types.
Expand Down
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.7.1.0")]
[assembly: AssemblyFileVersion("0.7.1.0")]
[assembly: AssemblyVersion("0.7.2.0")]
[assembly: AssemblyFileVersion("0.7.2.0")]
21 changes: 12 additions & 9 deletions RestAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class RestAPI
private Func<string, string> jsonSeFilter;
private Func<string, string> jsonDeseFilter;
private Action<HttpWebRequest> webRequestFilter;
private Action<HttpWebResponse> webResponseFilter;

/// <summary>
/// Initialize the RestAPI object
Expand All @@ -35,10 +36,12 @@ public class RestAPI
/// <param name="jsonSerializeFilter">Provide a function to modify the json string after serilizing.</param>
/// <param name="jsonDeserializeFilter">Provide a function to modify the json string before deserilizing.</param>
/// <param name="requestFilter">Provide a function to modify the HttpWebRequest object.</param>
/// <param name="responseFilter">Provide a function to grab information from the HttpWebResponse object.</param>
public RestAPI(string url, string key, string secret, bool authorizedHeader = true,
Func<string, string> jsonSerializeFilter = null,
Func<string, string> jsonDeserializeFilter = null,
Action<HttpWebRequest> requestFilter = null)//, bool useProxy = false)
Action<HttpWebRequest> requestFilter = null,
Action<HttpWebResponse> responseFilter = null)//, bool useProxy = false)
{
if (string.IsNullOrEmpty(url))
throw new Exception("Please use a valid WooCommerce Restful API url.");
Expand All @@ -50,6 +53,8 @@ public RestAPI(string url, string key, string secret, bool authorizedHeader = tr
Version = APIVersion.Version1;
else if (urlLower.EndsWith("wp-json/wc/v2"))
Version = APIVersion.Version2;
else if (urlLower.Contains("wp-json/wc-"))
Version = APIVersion.ThirdPartyPlugins;
else
{
Version = APIVersion.Unknown;
Expand All @@ -69,6 +74,7 @@ public RestAPI(string url, string key, string secret, bool authorizedHeader = tr
jsonSeFilter = jsonSerializeFilter;
jsonDeseFilter = jsonDeserializeFilter;
webRequestFilter = requestFilter;
webResponseFilter = responseFilter;

//wc_Proxy = useProxy;
}
Expand Down Expand Up @@ -205,17 +211,13 @@ private string GetOAuthEndPoint(string method, string endpoint, Dictionary<strin
foreach (var p in parms)
dic.Add(p.Key, p.Value);

string base_request_uri = Uri.EscapeDataString(wc_url + endpoint).Replace("%2f", "%2F").Replace("%3a", "%3A");
string base_request_uri = method.ToUpper() + "&" + Uri.EscapeDataString(wc_url + endpoint) + "&";
string stringToSign = string.Empty;

foreach (var parm in dic.OrderBy(x => x.Key))
stringToSign += Uri.EscapeDataString(parm.Key) + "%3D" + Uri.EscapeDataString(Uri.EscapeDataString(parm.Value)) + "%26";
stringToSign += Uri.EscapeDataString(parm.Key) + "=" + Uri.EscapeDataString(parm.Value) + "&";

base_request_uri = method.ToUpper() + "&" + base_request_uri + "&" + stringToSign.Substring(0, stringToSign.Length - 3);

Common.DebugInfo.Append(base_request_uri);

stringToSign += "oauth_signature%3D" + Common.GetSHA256(wc_secret, base_request_uri);
base_request_uri = base_request_uri + Uri.EscapeDataString(stringToSign.TrimEnd('&'));

dic.Add("oauth_signature", Common.GetSHA256(wc_secret, base_request_uri));

Expand Down Expand Up @@ -317,6 +319,7 @@ public enum APIVersion
Unknown = 0,
Legacy = 1,
Version1 = 2,
Version2 = 3
Version2 = 3,
ThirdPartyPlugins = 99
}
}
3 changes: 2 additions & 1 deletion WooCommerce/v2/Product.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,11 @@ public class Product : JsonObject
[DataMember(EmitDefaultValue = false)]
public bool? manage_stock { get; set; }

[DataMember(EmitDefaultValue = false, Name = "stock_quantity")]
private object stock_quantityValue { get; set; }
/// <summary>
/// Stock quantity.
/// </summary>
[DataMember(EmitDefaultValue = false)]
public int? stock_quantity { get; set; }

/// <summary>
Expand Down
3 changes: 2 additions & 1 deletion WooCommerce/v2/Variation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,11 @@ public class Variation : JsonObject
[DataMember(EmitDefaultValue = false)]
public object manage_stock { get; set; }

[DataMember(EmitDefaultValue = false, Name = "stock_quantity")]
private object stock_quantityValue { get; set; }
/// <summary>
/// Stock quantity.
/// </summary>
[DataMember(EmitDefaultValue = false)]
public int? stock_quantity { get; set; }

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion WooCommerceNET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
</PropertyGroup>
<ItemGroup>
<!-- A reference to the entire .NET Framework is automatically included -->
<None Include="Changes.md" />
<None Include="License.md" />
<None Include="Readme.md" />
</ItemGroup>
Expand Down Expand Up @@ -87,7 +88,6 @@
<Compile Include="WooCommerce\v2\WCObject.cs" />
<Compile Include="WooCommerce\v2\Webhook.cs" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>
Expand Down

0 comments on commit 9f2a724

Please sign in to comment.