47 lines
1.2 KiB
C#
47 lines
1.2 KiB
C#
using System.Xml.Linq;
|
|
using Microsoft.Extensions.Options;
|
|
using Serilog;
|
|
using USPS.Configuration;
|
|
|
|
namespace USPS.Communication
|
|
{
|
|
public class UspsService : IUspsService
|
|
{
|
|
private readonly UspsSettings _settings;
|
|
|
|
public UspsService(
|
|
IOptions<UspsSettings> settings)
|
|
{
|
|
|
|
_settings = settings.Value;
|
|
}
|
|
|
|
public async Task<XElement> SendMessage(string request)
|
|
{
|
|
try
|
|
{
|
|
var hc = new HttpClient();
|
|
var result = await hc.GetAsync(request);
|
|
|
|
if (result.IsSuccessStatusCode)
|
|
{
|
|
var resultString = await result.Content.ReadAsStringAsync();
|
|
var xdoc = XDocument.Parse(resultString);
|
|
XElement xel = XElement.Parse(xdoc.ToString());
|
|
return xel;
|
|
}
|
|
else
|
|
{
|
|
throw new Exception("Bad status code from USPS");
|
|
}
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Debug("{exception}", e.Message);
|
|
throw;
|
|
}
|
|
}
|
|
}
|
|
}
|