Skip to content

Commit 3eb8bac

Browse files
committed
chore(replenishment): sync Replenishment API models and service with upstream v1.9.28
Replace AMZDW fork's Replenishment implementation with the upstream-accepted version from abuzuhri/Amazon-SP-API-CSharp v1.9.28. Upstream incorporated the original PR and extended the models: ListOfferMetricsResponseOffer now correctly reflects the flat API response structure, and the request models have been updated to use JsonProperty throughout with revised pagination fields. Also renames ReplenishmentApi url class references to ReplenishmentApiUrls to match the naming convention used in ApiUrls.cs.
1 parent 9623a18 commit 3eb8bac

30 files changed

Lines changed: 304 additions & 688 deletions
Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,17 @@
1-
using Newtonsoft.Json;
1+
using Newtonsoft.Json;
22
using Newtonsoft.Json.Converters;
33

44
namespace FikaAmazonAPI.AmazonSpApiSDK.Models.Replenishment
55
{
66
/// <summary>
7-
/// Enum representing different aggregation frequencies for data.
7+
/// The time period used to group data in the response. Only valid for the PERFORMANCE time period type.
88
/// </summary>
99
[JsonConverter(typeof(StringEnumConverter))]
1010
public enum AggregationFrequency
1111
{
12-
/// <summary>
13-
/// ISO Calendar Week
14-
/// </summary>
1512
WEEK,
16-
/// <summary>
17-
/// ISO Calendar Month
18-
/// </summary>
1913
MONTH,
20-
/// <summary>
21-
/// ISO Calendar Quarter
22-
/// </summary>
2314
QUARTER,
24-
/// <summary>
25-
/// ISO Calendar Year
26-
/// </summary>
2715
YEAR
2816
}
29-
}
17+
}

Source/FikaAmazonAPI/AmazonSpApiSDK/Models/Replenishment/AutoEnrollmentPreference.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,11 @@
33

44
namespace FikaAmazonAPI.AmazonSpApiSDK.Models.Replenishment
55
{
6-
/// <summary>
7-
/// The seller's preference for automatic enrollment in the replenishment program.
8-
/// </summary>
6+
/// <summary>Auto-enrollment preference: OPTED_IN or OPTED_OUT.</summary>
97
[JsonConverter(typeof(StringEnumConverter))]
108
public enum AutoEnrollmentPreference
119
{
12-
/// <summary>The seller has opted in to automatic enrollment.</summary>
1310
OPTED_IN,
14-
15-
/// <summary>The seller has opted out of automatic enrollment.</summary>
1611
OPTED_OUT
1712
}
1813
}

Source/FikaAmazonAPI/AmazonSpApiSDK/Models/Replenishment/EligibilityStatus.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,13 @@
33

44
namespace FikaAmazonAPI.AmazonSpApiSDK.Models.Replenishment
55
{
6-
/// <summary>
7-
/// The eligibility status of an offer in the replenishment program.
8-
/// </summary>
6+
/// <summary>The current eligibility status of an offer.</summary>
97
[JsonConverter(typeof(StringEnumConverter))]
108
public enum EligibilityStatus
119
{
12-
/// <summary>The offer is eligible for the replenishment program.</summary>
1310
ELIGIBLE,
14-
15-
/// <summary>The offer is not eligible for the replenishment program.</summary>
1611
INELIGIBLE,
17-
18-
/// <summary>The offer has been suspended from the replenishment program.</summary>
1912
SUSPENDED,
20-
21-
/// <summary>The offer is available for replenishment-only ordering.</summary>
2213
REPLENISHMENT_ONLY_ORDERING
2314
}
2415
}

Source/FikaAmazonAPI/AmazonSpApiSDK/Models/Replenishment/EnrollmentMethod.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,11 @@
33

