Skip to content

Commit

Permalink
Version 0.8.4
Browse files Browse the repository at this point in the history
  • Loading branch information
XiaoFaye committed Nov 20, 2021
1 parent 6fbe6a9 commit e90213c
Show file tree
Hide file tree
Showing 46 changed files with 208 additions and 189 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
################################################################################
# This .gitignore file was automatically created by Microsoft(R) Visual Studio.
################################################################################

/.vs
/obj/Debug/netstandard2.0
/obj
/bin
8 changes: 8 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@

Version History
-------------------
* v0.8.4 update
1. Change all id field to 64bit integer (unsigned long) to prevent overflow. #560
2. Create RestClient.cs to use HttpClient, as Blazor does not support HttpWebRequest. PR#639
3. Accept '&' in password while calling WordPress Restful API. PR#527
4. Close HttpWebRequest write stream when finish. PR#529
5. Add WCObject.MetaDisplayValueProcessor function. PR#600
6. Add OrderCouponLineMeta class. PR#600
7. Change MetaData.display_value field to type object and run it through MetaDisplayValueProcessor() if configured. PR#600
* v0.8.3 update
1. Fix error while creating a refund. #476
2. Allow authenticate Woocommerce API with JWT (set WCAuthWithJWT to true). #478
Expand Down
38 changes: 23 additions & 15 deletions RestAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,11 @@ public virtual async Task<string> SendHttpClientRequest<T>(string endpoint, Requ
if (JWTRequestFilter != null)
JWTRequestFilter.Invoke(request);

var buffer = Encoding.UTF8.GetBytes($"username={wc_key}&password={wc_secret}");
Stream dataStream = await request.GetRequestStreamAsync().ConfigureAwait(false);
dataStream.Write(buffer, 0, buffer.Length);
var buffer = Encoding.UTF8.GetBytes($"username={wc_key}&password={WebUtility.UrlEncode(wc_secret)}");
using (Stream dataStream = await request.GetRequestStreamAsync().ConfigureAwait(false))
{
dataStream.Write(buffer, 0, buffer.Length);
}
WebResponse response = await request.GetResponseAsync().ConfigureAwait(false);
Stream resStream = response.GetResponseStream();
string result = await GetStreamContent(resStream, "UTF-8").ConfigureAwait(false);
Expand Down Expand Up @@ -231,8 +233,10 @@ public virtual async Task<string> SendHttpClientRequest<T>(string endpoint, Requ
{
httpWebRequest.ContentType = "application/json";
var buffer = Encoding.UTF8.GetBytes(SerializeJSon(requestBody));
Stream dataStream = await httpWebRequest.GetRequestStreamAsync().ConfigureAwait(false);
dataStream.Write(buffer, 0, buffer.Length);
using (Stream dataStream = await httpWebRequest.GetRequestStreamAsync().ConfigureAwait(false))
{
dataStream.Write(buffer, 0, buffer.Length);
}
}
else
{
Expand All @@ -243,23 +247,27 @@ public virtual async Task<string> SendHttpClientRequest<T>(string endpoint, Requ
httpWebRequest.Headers["Content-Disposition"] = $"form-data; filename=\"{parms["name"]}\"";
httpWebRequest.ContentType = "application/x-www-form-urlencoded";

Stream dataStream = await httpWebRequest.GetRequestStreamAsync().ConfigureAwait(false);
FileStream fileStream = new FileStream(parms["path"], FileMode.Open, FileAccess.Read);
byte[] buffer = new byte[4096];
int bytesRead = 0;

while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
using (Stream dataStream = await httpWebRequest.GetRequestStreamAsync().ConfigureAwait(false))
{
dataStream.Write(buffer, 0, bytesRead);
FileStream fileStream = new FileStream(parms["path"], FileMode.Open, FileAccess.Read);
byte[] buffer = new byte[4096];
int bytesRead = 0;

while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
{
dataStream.Write(buffer, 0, bytesRead);
}
fileStream.Close();
}
fileStream.Close();
}
else
{
httpWebRequest.ContentType = "application/json";
var buffer = Encoding.UTF8.GetBytes(requestBody.ToString());
Stream dataStream = await httpWebRequest.GetRequestStreamAsync().ConfigureAwait(false);
dataStream.Write(buffer, 0, buffer.Length);
using (Stream dataStream = await httpWebRequest.GetRequestStreamAsync().ConfigureAwait(false))
{
dataStream.Write(buffer, 0, buffer.Length);
}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion RestClient.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
Expand Down Expand Up @@ -46,7 +47,7 @@ public override async Task<string> SendHttpClientRequest<T>(string endpoint, Req
//if (JWTRequestFilter != null)
// JWTRequestFilter.Invoke(request);

request.Content = new StringContent($"username={wc_key}&password={wc_secret}",
request.Content = new StringContent($"username={wc_key}&password={WebUtility.UrlEncode(wc_secret)}",
Encoding.UTF8,
"application/x-www-form-urlencoded");

Expand Down
26 changes: 11 additions & 15 deletions WooCommerce.NET.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<PackageId>WooCommerceNET</PackageId>
<Version>0.8.3</Version>
<Version>0.8.4</Version>
<Authors>JamesYang@NZ</Authors>
<Company>JamesYang@NZ</Company>
<Description>A .NET Wrapper for WooCommerce/WordPress REST API</Description>
Expand All @@ -15,25 +15,21 @@
GitHub: https://github.com/XiaoFaye/WooCommerce.NET
Changes Doc: https://github.com/XiaoFaye/WooCommerce.NET/blob/master/Changes.md

* v0.8.3 update
1. Fix error while creating a refund. #476
2. Allow authenticate Woocommerce API with JWT (set WCAuthWithJWT to true). #478
3. Fix error on retrieving refund. #484
4. Fix error on deserialize BatchObject. #523
5. Fix error on date format. #524
6. Add user-friendly attribute names and values to Metadata. #558
7. Change all id field to unsigned 32bit integer to prevent overflow. #560
8. Change functions in BaseObject to virtual to support Unit Test. #568
9. Add function to delete tax class by slug. #576
10. Allow WC Plugins to use WCObject.
11. Add UpdateRangeRaw to ignore deserialize return json. #523</PackageReleaseNotes>
* v0.8.4 update
1. Change all id field to 64bit integer (unsigned long) to prevent overflow. #560
2. Create RestClient.cs to use HttpClient, as Blazor does not support HttpWebRequest. PR#639
3. Accept '&amp;' in password while calling WordPress Restful API. PR#527
4. Close HttpWebRequest write stream when finish. PR#529
5. Add WCObject.MetaDisplayValueProcessor function. PR#600
6. Add OrderCouponLineMeta class. PR#600
7. Change MetaData.display_value field to type object and run it through MetaDisplayValueProcessor() if configured. PR#600</PackageReleaseNotes>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<AssemblyVersion>0.8.3.0</AssemblyVersion>
<AssemblyVersion>0.8.4.0</AssemblyVersion>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>sn.key.snk</AssemblyOriginatorKeyFile>
<PackageLicenseFile>License.md</PackageLicenseFile>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<FileVersion>0.8.3.0</FileVersion>
<FileVersion>0.8.4.0</FileVersion>
<PackageTags>WooCommerce Wordpress Restful API</PackageTags>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion WooCommerce/Legacy/Coupon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class Coupon : JsonObject
/// read-only
/// </summary>
[DataMember(EmitDefaultValue = false)]
public uint? id { get; set; }
public ulong? id { get; set; }

/// <summary>
/// Coupon code, always lowercase
Expand Down
2 changes: 1 addition & 1 deletion WooCommerce/Legacy/Customer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class Customer
/// read-only
/// </summary>
[DataMember(EmitDefaultValue = false)]
public uint? id { get; set; }
public ulong? id { get; set; }

/// <summary>
/// UTC DateTime when the customer was created
Expand Down
20 changes: 10 additions & 10 deletions WooCommerce/Legacy/Order.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class Order
/// read-only
/// </summary>
[DataMember(EmitDefaultValue = false)]
public uint? id { get; set; }
public ulong? id { get; set; }

/// <summary>
/// Order number
Expand Down Expand Up @@ -167,7 +167,7 @@ public class Order
/// required when creating a new order
/// </summary>
[DataMember(EmitDefaultValue = false)]
public uint? customer_id { get; set; }
public ulong? customer_id { get; set; }

/// <summary>
/// URL to view the order in frontend
Expand Down Expand Up @@ -273,7 +273,7 @@ public class LineItem
/// read-only
/// </summary>
[DataMember(EmitDefaultValue = false)]
public uint? id { get; set; }
public ulong? id { get; set; }

/// <summary>
/// Line item subtotal
Expand Down Expand Up @@ -400,7 +400,7 @@ public class ShippingLine
/// read-only
/// </summary>
[DataMember(EmitDefaultValue = false)]
public uint? id { get; set; }
public ulong? id { get; set; }

/// <summary>
/// Shipping method ID
Expand Down Expand Up @@ -438,14 +438,14 @@ public class TaxLine
/// read-only
/// </summary>
[DataMember(EmitDefaultValue = false)]
public uint? id { get; set; }
public ulong? id { get; set; }

/// <summary>
/// Tax rate ID
/// read-only
/// </summary>
[DataMember(EmitDefaultValue = false)]
public int? rate_id { get; set; }
public ulong? rate_id { get; set; }

/// <summary>
/// Tax rate code
Expand Down Expand Up @@ -492,7 +492,7 @@ public class FeeLine
/// read-only
/// </summary>
[DataMember(EmitDefaultValue = false)]
public uint? id { get; set; }
public ulong? id { get; set; }

/// <summary>
/// Shipping method title
Expand Down Expand Up @@ -543,7 +543,7 @@ public class CouponLine
/// read-only
/// </summary>
[DataMember(EmitDefaultValue = false)]
public uint? id { get; set; }
public ulong? id { get; set; }

/// <summary>
/// Coupon code
Expand Down Expand Up @@ -576,7 +576,7 @@ public class Order_Note
/// read-only
/// </summary>
[DataMember(EmitDefaultValue = false)]
public uint? id { get; set; }
public ulong? id { get; set; }

/// <summary>
/// UTC DateTime when the order note was created
Expand Down Expand Up @@ -615,7 +615,7 @@ public class Order_Refund
/// read-only
/// </summary>
[DataMember(EmitDefaultValue = false)]
public uint? id { get; set; }
public ulong? id { get; set; }

/// <summary>
/// UTC DateTime when the order refund was created
Expand Down
24 changes: 12 additions & 12 deletions WooCommerce/Legacy/Product.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class Product : JsonObject
/// read-only
/// </summary>
[DataMember(EmitDefaultValue = false)]
public uint? id { get; set; }
public ulong? id { get; set; }

/// <summary>
/// Product slug
Expand Down Expand Up @@ -338,7 +338,7 @@ public class Product : JsonObject
/// Product parent ID (post_parent)
/// </summary>
[DataMember(EmitDefaultValue = false)]
public uint? parent_id { get; set; }
public ulong? parent_id { get; set; }

/// <summary>
/// List of product categories names (string). In write-mode need to pass a array of categories IDs (integer) (uses wp_set_object_terms())
Expand Down Expand Up @@ -502,7 +502,7 @@ public class Image
/// Image ID (attachment ID)
/// </summary>
[DataMember(EmitDefaultValue = false)]
public uint? id { get; set; }
public ulong? id { get; set; }

/// <summary>
/// UTC DateTime when the image was created
Expand Down Expand Up @@ -670,7 +670,7 @@ public class Variation
/// read-only
/// </summary>
[DataMember(EmitDefaultValue = false)]
public uint? id { get; set; }
public ulong? id { get; set; }

/// <summary>
/// UTC DateTime when the variation was created
Expand Down Expand Up @@ -876,7 +876,7 @@ public class ProductAttribute
/// read-only
/// </summary>
[DataMember(EmitDefaultValue = false)]
public uint? id { get; set; }
public ulong? id { get; set; }

/// <summary>
/// Attribute name
Expand Down Expand Up @@ -919,7 +919,7 @@ public class ProductAttributeTerm
/// read-only
/// </summary>
[DataMember(EmitDefaultValue = false)]
public uint? id { get; set; }
public ulong? id { get; set; }

/// <summary>
/// Term name
Expand Down Expand Up @@ -958,7 +958,7 @@ public class Product_Category
/// read-only
/// </summary>
[DataMember(EmitDefaultValue = false)]
public uint? id { get; set; }
public ulong? id { get; set; }

/// <summary>
/// Category name
Expand All @@ -977,7 +977,7 @@ public class Product_Category
/// Category parent
/// </summary>
[DataMember(EmitDefaultValue = false)]
public uint? parent { get; set; }
public ulong? parent { get; set; }

/// <summary>
/// Category description
Expand Down Expand Up @@ -1013,7 +1013,7 @@ public class ShippingClass
/// read-only
/// </summary>
[DataMember(EmitDefaultValue = false)]
public uint? id { get; set; }
public ulong? id { get; set; }

/// <summary>
/// Shipping Class name
Expand All @@ -1032,7 +1032,7 @@ public class ShippingClass
/// Shipping Class parent
/// </summary>
[DataMember(EmitDefaultValue = false)]
public uint? parent { get; set; }
public ulong? parent { get; set; }

/// <summary>
/// Shipping Class description
Expand All @@ -1056,7 +1056,7 @@ public class ProductTag
/// read-only
/// </summary>
[DataMember(EmitDefaultValue = false)]
public uint? id { get; set; }
public ulong? id { get; set; }

/// <summary>
/// Tag name
Expand Down Expand Up @@ -1101,7 +1101,7 @@ public class ProductReview
/// read-only
/// </summary>
[DataMember(EmitDefaultValue = false)]
public uint? id { get; set; }
public ulong? id { get; set; }

/// <summary>
/// UTC DateTime when the review was created
Expand Down
2 changes: 1 addition & 1 deletion WooCommerce/Legacy/Tax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class Tax
/// read-only
/// </summary>
[DataMember(EmitDefaultValue = false)]
public uint? id { get; set; }
public ulong? id { get; set; }

/// <summary>
/// Country code. See ISO 3166 Codes (Countries) for more details
Expand Down
Loading

0 comments on commit e90213c

Please sign in to comment.