diff --git a/Base/BaseObject.cs b/Base/BaseObject.cs index f770caf..3513b37 100644 --- a/Base/BaseObject.cs +++ b/Base/BaseObject.cs @@ -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?)) { diff --git a/Changes.md b/Changes.md index f8a9f69..5a4f7a5 100644 --- a/Changes.md +++ b/Changes.md @@ -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. diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 11b0d06..35d5585 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -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")] diff --git a/RestAPI.cs b/RestAPI.cs index c3270b3..00590af 100644 --- a/RestAPI.cs +++ b/RestAPI.cs @@ -24,6 +24,7 @@ public class RestAPI private Func jsonSeFilter; private Func jsonDeseFilter; private Action webRequestFilter; + private Action webResponseFilter; /// /// Initialize the RestAPI object @@ -35,10 +36,12 @@ public class RestAPI /// Provide a function to modify the json string after serilizing. /// Provide a function to modify the json string before deserilizing. /// Provide a function to modify the HttpWebRequest object. + /// Provide a function to grab information from the HttpWebResponse object. public RestAPI(string url, string key, string secret, bool authorizedHeader = true, Func jsonSerializeFilter = null, Func jsonDeserializeFilter = null, - Action requestFilter = null)//, bool useProxy = false) + Action requestFilter = null, + Action responseFilter = null)//, bool useProxy = false) { if (string.IsNullOrEmpty(url)) throw new Exception("Please use a valid WooCommerce Restful API url."); @@ -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; @@ -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; } @@ -205,17 +211,13 @@ private string GetOAuthEndPoint(string method, string endpoint, Dictionary 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)); @@ -317,6 +319,7 @@ public enum APIVersion Unknown = 0, Legacy = 1, Version1 = 2, - Version2 = 3 + Version2 = 3, + ThirdPartyPlugins = 99 } } diff --git a/WooCommerce/v2/Product.cs b/WooCommerce/v2/Product.cs index a5118f7..5cfd930 100644 --- a/WooCommerce/v2/Product.cs +++ b/WooCommerce/v2/Product.cs @@ -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; } /// /// Stock quantity. /// - [DataMember(EmitDefaultValue = false)] public int? stock_quantity { get; set; } /// diff --git a/WooCommerce/v2/Variation.cs b/WooCommerce/v2/Variation.cs index 5dad0f2..88af5c8 100644 --- a/WooCommerce/v2/Variation.cs +++ b/WooCommerce/v2/Variation.cs @@ -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; } /// /// Stock quantity. /// - [DataMember(EmitDefaultValue = false)] public int? stock_quantity { get; set; } /// diff --git a/WooCommerceNET.csproj b/WooCommerceNET.csproj index 5a10a6e..6e30927 100644 --- a/WooCommerceNET.csproj +++ b/WooCommerceNET.csproj @@ -37,6 +37,7 @@ + @@ -87,7 +88,6 @@ -