44
namespace FikaAmazonAPI.AmazonSpApiSDK.Models.Replenishment
55
{
6-
/// <summary>
7-
/// The method by which an offer was enrolled in the replenishment program.
8-
/// </summary>
6+
/// <summary>The enrollment method used to enroll the offer into the program.</summary>
97
[JsonConverter(typeof(StringEnumConverter))]
108
public enum EnrollmentMethod
119
{
12-
/// <summary>The offer was manually enrolled by the seller.</summary>
1310
MANUAL,
14-
15-
/// <summary>The offer was automatically enrolled by Amazon.</summary>
1611
AUTOMATIC
1712
}
1813
}
Lines changed: 13 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -1,133 +1,28 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.ComponentModel.DataAnnotations;
4-
using System.Runtime.Serialization;
51
using Newtonsoft.Json;
2+
using System.Collections.Generic;
63

74
namespace FikaAmazonAPI.AmazonSpApiSDK.Models.Replenishment
85
{
9-
public class GetSellingPartnerMetricsRequest : IEquatable<GetSellingPartnerMetricsRequest>, IValidatableObject
6+
/// <summary>Request body for getSellingPartnerMetrics.</summary>
7+
public class GetSellingPartnerMetricsRequest
108
{
11-
[JsonConstructor]
12-
public GetSellingPartnerMetricsRequest() { }
13-
14-
/// <summary>
15-
/// An optional time period used to group data in the response.
16-
/// </summary>
17-
/// <remarks>
18-
/// This is only valid for the PERFORMANCE time period type.
19-
/// </remarks>
20-
[DataMember(Name = "aggregationFrequency", EmitDefaultValue = false)]
9+
[JsonProperty("aggregationFrequency")]
2110
public AggregationFrequency? AggregationFrequency { get; set; }
2211

23-
/// <summary>
24-
/// A time interval used to compute metrics.
25-
/// </summary>
26-
[DataMember(Name = "timeInterval", EmitDefaultValue = false)]
12+
[JsonProperty("timeInterval")]
2713
public TimeInterval TimeInterval { get; set; }
2814

29-
/// <summary>
30-
/// An optional list of metrics to request. If no metric value is provided, data for all metrics will be returned.
31-
/// </summary>
32-
[DataMember(Name = "metrics", EmitDefaultValue = false)]
33-
public Metric[] Metrics { get; set; }
15+
/// <summary>If null, all metrics are returned.</summary>
16+
[JsonProperty("metrics")]
17+
public List<Metric> Metrics { get; set; }
3418

35-
/// <summary>
36-
/// The time period type that determines whether the metrics requested are backward-looking (performance)
37-
/// or forward-looking (forecast).
38-
/// </summary>
39-
[DataMember(Name = "timePeriodType", EmitDefaultValue = false)]
19+
[JsonProperty("timePeriodType")]
4020
public TimePeriodType TimePeriodType { get; set; }
4121

42-
/// <summary>
43-
/// Amazon marketplace identifier.
44-
/// </summary>
45-
[DataMember(Name = "marketplaceId", EmitDefaultValue = false)]
22+
[JsonProperty("marketplaceId")]
4623
public string MarketplaceId { get; set; }
4724

48-
/// <summary>
49-
/// A list of replenishment program types for which to return metrics.
50-
/// </summary>
51-
[DataMember(Name = "programTypes", EmitDefaultValue = false)]
52-
public ProgramType[] ProgramTypes { get; set; }
53-
54-
/// <inheritdoc />
55-
public bool Equals(GetSellingPartnerMetricsRequest other)
56-
{
57-
if (other == null)
58-
return false;
59-
60-
return AggregationFrequency == other.AggregationFrequency &&
61-
Equals(TimeInterval, other.TimeInterval) &&
62-
Equals(Metrics, other.Metrics) &&
63-
TimePeriodType == other.TimePeriodType &&
64-
string.Equals(MarketplaceId, other.MarketplaceId, StringComparison.Ordinal);
65-
}
66-
67-
/// <inheritdoc />
68-
public override bool Equals(object obj)
69-
{
70-
if (obj is GetSellingPartnerMetricsRequest otherRequest)
71-
return Equals(otherRequest);
72-
73-
return false;
74-
}
75-
76-
/// <inheritdoc />
77-
public override int GetHashCode()
78-
{
79-
int hash = 17;
80-
hash = hash * 23 + (AggregationFrequency != null ? AggregationFrequency.GetHashCode() : 0);
81-
hash = hash * 23 + (TimeInterval != null ? TimeInterval.GetHashCode() : 0);
82-
hash = hash * 23 + (Metrics != null ? GetArrayHashCode(Metrics) : 0);
83-
hash = hash * 23 + TimePeriodType.GetHashCode();
84-
hash = hash * 23 + (MarketplaceId != null ? MarketplaceId.GetHashCode() : 0);
85-
return hash;
86-
}
87-
88-
/// <summary>
89-
/// Calculates the hash code for an array.
90-
/// </summary>
91-
/// <param name="array">The array for which to calculate the hash code.</param>
92-
/// <returns>The hash code value calculated based on the elements of the array.</returns>
93-
private int GetArrayHashCode<T>(T[] array)
94-
{
95-
if (array == null) return 0;
96-
int hash = 17;
97-
foreach (var item in array)
98-
{
99-
hash = hash * 23 + (item != null ? item.GetHashCode() : 0);
100-
}
101-
102-
return hash;
103-
}
104-
105-
/// <inheritdoc />
106-
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
107-
{
108-
// Ensure MarketplaceId is not null or empty
109-
if (string.IsNullOrWhiteSpace(MarketplaceId))
110-
{
111-
yield return new ValidationResult(
112-
"MarketplaceId is required.",
113-
new[] { nameof(MarketplaceId) });
114-
}
115-
116-
// Ensure TimeInterval is not null
117-
if (TimeInterval == null)
118-
{
119-
yield return new ValidationResult(
120-
"TimeInterval is required.",
121-
new[] { nameof(TimeInterval) });
122-
}
123-
124-
// AggregationFrequency is only valid when TimePeriodType is PERFORMANCE
125-
if (TimePeriodType != TimePeriodType.PERFORMANCE && AggregationFrequency != null)
126-
{
127-
yield return new ValidationResult(
128-
$"{nameof(AggregationFrequency)} is only valid when {nameof(TimePeriodType)} is " +
129-
$"{nameof(TimePeriodType.PERFORMANCE)}.", new[] { nameof(AggregationFrequency) });
130-
}
131-
}
25+
[JsonProperty("programTypes")]
26+
public List<ProgramType> ProgramTypes { get; set; }
13227
}
133-
}
28+
}
Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1+
using Newtonsoft.Json;
12
using System.Collections.Generic;
2-
using System.Runtime.Serialization;
33

