-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathEasyPostService.cs
More file actions
24 lines (22 loc) · 1018 Bytes
/
EasyPostService.cs
File metadata and controls
24 lines (22 loc) · 1018 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
using OrderCloud.Catalyst;
using OrderCloud.SDK;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrderCloud.Integrations.Shipping.EasyPost
{
public class EasyPostService : OCIntegrationService, IShippingRatesCalculator
{
public EasyPostService(EasyPostConfig defaultConfig) : base(defaultConfig) { }
public async Task<List<List<ShippingRate>>> CalculateShippingRatesAsync(IEnumerable<ShippingPackage> shippingPackages, OCIntegrationConfig overrideConfig = null)
{
var config = ValidateConfig<EasyPostConfig>(overrideConfig ?? _defaultConfig);
var easyPostShipments = shippingPackages.Select(p => EasyPostPackageMapper.ToEasyPostShipment(p, config.CarrierAccountIDs));
var responses = await Throttler.RunAsync(easyPostShipments, 100, 6, ship => EasyPostClient.PostShipmentAsync(ship, config));
var shipMethods = responses.Select(EasyPostRateMapper.ToOrderCloudShipMethods).ToList();
return shipMethods;
}
}
}