Skip to content

Commit

Permalink
Merge pull request #772 from prorena/main
Browse files Browse the repository at this point in the history
Fixed confusing exception message for ParameterPatchListingItem
  • Loading branch information
abuzuhri authored Oct 4, 2024
2 parents c162ab7 + cb85602 commit 5f2cc36
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 7 deletions.
39 changes: 39 additions & 0 deletions Source/FikaAmazonAPI.SampleCode/ListingstemsSample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using FikaAmazonAPI.Parameter.ListingItem;
using FikaAmazonAPI.Utils;

namespace FikaAmazonAPI.SampleCode
{
public class ListingsItemsSample
{
private readonly AmazonConnection amazonConnection;
public ListingsItemsSample(AmazonConnection amazonConnection)
{
this.amazonConnection = amazonConnection;
}

public async Task SetListingsItemAttribute(string sellerId)
{
var sku = "MP-23Q3W00058-Q898-03";
var marketPlace = MarketPlace.Germany;

PatchOperation[] patches = new PatchOperation[1];

patches[0] = new PatchOperation()
{
op = Op.replace,
path = "/attributes/gpsr_safety_attestation",
value = new object[] { true }
};

ParameterPatchListingItem parameter = new()
{
listingsItemPatchRequest = new ListingsItemPatchRequest() { patches = patches, productType = "BRA" },
sellerId = sellerId,
sku = sku,
marketplaceIds = new string[] { marketPlace.ID }
};

await amazonConnection.ListingsItem.PatchListingsItemAsync(parameter);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ public bool Check()
}
if (this.listingsItemPatchRequest == null)
{
throw new InvalidDataException("ListingsItemPutRequest is a required property for ParameterPatchListingItem and cannot be null");
throw new InvalidDataException("ListingsItemPatchRequest is a required property for ParameterPatchListingItem and cannot be null");
}
if (string.IsNullOrWhiteSpace(this.listingsItemPatchRequest.productType))
if (string.IsNullOrWhiteSpace(this.listingsItemPatchRequest.productType))
{
throw new InvalidDataException("ListingsItemPutRequest is a required property for ParameterPatchListingItem and cannot be null");
throw new InvalidDataException("ListingsItemPatchRequest.productType is a required property for ParameterPatchListingItem and cannot be null");
}
if (this.listingsItemPatchRequest.patches==null|| !this.listingsItemPatchRequest.patches.Any())
if (this.listingsItemPatchRequest.patches == null || !this.listingsItemPatchRequest.patches.Any())
{
throw new InvalidDataException("Patches is a required property for ParameterPatchListingItem and cannot be null");
}
return true;
return true;
}

public string sellerId { get; set; }
Expand All @@ -47,7 +47,7 @@ public bool Check()

public string issueLocale { get; set; }

public ListingsItemPatchRequest listingsItemPatchRequest { get; set; }
public ListingsItemPatchRequest listingsItemPatchRequest { get; set; }

}

Expand Down
8 changes: 7 additions & 1 deletion Source/FikaAmazonAPI/Parameter/ParameterBased.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using FikaAmazonAPI.Parameter;
using FikaAmazonAPI.Utils;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System;
using System.Collections;
using System.Collections.Generic;
Expand Down Expand Up @@ -67,7 +68,12 @@ public virtual List<KeyValuePair<string, string>> getParameters()
}
else
{
output = JsonConvert.SerializeObject(value);
var settings = new JsonSerializerSettings()
{
Converters = new List<JsonConverter>() { new StringEnumConverter() }
};

output = JsonConvert.SerializeObject(value, settings);
}


Expand Down

0 comments on commit 5f2cc36

Please sign in to comment.