44
namespace FikaAmazonAPI.AmazonSpApiSDK.Models.Replenishment
55
{
6-
/// <summary>
7-
/// The response body for the getSellingPartnerMetrics operation.
8-
/// </summary>
6+
/// <summary>Response schema for getSellingPartnerMetrics.</summary>
97
public class GetSellingPartnerMetricsResponse
108
{
11-
/// <summary>
12-
/// A list of metrics for the selling partner account.
13-
/// </summary>
14-
[DataMember(Name = "metrics", EmitDefaultValue = false)]
15-
public List<ReplenishmentMetric> Metrics { get; set; }
9+
[JsonProperty("metrics")]
10+
public List<GetSellingPartnerMetricsResponseMetric> Metrics { get; set; }
1611
}
1712
}
Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,17 @@
1-
using System.Runtime.Serialization;
21
using Newtonsoft.Json;
32

43
namespace FikaAmazonAPI.AmazonSpApiSDK.Models.Replenishment
54
{
6-
/// <summary>
7-
/// The request body for the listOfferMetrics operation.
8-
/// </summary>
5+
/// <summary>Request body for listOfferMetrics.</summary>
96
public class ListOfferMetricsRequest
107
{
11-
[JsonConstructor]
12-
public ListOfferMetricsRequest() { }
13-
14-
/// <summary>
15-
/// Pagination parameters for the response.
16-
/// </summary>
17-
[DataMember(Name = "pagination", EmitDefaultValue = false)]
8+
[JsonProperty("pagination")]
189
public ListOfferMetricsRequestPagination Pagination { get; set; }
1910

20-
/// <summary>
21-
/// Filters to apply to the results.
22-
/// </summary>
23-
[DataMember(Name = "filters", EmitDefaultValue = false)]
24-
public ListOfferMetricsRequestFilters Filters { get; set; }
25-
26-
/// <summary>
27-
/// Sort options for the results.
28-
/// </summary>
29-
[DataMember(Name = "sort", EmitDefaultValue = false)]
11+
[JsonProperty("sort")]
3012
public ListOfferMetricsRequestSort Sort { get; set; }
13+
14+
[JsonProperty("filters")]
15+
public ListOfferMetricsRequestFilters Filters { get; set; }
3116
}
3217
}
Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,30 @@
1+
using Newtonsoft.Json;
12
using System.Collections.Generic;
2-
using System.Runtime.Serialization;
33

