Skip to content

Commit f8a453b

Browse files
committed
Align ShippingV2 models and ShippingServiceV2 helpers with Amazon Shipping API v2 docs
1 parent 2432c06 commit f8a453b

File tree

4 files changed

+217
-27
lines changed

4 files changed

+217
-27
lines changed

Source/FikaAmazonAPI/AmazonSpApiSDK/Models/ShippingV2/Event.cs

Lines changed: 96 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,58 +4,145 @@
44
using System.Collections.Generic;
55
using System.Runtime.Serialization;
66
using Newtonsoft.Json;
7+
using System.ComponentModel.DataAnnotations;
78

8-
namespace FikaAmazonAPI.AmazonSpApiSDK.Models.ShippingV2 {
9+
namespace FikaAmazonAPI.AmazonSpApiSDK.Models.ShippingV2
10+
{
911

1012
/// <summary>
1113
/// A tracking event.
1214
/// </summary>
1315
[DataContract]
14-
public class Event {
16+
public partial class Event : IEquatable<Event>, IValidatableObject
17+
{
1518
/// <summary>
1619
/// Gets or Sets EventCode
1720
/// </summary>
18-
[DataMember(Name="eventCode", EmitDefaultValue=false)]
21+
[DataMember(Name = "eventCode", EmitDefaultValue = false)]
1922
[JsonProperty(PropertyName = "eventCode")]
2023
public EventCode EventCode { get; set; }
2124

2225
/// <summary>
2326
/// Gets or Sets Location
2427
/// </summary>
25-
[DataMember(Name="location", EmitDefaultValue=false)]
28+
[DataMember(Name = "location", EmitDefaultValue = false)]
2629
[JsonProperty(PropertyName = "location")]
2730
public Location Location { get; set; }
2831

2932
/// <summary>
3033
/// The ISO 8601 formatted timestamp of the event.
3134
/// </summary>
3235
/// <value>The ISO 8601 formatted timestamp of the event.</value>
33-
[DataMember(Name="eventTime", EmitDefaultValue=false)]
36+
[DataMember(Name = "eventTime", EmitDefaultValue = false)]
3437
[JsonProperty(PropertyName = "eventTime")]
3538
public DateTime? EventTime { get; set; }
3639

40+
/// <summary>
41+
/// Gets or Sets ShipmentType
42+
/// </summary>
43+
[DataMember(Name = "shipmentType", EmitDefaultValue = false)]
44+
[JsonProperty(PropertyName = "shipmentType", NullValueHandling = NullValueHandling.Ignore)]
45+
public ShipmentType? ShipmentType { get; set; }
46+
3747

3848
/// <summary>
39-
/// Get the string presentation of the object
49+
/// Returns the string presentation of the object
4050
/// </summary>
4151
/// <returns>String presentation of the object</returns>
42-
public override string ToString() {
52+
public override string ToString()
53+
{
4354
var sb = new StringBuilder();
4455
sb.Append("class Event {\n");
4556
sb.Append(" EventCode: ").Append(EventCode).Append("\n");
4657
sb.Append(" Location: ").Append(Location).Append("\n");
4758
sb.Append(" EventTime: ").Append(EventTime).Append("\n");
59+
sb.Append(" ShipmentType: ").Append(ShipmentType).Append("\n");
4860
sb.Append("}\n");
4961
return sb.ToString();
5062
}
5163

64+
/// <summary>
65+
/// Returns true if objects are equal
66+
/// </summary>
67+
/// <param name="input">Object to be compared</param>
68+
/// <returns>Boolean</returns>
69+
public override bool Equals(object input)
70+
{
71+
return this.Equals(input as Event);
72+
}
73+
74+
/// <summary>
75+
/// Returns true if ModelEvent instances are equal
76+
/// </summary>
77+
/// <param name="input">Instance of ModelEvent to be compared</param>
78+
/// <returns>Boolean</returns>
79+
public bool Equals(Event input)
80+
{
81+
if (input == null)
82+
return false;
83+
84+
return
85+
(
86+
this.EventCode == input.EventCode ||
87+
(this.EventCode != null &&
88+
this.EventCode.Equals(input.EventCode))
89+
) &&
90+
(
91+
this.Location == input.Location ||
92+
(this.Location != null &&
93+
this.Location.Equals(input.Location))
94+
) &&
95+
(
96+
this.EventTime == input.EventTime ||
97+
(this.EventTime != null &&
98+
this.EventTime.Equals(input.EventTime))
99+
) &&
100+
(
101+
this.ShipmentType == input.ShipmentType ||
102+
(this.ShipmentType != null &&
103+
this.ShipmentType.Equals(input.ShipmentType))
104+
);
105+
}
106+
107+
/// <summary>
108+
/// Gets the hash code
109+
/// </summary>
110+
/// <returns>Hash code</returns>
111+
public override int GetHashCode()
112+
{
113+
unchecked // Overflow is fine, just wrap
114+
{
115+
int hashCode = 41;
116+
if (this.EventCode != null)
117+
hashCode = hashCode * 59 + this.EventCode.GetHashCode();
118+
if (this.Location != null)
119+
hashCode = hashCode * 59 + this.Location.GetHashCode();
120+
if (this.EventTime != null)
121+
hashCode = hashCode * 59 + this.EventTime.GetHashCode();
122+
if (this.ShipmentType != null)
123+
hashCode = hashCode * 59 + this.ShipmentType.GetHashCode();
124+
return hashCode;
125+
}
126+
}
127+
128+
/// <summary>
129+
/// To validate all properties of the instance
130+
/// </summary>
131+
/// <param name="validationContext">Validation context</param>
132+
/// <returns>Validation Result</returns>
133+
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
134+
{
135+
yield break;
136+
}
137+
52138
/// <summary>
53139
/// Get the JSON string presentation of the object
54140
/// </summary>
55141
/// <returns>JSON string presentation of the object</returns>
56-
public string ToJson() {
142+
public string ToJson()
143+
{
57144
return JsonConvert.SerializeObject(this, Formatting.Indented);
58145
}
59146

60-
}
147+
}
61148
}

Source/FikaAmazonAPI/AmazonSpApiSDK/Models/ShippingV2/EventCode.cs

Lines changed: 83 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,98 @@
44
using System.Collections.Generic;
55
using System.Runtime.Serialization;
66
using Newtonsoft.Json;
7+
using Newtonsoft.Json.Converters;
78

8-
namespace FikaAmazonAPI.AmazonSpApiSDK.Models.ShippingV2 {
9+
namespace FikaAmazonAPI.AmazonSpApiSDK.Models.ShippingV2
10+
{
911

1012
/// <summary>
1113
/// The tracking event type.
1214
/// </summary>
1315
[DataContract]
14-
public class EventCode {
1516

17+
/// <summary>
18+
/// The tracking event type.
19+
/// </summary>
20+
/// <value>The tracking event type.</value>
21+
[JsonConverter(typeof(StringEnumConverter))]
22+
public enum EventCode
23+
{
1624
/// <summary>
17-
/// Get the string presentation of the object
25+
/// Enum ReadyForReceive for value: ReadyForReceive
1826
/// </summary>
19-
/// <returns>String presentation of the object</returns>
20-
public override string ToString() {
21-
var sb = new StringBuilder();
22-
sb.Append("class EventCode {\n");
23-
sb.Append("}\n");
24-
return sb.ToString();
25-
}
26-
27+
[EnumMember(Value = "ReadyForReceive")]
28+
ReadyForReceive = 1,
29+
/// <summary>
30+
/// Enum PickupDone for value: PickupDone
31+
/// </summary>
32+
[EnumMember(Value = "PickupDone")]
33+
PickupDone = 2,
34+
/// <summary>
35+
/// Enum Delivered for value: Delivered
36+
/// </summary>
37+
[EnumMember(Value = "Delivered")]
38+
Delivered = 3,
39+
/// <summary>
40+
/// Enum Departed for value: Departed
41+
/// </summary>
42+
[EnumMember(Value = "Departed")]
43+
Departed = 4,
44+
/// <summary>
45+
/// Enum DeliveryAttempted for value: DeliveryAttempted
46+
/// </summary>
47+
[EnumMember(Value = "DeliveryAttempted")]
48+
DeliveryAttempted = 5,
49+
/// <summary>
50+
/// Enum Lost for value: Lost
51+
/// </summary>
52+
[EnumMember(Value = "Lost")]
53+
Lost = 6,
54+
/// <summary>
55+
/// Enum OutForDelivery for value: OutForDelivery
56+
/// </summary>
57+
[EnumMember(Value = "OutForDelivery")]
58+
OutForDelivery = 7,
59+
/// <summary>
60+
/// Enum ArrivedAtCarrierFacility for value: ArrivedAtCarrierFacility
61+
/// </summary>
62+
[EnumMember(Value = "ArrivedAtCarrierFacility")]
63+
ArrivedAtCarrierFacility = 8,
64+
/// <summary>
65+
/// Enum Rejected for value: Rejected
66+
/// </summary>
67+
[EnumMember(Value = "Rejected")]
68+
Rejected = 9,
69+
/// <summary>
70+
/// Enum Undeliverable for value: Undeliverable
71+
/// </summary>
72+
[EnumMember(Value = "Undeliverable")]
73+
Undeliverable = 10,
74+
/// <summary>
75+
/// Enum PickupCancelled for value: PickupCancelled
76+
/// </summary>
77+
[EnumMember(Value = "PickupCancelled")]
78+
PickupCancelled = 11,
79+
/// <summary>
80+
/// Enum ReturnInitiated for value: ReturnInitiated
81+
/// </summary>
82+
[EnumMember(Value = "ReturnInitiated")]
83+
ReturnInitiated = 12,
84+
/// <summary>
85+
/// Enum AvailableForPickup for value: AvailableForPickup
86+
/// </summary>
87+
[EnumMember(Value = "AvailableForPickup")]
88+
AvailableForPickup = 13,
89+
/// <summary>
90+
/// Enum RecipientRequestedAlternateDeliveryTiming for value: RecipientRequestedAlternateDeliveryTiming
91+
/// </summary>
92+
[EnumMember(Value = "RecipientRequestedAlternateDeliveryTiming")]
93+
RecipientRequestedAlternateDeliveryTiming = 14,
2794
/// <summary>
28-
/// Get the JSON string presentation of the object
95+
/// Enum PackageReceivedByCarrier for value: PackageReceivedByCarrier
2996
/// </summary>
30-
/// <returns>JSON string presentation of the object</returns>
31-
public string ToJson() {
32-
return JsonConvert.SerializeObject(this, Formatting.Indented);
33-
}
97+
[EnumMember(Value = "PackageReceivedByCarrier")]
98+
PackageReceivedByCarrier = 15
99+
}
34100

35-
}
36-
}
101+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using System.Text;
3+
using System.Collections;
4+
using System.Collections.Generic;
5+
using System.Runtime.Serialization;
6+
using Newtonsoft.Json;
7+
using Newtonsoft.Json.Converters;
8+
9+
namespace FikaAmazonAPI.AmazonSpApiSDK.Models.ShippingV2 {
10+
11+
/// <summary>
12+
/// Shipment type.
13+
/// </summary>
14+
/// <value>Shipment type.</value>
15+
[JsonConverter(typeof(StringEnumConverter))]
16+
public enum ShipmentType
17+
{
18+
19+
[EnumMember(Value = "FORWARD")]
20+
FORWARD = 1,
21+
22+
[EnumMember(Value = "RETURNS")]
23+
RETURNS = 2
24+
}
25+
26+
}
27+

Source/FikaAmazonAPI/Services/ShippingServiceV2.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,16 @@ public async Task<GetTrackingResult> GetTrackingAsync(string carrierId, string t
6868
return response.Payload;
6969
return null;
7070
}
71+
72+
public GetShipmentDocumentsResult GetShipmentDocuments(string shipmentId, string packageClientReferenceId, string format) =>
73+
Task.Run(() => GetShipmentDocumentsAsync(shipmentId, packageClientReferenceId, format)).ConfigureAwait(false).GetAwaiter().GetResult();
74+
public async Task<GetShipmentDocumentsResult> GetShipmentDocumentsAsync(string shipmentId, string packageClientReferenceId, string format, CancellationToken cancellationToken = default)
75+
{
76+
await CreateAuthorizedRequestAsync(ShippingApiV2Urls.GetShipmentDocuments(shipmentId, packageClientReferenceId, format), RestSharp.Method.Get, cancellationToken: cancellationToken);
77+
var response = await ExecuteRequestAsync<GetShipmentDocumentsResponse>(RateLimitType.ShippingV2_GetShipmentDocument, cancellationToken);
78+
if (response != null && response.Payload != null)
79+
return response.Payload;
80+
return null;
81+
}
7182
}
7283
}

0 commit comments

Comments
 (0)