From 30ac503ee916d15120fe6a2fadb6dccf98e29903 Mon Sep 17 00:00:00 2001
From: Iavor Jelev <50323921+iavorJ@users.noreply.github.com>
Date: Thu, 2 Apr 2020 18:31:13 +0200
Subject: [PATCH] Extend catalog service with create
This commit contains a number of fixes, e.g. a way to create
catalogs programmatically (for admins only, for now).
---
.../Catalogs/CreateTests.cs | 58 ++++++
.../Meplato.Store2.Tests.csproj | 2 +
.../TestData/catalogs.create.success | 11 ++
src/Meplato.Store2/Catalogs/Service.cs | 176 +++++++++++++++++-
src/Meplato.Store2/Jobs/Service.cs | 8 +-
src/Meplato.Store2/Products/Service.cs | 34 +++-
src/Meplato.Store2/Service.cs | 8 +-
7 files changed, 282 insertions(+), 15 deletions(-)
create mode 100644 src/Meplato.Store2.Tests/Catalogs/CreateTests.cs
create mode 100644 src/Meplato.Store2.Tests/TestData/catalogs.create.success
diff --git a/src/Meplato.Store2.Tests/Catalogs/CreateTests.cs b/src/Meplato.Store2.Tests/Catalogs/CreateTests.cs
new file mode 100644
index 0000000..3841d2b
--- /dev/null
+++ b/src/Meplato.Store2.Tests/Catalogs/CreateTests.cs
@@ -0,0 +1,58 @@
+#region Copyright and terms of services
+
+// Copyright (c) 2013-present Meplato GmbH.
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+// in compliance with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software distributed under the License
+// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+// or implied. See the License for the specific language governing permissions and limitations under
+// the License.
+
+#endregion
+
+using System.Threading.Tasks;
+using Meplato.Store2.Catalogs;
+using NUnit.Framework;
+
+namespace Meplato.Store2.Tests.Catalogs
+{
+ [TestFixture]
+ public class CreateTests : TestCase
+ {
+ [Test]
+ public async Task TestCreate()
+ {
+ MockFromFile("catalogs.create.success");
+
+ var service = GetCatalogsService();
+ Assert.NotNull(service);
+
+ var create = new CreateCatalog()
+ {
+ MerchantId = 1,
+ Name = "test2",
+ // Description = "",
+ // ProjectID = 0,
+ ProjectMpcc = "meplato",
+ ValidFrom = null,
+ ValidUntil = null,
+ Country = "DE",
+ Currency = "EUR",
+ Language = "de",
+ Target = "mall",
+ SageNumber = "",
+ SageContract = ""
+ };
+
+ var response = await service.Create().Catalog(create).Do();
+ Assert.NotNull(response);
+ Assert.AreEqual("store#catalog", response.Kind);
+ Assert.AreEqual(81, response.Id);
+ Assert.AreEqual("48F31F33AD", response.Pin);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Meplato.Store2.Tests/Meplato.Store2.Tests.csproj b/src/Meplato.Store2.Tests/Meplato.Store2.Tests.csproj
index 5a025a1..b098a25 100644
--- a/src/Meplato.Store2.Tests/Meplato.Store2.Tests.csproj
+++ b/src/Meplato.Store2.Tests/Meplato.Store2.Tests.csproj
@@ -69,6 +69,7 @@
+
@@ -103,6 +104,7 @@
+
Always
diff --git a/src/Meplato.Store2.Tests/TestData/catalogs.create.success b/src/Meplato.Store2.Tests/TestData/catalogs.create.success
new file mode 100644
index 0000000..c11809f
--- /dev/null
+++ b/src/Meplato.Store2.Tests/TestData/catalogs.create.success
@@ -0,0 +1,11 @@
+HTTP/1.1 201 Created
+Content-Type: application/json; charset=utf-8
+P3p: CP="This is not a P3P policy!"
+Vary: Cookie
+X-Content-Type-Options: nosniff
+X-Frame-Options: SAMEORIGIN
+X-Ua-Compatible: IE=edge
+X-Xss-Protection: 1; mode=block
+Date: Wed, 01 Apr 2015 13:53:54 GMT
+
+{"kind":"store#catalog","selfLink":"https://store3.go/api/v2/catalogs/48F31F33AD","id":81,"type":"corporate","merchantId":1,"merchantMpcc":"meplato","merchantMpsc":"meplato-sc","merchantName":"Meplato GmbH","projectId":1,"projectMpcc":"meplato","projectMpbc":"meplato","projectName":"Meplato","project":{"id":1,"type":"corporate","mpcc":"meplato","mpbc":"meplato","name":"Meplato","profile":{"nameExists":{"policy":1},"categoriesExists":{"policy":1},"eclassesValid":{"policy":0,"version":"5.1"},"orderUnitValues":{"policy":0},"contentUnitValues":{"policy":0}},"customization":{"hooks":[{"kind":"publish_initial","via":"smtp","target":"oe+dev-initial-publish@meplato.de"}]},"script":"","visible":true,"country":"DE","language":"de","locale":"de_DE","timeZone":"Europe/Berlin","currency":"EUR","ou":"PCE","catalogPriceInitial":0,"catalogPriceRecurring":0,"catalogPriceCurrency":"EUR","catalogPriceInterval":"yearly","target":"mall","companyGroup":"","created":"2017-10-09T14:29:35Z","updated":"2020-01-02T08:47:32Z"},"slug":"test2","name":"test2","pin":"48F31F33AD","validFrom":"2020-03-13","validUntil":"2099-12-31","currency":"EUR","country":"DE","language":"de","state":"idle","created":"2020-03-13T15:39:52.004116159Z","updated":"2020-03-13T15:39:52.004116159Z","lockedForDownload":false,"supportsOciDetail":false,"supportsOciDetailadd":false,"supportsOciValidate":false,"supportsOciSourcing":false,"supportsOciBackgroundsearch":false,"supportsOciQuantitycheck":false,"supportsOciDownloadjson":false,"keepOriginalBlobs":false,"target":"","showImportFailure":false}
diff --git a/src/Meplato.Store2/Catalogs/Service.cs b/src/Meplato.Store2/Catalogs/Service.cs
index 5680ffb..35a2699 100644
--- a/src/Meplato.Store2/Catalogs/Service.cs
+++ b/src/Meplato.Store2/Catalogs/Service.cs
@@ -1,5 +1,5 @@
#region Copyright and terms of services
-// Copyright (c) 2015-2016 Meplato GmbH.
+// Copyright (c) 2013-present Meplato GmbH.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
// in compliance with the License. You may obtain a copy of the License at
@@ -17,8 +17,8 @@
// The file implements the Meplato Store API.
//
// Author: Meplato API Team
-// Version: 2.1.6
-// License: Copyright (c) 2015-2018 Meplato GmbH. All rights reserved.
+// Version: 2.1.7
+// License: Copyright (c) 2015-2020 Meplato GmbH. All rights reserved.
// See Terms of Service
// See External documentation
@@ -40,7 +40,7 @@ public class Service
{
#region Service
public const string Title = "Meplato Store API";
- public const string Version = "2.1.6";
+ public const string Version = "2.1.7";
public const string UserAgent = "meplato-csharp-client/2.0";
public const string DefaultBaseURL = "https://store.meplato.com/api/v2";
@@ -100,6 +100,13 @@ public string GetAuthorizationHeader()
return null;
}
+ ///
+ /// Create a new catalog (admin only).
+ ///
+ public CreateService Create() {
+ return new CreateService(this);
+ }
+
///
/// Get a single catalog.
///
@@ -452,6 +459,13 @@ public class Catalog
[JsonProperty("supportsOciValidate")]
public bool SupportsOciValidate { get; set; }
+ ///
+ /// Target represents the target system which can be either an
+ /// empty string, "catscout" or "mall".
+ ///
+ [JsonProperty("target")]
+ public string Target { get; set; }
+
///
/// Type of catalog, e.g. corporate or basic.
///
@@ -480,6 +494,101 @@ public class Catalog
#endregion // Catalog
}
+ ///
+ /// CreateCatalog holds the properties of a new catalog.
+ ///
+ public class CreateCatalog
+ {
+ #region CreateCatalog
+
+ ///
+ /// Country is the ISO-3166 alpha-2 code for the country that the
+ /// catalog is destined for (e.g. DE or US).
+ ///
+ [JsonProperty("country")]
+ public string Country { get; set; }
+
+ ///
+ /// Currency is the ISO-4217 currency code that is used for all
+ /// products in the catalog (e.g. EUR or USD).
+ ///
+ [JsonProperty("currency")]
+ public string Currency { get; set; }
+
+ ///
+ /// Description of the catalog.
+ ///
+ [JsonProperty("description")]
+ public string Description { get; set; }
+
+ ///
+ /// Language is the IETF language tag of the language of all
+ /// products in the catalog (e.g. de or pt-BR).
+ ///
+ [JsonProperty("language")]
+ public string Language { get; set; }
+
+ ///
+ /// ID of the merchant.
+ ///
+ [JsonProperty("merchantId")]
+ public long MerchantId { get; set; }
+
+ ///
+ /// Name of the catalog.
+ ///
+ [JsonProperty("name")]
+ public string Name { get; set; }
+
+ ///
+ /// ID of the project.
+ ///
+ [JsonProperty("projectId")]
+ public long ProjectId { get; set; }
+
+ ///
+ /// MPCC of the project.
+ ///
+ [JsonProperty("projectMpcc")]
+ public string ProjectMpcc { get; set; }
+
+ ///
+ /// SageContract represents the internal identifier at Meplato for
+ /// the contract of this catalog.
+ ///
+ [JsonProperty("sageContract")]
+ public string SageContract { get; set; }
+
+ ///
+ /// SageNumber represents the internal identifier at Meplato for
+ /// the merchant of this catalog.
+ ///
+ [JsonProperty("sageNumber")]
+ public string SageNumber { get; set; }
+
+ ///
+ /// Target represents the target system which can be either an
+ /// empty string, "catscout" or "mall".
+ ///
+ [JsonProperty("target")]
+ public string Target { get; set; }
+
+ ///
+ /// ValidFrom is the date the catalog becomes effective
+ /// (YYYY-MM-DD).
+ ///
+ [JsonProperty("validFrom")]
+ public string ValidFrom { get; set; }
+
+ ///
+ /// ValidUntil is the date the catalog expires (YYYY-MM-DD).
+ ///
+ [JsonProperty("validUntil")]
+ public string ValidUntil { get; set; }
+
+ #endregion // CreateCatalog
+ }
+
///
/// CustField describes a generic name/value pair. Its purpose is
/// to provide a mechanism for customer-specific fields.
@@ -819,6 +928,65 @@ public class SearchResponse
#endregion // SearchResponse
}
+ ///
+ /// CreateService: Create a new catalog (admin only).
+ ///
+ public class CreateService
+ {
+ #region CreateService
+
+ private readonly Service _service;
+ private readonly IDictionary _opt = new Dictionary();
+ private readonly IDictionary _hdr = new Dictionary();
+
+ private CreateCatalog _catalog;
+
+ ///
+ /// Creates a new instance of CreateService.
+ ///
+ public CreateService(Service service)
+ {
+ _service = service;
+ }
+
+ ///
+ /// Catalog properties of the new catalog.
+ ///
+ public CreateService Catalog(CreateCatalog catalog)
+ {
+ _catalog = catalog;
+ return this;
+ }
+
+ ///
+ /// Execute the operation.
+ ///
+ public async Task Do()
+ {
+ // Make a copy of the parameters and add the path parameters to it
+ var parameters = new Dictionary();
+
+ // Make a copy of the header parameters and set UA
+ var headers = new Dictionary();
+ string authorization = _service.GetAuthorizationHeader();
+ if (!string.IsNullOrEmpty(authorization))
+ {
+ headers["Authorization"] = authorization;
+ }
+
+ var uriTemplate = _service.BaseURL + "/catalogs";
+ var response = await _service.Client.Execute(
+ HttpMethod.Post,
+ uriTemplate,
+ parameters,
+ headers,
+ _catalog);
+ return response.GetBodyJSON();
+ }
+
+ #endregion // CreateService
+ }
+
///
/// GetService: Get a single catalog.
///
diff --git a/src/Meplato.Store2/Jobs/Service.cs b/src/Meplato.Store2/Jobs/Service.cs
index ba11aef..bed9933 100644
--- a/src/Meplato.Store2/Jobs/Service.cs
+++ b/src/Meplato.Store2/Jobs/Service.cs
@@ -1,5 +1,5 @@
#region Copyright and terms of services
-// Copyright (c) 2015-2016 Meplato GmbH.
+// Copyright (c) 2013-present Meplato GmbH.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
// in compliance with the License. You may obtain a copy of the License at
@@ -17,8 +17,8 @@
// The file implements the Meplato Store API.
//
// Author: Meplato API Team
-// Version: 2.1.6
-// License: Copyright (c) 2015-2018 Meplato GmbH. All rights reserved.
+// Version: 2.1.7
+// License: Copyright (c) 2015-2020 Meplato GmbH. All rights reserved.
// See Terms of Service
// See External documentation
@@ -40,7 +40,7 @@ public class Service
{
#region Service
public const string Title = "Meplato Store API";
- public const string Version = "2.1.6";
+ public const string Version = "2.1.7";
public const string UserAgent = "meplato-csharp-client/2.0";
public const string DefaultBaseURL = "https://store.meplato.com/api/v2";
diff --git a/src/Meplato.Store2/Products/Service.cs b/src/Meplato.Store2/Products/Service.cs
index c3384d0..0ee17cf 100644
--- a/src/Meplato.Store2/Products/Service.cs
+++ b/src/Meplato.Store2/Products/Service.cs
@@ -1,5 +1,5 @@
#region Copyright and terms of services
-// Copyright (c) 2015-2016 Meplato GmbH.
+// Copyright (c) 2013-present Meplato GmbH.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
// in compliance with the License. You may obtain a copy of the License at
@@ -17,7 +17,7 @@
// The file implements the Meplato Store API.
//
// Author: Meplato API Team
-// Version: 2.1.6
+// Version: 2.1.7
// License: Copyright (c) 2015-2018 Meplato GmbH. All rights reserved.
// See Terms of Service
// See External documentation
@@ -41,7 +41,7 @@ public class Service
{
#region Service
public const string Title = "Meplato Store API";
- public const string Version = "2.1.6";
+ public const string Version = "2.1.7";
public const string UserAgent = "meplato-csharp-client/2.0";
public const string DefaultBaseURL = "https://store.meplato.com/api/v2";
@@ -3381,6 +3381,30 @@ public void ResetCuPerOu()
private double? _cuPerOu;
private bool _hasCuPerOu;
+
+ ///
+ /// Currency is the ISO currency code for the prices, e.g. EUR or
+ /// GBP. If you pass an empty currency code, it will be initialized
+ /// with the catalog's currency.
+ ///
+ public string Currency
+ {
+ get => _currency;
+ set
+ {
+ _currency = value;
+ _hasCurrency = true;
+ }
+ }
+
+ public void ResetCurrency()
+ {
+ _currency = null;
+ _hasCurrency = false;
+ }
+
+ private string _currency;
+ private bool _hasCurrency;
///
/// CustField1 is the CUST_FIELD1 of the SAP OCI specification. It
@@ -5469,6 +5493,10 @@ public virtual void GetObjectData(SerializationInfo info, StreamingContext conte
{
info.AddValue("cuPerOu", _cuPerOu);
}
+ if (_hasCurrency)
+ {
+ info.AddValue("currency", _currency);
+ }
if (_hasCustFields)
{
info.AddValue("custFields", _custFields);
diff --git a/src/Meplato.Store2/Service.cs b/src/Meplato.Store2/Service.cs
index 506a089..49237ad 100644
--- a/src/Meplato.Store2/Service.cs
+++ b/src/Meplato.Store2/Service.cs
@@ -1,5 +1,5 @@
#region Copyright and terms of services
-// Copyright (c) 2015-2016 Meplato GmbH.
+// Copyright (c) 2013-present Meplato GmbH.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
// in compliance with the License. You may obtain a copy of the License at
@@ -17,8 +17,8 @@
// The file implements the Meplato Store API.
//
// Author: Meplato API Team
-// Version: 2.1.6
-// License: Copyright (c) 2015-2018 Meplato GmbH. All rights reserved.
+// Version: 2.1.7
+// License: Copyright (c) 2015-2020 Meplato GmbH. All rights reserved.
// See Terms of Service
// See External documentation
@@ -39,7 +39,7 @@ public class Service
{
#region Service
public const string Title = "Meplato Store API";
- public const string Version = "2.1.6";
+ public const string Version = "2.1.7";
public const string UserAgent = "meplato-csharp-client/2.0";
public const string DefaultBaseURL = "https://store.meplato.com/api/v2";