diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..52a8437
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,10 @@
+################################################################################
+# This .gitignore file was automatically created by Microsoft(R) Visual Studio.
+################################################################################
+
+*.user
+/.vs
+/OpenAPI Client/bin
+/OpenAPI Client/obj
+/OpenAPI Client Unit Tests/bin
+/OpenAPI Client Unit Tests/obj
diff --git a/Directory.Build.props b/Directory.Build.props
new file mode 100644
index 0000000..5b7c030
--- /dev/null
+++ b/Directory.Build.props
@@ -0,0 +1,21 @@
+
+
+
+ None
+ false
+
+
+
+ true
+ false
+ git
+
+ true
+ embedded
+ false
+ $(MSBuildProjectName.Contains('Tests'))
+ $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb
+ 8.0
+
+
+
\ No newline at end of file
diff --git a/OpenAPI Client Unit Tests/Accounts/LoginTest.cs b/OpenAPI Client Unit Tests/Accounts/LoginTest.cs
index a13ab7a..e095a58 100644
--- a/OpenAPI Client Unit Tests/Accounts/LoginTest.cs
+++ b/OpenAPI Client Unit Tests/Accounts/LoginTest.cs
@@ -1,21 +1,23 @@
-using Bol.OpenAPI.Client;
+using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace OpenAPI_Client_Unit_Tests
{
[TestClass]
public class LoginTest
+ : ConfiguredTestBase
{
- private OpenApiClient client = new OpenApiClient(Constants.API_KEY);
-
+ ///
+ /// Usage of this call is limited and only on request by email to developercenter@bol.com.
+ /// https://partnerblog.bol.com/documentatie/open-api/handleiding/api-requests/accounts/post-accountsv4login/
+ ///
[TestMethod]
- public void TestLogin()
+ public async Task TestLogin()
{
- // Insert proper private token that has user permission.
-
//Login login = client.Login("", null);
//Assert.IsNotNull(login.Name);
//Assert.IsNotNull(login.SessionId);
+ await Task.CompletedTask;
}
}
}
diff --git a/OpenAPI Client Unit Tests/Accounts/LogoutTest.cs b/OpenAPI Client Unit Tests/Accounts/LogoutTest.cs
index f9f5e92..7853d03 100644
--- a/OpenAPI Client Unit Tests/Accounts/LogoutTest.cs
+++ b/OpenAPI Client Unit Tests/Accounts/LogoutTest.cs
@@ -1,18 +1,23 @@
-using Bol.OpenAPI.Client;
+using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace OpenAPI_Client_Unit_Tests
{
[TestClass]
public class LogoutTest
+ : ConfiguredTestBase
{
- private OpenApiClient client = new OpenApiClient(Constants.API_KEY);
-
+ ///
+ /// Usage of this call is limited and only on request by email to developercenter@bol.com.
+ /// https://partnerblog.bol.com/documentatie/open-api/handleiding/api-requests/accounts/post-accountsv4logout/
+ ///
[TestMethod]
- public void TestLogout()
+ public async Task TestLogout()
{
- Login login = client.Login("M3F7zteABWh8tpGkZyitU003zUtohfZ6kLV5ZohuNFlqDS6LntSL1z6Me3yslsJX9hQGeh5VJor1P8hs9swT8Q1RhqGMRuxOBxYOGZp6YTFRi0X5BADsUDdUWX3YknbV3JgDIY30dwZNNHGa4em8YnPsl9j9LvESiQoC7RQhHoV94DfmMX31AIeMsliYqZVqN2e2wRcdekUvQJRGOltgEMh8GlL4IfG3c8KglOGCJZqUwYnfRzeEOjcKrgH4Los9", null);
- client.Logout(login.SessionId);
+ //var token = await client.GetRequestAuthTokenAsync(null, null);
+ //var login = await client.LoginAsync(token.PrivateToken, null);
+ //client.LogoutAsync(login.SessionId);
+ await Task.CompletedTask;
}
}
}
diff --git a/OpenAPI Client Unit Tests/Accounts/RequestAuthTokenTest.cs b/OpenAPI Client Unit Tests/Accounts/RequestAuthTokenTest.cs
index d1b03bf..f36a1af 100644
--- a/OpenAPI Client Unit Tests/Accounts/RequestAuthTokenTest.cs
+++ b/OpenAPI Client Unit Tests/Accounts/RequestAuthTokenTest.cs
@@ -1,17 +1,17 @@
-using Bol.OpenAPI.Client;
+using System.Threading.Tasks;
+using Bol.OpenAPI.Client;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace OpenAPI_Client_Unit_Tests
{
[TestClass]
public class RequestAuthTokenTest
+ : ConfiguredTestBase
{
- private OpenApiClient client = new OpenApiClient(Constants.API_KEY);
-
[TestMethod]
- public void TestGetRequestAuthToken()
+ public async Task TestGetRequestAuthToken()
{
- RequestAuthToken requestAuthToken = client.GetRequestAuthToken("https://m.bol.com/nl/", "https://m.bol.com/nl/error/");
+ var requestAuthToken = await _client.GetRequestAuthTokenAsync("https://m.bol.com/nl/", "https://m.bol.com/nl/error/");
Assert.IsNotNull(requestAuthToken.Code);
Assert.IsNotNull(requestAuthToken.PrivateToken);
Assert.IsNotNull(requestAuthToken.Url);
diff --git a/OpenAPI Client Unit Tests/Accounts/SessionTest.cs b/OpenAPI Client Unit Tests/Accounts/SessionTest.cs
index 3ccbedd..e7ad43d 100644
--- a/OpenAPI Client Unit Tests/Accounts/SessionTest.cs
+++ b/OpenAPI Client Unit Tests/Accounts/SessionTest.cs
@@ -1,17 +1,16 @@
-using Bol.OpenAPI.Client;
+using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace OpenAPI_Client_Unit_Tests
{
[TestClass]
public class SessionTest
+ : ConfiguredTestBase
{
- private OpenApiClient client = new OpenApiClient(Constants.API_KEY);
-
[TestMethod]
- public void TestGetSession()
+ public async Task TestGetSession()
{
- Session session = client.GetSession();
+ var session = await _client.GetSessionAsync();
Assert.IsNotNull(session.SessionId);
}
}
diff --git a/OpenAPI Client Unit Tests/Accounts/WishListTest.cs b/OpenAPI Client Unit Tests/Accounts/WishListTest.cs
index 28c53ff..b155cbd 100644
--- a/OpenAPI Client Unit Tests/Accounts/WishListTest.cs
+++ b/OpenAPI Client Unit Tests/Accounts/WishListTest.cs
@@ -1,55 +1,54 @@
-using Bol.OpenAPI.Client;
+using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace OpenAPI_Client_Unit_Tests
{
[TestClass]
public class WishListTest
+ : ConfiguredTestBase
{
- private OpenApiClient client = new OpenApiClient(Constants.API_KEY);
-
[TestMethod]
- public void TestGetWishList()
+ public async Task TestGetWishList()
{
- Session session = client.GetSession();
+ var session = await _client.GetSessionAsync();
Assert.IsNotNull(session.SessionId);
- WishList wishList = client.GetWishList(session.SessionId);
+ var wishList = await _client.GetWishListAsync(session.SessionId);
Assert.IsTrue(wishList.WishListItems.Count == 0);
}
[TestMethod]
- public void TestAddItemToWishList()
+ public async Task TestAddItemToWishList()
{
- Session session = client.GetSession();
+ var session = await _client.GetSessionAsync();
Assert.IsNotNull(session.SessionId);
- WishList wishList = client.GetWishList(session.SessionId);
+ var wishList = await _client.GetWishListAsync(session.SessionId);
Assert.IsTrue(wishList.WishListItems.Count == 0);
- client.AddItemToWishList(session.SessionId, "1004004012288125");
+ await _client.AddItemToWishListAsync(session.SessionId, "1004004012288125");
- wishList = client.GetWishList(session.SessionId);
+ wishList = await _client.GetWishListAsync(session.SessionId);
Assert.IsTrue(wishList.WishListItems.Count == 1);
}
[TestMethod]
- public void TestRemoveItemFromWishList()
+ public async Task TestRemoveItemFromWishList()
{
- Session session = client.GetSession();
+ var session = await _client.GetSessionAsync();
Assert.IsNotNull(session.SessionId);
- WishList wishList = client.GetWishList(session.SessionId);
+ var wishList = await _client.GetWishListAsync(session.SessionId);
Assert.IsTrue(wishList.WishListItems.Count == 0);
- client.AddItemToWishList(session.SessionId, "1004004012288125");
+ await _client.AddItemToWishListAsync(session.SessionId, "1004004012288125");
- wishList = client.GetWishList(session.SessionId);
+ wishList = await _client.GetWishListAsync(session.SessionId);
Assert.IsTrue(wishList.WishListItems.Count == 1);
- client.RemoveItemFromWishList(session.SessionId, wishList.WishListItems[0].Id);
+ await _client.RemoveItemFromWishListAsync(session.SessionId, wishList.WishListItems[0].Id);
- wishList = client.GetWishList(session.SessionId);
+ wishList = await _client.GetWishListAsync(session.SessionId);
Assert.IsTrue(wishList.WishListItems.Count == 0);
}
diff --git a/OpenAPI Client Unit Tests/Catalog/BrowseTest.cs b/OpenAPI Client Unit Tests/Catalog/BrowseTest.cs
index 63add10..dffb3e5 100644
--- a/OpenAPI Client Unit Tests/Catalog/BrowseTest.cs
+++ b/OpenAPI Client Unit Tests/Catalog/BrowseTest.cs
@@ -1,34 +1,35 @@
-using Bol.OpenAPI.Client;
-using Bol.OpenAPI.Request.Catalog;
-using Bol.OpenAPI.Request.Common;
+using System.Threading.Tasks;
+using Bol.OpenAPI.Client.Request.Catalog;
+using Bol.OpenAPI.Client.Request.Common;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace OpenAPI_Client_Unit_Tests
{
[TestClass]
public class BrowseTest
+ : ConfiguredTestBase
{
- private OpenApiClient client = new OpenApiClient(Constants.API_KEY);
-
[TestMethod]
- public void TestBrowse()
+ public async Task TestBrowse()
{
- ListResultsRequest listResultsRequest = new ListResultsRequest();
- listResultsRequest.Type = EnumTypes.ListType.DEFAULT;
- listResultsRequest.CategoryId = "3135";
- listResultsRequest.IncludeAttributes = true;
- listResultsRequest.Offset = 10;
- listResultsRequest.Limit = 10;
- listResultsRequest.DataOutputs = new EnumTypes.DataOutputType[] {
+ var listResultsRequest = new ListResultsRequest
+ {
+ Type = EnumTypes.ListType.DEFAULT,
+ CategoryId = "3135",
+ IncludeAttributes = true,
+ Offset = 10,
+ Limit = 10,
+ DataOutputs = new[] {
EnumTypes.DataOutputType.PRODUCTS,
EnumTypes.DataOutputType.CATEGORIES,
EnumTypes.DataOutputType.REFINEMENTS
- };
- listResultsRequest.Offers = new EnumTypes.OfferType[] {
+ },
+ Offers = new[] {
EnumTypes.OfferType.ALL
- };
+ }
+ };
- ListResults listResults = client.Browse(listResultsRequest);
+ var listResults = await _client.BrowseAsync(listResultsRequest);
Assert.IsTrue(listResults.TotalResultSize > 0);
Assert.IsNotNull(listResults.Categories);
Assert.IsTrue(listResults.Categories.Count > 0);
diff --git a/OpenAPI Client Unit Tests/Catalog/ProductOffersTest.cs b/OpenAPI Client Unit Tests/Catalog/ProductOffersTest.cs
index 6da53cd..07c0db4 100644
--- a/OpenAPI Client Unit Tests/Catalog/ProductOffersTest.cs
+++ b/OpenAPI Client Unit Tests/Catalog/ProductOffersTest.cs
@@ -1,25 +1,26 @@
-using Bol.OpenAPI.Client;
-using Bol.OpenAPI.Request.Catalog;
-using Bol.OpenAPI.Request.Common;
+using System.Threading.Tasks;
+using Bol.OpenAPI.Client.Request.Catalog;
+using Bol.OpenAPI.Client.Request.Common;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace OpenAPI_Client_Unit_Tests.Catalog
{
[TestClass]
public class ProductOffersTest
+ : ConfiguredTestBase
{
- private OpenApiClient client = new OpenApiClient(Constants.API_KEY);
-
[TestMethod]
- public void TestGetProductOffers()
+ public async Task TestGetProductOffers()
{
- ProductOffersRequest productOffersRequest = new ProductOffersRequest();
- productOffersRequest.Id = "1004004012288125";
- productOffersRequest.Offers = new EnumTypes.OfferType[] {
+ var productOffersRequest = new ProductOffersRequest
+ {
+ Id = "1004004012288125",
+ Offers = new[] {
EnumTypes.OfferType.ALL
+ }
};
- ProductOffers productOffers = client.GetProductOffers(productOffersRequest);
+ var productOffers = await _client.GetProductOffersAsync(productOffersRequest);
Assert.IsNotNull(productOffers.OfferData);
Assert.IsNotNull(productOffers.OfferData.Offers);
Assert.IsTrue(productOffers.OfferData.Offers.Count > 0);
diff --git a/OpenAPI Client Unit Tests/Catalog/ProductRecommendationsTest.cs b/OpenAPI Client Unit Tests/Catalog/ProductRecommendationsTest.cs
index bf69a26..ba93238 100644
--- a/OpenAPI Client Unit Tests/Catalog/ProductRecommendationsTest.cs
+++ b/OpenAPI Client Unit Tests/Catalog/ProductRecommendationsTest.cs
@@ -1,28 +1,29 @@
-using Bol.OpenAPI.Client;
-using Bol.OpenAPI.Request.Catalog;
-using Bol.OpenAPI.Request.Common;
+using System.Threading.Tasks;
+using Bol.OpenAPI.Client.Request.Catalog;
+using Bol.OpenAPI.Client.Request.Common;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace OpenAPI_Client_Unit_Tests.Catalog
{
[TestClass]
public class ProductRecommendationsTest
+ : ConfiguredTestBase
{
- private OpenApiClient client = new OpenApiClient(Constants.API_KEY);
-
[TestMethod]
- public void TestGetProductRecommendation()
+ public async Task TestGetProductRecommendation()
{
- ProductRecommendationsRequest productRecommendationsRequest = new ProductRecommendationsRequest();
- productRecommendationsRequest.Id = "1004004012288125";
- productRecommendationsRequest.IncludeAttributes = true;
- productRecommendationsRequest.Offers = new EnumTypes.OfferType[] {
+ var productRecommendationsRequest = new ProductRecommendationsRequest
+ {
+ Id = "1004004012288125",
+ IncludeAttributes = true,
+ Offers = new[] {
EnumTypes.OfferType.ALL
+ },
+ Offset = 0,
+ Limit = 10
};
- productRecommendationsRequest.Offset = 0;
- productRecommendationsRequest.Limit = 10;
- ProductRecommendations productRecommendations = client.GetProductRecommendations(productRecommendationsRequest);
+ var productRecommendations = await _client.GetProductRecommendationsAsync(productRecommendationsRequest);
Assert.IsNotNull(productRecommendations.Products);
Assert.IsTrue(productRecommendations.Products.Count > 0);
}
diff --git a/OpenAPI Client Unit Tests/Catalog/ProductsTest.cs b/OpenAPI Client Unit Tests/Catalog/ProductsTest.cs
index 16579cd..7438e48 100644
--- a/OpenAPI Client Unit Tests/Catalog/ProductsTest.cs
+++ b/OpenAPI Client Unit Tests/Catalog/ProductsTest.cs
@@ -1,41 +1,44 @@
-using Bol.OpenAPI.Client;
-using Bol.OpenAPI.Request.Catalog;
-using Bol.OpenAPI.Request.Common;
+using System.Threading.Tasks;
+using Bol.OpenAPI.Client.Request.Catalog;
+using Bol.OpenAPI.Client.Request.Common;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace OpenAPI_Client_Unit_Tests.Catalog
{
[TestClass]
public class ProductsTest
+ : ConfiguredTestBase
{
- private OpenApiClient client = new OpenApiClient(Constants.API_KEY);
-
[TestMethod]
- public void TestGetProduct()
+ public async Task TestGetProduct()
{
- ProductsRequest productsRequest = new ProductsRequest();
- productsRequest.Ids = new string[] { "1004004012288125" };
- productsRequest.IncludeAttributes = true;
- productsRequest.Offers = new EnumTypes.OfferType[] {
+ var productsRequest = new ProductsRequest
+ {
+ Ids = new[] { "1004004012288125" },
+ IncludeAttributes = true,
+ Offers = new[] {
EnumTypes.OfferType.ALL
+ }
};
- ProductList productList = client.GetProducts(productsRequest);
+ var productList = await _client.GetProductsAsync(productsRequest);
Assert.IsNotNull(productList.Products);
Assert.IsTrue(productList.Products.Count == 1);
}
[TestMethod]
- public void TestGetProducts()
+ public async Task TestGetProducts()
{
- ProductsRequest productsRequest = new ProductsRequest();
- productsRequest.Ids = new string[] { "1004004012288125", "1004004012257956" };
- productsRequest.IncludeAttributes = true;
- productsRequest.Offers = new EnumTypes.OfferType[] {
+ var productsRequest = new ProductsRequest
+ {
+ Ids = new[] { "1004004012288125", "1004004012257956" },
+ IncludeAttributes = true,
+ Offers = new[] {
EnumTypes.OfferType.ALL
+ }
};
- ProductList productList = client.GetProducts(productsRequest);
+ var productList = await _client.GetProductsAsync(productsRequest);
Assert.IsNotNull(productList.Products);
Assert.IsTrue(productList.Products.Count == 2);
}
diff --git a/OpenAPI Client Unit Tests/Catalog/RelatedProductsTest.cs b/OpenAPI Client Unit Tests/Catalog/RelatedProductsTest.cs
index 94bad13..0b50045 100644
--- a/OpenAPI Client Unit Tests/Catalog/RelatedProductsTest.cs
+++ b/OpenAPI Client Unit Tests/Catalog/RelatedProductsTest.cs
@@ -1,41 +1,48 @@
-using Bol.OpenAPI.Client;
-using Bol.OpenAPI.Request.Catalog;
-using Bol.OpenAPI.Request.Common;
+using System.Threading.Tasks;
+using Bol.OpenAPI.Client.Request.Catalog;
+using Bol.OpenAPI.Client.Request.Common;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace OpenAPI_Client_Unit_Tests.Catalog
{
[TestClass]
public class RelatedProductsTest
+ : ConfiguredTestBase
{
- private OpenApiClient client = new OpenApiClient(Constants.API_KEY);
-
[TestMethod]
- public void TestGetProductFamilies()
+ public async Task TestGetProductFamilies()
{
- RelatedProductsRequest relatedProductsRequest = new RelatedProductsRequest();
- relatedProductsRequest.Id = "9200000009187246";
- relatedProductsRequest.DataSet = new EnumTypes.DataSetType[] {
+ var relatedProductsRequest = new RelatedProductsRequest
+ {
+ Id = "9000000012049645",
+ DataSet = new[] {
EnumTypes.DataSetType.PRODUCT_FAMILY
+ }
};
- RelatedProducts relatedProducts = client.GetRelatedProducts(relatedProductsRequest);
+ var relatedProducts = await _client.GetRelatedProductsAsync(relatedProductsRequest);
Assert.IsNotNull(relatedProducts.ProductFamilies);
Assert.IsTrue(relatedProducts.ProductFamilies.Count > 0);
}
+ ///
+ /// This method returns API error
+ ///
[TestMethod]
- public void TestGetAccessories()
+ public async Task TestGetAccessories()
{
- RelatedProductsRequest relatedProductsRequest = new RelatedProductsRequest();
- relatedProductsRequest.Id = "9200000010642550";
- relatedProductsRequest.DataSet = new EnumTypes.DataSetType[] {
- EnumTypes.DataSetType.ACCESSORIES,
- };
+ //var relatedProductsRequest = new RelatedProductsRequest
+ //{
+ // Id = "9200000010642550",
+ // DataSet = new EnumTypes.DataSetType[] {
+ // EnumTypes.DataSetType.ACCESSORIES,
+ //}
+ //};
- RelatedProducts relatedProducts = client.GetRelatedProducts(relatedProductsRequest);
- Assert.IsNotNull(relatedProducts.Accessories);
- Assert.IsTrue(relatedProducts.Accessories.Count > 0);
+ //var relatedProducts = client.GetRelatedProducts(relatedProductsRequest);
+ //Assert.IsNotNull(relatedProducts.Accessories);
+ //Assert.IsTrue(relatedProducts.Accessories.Count > 0);
+ await Task.CompletedTask;
}
}
}
diff --git a/OpenAPI Client Unit Tests/Catalog/SearchTest.cs b/OpenAPI Client Unit Tests/Catalog/SearchTest.cs
index 5af8a8c..3b83291 100644
--- a/OpenAPI Client Unit Tests/Catalog/SearchTest.cs
+++ b/OpenAPI Client Unit Tests/Catalog/SearchTest.cs
@@ -1,33 +1,34 @@
-using Bol.OpenAPI.Client;
-using Bol.OpenAPI.Request.Catalog;
-using Bol.OpenAPI.Request.Common;
+using System.Threading.Tasks;
+using Bol.OpenAPI.Client.Request.Catalog;
+using Bol.OpenAPI.Client.Request.Common;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace OpenAPI_Client_Unit_Tests
{
[TestClass]
public class SearchTest
+ : ConfiguredTestBase
{
- private OpenApiClient client = new OpenApiClient(Constants.API_KEY);
-
[TestMethod]
- public void TestSearch()
+ public async Task TestSearch()
{
- SearchResultsRequest searchResultsRequest = new SearchResultsRequest();
- searchResultsRequest.Query = "halo";
- searchResultsRequest.IncludeAttributes = true;
- searchResultsRequest.Offset = 10;
- searchResultsRequest.Limit = 10;
- searchResultsRequest.DataOutputs = new EnumTypes.DataOutputType[] {
+ var searchResultsRequest = new SearchResultsRequest
+ {
+ Query = "halo",
+ IncludeAttributes = true,
+ Offset = 10,
+ Limit = 10,
+ DataOutputs = new[] {
EnumTypes.DataOutputType.PRODUCTS,
EnumTypes.DataOutputType.CATEGORIES,
EnumTypes.DataOutputType.REFINEMENTS
- };
- searchResultsRequest.Offers = new EnumTypes.OfferType[] {
+ },
+ Offers = new[] {
EnumTypes.OfferType.ALL
- };
-
- SearchResults searchResults = client.Search(searchResultsRequest);
+ }
+ };
+
+ var searchResults = await _client.SearchAsync(searchResultsRequest);
Assert.IsTrue(searchResults.TotalResultSize > 0);
Assert.IsNotNull(searchResults.Categories);
Assert.IsTrue(searchResults.Categories.Count > 0);
diff --git a/OpenAPI Client Unit Tests/Catalog/SellerTest.cs b/OpenAPI Client Unit Tests/Catalog/SellerTest.cs
index 18f973f..68a9a46 100644
--- a/OpenAPI Client Unit Tests/Catalog/SellerTest.cs
+++ b/OpenAPI Client Unit Tests/Catalog/SellerTest.cs
@@ -8,19 +8,21 @@ namespace OpenAPI_Client_Unit_Tests.Catalog
[TestClass]
public class SellerTest
{
- private OpenApiClient client = new OpenApiClient(Constants.API_KEY);
+ private readonly OpenApiClient _client = new OpenApiClient(Constants.ApiKey);
[TestMethod]
public void TestGetSellerList()
{
- SellerListRequest sellerListRequest = new SellerListRequest();
- sellerListRequest.Id = "656476";
- sellerListRequest.IncludeAttributes = true;
- sellerListRequest.Offset = 0;
- sellerListRequest.Limit = 10;
- sellerListRequest.Sort = EnumTypes.SortingMethod.DATE_DESC;
+ var sellerListRequest = new SellerListRequest
+ {
+ Id = "1023995",
+ IncludeAttributes = true,
+ Offset = 0,
+ Limit = 10,
+ Sort = EnumTypes.SortingMethod.DATE_DESC
+ };
- SellerList sellerList = client.GetSellerList(sellerListRequest);
+ var sellerList = _client.GetSellerList(sellerListRequest);
Assert.IsNotNull(sellerList.Products);
Assert.IsTrue(sellerList.Products.Count > 0);
}
diff --git a/OpenAPI Client Unit Tests/Checkout/BasketTest.cs b/OpenAPI Client Unit Tests/Checkout/BasketTest.cs
index 08130d1..2d133d0 100644
--- a/OpenAPI Client Unit Tests/Checkout/BasketTest.cs
+++ b/OpenAPI Client Unit Tests/Checkout/BasketTest.cs
@@ -1,77 +1,118 @@
-using Bol.OpenAPI.Client;
+using System.Linq;
+using System.Threading.Tasks;
+using Bol.OpenAPI.Client.Request.Catalog;
+using Bol.OpenAPI.Client.Request.Common;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace OpenAPI_Client_Unit_Tests
{
[TestClass]
public class BasketTest
+ : ConfiguredTestBase
{
- private OpenApiClient client = new OpenApiClient(Constants.API_KEY);
-
[TestMethod]
- public void TestGetBasket()
+ public async Task TestGetBasket()
{
- Session session = client.GetSession();
+ var session = await _client.GetSessionAsync();
Assert.IsNotNull(session.SessionId);
- Basket basket = client.GetBasket(session.SessionId);
+ var basket = await _client.GetBasketAsync(session.SessionId);
Assert.IsTrue(basket.BasketItems.Count == 0);
}
[TestMethod]
- public void TestAddItemToBasket()
+ public async Task TestAddItemToBasket()
{
- Session session = client.GetSession();
+ var session = await _client.GetSessionAsync();
Assert.IsNotNull(session.SessionId);
- Basket basket = client.GetBasket(session.SessionId);
+ var basket = await _client.GetBasketAsync(session.SessionId);
Assert.IsTrue(basket.BasketItems.Count == 0);
- client.AddItemToBasket(session.SessionId, "1004004012288125", 1, "192.168.0.1");
+ var productOffersRequest = new ProductOffersRequest
+ {
+ Id = "1004004012288125",
+ Offers = new[] {
+ EnumTypes.OfferType.ALL
+ }
+ };
+
+ var productOffers = await _client.GetProductOffersAsync(productOffersRequest);
+ Assert.IsNotNull(productOffers.OfferData);
+ Assert.IsNotNull(productOffers.OfferData.Offers);
+ Assert.IsTrue(productOffers.OfferData.Offers.Count > 0);
- basket = client.GetBasket(session.SessionId);
+ await _client.AddItemToBasketAsync(session.SessionId, productOffers.OfferData.Offers.First().Id, 1, "192.168.0.1");
+
+ basket = await _client.GetBasketAsync(session.SessionId);
Assert.IsTrue(basket.BasketItems.Count == 1);
}
[TestMethod]
- public void TestChangeItemQuantityInBasket()
+ public async Task TestChangeItemQuantityInBasket()
{
- Session session = client.GetSession();
+ var session = await _client.GetSessionAsync();
Assert.IsNotNull(session.SessionId);
- Basket basket = client.GetBasket(session.SessionId);
+ var basket = await _client.GetBasketAsync(session.SessionId);
Assert.IsTrue(basket.BasketItems.Count == 0);
- client.AddItemToBasket(session.SessionId, "1004004012288125", 1, "192.168.0.1");
+ var productOffersRequest = new ProductOffersRequest
+ {
+ Id = "1004004012288125",
+ Offers = new[] {
+ EnumTypes.OfferType.ALL
+ }
+ };
+
+ var productOffers = await _client.GetProductOffersAsync(productOffersRequest);
+ Assert.IsNotNull(productOffers.OfferData);
+ Assert.IsNotNull(productOffers.OfferData.Offers);
+ Assert.IsTrue(productOffers.OfferData.Offers.Count > 0);
- basket = client.GetBasket(session.SessionId);
+ await _client.AddItemToBasketAsync(session.SessionId, productOffers.OfferData.Offers.First().Id, 1, "192.168.0.1");
+
+ basket = await _client.GetBasketAsync(session.SessionId);
Assert.IsTrue(basket.BasketItems.Count == 1);
Assert.IsTrue(basket.BasketItems[0].Quantity == 1);
- client.ChangeItemQuantityInBasket(session.SessionId, basket.BasketItems[0].Id, 2);
+ await _client.ChangeItemQuantityInBasketAsync(session.SessionId, basket.BasketItems[0].Id, 2);
- basket = client.GetBasket(session.SessionId);
+ basket = await _client.GetBasketAsync(session.SessionId);
Assert.IsTrue(basket.BasketItems.Count == 1);
Assert.IsTrue(basket.BasketItems[0].Quantity == 2);
}
[TestMethod]
- public void TestRemoveItemFromBasket()
+ public async Task TestRemoveItemFromBasket()
{
- Session session = client.GetSession();
+ var session = await _client.GetSessionAsync();
Assert.IsNotNull(session.SessionId);
- Basket basket = client.GetBasket(session.SessionId);
+ var basket = await _client.GetBasketAsync(session.SessionId);
Assert.IsTrue(basket.BasketItems.Count == 0);
- client.AddItemToBasket(session.SessionId, "1004004012288125", 1, "192.168.0.1");
+ var productOffersRequest = new ProductOffersRequest
+ {
+ Id = "1004004012288125",
+ Offers = new[] {
+ EnumTypes.OfferType.ALL
+ }
+ };
+
+ var productOffers = await _client.GetProductOffersAsync(productOffersRequest);
+ Assert.IsNotNull(productOffers.OfferData);
+ Assert.IsNotNull(productOffers.OfferData.Offers);
+ Assert.IsTrue(productOffers.OfferData.Offers.Count > 0);
+
+ await _client.AddItemToBasketAsync(session.SessionId, productOffers.OfferData.Offers.First().Id, 1, "192.168.0.1");
- basket = client.GetBasket(session.SessionId);
+ basket = await _client.GetBasketAsync(session.SessionId);
Assert.IsTrue(basket.BasketItems.Count == 1);
- client.RemoveItemFromBasket(session.SessionId, basket.BasketItems[0].Id);
+ await _client.RemoveItemFromBasketAsync(session.SessionId, basket.BasketItems[0].Id);
- basket = client.GetBasket(session.SessionId);
+ basket = await _client.GetBasketAsync(session.SessionId);
Assert.IsTrue(basket.BasketItems.Count == 0);
}
}
diff --git a/OpenAPI Client Unit Tests/ConfiguredTestBase.cs b/OpenAPI Client Unit Tests/ConfiguredTestBase.cs
new file mode 100644
index 0000000..9bec719
--- /dev/null
+++ b/OpenAPI Client Unit Tests/ConfiguredTestBase.cs
@@ -0,0 +1,21 @@
+using Bol.OpenAPI.Client;
+using Microsoft.Extensions.Configuration;
+
+namespace OpenAPI_Client_Unit_Tests
+{
+ public class ConfiguredTestBase
+ {
+ protected readonly OpenApiClient _client;
+
+ public ConfiguredTestBase()
+ {
+ // the type specified here is just so the secrets library can
+ // find the UserSecretId we added in the csproj file
+ var builder = new ConfigurationBuilder()
+ .AddUserSecrets();
+
+ var configuration = builder.Build();
+ _client = new OpenApiClient(configuration["ApiKey"]);
+ }
+ }
+}
\ No newline at end of file
diff --git a/OpenAPI Client Unit Tests/Constants.cs b/OpenAPI Client Unit Tests/Constants.cs
index d0e1f5f..5142f2e 100644
--- a/OpenAPI Client Unit Tests/Constants.cs
+++ b/OpenAPI Client Unit Tests/Constants.cs
@@ -1,8 +1,7 @@
-
-namespace OpenAPI_Client_Unit_Tests
+namespace OpenAPI_Client_Unit_Tests
{
- class Constants
+ internal static class Constants
{
- public const string API_KEY = "";
+ public const string ApiKey = "";
}
}
diff --git a/OpenAPI Client Unit Tests/OpenAPI Client Unit Tests.csproj b/OpenAPI Client Unit Tests/OpenAPI Client Unit Tests.csproj
index 92e9055..5fa86fc 100644
--- a/OpenAPI Client Unit Tests/OpenAPI Client Unit Tests.csproj
+++ b/OpenAPI Client Unit Tests/OpenAPI Client Unit Tests.csproj
@@ -1,109 +1,28 @@
-
-
+
+
- Debug
- AnyCPU
- {A3D23BDF-4BCB-4F30-9C53-0F5DED290C5C}
- Library
- Properties
- OpenAPI_Client_Unit_Tests
- OpenAPI Client Unit Tests
- v4.5
- 512
- {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
- 10.0
- $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
- $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages
- False
- UnitTest
-
-
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE
- prompt
- 4
-
-
- pdbonly
- true
- bin\Release\
- TRACE
- prompt
- 4
+ netcoreapp3.0
+ a48bae6e-f2bc-4ce3-88ec-6877c4f19ca0
+
-
- ..\packages\Newtonsoft.Json.5.0.6\lib\net45\Newtonsoft.Json.dll
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
-
+
+
-
- {c0018817-5853-4fbf-be44-cbecb2589300}
- OpenAPI Client
-
+
-
-
-
-
- False
-
-
- False
-
-
- False
-
-
- False
-
-
-
-
-
-
-
+
\ No newline at end of file
diff --git a/OpenAPI Client Unit Tests/Properties/AssemblyInfo.cs b/OpenAPI Client Unit Tests/Properties/AssemblyInfo.cs
deleted file mode 100644
index c68497e..0000000
--- a/OpenAPI Client Unit Tests/Properties/AssemblyInfo.cs
+++ /dev/null
@@ -1,36 +0,0 @@
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-// General Information about an assembly is controlled through the following
-// set of attributes. Change these attribute values to modify the information
-// associated with an assembly.
-[assembly: AssemblyTitle("OpenAPI Client Unit Tests")]
-[assembly: AssemblyDescription("")]
-[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("Bol.com")]
-[assembly: AssemblyProduct("OpenAPI Client Unit Tests")]
-[assembly: AssemblyCopyright("Copyright © Bol.com 2013")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-
-// Setting ComVisible to false makes the types in this assembly not visible
-// to COM components. If you need to access a type in this assembly from
-// COM, set the ComVisible attribute to true on that type.
-[assembly: ComVisible(false)]
-
-// The following GUID is for the ID of the typelib if this project is exposed to COM
-[assembly: Guid("f9ed5315-ee19-4ae6-8d2a-2ce1a63168d2")]
-
-// Version information for an assembly consists of the following four values:
-//
-// Major Version
-// Minor Version
-// Build Number
-// Revision
-//
-// 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("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/OpenAPI Client Unit Tests/Utils/PingTest.cs b/OpenAPI Client Unit Tests/Utils/PingTest.cs
index ca718e0..c52cc33 100644
--- a/OpenAPI Client Unit Tests/Utils/PingTest.cs
+++ b/OpenAPI Client Unit Tests/Utils/PingTest.cs
@@ -1,17 +1,16 @@
-using Bol.OpenAPI.Client;
+using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace OpenAPI_Client_Unit_Tests
{
[TestClass]
public class PingTest
+ : ConfiguredTestBase
{
- private OpenApiClient client = new OpenApiClient(Constants.API_KEY);
-
[TestMethod]
- public void TestPing()
+ public async Task TestPing()
{
- Pong pong = client.Ping();
+ var pong = await _client.PingAsync();
Assert.IsNotNull(pong.Message);
}
}
diff --git a/OpenAPI Client Unit Tests/packages.config b/OpenAPI Client Unit Tests/packages.config
deleted file mode 100644
index a3b7dcc..0000000
--- a/OpenAPI Client Unit Tests/packages.config
+++ /dev/null
@@ -1,4 +0,0 @@
-
-
-
-
\ No newline at end of file
diff --git a/OpenAPI Client.sln b/OpenAPI Client.sln
index df810e9..4edafa6 100644
--- a/OpenAPI Client.sln
+++ b/OpenAPI Client.sln
@@ -1,9 +1,19 @@
Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio Express 2012 for Windows Desktop
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenAPI Client", "OpenAPI Client\OpenAPI Client.csproj", "{C0018817-5853-4FBF-BE44-CBECB2589300}"
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.29519.161
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenAPI Client", "OpenAPI Client\OpenAPI Client.csproj", "{C0018817-5853-4FBF-BE44-CBECB2589300}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenAPI Client Unit Tests", "OpenAPI Client Unit Tests\OpenAPI Client Unit Tests.csproj", "{A3D23BDF-4BCB-4F30-9C53-0F5DED290C5C}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenAPI Client Unit Tests", "OpenAPI Client Unit Tests\OpenAPI Client Unit Tests.csproj", "{2D251878-ABDC-401F-AFF2-A3163EE7BCF8}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{E252C587-24FD-408D-8A5B-508EFCAC310F}"
+ ProjectSection(SolutionItems) = preProject
+ .gitignore = .gitignore
+ Directory.Build.props = Directory.Build.props
+ OpenAPI Client.sln.DotSettings = OpenAPI Client.sln.DotSettings
+ README.md = README.md
+ EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -15,12 +25,15 @@ Global
{C0018817-5853-4FBF-BE44-CBECB2589300}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C0018817-5853-4FBF-BE44-CBECB2589300}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C0018817-5853-4FBF-BE44-CBECB2589300}.Release|Any CPU.Build.0 = Release|Any CPU
- {A3D23BDF-4BCB-4F30-9C53-0F5DED290C5C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {A3D23BDF-4BCB-4F30-9C53-0F5DED290C5C}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {A3D23BDF-4BCB-4F30-9C53-0F5DED290C5C}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {A3D23BDF-4BCB-4F30-9C53-0F5DED290C5C}.Release|Any CPU.Build.0 = Release|Any CPU
+ {2D251878-ABDC-401F-AFF2-A3163EE7BCF8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {2D251878-ABDC-401F-AFF2-A3163EE7BCF8}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {2D251878-ABDC-401F-AFF2-A3163EE7BCF8}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {2D251878-ABDC-401F-AFF2-A3163EE7BCF8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {032E093A-207E-4BB0-B9DD-7026C8D716C8}
+ EndGlobalSection
EndGlobal
diff --git a/OpenAPI Client.sln.DotSettings b/OpenAPI Client.sln.DotSettings
new file mode 100644
index 0000000..5357ff2
--- /dev/null
+++ b/OpenAPI Client.sln.DotSettings
@@ -0,0 +1,15 @@
+
+ <Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" />
+ <Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" />
+ True
+ True
+ True
+ True
+ True
+ True
+ True
+ True
+ True
+ True
+ True
+
\ No newline at end of file
diff --git a/OpenAPI Client.v11.suo b/OpenAPI Client.v11.suo
deleted file mode 100644
index 64004c8..0000000
Binary files a/OpenAPI Client.v11.suo and /dev/null differ
diff --git a/OpenAPI Client.v12.suo b/OpenAPI Client.v12.suo
deleted file mode 100644
index 5478207..0000000
Binary files a/OpenAPI Client.v12.suo and /dev/null differ
diff --git a/OpenAPI Client/BasicApiException.cs b/OpenAPI Client/BasicApiException.cs
new file mode 100644
index 0000000..e55b142
--- /dev/null
+++ b/OpenAPI Client/BasicApiException.cs
@@ -0,0 +1,26 @@
+namespace Bol.OpenAPI.Client
+{
+ public class BasicApiException
+ : System.ApplicationException
+ {
+ public string Status { get; set; }
+
+ public BasicApiException() { }
+
+ public BasicApiException(string status, string message)
+ : base(message)
+ {
+ Status = status;
+ }
+
+ public BasicApiException(string message)
+ : base(message)
+ {
+ }
+
+ public BasicApiException(string message, System.Exception innerException)
+ : base(message, innerException)
+ {
+ }
+ }
+}
diff --git a/OpenAPI Client/Builder/AccountsRequestBuilder.cs b/OpenAPI Client/Builder/AccountsRequestBuilder.cs
index 65c1ee5..f532d8c 100644
--- a/OpenAPI Client/Builder/AccountsRequestBuilder.cs
+++ b/OpenAPI Client/Builder/AccountsRequestBuilder.cs
@@ -1,17 +1,20 @@
-using System.Collections.Specialized;
-using System.Net;
-
-namespace Bol.OpenAPI.Util
+namespace Bol.OpenAPI.Client.Builder
{
- class AccountsRequestBuilder
+ using System.Collections.Specialized;
+ using System.Net;
+ using Bol.OpenAPI.Client.Util;
+
+ internal static class AccountsRequestBuilder
{
public static HttpWebRequest ConstructSessionRequest(string apiKey)
{
- NameValueCollection queryParams = new NameValueCollection();
- queryParams.Add("apikey", apiKey);
- string queryString = HttpUtils.ToQueryString(queryParams);
+ var queryParams = new NameValueCollection
+ {
+ { "apikey", apiKey }
+ };
+ var queryString = HttpUtils.ToQueryString(queryParams);
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Constants.URL_PREFIX + "/accounts/v4/sessions/" + queryString);
+ var request = (HttpWebRequest)WebRequest.Create(Constants.URL_PREFIX + "/accounts/v4/sessions/" + queryString);
request.Method = "GET";
request.Accept = "application/json";
@@ -20,8 +23,10 @@ public static HttpWebRequest ConstructSessionRequest(string apiKey)
public static HttpWebRequest ConstructAuthTokenRequest(string apiKey, string successUrl, string errorUrl)
{
- NameValueCollection queryParams = new NameValueCollection();
- queryParams.Add("apikey", apiKey);
+ var queryParams = new NameValueCollection
+ {
+ { "apikey", apiKey }
+ };
if (successUrl != null)
{
@@ -32,9 +37,9 @@ public static HttpWebRequest ConstructAuthTokenRequest(string apiKey, string suc
queryParams.Add("errorUrl", errorUrl);
}
- string queryString = HttpUtils.ToQueryString(queryParams);
+ var queryString = HttpUtils.ToQueryString(queryParams);
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Constants.URL_PREFIX + "/accounts/v4/authtokens/" + queryString);
+ var request = (HttpWebRequest)WebRequest.Create(Constants.URL_PREFIX + "/accounts/v4/authtokens/" + queryString);
request.Method = "POST";
request.Accept = "application/json";
@@ -43,80 +48,90 @@ public static HttpWebRequest ConstructAuthTokenRequest(string apiKey, string suc
public static HttpWebRequest ConstructLoginRequest(string apiKey, string privateToken, string sessionId)
{
- NameValueCollection queryParams = new NameValueCollection();
- queryParams.Add("apikey", apiKey);
+ var queryParams = new NameValueCollection
+ {
+ { "apikey", apiKey }
+ };
if (privateToken != null)
{
queryParams.Add("privatetoken", privateToken);
}
- string queryString = HttpUtils.ToQueryString(queryParams);
+ var queryString = HttpUtils.ToQueryString(queryParams);
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Constants.URL_PREFIX + "/accounts/v4/login/" + queryString);
+ var request = (HttpWebRequest)WebRequest.Create(Constants.URL_PREFIX + "/accounts/v4/login/" + queryString);
request.Method = "POST";
request.Accept = "application/json";
- HttpUtils.AddSessionheader(request, sessionId);
+ HttpUtils.AddSessionHeader(request, sessionId);
return request;
}
public static HttpWebRequest ConstructLogoutRequest(string apiKey, string sessionId)
{
- NameValueCollection queryParams = new NameValueCollection();
- queryParams.Add("apikey", apiKey);
+ var queryParams = new NameValueCollection
+ {
+ { "apikey", apiKey }
+ };
- string queryString = HttpUtils.ToQueryString(queryParams);
+ var queryString = HttpUtils.ToQueryString(queryParams);
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Constants.URL_PREFIX + "/accounts/v4/logout/" + queryString);
+ var request = (HttpWebRequest)WebRequest.Create(Constants.URL_PREFIX + "/accounts/v4/logout/" + queryString);
request.Method = "POST";
request.Accept = "application/json";
- HttpUtils.AddSessionheader(request, sessionId);
+ HttpUtils.AddSessionHeader(request, sessionId);
return request;
}
public static HttpWebRequest ConstructWishListRequest(string apiKey, string sessionId)
{
- NameValueCollection queryParams = new NameValueCollection();
- queryParams.Add("apikey", apiKey);
+ var queryParams = new NameValueCollection
+ {
+ { "apikey", apiKey }
+ };
- string queryString = HttpUtils.ToQueryString(queryParams);
+ var queryString = HttpUtils.ToQueryString(queryParams);
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Constants.URL_PREFIX + "/accounts/v4/wishlists/" + queryString);
+ var request = (HttpWebRequest)WebRequest.Create(Constants.URL_PREFIX + "/accounts/v4/wishlists/" + queryString);
request.Method = "GET";
request.Accept = "application/json";
- HttpUtils.AddSessionheader(request, sessionId);
+ HttpUtils.AddSessionHeader(request, sessionId);
return request;
}
public static HttpWebRequest ConstructWishListAddItemRequest(string apiKey, string sessionId, string productId)
{
- NameValueCollection queryParams = new NameValueCollection();
- queryParams.Add("apikey", apiKey);
+ var queryParams = new NameValueCollection
+ {
+ { "apikey", apiKey }
+ };
- string queryString = HttpUtils.ToQueryString(queryParams);
+ var queryString = HttpUtils.ToQueryString(queryParams);
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Constants.URL_PREFIX + "/accounts/v4/wishlists/" + productId + "/" + queryString);
+ var request = (HttpWebRequest)WebRequest.Create(Constants.URL_PREFIX + "/accounts/v4/wishlists/" + productId + "/" + queryString);
request.Method = "POST";
request.Accept = "application/json";
- HttpUtils.AddSessionheader(request, sessionId);
+ HttpUtils.AddSessionHeader(request, sessionId);
return request;
}
public static HttpWebRequest ConstructWishListRemoveItemRequest(string apiKey, string sessionId, string wishListItemId)
{
- NameValueCollection queryParams = new NameValueCollection();
- queryParams.Add("apikey", apiKey);
+ var queryParams = new NameValueCollection
+ {
+ { "apikey", apiKey }
+ };
- string queryString = HttpUtils.ToQueryString(queryParams);
+ var queryString = HttpUtils.ToQueryString(queryParams);
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Constants.URL_PREFIX + "/accounts/v4/wishlists/" + wishListItemId + "/" + queryString);
+ var request = (HttpWebRequest)WebRequest.Create(Constants.URL_PREFIX + "/accounts/v4/wishlists/" + wishListItemId + "/" + queryString);
request.Method = "DELETE";
request.Accept = "application/json";
- HttpUtils.AddSessionheader(request, sessionId);
+ HttpUtils.AddSessionHeader(request, sessionId);
return request;
}
diff --git a/OpenAPI Client/Builder/CatalogRequestBuilder.cs b/OpenAPI Client/Builder/CatalogRequestBuilder.cs
index 6bdd43e..2eb07c0 100644
--- a/OpenAPI Client/Builder/CatalogRequestBuilder.cs
+++ b/OpenAPI Client/Builder/CatalogRequestBuilder.cs
@@ -1,15 +1,18 @@
-using Bol.OpenAPI.Request.Catalog;
-using System.Collections.Specialized;
-using System.Net;
-
-namespace Bol.OpenAPI.Util
+namespace Bol.OpenAPI.Client.Builder
{
- class CatalogRequestBuilder
+ using System.Collections.Specialized;
+ using System.Net;
+ using Bol.OpenAPI.Client.Request.Catalog;
+ using Bol.OpenAPI.Client.Util;
+
+ internal static class CatalogRequestBuilder
{
public static HttpWebRequest ConstructSearchRequest(string apiKey, SearchResultsRequest searchResultsRequest)
{
- NameValueCollection queryParams = new NameValueCollection();
- queryParams.Add("apikey", apiKey);
+ var queryParams = new NameValueCollection
+ {
+ { "apikey", apiKey }
+ };
if (searchResultsRequest.Query != null)
{
@@ -21,7 +24,7 @@ public static HttpWebRequest ConstructSearchRequest(string apiKey, SearchResults
}
if (searchResultsRequest.CategoryId != null || searchResultsRequest.RefinementIds != null)
{
- string ids = FormatterUtils.CombineCategoryAndRefinementIds(searchResultsRequest.CategoryId, searchResultsRequest.RefinementIds);
+ var ids = FormatterUtils.CombineCategoryAndRefinementIds(searchResultsRequest.CategoryId, searchResultsRequest.RefinementIds);
queryParams.Add("ids", ids);
}
if (searchResultsRequest.ListId != null)
@@ -57,9 +60,9 @@ public static HttpWebRequest ConstructSearchRequest(string apiKey, SearchResults
queryParams.Add("limit", searchResultsRequest.Limit.ToString().ToLower());
}
- string queryString = HttpUtils.ToQueryString(queryParams);
+ var queryString = HttpUtils.ToQueryString(queryParams);
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Constants.URL_PREFIX + "/catalog/v4/search/" + queryString);
+ var request = (HttpWebRequest)WebRequest.Create(Constants.URL_PREFIX + "/catalog/v4/search/" + queryString);
request.Method = "GET";
request.Accept = "application/json";
@@ -68,8 +71,10 @@ public static HttpWebRequest ConstructSearchRequest(string apiKey, SearchResults
public static HttpWebRequest ConstructListRequest(string apiKey, ListResultsRequest listResultsRequest)
{
- NameValueCollection queryParams = new NameValueCollection();
- queryParams.Add("apikey", apiKey);
+ var queryParams = new NameValueCollection
+ {
+ { "apikey", apiKey }
+ };
if (listResultsRequest.Type != null)
{
@@ -77,7 +82,7 @@ public static HttpWebRequest ConstructListRequest(string apiKey, ListResultsRequ
}
if (listResultsRequest.CategoryId != null || listResultsRequest.RefinementIds != null)
{
- string ids = FormatterUtils.CombineCategoryAndRefinementIds(listResultsRequest.CategoryId, listResultsRequest.RefinementIds);
+ var ids = FormatterUtils.CombineCategoryAndRefinementIds(listResultsRequest.CategoryId, listResultsRequest.RefinementIds);
queryParams.Add("ids", ids);
}
if (listResultsRequest.ListId != null)
@@ -109,9 +114,9 @@ public static HttpWebRequest ConstructListRequest(string apiKey, ListResultsRequ
queryParams.Add("limit", listResultsRequest.Limit.ToString().ToLower());
}
- string queryString = HttpUtils.ToQueryString(queryParams);
+ var queryString = HttpUtils.ToQueryString(queryParams);
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Constants.URL_PREFIX + "/catalog/v4/lists/" + queryString);
+ var request = (HttpWebRequest)WebRequest.Create(Constants.URL_PREFIX + "/catalog/v4/lists/" + queryString);
request.Method = "GET";
request.Accept = "application/json";
@@ -120,8 +125,10 @@ public static HttpWebRequest ConstructListRequest(string apiKey, ListResultsRequ
public static HttpWebRequest ConstructProductsRequest(string apiKey, ProductsRequest productsRequest)
{
- NameValueCollection queryParams = new NameValueCollection();
- queryParams.Add("apikey", apiKey);
+ var queryParams = new NameValueCollection
+ {
+ { "apikey", apiKey }
+ };
if (productsRequest.IncludeAttributes != null)
{
@@ -132,50 +139,60 @@ public static HttpWebRequest ConstructProductsRequest(string apiKey, ProductsReq
queryParams.Add("offers", FormatterUtils.FormatOffer(productsRequest.Offers));
}
- string queryString = HttpUtils.ToQueryString(queryParams);
+ var queryString = HttpUtils.ToQueryString(queryParams);
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Constants.URL_PREFIX + "/catalog/v4/products/" + FormatterUtils.FormatIds(productsRequest.Ids) + "/" + queryString);
+ var request = (HttpWebRequest)WebRequest.Create(Constants.URL_PREFIX + "/catalog/v4/products/" + FormatterUtils.FormatIds(productsRequest.Ids) + "/" + queryString);
request.Method = "GET";
request.Accept = "application/json";
return request;
}
- public static HttpWebRequest ConstructSellerListRequest(string apiKey, SellerListRequest sellerListRequest)
- {
- NameValueCollection queryParams = new NameValueCollection();
- queryParams.Add("apikey", apiKey);
-
- if (sellerListRequest.IncludeAttributes != null)
- {
- queryParams.Add("includeattributes", sellerListRequest.IncludeAttributes.ToString().ToLower());
- }
- if (sellerListRequest.Sort != null)
- {
- queryParams.Add("sort", EnumUtils.StringValueOf(sellerListRequest.Sort));
- }
- if (sellerListRequest.Offset != null)
- {
- queryParams.Add("offset", sellerListRequest.Offset.ToString().ToLower());
- }
- if (sellerListRequest.Limit != null)
- {
- queryParams.Add("limit", sellerListRequest.Limit.ToString().ToLower());
- }
-
- string queryString = HttpUtils.ToQueryString(queryParams);
-
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Constants.URL_PREFIX + "/catalog/v4/sellerlists/" + sellerListRequest.Id + "/" + queryString);
- request.Method = "GET";
- request.Accept = "application/json";
-
- return request;
- }
+ /////
+ ///// Constructs the seller list request.
+ /////
+ ///// The API key.
+ ///// The seller list request.
+ ///// A typed
+ //public static HttpWebRequest ConstructSellerListRequest(string apiKey, SellerListRequest sellerListRequest)
+ //{
+ // var queryParams = new NameValueCollection
+ // {
+ // { "apikey", apiKey }
+ // };
+
+ // if (sellerListRequest.IncludeAttributes != null)
+ // {
+ // queryParams.Add("includeattributes", sellerListRequest.IncludeAttributes.ToString().ToLower());
+ // }
+ // if (sellerListRequest.Sort != null)
+ // {
+ // queryParams.Add("sort", EnumUtils.StringValueOf(sellerListRequest.Sort));
+ // }
+ // if (sellerListRequest.Offset != null)
+ // {
+ // queryParams.Add("offset", sellerListRequest.Offset.ToString().ToLower());
+ // }
+ // if (sellerListRequest.Limit != null)
+ // {
+ // queryParams.Add("limit", sellerListRequest.Limit.ToString().ToLower());
+ // }
+
+ // var queryString = HttpUtils.ToQueryString(queryParams);
+
+ // var request = (HttpWebRequest)WebRequest.Create(Constants.URL_PREFIX + "/catalog/v4/sellerlists/" + sellerListRequest.Id + "/" + queryString);
+ // request.Method = "GET";
+ // request.Accept = "application/json";
+
+ // return request;
+ //}
public static HttpWebRequest ConstructProductRecommendationsRequest(string apiKey, ProductRecommendationsRequest productRecommendationsRequest)
{
- NameValueCollection queryParams = new NameValueCollection();
- queryParams.Add("apikey", apiKey);
+ var queryParams = new NameValueCollection
+ {
+ { "apikey", apiKey }
+ };
if (productRecommendationsRequest.IncludeAttributes != null)
{
@@ -190,9 +207,9 @@ public static HttpWebRequest ConstructProductRecommendationsRequest(string apiKe
queryParams.Add("limit", productRecommendationsRequest.Limit.ToString().ToLower());
}
- string queryString = HttpUtils.ToQueryString(queryParams);
+ var queryString = HttpUtils.ToQueryString(queryParams);
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Constants.URL_PREFIX + "/catalog/v4/recommendations/" + productRecommendationsRequest.Id + "/" + queryString);
+ var request = (HttpWebRequest)WebRequest.Create(Constants.URL_PREFIX + "/catalog/v4/recommendations/" + productRecommendationsRequest.Id + "/" + queryString);
request.Method = "GET";
request.Accept = "application/json";
@@ -201,17 +218,19 @@ public static HttpWebRequest ConstructProductRecommendationsRequest(string apiKe
public static HttpWebRequest ConstructProductOffersRequest(string apiKey, ProductOffersRequest productOffersRequest)
{
- NameValueCollection queryParams = new NameValueCollection();
- queryParams.Add("apikey", apiKey);
+ var queryParams = new NameValueCollection
+ {
+ { "apikey", apiKey }
+ };
if (productOffersRequest.Offers != null)
{
queryParams.Add("offers", FormatterUtils.FormatOffer(productOffersRequest.Offers));
- }
+ }
- string queryString = HttpUtils.ToQueryString(queryParams);
+ var queryString = HttpUtils.ToQueryString(queryParams);
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Constants.URL_PREFIX + "/catalog/v4/offers/" + productOffersRequest.Id + "/" + queryString);
+ var request = (HttpWebRequest)WebRequest.Create(Constants.URL_PREFIX + "/catalog/v4/offers/" + productOffersRequest.Id + "/" + queryString);
request.Method = "GET";
request.Accept = "application/json";
@@ -220,17 +239,19 @@ public static HttpWebRequest ConstructProductOffersRequest(string apiKey, Produc
public static HttpWebRequest ConstructRelatedProductsRequest(string apiKey, RelatedProductsRequest relatedProductsRequest)
{
- NameValueCollection queryParams = new NameValueCollection();
- queryParams.Add("apikey", apiKey);
+ var queryParams = new NameValueCollection
+ {
+ { "apikey", apiKey }
+ };
if (relatedProductsRequest.DataSet != null)
{
queryParams.Add("dataset", FormatterUtils.FormatDataSet(relatedProductsRequest.DataSet));
}
- string queryString = HttpUtils.ToQueryString(queryParams);
+ var queryString = HttpUtils.ToQueryString(queryParams);
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Constants.URL_PREFIX + "/catalog/v4/relatedproducts/" + relatedProductsRequest.Id + "/" + queryString);
+ var request = (HttpWebRequest)WebRequest.Create(Constants.URL_PREFIX + "/catalog/v4/relatedproducts/" + relatedProductsRequest.Id + "/" + queryString);
request.Method = "GET";
request.Accept = "application/json";
diff --git a/OpenAPI Client/Builder/CheckoutRequestBuilder.cs b/OpenAPI Client/Builder/CheckoutRequestBuilder.cs
index 24d41a0..bc52c39 100644
--- a/OpenAPI Client/Builder/CheckoutRequestBuilder.cs
+++ b/OpenAPI Client/Builder/CheckoutRequestBuilder.cs
@@ -1,66 +1,75 @@
-using System.Collections.Specialized;
-using System.Net;
-
-namespace Bol.OpenAPI.Util
+namespace Bol.OpenAPI.Client.Builder
{
- class CheckoutRequestBuilder
+ using System.Collections.Specialized;
+ using System.Net;
+ using Bol.OpenAPI.Client.Util;
+
+ internal static class CheckoutRequestBuilder
{
public static HttpWebRequest ConstructBasketRequest(string apiKey, string sessionId)
{
- NameValueCollection queryParams = new NameValueCollection();
- queryParams.Add("apikey", apiKey);
+ var queryParams = new NameValueCollection
+ {
+ { "apikey", apiKey }
+ };
- string queryString = HttpUtils.ToQueryString(queryParams);
+ var queryString = HttpUtils.ToQueryString(queryParams);
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Constants.URL_PREFIX + "/checkout/v4/baskets/" + queryString);
+ var request = (HttpWebRequest)WebRequest.Create(Constants.URL_PREFIX + "/checkout/v4/baskets/" + queryString);
request.Method = "GET";
request.Accept = "application/json";
- HttpUtils.AddSessionheader(request, sessionId);
+ HttpUtils.AddSessionHeader(request, sessionId);
return request;
}
public static HttpWebRequest ConstructBasketAddItemRequest(string apiKey, string sessionId, string offerId, int quantity, string ipAddress)
{
- NameValueCollection queryParams = new NameValueCollection();
- queryParams.Add("apikey", apiKey);
+ var queryParams = new NameValueCollection
+ {
+ { "apikey", apiKey }
+ };
- string queryString = HttpUtils.ToQueryString(queryParams);
+ var queryString = HttpUtils.ToQueryString(queryParams);
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Constants.URL_PREFIX + "/checkout/v4/baskets/" + offerId + "/" + quantity + "/" + ipAddress + "/" + queryString);
+ var request = (HttpWebRequest)WebRequest.Create(Constants.URL_PREFIX + "/checkout/v4/baskets/" + offerId + "/" + quantity + "/" + ipAddress + "/" + queryString);
request.Method = "POST";
request.Accept = "application/json";
- HttpUtils.AddSessionheader(request, sessionId);
+ HttpUtils.AddSessionHeader(request, sessionId);
return request;
}
public static HttpWebRequest ConstructBasketChangeItemQuantityRequest(string apiKey, string sessionId, string basketItemId, int quantity)
{
- NameValueCollection queryParams = new NameValueCollection();
- queryParams.Add("apikey", apiKey);
+ var queryParams = new NameValueCollection
+ {
+ { "apikey", apiKey }
+ };
- string queryString = HttpUtils.ToQueryString(queryParams);
+ var queryString = HttpUtils.ToQueryString(queryParams);
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Constants.URL_PREFIX + "/checkout/v4/baskets/" + basketItemId + "/" + quantity + "/" + queryString);
+ var request = (HttpWebRequest)WebRequest.Create(Constants.URL_PREFIX + "/checkout/v4/baskets/" + basketItemId + "/" + quantity + "/" + queryString);
request.Method = "PUT";
request.Accept = "application/json";
- HttpUtils.AddSessionheader(request, sessionId);
+ HttpUtils.AddSessionHeader(request, sessionId);
return request;
}
public static HttpWebRequest ConstructBasketRemoveItemQuantityRequest(string apiKey, string sessionId, string basketItemId)
{
- NameValueCollection queryParams = new NameValueCollection();
- queryParams.Add("apikey", apiKey);
+ var queryParams = new NameValueCollection
+ {
+ { "apikey", apiKey }
+ };
- string queryString = HttpUtils.ToQueryString(queryParams);
+ var queryString = HttpUtils.ToQueryString(queryParams);
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Constants.URL_PREFIX + "/checkout/v4/baskets/" + basketItemId + "/" + queryString);
+ var request = (HttpWebRequest)WebRequest.Create(Constants.URL_PREFIX + "/checkout/v4/baskets/" + basketItemId + "/" + queryString);
request.Method = "DELETE";
request.Accept = "application/json";
- HttpUtils.AddSessionheader(request, sessionId);
+ HttpUtils.AddSessionHeader(request, sessionId);
return request;
}
diff --git a/OpenAPI Client/Builder/UtilsRequestBuilder.cs b/OpenAPI Client/Builder/UtilsRequestBuilder.cs
index bc34020..46352c9 100644
--- a/OpenAPI Client/Builder/UtilsRequestBuilder.cs
+++ b/OpenAPI Client/Builder/UtilsRequestBuilder.cs
@@ -1,21 +1,24 @@
-using System.Collections.Specialized;
-using System.Net;
-
-namespace Bol.OpenAPI.Util
+namespace Bol.OpenAPI.Client.Builder
{
- class UtilsRequestBuilder
+ using System.Collections.Specialized;
+ using System.Net;
+ using Bol.OpenAPI.Client.Util;
+
+ internal static class UtilsRequestBuilder
{
public static HttpWebRequest ConstructPingRequest(string apiKey)
{
- NameValueCollection queryParams = new NameValueCollection();
- queryParams.Add("apikey", apiKey);
- string queryString = HttpUtils.ToQueryString(queryParams);
+ var queryParams = new NameValueCollection
+ {
+ { "apikey", apiKey }
+ };
+ var queryString = HttpUtils.ToQueryString(queryParams);
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Constants.URL_PREFIX + "/utils/v4/ping/" + queryString);
+ var request = (HttpWebRequest)WebRequest.Create(Constants.URL_PREFIX + "/utils/v4/ping/" + queryString);
request.Method = "GET";
request.Accept = "application/json";
return request;
- }
+ }
}
}
diff --git a/OpenAPI Client/Client/OpenApiClient.cs b/OpenAPI Client/Client/OpenApiClient.cs
deleted file mode 100644
index 26b748a..0000000
--- a/OpenAPI Client/Client/OpenApiClient.cs
+++ /dev/null
@@ -1,259 +0,0 @@
-using Bol.OpenAPI.Utils;
-using System;
-using System.Collections.Generic;
-using System.Collections.Specialized;
-using System.Net;
-using System.Text;
-using System.Web;
-using System.Xml.Serialization;
-
-namespace Bol.OpenAPI.Client
-{
- ///
- /// OpenAPI client.
- ///
- public class OpenApiClient
- {
- private const string URL_PREFIX = "https://openapi.bol.com/openapi/services/rest";
- private string accessKeyId;
- private string secretAccessKey;
-
- ///
- /// Constructs the OpenAPI client.
- ///
- /// The access key id.
- /// The secret access key.
- public OpenApiClient(string accessKeyId, string secretAccessKey)
- {
- this.accessKeyId = accessKeyId;
- this.secretAccessKey = secretAccessKey;
- }
-
- ///
- /// Pings the OpenAPI server.
- ///
- /// True when the server pongs back.
- public Boolean Ping()
- {
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL_PREFIX + "/utils/v3/ping");
- request.Method = "GET";
-
- // Handle request
- AuthUtils.HandleRequest(request, accessKeyId, secretAccessKey, null, null);
- HttpWebResponse response = (HttpWebResponse)request.GetResponse();
- response.Close();
-
- return HttpStatusCode.OK == response.StatusCode;
- }
-
- ///
- /// Searches for products.
- ///
- /// The search results request.
- /// The search results response.
- public SearchResultsResponse Search(SearchResultsRequest searchResultsRequest)
- {
- SearchResultsResponse searchResultsResponse = null;
-
- // Prepare request
- NameValueCollection queryParams = new NameValueCollection();
- if (searchResultsRequest.Term != null)
- {
- queryParams.Add("term", searchResultsRequest.Term);
- }
- if (searchResultsRequest.Offset != null)
- {
- queryParams.Add("offset", searchResultsRequest.Offset.ToString());
- }
- if (searchResultsRequest.NrProducts != null)
- {
- queryParams.Add("nrProducts", searchResultsRequest.NrProducts.ToString());
- }
- if (searchResultsRequest.SortingMethod != null)
- {
- queryParams.Add("sortingMethod", EnumUtils.stringValueOf(searchResultsRequest.SortingMethod));
- }
- if (searchResultsRequest.SortingAscending != null)
- {
- queryParams.Add("sortingAscending", searchResultsRequest.SortingAscending.ToString());
- }
- if (searchResultsRequest.IncludeProducts != null)
- {
- queryParams.Add("includeProducts", searchResultsRequest.IncludeProducts.ToString());
- }
- if (searchResultsRequest.IncludeCategories != null)
- {
- queryParams.Add("includeCategories", searchResultsRequest.IncludeCategories.ToString());
- }
- if (searchResultsRequest.IncludeRefinements != null)
- {
- queryParams.Add("includeRefinements", searchResultsRequest.IncludeRefinements.ToString());
- }
- if (searchResultsRequest.IncludeAttributes != null)
- {
- queryParams.Add("includeAttributes", searchResultsRequest.IncludeAttributes.ToString());
- }
-
- string queryString = ToQueryString(queryParams);
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL_PREFIX + "/catalog/v3/searchresults/" + queryString);
- request.Method = "GET";
-
- // Handle request
- AuthUtils.HandleRequest(request, accessKeyId, secretAccessKey, null, queryParams);
- HttpWebResponse response = (HttpWebResponse)request.GetResponse();
-
- // Load XML document
- if (HttpStatusCode.OK == response.StatusCode)
- {
- XmlSerializer ser = new XmlSerializer(typeof(SearchResultsResponse));
- object obj = ser.Deserialize(response.GetResponseStream());
- searchResultsResponse = (SearchResultsResponse)obj;
- response.Close();
- }
-
- return searchResultsResponse;
- }
-
- ///
- /// Gets the product or category/refinement results list.
- ///
- /// The list result request.
- /// The list result response.
- public ListResultResponse GetList(ListResultRequest listResultRequest)
- {
- ListResultResponse listResultResponse = null;
-
- // Prepare request
- NameValueCollection queryParams = new NameValueCollection();
- if (listResultRequest.Offset != null)
- {
- queryParams.Add("offset", listResultRequest.Offset.ToString());
- }
- if (listResultRequest.NrProducts != null)
- {
- queryParams.Add("nrProducts", listResultRequest.NrProducts.ToString());
- }
- if (listResultRequest.SortingMethod != null)
- {
- queryParams.Add("sortingMethod", EnumUtils.stringValueOf(listResultRequest.SortingMethod));
- }
- if (listResultRequest.SortingAscending != null)
- {
- queryParams.Add("sortingAscending", listResultRequest.SortingAscending.ToString());
- }
- if (listResultRequest.IncludeProducts != null)
- {
- queryParams.Add("includeProducts", listResultRequest.IncludeProducts.ToString());
- }
- if (listResultRequest.IncludeCategories != null)
- {
- queryParams.Add("includeCategories", listResultRequest.IncludeCategories.ToString());
- }
- if (listResultRequest.IncludeRefinements != null)
- {
- queryParams.Add("includeRefinements", listResultRequest.IncludeRefinements.ToString());
- }
- if (listResultRequest.IncludeAttributes != null)
- {
- queryParams.Add("includeAttributes", listResultRequest.IncludeAttributes.ToString());
- }
-
- string queryString = ToQueryString(queryParams);
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL_PREFIX + "/catalog/v3/listresults/" + EnumUtils.stringValueOf(listResultRequest.Type) + "/" + HttpUtility.UrlEncode(combineCategoryAndRefinementIds(listResultRequest.CategoryId, listResultRequest.RefinementIds), UTF8Encoding.UTF8) + "/" + queryString);
- request.Method = "GET";
-
- // Handle request
- AuthUtils.HandleRequest(request, accessKeyId, secretAccessKey, null, queryParams);
- HttpWebResponse response = (HttpWebResponse)request.GetResponse();
-
- // Load XML document
- if (HttpStatusCode.OK == response.StatusCode)
- {
- XmlSerializer ser = new XmlSerializer(typeof(ListResultResponse));
- object obj = ser.Deserialize(response.GetResponseStream());
- listResultResponse = (ListResultResponse)obj;
- response.Close();
- }
-
- return listResultResponse;
- }
-
- ///
- /// Gets the product.
- ///
- /// The product id.
- /// The product response.
- public ProductResponse GetProduct(string id)
- {
- ProductResponse productResponse = null;
-
- // Prepare request
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL_PREFIX + "/catalog/v3/products/" + id);
- request.Method = "GET";
-
- // Handle request
- AuthUtils.HandleRequest(request, accessKeyId, secretAccessKey);
- HttpWebResponse response = (HttpWebResponse)request.GetResponse();
-
- // Load XML document
- if (HttpStatusCode.OK == response.StatusCode)
- {
- XmlSerializer ser = new XmlSerializer(typeof(ProductResponse));
- object obj = ser.Deserialize(response.GetResponseStream());
- productResponse = (ProductResponse)obj;
- response.Close();
- }
-
- return productResponse;
- }
-
- ///
- /// Converts a name-value collection into a query string.
- ///
- /// The name-value collection.
- /// The query string.
- private string ToQueryString(NameValueCollection nvc)
- {
- if (nvc != null && nvc.Count > 0)
- {
- // Does not support multi-value parameters, but for now we can accept that
- return "?" + string.Join("&", Array.ConvertAll(nvc.AllKeys, key => string.Format("{0}={1}", HttpUtility.UrlEncode(key), HttpUtility.UrlEncode(nvc[key]))));
- }
- else
- {
- return "";
- }
- }
-
- ///
- /// Combines the category and refinement ids.
- ///
- /// The category id.
- /// The list of refinement ids.
- /// The combined string of category and refinement ids.
- private String combineCategoryAndRefinementIds(string categoryId, List refinementIds)
- {
- StringBuilder sb = new StringBuilder();
- if (categoryId != null)
- {
- sb.Append(categoryId);
- }
- if (refinementIds != null && refinementIds.Count > 0)
- {
- sb.Append(' ');
-
- for (int i = 0; i < refinementIds.Count; i++)
- {
- sb.Append(refinementIds[i]);
-
- if (i + 1 < refinementIds.Count)
- {
- sb.Append(' ');
- }
- }
- }
-
- return sb.ToString();
- }
- }
-}
diff --git a/OpenAPI Client/Constants.cs b/OpenAPI Client/Constants.cs
index d02d0e5..dde53e5 100644
--- a/OpenAPI Client/Constants.cs
+++ b/OpenAPI Client/Constants.cs
@@ -1,7 +1,6 @@
-
-namespace Bol.OpenAPI
+namespace Bol.OpenAPI.Client
{
- class Constants
+ internal static class Constants
{
public const string URL_PREFIX = "https://api.bol.com";
}
diff --git a/OpenAPI Client/Exception/BasicApiException.cs b/OpenAPI Client/Exception/BasicApiException.cs
deleted file mode 100644
index 4459c70..0000000
--- a/OpenAPI Client/Exception/BasicApiException.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-
-namespace Bol.OpenAPI.Exception
-{
- public class BasicApiException : System.ApplicationException
- {
- public string Status { get; set; }
-
- public BasicApiException() { }
-
- public BasicApiException(string status, string message) : base(message)
- {
- this.Status = status;
- }
- }
-}
diff --git a/OpenAPI Client/Exception/Handler/ExceptionHandler.cs b/OpenAPI Client/Exception/Handler/ExceptionHandler.cs
index 41463e3..455d747 100644
--- a/OpenAPI Client/Exception/Handler/ExceptionHandler.cs
+++ b/OpenAPI Client/Exception/Handler/ExceptionHandler.cs
@@ -1,21 +1,20 @@
-using Newtonsoft.Json;
-using System.IO;
-using System.Net;
-using System.Text;
-
-namespace Bol.OpenAPI.Exception.Handler
+namespace Bol.OpenAPI.Client.Exception.Handler
{
- class ExceptionHandler
+ using System;
+ using System.IO;
+ using System.Net;
+ using System.Text;
+ using Newtonsoft.Json;
+
+ internal static class ExceptionHandler
{
public static BasicApiException HandleBasicApiException(HttpWebResponse response)
{
- using (Stream stream = response.GetResponseStream())
- {
- StreamReader reader = new StreamReader(stream, Encoding.UTF8);
- string responseString = reader.ReadToEnd();
- Error error = JsonConvert.DeserializeObject(responseString);
- return new BasicApiException(error.Code, error.Message);
- }
+ using var stream = response.GetResponseStream();
+ var reader = new StreamReader(stream ?? throw new InvalidOperationException(), Encoding.UTF8);
+ var responseString = reader.ReadToEnd();
+ var error = JsonConvert.DeserializeObject(responseString);
+ return new BasicApiException(error.Code, error.Message);
}
}
}
diff --git a/OpenAPI Client/Generated/openapi-4.0.0.cs b/OpenAPI Client/Generated/openapi-4.0.0.cs
index 86ff47f..6977e3a 100644
--- a/OpenAPI Client/Generated/openapi-4.0.0.cs
+++ b/OpenAPI Client/Generated/openapi-4.0.0.cs
@@ -20,11 +20,11 @@ public string SessionId
{
get
{
- return this.sessionIdField;
+ return sessionIdField;
}
set
{
- this.sessionIdField = value;
+ sessionIdField = value;
}
}
@@ -32,11 +32,11 @@ public string Name
{
get
{
- return this.nameField;
+ return nameField;
}
set
{
- this.nameField = value;
+ nameField = value;
}
}
@@ -44,11 +44,11 @@ public bool MergedBasket
{
get
{
- return this.mergedBasketField;
+ return mergedBasketField;
}
set
{
- this.mergedBasketField = value;
+ mergedBasketField = value;
}
}
}
@@ -66,11 +66,11 @@ public string PrivateToken
{
get
{
- return this.privateTokenField;
+ return privateTokenField;
}
set
{
- this.privateTokenField = value;
+ privateTokenField = value;
}
}
@@ -78,11 +78,11 @@ public string Code
{
get
{
- return this.codeField;
+ return codeField;
}
set
{
- this.codeField = value;
+ codeField = value;
}
}
@@ -90,11 +90,11 @@ public string Url
{
get
{
- return this.urlField;
+ return urlField;
}
set
{
- this.urlField = value;
+ urlField = value;
}
}
}
@@ -108,11 +108,11 @@ public string SessionId
{
get
{
- return this.sessionIdField;
+ return sessionIdField;
}
set
{
- this.sessionIdField = value;
+ sessionIdField = value;
}
}
}
@@ -124,18 +124,18 @@ public partial class ProductList
public ProductList()
{
- this.productsField = new List();
+ productsField = new List();
}
public List Products
{
get
{
- return this.productsField;
+ return productsField;
}
set
{
- this.productsField = value;
+ productsField = value;
}
}
}
@@ -183,26 +183,26 @@ public partial class Product
public Product()
{
- this.parentCategoryPathsField = new List();
- this.promotionsField = new List();
- this.offerDataField = new OfferData();
- this.mediaField = new List();
- this.imagesField = new List();
- this.urlsField = new List();
- this.entityGroupsField = new List();
- this.attributeGroupsField = new List();
- this.trackListsField = new List();
+ parentCategoryPathsField = new List();
+ promotionsField = new List();
+ offerDataField = new OfferData();
+ mediaField = new List();
+ imagesField = new List();
+ urlsField = new List();
+ entityGroupsField = new List();
+ attributeGroupsField = new List();
+ trackListsField = new List();
}
public string Id
{
get
{
- return this.idField;
+ return idField;
}
set
{
- this.idField = value;
+ idField = value;
}
}
@@ -210,11 +210,11 @@ public string EAN
{
get
{
- return this.eANField;
+ return eANField;
}
set
{
- this.eANField = value;
+ eANField = value;
}
}
@@ -222,11 +222,11 @@ public string GPC
{
get
{
- return this.gPCField;
+ return gPCField;
}
set
{
- this.gPCField = value;
+ gPCField = value;
}
}
@@ -234,11 +234,11 @@ public string Title
{
get
{
- return this.titleField;
+ return titleField;
}
set
{
- this.titleField = value;
+ titleField = value;
}
}
@@ -246,11 +246,11 @@ public string Subtitle
{
get
{
- return this.subtitleField;
+ return subtitleField;
}
set
{
- this.subtitleField = value;
+ subtitleField = value;
}
}
@@ -258,11 +258,11 @@ public string Summary
{
get
{
- return this.summaryField;
+ return summaryField;
}
set
{
- this.summaryField = value;
+ summaryField = value;
}
}
@@ -270,24 +270,24 @@ public int Rating
{
get
{
- return this.ratingField;
+ return ratingField;
}
set
{
- this.ratingField = value;
+ ratingField = value;
}
}
- [System.Xml.Serialization.XmlIgnoreAttribute()]
+ [XmlIgnore()]
public bool RatingSpecified
{
get
{
- return this.ratingFieldSpecified;
+ return ratingFieldSpecified;
}
set
{
- this.ratingFieldSpecified = value;
+ ratingFieldSpecified = value;
}
}
@@ -295,11 +295,11 @@ public string ShortDescription
{
get
{
- return this.shortDescriptionField;
+ return shortDescriptionField;
}
set
{
- this.shortDescriptionField = value;
+ shortDescriptionField = value;
}
}
@@ -307,11 +307,11 @@ public string LongDescription
{
get
{
- return this.longDescriptionField;
+ return longDescriptionField;
}
set
{
- this.longDescriptionField = value;
+ longDescriptionField = value;
}
}
@@ -319,11 +319,11 @@ public List TrackLists
{
get
{
- return this.trackListsField;
+ return trackListsField;
}
set
{
- this.trackListsField = value;
+ trackListsField = value;
}
}
@@ -331,11 +331,11 @@ public List AttributeGroups
{
get
{
- return this.attributeGroupsField;
+ return attributeGroupsField;
}
set
{
- this.attributeGroupsField = value;
+ attributeGroupsField = value;
}
}
@@ -343,11 +343,11 @@ public List EntityGroups
{
get
{
- return this.entityGroupsField;
+ return entityGroupsField;
}
set
{
- this.entityGroupsField = value;
+ entityGroupsField = value;
}
}
@@ -355,11 +355,11 @@ public List Urls
{
get
{
- return this.urlsField;
+ return urlsField;
}
set
{
- this.urlsField = value;
+ urlsField = value;
}
}
@@ -367,11 +367,11 @@ public List Images
{
get
{
- return this.imagesField;
+ return imagesField;
}
set
{
- this.imagesField = value;
+ imagesField = value;
}
}
@@ -379,11 +379,11 @@ public List Media
{
get
{
- return this.mediaField;
+ return mediaField;
}
set
{
- this.mediaField = value;
+ mediaField = value;
}
}
@@ -391,11 +391,11 @@ public OfferData OfferData
{
get
{
- return this.offerDataField;
+ return offerDataField;
}
set
{
- this.offerDataField = value;
+ offerDataField = value;
}
}
@@ -403,25 +403,25 @@ public List Promotions
{
get
{
- return this.promotionsField;
+ return promotionsField;
}
set
{
- this.promotionsField = value;
+ promotionsField = value;
}
}
- [System.Xml.Serialization.XmlArrayAttribute(Order = 17)]
- [System.Xml.Serialization.XmlArrayItemAttribute("ParentCategories", typeof(ParentCategory), IsNullable = false)]
+ [XmlArray(Order = 17)]
+ [XmlArrayItem("ParentCategories", typeof(ParentCategory), IsNullable = false)]
public List ParentCategoryPaths
{
get
{
- return this.parentCategoryPathsField;
+ return parentCategoryPathsField;
}
set
{
- this.parentCategoryPathsField = value;
+ parentCategoryPathsField = value;
}
}
}
@@ -435,18 +435,18 @@ public partial class TrackList
public TrackList()
{
- this.trackField = new List