-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStampsTrackingProvider.cs
More file actions
51 lines (43 loc) · 1.78 KB
/
StampsTrackingProvider.cs
File metadata and controls
51 lines (43 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using EasyKeys.Shipping.Abstractions.Models;
using EasyKeys.Shipping.Stamps.Abstractions.Services;
using StampsClient.v111;
namespace EasyKeys.Shipping.Stamps.Tracking
{
public class StampsTrackingProvider : IStampsTrackingProvider
{
private readonly IStampsClientService _stampsClient;
public StampsTrackingProvider(IStampsClientService stampsClient)
{
_stampsClient = stampsClient ?? throw new ArgumentNullException(nameof(stampsClient));
}
public async Task<TrackingInformation> TrackShipmentAsync(string trackingId, CancellationToken cancellationToken)
{
var trackingInformation = new TrackingInformation();
var trackRequest = new TrackShipmentRequest()
{
Item1 = trackingId,
Carrier = Carrier.All
};
try
{
var trackingResults = await _stampsClient.TrackShipmentAsync(trackRequest, cancellationToken);
foreach (var trackingEvent in trackingResults.TrackingEvents)
{
var address = new Shipping.Abstractions.Models.Address(trackingEvent.City, trackingEvent.State, trackingEvent.Zip, trackingEvent.Country);
trackingInformation.TrackingEvents.Add(new TrackingEvent()
{
Event = trackingEvent.Event,
TimeStamp = trackingEvent.Timestamp,
SignedBy = trackingEvent.SignedBy,
Address = address,
});
}
}
catch (Exception ex)
{
trackingInformation.InternalErrors.Add(ex.Message);
}
return trackingInformation;
}
}
}