Skip to content

Commit 3791f83

Browse files
committed
Sandbox functionality in listings items
1 parent 62e05b5 commit 3791f83

File tree

7 files changed

+107
-24
lines changed

7 files changed

+107
-24
lines changed

Source/FikaAmazonAPI/Parameter/ListingsItems/ParameterDeleteListingItem.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using FikaAmazonAPI.Search;
2+
using FikaAmazonAPI.Utils;
23
using System;
34
using System.Collections.Generic;
45
using System.IO;
@@ -9,9 +10,10 @@ namespace FikaAmazonAPI.Parameter.ListingItem
910
{
1011
public class ParameterDeleteListingItem: ParameterBased
1112
{
12-
1313
public bool Check()
1414
{
15+
if (TestCase == Constants.TestCase400)
16+
sku = "BadSKU";
1517
if (string.IsNullOrWhiteSpace(this.sellerId))
1618
{
1719
throw new InvalidDataException("SellerId is a required property for ParameterDeleteListingItem and cannot be null");

Source/FikaAmazonAPI/Parameter/ListingsItems/ParameterGetListingsItem.cs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,49 @@
44
using Newtonsoft.Json.Converters;
55
using System;
66
using System.Collections.Generic;
7+
using System.IO;
8+
using System.Linq;
79
using System.Text;
10+
using static FikaAmazonAPI.Utils.Constants;
811

9-
namespace FikaAmazonAPI.Parameter.ListingsItems
12+
namespace FikaAmazonAPI.Parameter.ListingItem
1013
{
1114
public class ParameterGetListingsItem : ParameterBased
1215
{
1316
public ParameterGetListingsItem()
1417
{
1518
}
1619

20+
public bool Check()
21+
{
22+
if (TestCase == TestCase400)
23+
sku = "BadSKU";
24+
if (string.IsNullOrWhiteSpace(sellerId))
25+
{
26+
throw new InvalidDataException("SellerId is a required property for ParameterPutListingItem and cannot be null");
27+
}
28+
if (string.IsNullOrWhiteSpace(sku))
29+
{
30+
throw new InvalidDataException("Sku is a required property for ParameterPutListingItem and cannot be null");
31+
}
32+
if (marketplaceIds == null || !marketplaceIds.Any())
33+
{
34+
throw new InvalidDataException("MarketplaceIds is a required property for ParameterPutListingItem and cannot be null");
35+
}
36+
if (includedData is null)
37+
{
38+
includedData = new List<ListingsIncludedData>();
39+
includedData.Add(ListingsIncludedData.Summaries);
40+
}
41+
if (includedData.Count == 0)
42+
includedData.Add(ListingsIncludedData.Summaries);
43+
return true;
44+
}
45+
46+
public string sellerId { get; set; }
47+
48+
public string sku { get; set; }
49+
1750
/// <summary>
1851
/// A list of MarketplaceId values. Used to select orders that were placed in the specified marketplaces. Max count : 50
1952
/// </summary>

Source/FikaAmazonAPI/Parameter/ListingsItems/ParameterPatchListingItem.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using FikaAmazonAPI.AmazonSpApiSDK.Models.Token;
22
using FikaAmazonAPI.Search;
3+
using FikaAmazonAPI.Utils;
34
using System;
45
using System.Collections.Generic;
56
using System.IO;
@@ -12,6 +13,8 @@ public class ParameterPatchListingItem : ParameterBased
1213
{
1314
public bool Check()
1415
{
16+
if (TestCase == Constants.TestCase400)
17+
sku = "BadSKU";
1518
if (string.IsNullOrWhiteSpace(this.sellerId))
1619
{
1720
throw new InvalidDataException("SellerId is a required property for ParameterPatchListingItem and cannot be null");

Source/FikaAmazonAPI/Parameter/ListingsItems/ParameterPutListingItem.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using FikaAmazonAPI.AmazonSpApiSDK.Models.Token;
22
using FikaAmazonAPI.Search;
3+
using FikaAmazonAPI.Utils;
34
using System;
45
using System.Collections.Generic;
56
using System.IO;
@@ -12,6 +13,8 @@ public class ParameterPutListingItem : ParameterBased
1213
{
1314
public bool Check()
1415
{
16+
if (TestCase == Constants.TestCase400)
17+
sku = "BadSKU";
1518
if (string.IsNullOrWhiteSpace(this.sellerId))
1619
{
1720
throw new InvalidDataException("SellerId is a required property for ParameterPutListingItem and cannot be null");

Source/FikaAmazonAPI/Services/ListingsItemService.cs

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.Text;
44
using FikaAmazonAPI.AmazonSpApiSDK.Models.ListingsItems;
55
using FikaAmazonAPI.Parameter.ListingItem;
6-
using FikaAmazonAPI.Parameter.ListingsItems;
76
using FikaAmazonAPI.Utils;
87
using static FikaAmazonAPI.Utils.Constants;
98

@@ -15,26 +14,12 @@ public ListingsItemService(AmazonCredential amazonCredential) : base(amazonCrede
1514
{
1615
}
1716

18-
public Item GetListingsItem(string sellerId, string sku, ParameterGetListingsItem listingsItemParameters)
17+
public Item GetListingsItem(ParameterGetListingsItem listingsItemParameters)
1918
{
20-
if (string.IsNullOrEmpty(sellerId))
21-
throw new ArgumentException($"'{nameof(sellerId)}' cannot be null or empty.", nameof(sellerId));
22-
23-
if (string.IsNullOrEmpty(sku))
24-
throw new ArgumentException($"'{nameof(sku)}' cannot be null or empty.", nameof(sku));
25-
26-
if (listingsItemParameters.includedData is null)
27-
{
28-
listingsItemParameters.includedData = new List<ListingsIncludedData>();
29-
listingsItemParameters.includedData.Add(ListingsIncludedData.Summaries);
30-
}
31-
if (listingsItemParameters.includedData.Count == 0)
32-
listingsItemParameters.includedData.Add(ListingsIncludedData.Summaries);
19+
listingsItemParameters.Check();
3320
var queryParameters = listingsItemParameters.getParameters();
34-
CreateAuthorizedRequest(ListingsItemsApiUrls.GetListingItem(sellerId, sku), RestSharp.Method.GET, queryParameters, parameter: listingsItemParameters);
35-
var response = ExecuteRequest<Item>();
36-
37-
return response;
21+
CreateAuthorizedRequest(ListingsItemsApiUrls.GetListingItem(listingsItemParameters.sellerId, listingsItemParameters.sku), RestSharp.Method.GET, queryParameters, parameter: listingsItemParameters);
22+
return ExecuteRequest<Item>();
3823
}
3924

4025
public ListingsItemSubmissionResponse PutListingsItem(ParameterPutListingItem parameterPutListingItem)

Source/FikaAmazonAPI/Utils/Constants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public class Constants
1212
public readonly static string AmazonToeknEndPoint = "https://api.amazon.com/auth/o2/token";
1313
public readonly static string DateISO8601Format = "yyyy-MM-ddTHH:mm:ss.fffZ";
1414
public readonly static string TestCase200 = "TEST_CASE_200";
15+
public readonly static string TestCase400 = "TEST_CASE_400";
1516

1617
[JsonConverter(typeof(StringEnumConverter))]
1718
public enum Environments

Source/FikaAmazonAPI/Utils/Sandbox.cs

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using FikaAmazonAPI.Parameter;
2-
using FikaAmazonAPI.Parameter.ListingsItems;
2+
using FikaAmazonAPI.Parameter.ListingItem;
33
using FikaAmazonAPI.Parameter.Order;
44
using FikaAmazonAPI.Search;
55
using System;
@@ -31,8 +31,64 @@ public static Dictionary<string, List<KeyValuePair<string, string>>> SandboxQuer
3131
queryParameters.Add(Constants.TestCase200, new List<KeyValuePair<string, string>>()
3232
{
3333
new KeyValuePair<string, string>("marketplaceIds", string.Join(",", parameterGetListingsItem.marketplaceIds)),
34-
//new KeyValuePair<string, string>("issueLocale", "en_US"),
35-
//new KeyValuePair<string, string>("includedData", "Summaries"),
34+
});
35+
}
36+
else if (testCase.Equals(Constants.TestCase400))
37+
{
38+
queryParameters.Add(Constants.TestCase400, new List<KeyValuePair<string, string>>()
39+
{
40+
new KeyValuePair<string, string>("marketplaceIds", string.Join(",", parameterGetListingsItem.marketplaceIds))
41+
});
42+
}
43+
}
44+
else if (instance is ParameterPutListingItem parameterPutListingsItem)
45+
{
46+
if (testCase.Equals(Constants.TestCase200))
47+
{
48+
queryParameters.Add(Constants.TestCase200, new List<KeyValuePair<string, string>>()
49+
{
50+
new KeyValuePair<string, string>("marketplaceIds", string.Join(",", parameterPutListingsItem.marketplaceIds)),
51+
});
52+
}
53+
else if (testCase.Equals(Constants.TestCase400))
54+
{
55+
queryParameters.Add(Constants.TestCase400, new List<KeyValuePair<string, string>>()
56+
{
57+
new KeyValuePair<string, string>("marketplaceIds", string.Join(",", parameterPutListingsItem.marketplaceIds))
58+
});
59+
}
60+
}
61+
else if (instance is ParameterDeleteListingItem parameterDeleteListingsItem)
62+
{
63+
if (testCase.Equals(Constants.TestCase200))
64+
{
65+
queryParameters.Add(Constants.TestCase200, new List<KeyValuePair<string, string>>()
66+
{
67+
new KeyValuePair<string, string>("marketplaceIds", string.Join(",", parameterDeleteListingsItem.marketplaceIds)),
68+
});
69+
}
70+
else if (testCase.Equals(Constants.TestCase400))
71+
{
72+
queryParameters.Add(Constants.TestCase400, new List<KeyValuePair<string, string>>()
73+
{
74+
new KeyValuePair<string, string>("marketplaceIds", string.Join(",", parameterDeleteListingsItem.marketplaceIds))
75+
});
76+
}
77+
}
78+
else if (instance is ParameterPatchListingItem parameterPatchListingItem)
79+
{
80+
if (testCase.Equals(Constants.TestCase200))
81+
{
82+
queryParameters.Add(Constants.TestCase200, new List<KeyValuePair<string, string>>()
83+
{
84+
new KeyValuePair<string, string>("marketplaceIds", string.Join(",", parameterPatchListingItem.marketplaceIds)),
85+
});
86+
}
87+
else if (testCase.Equals(Constants.TestCase400))
88+
{
89+
queryParameters.Add(Constants.TestCase400, new List<KeyValuePair<string, string>>()
90+
{
91+
new KeyValuePair<string, string>("marketplaceIds", string.Join(",", parameterPatchListingItem.marketplaceIds))
3692
});
3793
}
3894
}

0 commit comments

Comments
 (0)