44
namespace FikaAmazonAPI.AmazonSpApiSDK.Models.Replenishment
55
{
66
/// <summary>
7-
/// Use this parameter to filter the results.
7+
/// Filters for listOfferMetrics. timeInterval, timePeriodType, programTypes, and marketplaceId are required.
88
/// </summary>
99
public class ListOfferMetricsRequestFilters
1010
{
11-
/// <summary>
12-
/// An optional time period used to group data in the response.
13-
/// </summary>
14-
[DataMember(Name = "aggregationFrequency", EmitDefaultValue = false)]
11+
[JsonProperty("aggregationFrequency")]
1512
public AggregationFrequency? AggregationFrequency { get; set; }
1613

17-
/// <summary>
18-
/// A time interval used to compute metrics.
19-
/// </summary>
20-
[DataMember(Name = "timeInterval", EmitDefaultValue = false)]
14+
[JsonProperty("timeInterval")]
2115
public TimeInterval TimeInterval { get; set; }
2216

23-
/// <summary>
24-
/// The time period type that determines whether metrics are backward-looking (performance) or forward-looking (forecast).
25-
/// </summary>
26-
[DataMember(Name = "timePeriodType", EmitDefaultValue = false)]
17+
[JsonProperty("timePeriodType")]
2718
public TimePeriodType TimePeriodType { get; set; }
2819

29-
/// <summary>
30-
/// Amazon marketplace identifier.
31-
/// </summary>
32-
[DataMember(Name = "marketplaceId", EmitDefaultValue = false)]
20+
[JsonProperty("marketplaceId")]
3321
public string MarketplaceId { get; set; }
3422

35-
/// <summary>
36-
/// A list of replenishment program types by which to filter results.
37-
/// </summary>
38-
[DataMember(Name = "programTypes", EmitDefaultValue = false)]
23+
[JsonProperty("programTypes")]
3924
public List<ProgramType> ProgramTypes { get; set; }
4025

41-
/// <summary>
42-
/// A list of ASINs by which to filter results.
43-
/// </summary>
44-
[DataMember(Name = "asins", EmitDefaultValue = false)]
26+
/// <summary>1–20 ASINs.</summary>
27+
[JsonProperty("asins")]
4528
public List<string> Asins { get; set; }
4629
}
4730
}
Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
using System.Runtime.Serialization;
1+
using Newtonsoft.Json;
22

33
namespace FikaAmazonAPI.AmazonSpApiSDK.Models.Replenishment
44
{
5-
/// <summary>
6-
/// Use this parameter to paginate through the response.
7-
/// </summary>
5+
/// <summary>Pagination for listOfferMetrics (limit 1–500, offset 0–9000).</summary>
86
public class ListOfferMetricsRequestPagination
97
{
10-
/// <summary>
11-
/// The number of results to return per page.
12-
/// </summary>
13-
[DataMember(Name = "numberOfResults", EmitDefaultValue = false)]
14-
public int? NumberOfResults { get; set; }
8+
[JsonProperty("limit")]
9+
public long Limit { get; set; } = 500;
10+
11+
[JsonProperty("offset")]
12+
public long Offset { get; set; } = 0;
1513
}
1614
}

0 commit comments

Comments
 (0)