first commit
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user