Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump RestSharp from 108.0.2 to 112.0.0 in /coffeecard/CoffeeCard.Library #282

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion coffeecard/CoffeeCard.Library/CoffeeCard.Library.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<PackageReference Include="MimeKit" Version="4.7.1" />
<PackageReference Include="NetEscapades.Configuration.Validation" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
<PackageReference Include="RestSharp" Version="108.0.2" />
<PackageReference Include="RestSharp" Version="112.0.0" />
<PackageReference Include="Serilog.AspNetCore" Version="6.0.1" />
<PackageReference Include="Serilog.Enrichers.CorrelationId" Version="3.0.1" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.4.0" />
Expand Down
16 changes: 9 additions & 7 deletions coffeecard/CoffeeCard.Library/Services/MailgunEmailSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@

namespace CoffeeCard.Library.Services;

public class MailgunEmailSender(MailgunSettings mailgunSettings) : IEmailSender
public class MailgunEmailSender(MailgunSettings mailgunSettings, IRestClient restClient) : IEmailSender
{
public async Task SendEmailAsync(MimeMessage mail)
{
using var client = new RestClient(mailgunSettings.MailgunApiUrl);
client.Authenticator = new HttpBasicAuthenticator("api", mailgunSettings.ApiKey);

var request = new RestRequest();
request.AddParameter("domain", mailgunSettings.Domain, ParameterType.UrlSegment);
Expand All @@ -23,12 +21,16 @@ public async Task SendEmailAsync(MimeMessage mail)
request.AddParameter("html", mail.HtmlBody);
request.Method = Method.Post;

var response = await client.ExecutePostAsync(request);
var response = await restClient.ExecutePostAsync(request);

if (!response.IsSuccessful)
{
Log.Error("Error sending request to Mailgun. StatusCode: {statusCode} ErrorMessage: {errorMessage}",
response.StatusCode, response.ErrorMessage);
Log.Error(
"Error sending request to Mailgun. StatusCode: {statusCode} ErrorMessage: {errorMessage}",
response.StatusCode,
response.ErrorMessage
);
}
}
}
}

12 changes: 12 additions & 0 deletions coffeecard/CoffeeCard.WebApi/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
using NJsonSchema.Generation;
using NSwag;
using NSwag.Generation.Processors.Security;
using RestSharp;
using RestSharp.Authenticators;
using AccountService = CoffeeCard.Library.Services.AccountService;
using IAccountService = CoffeeCard.Library.Services.IAccountService;
using IPurchaseService = CoffeeCard.Library.Services.IPurchaseService;
Expand Down Expand Up @@ -95,6 +97,16 @@ public void ConfigureServices(IServiceCollection services)
services.AddScoped<ClaimsUtilities>();
services.AddSingleton(_environment.ContentRootFileProvider);

services.AddSingleton<IRestClient>(provider =>
{
var mailgunSettings = provider.GetRequiredService<MailgunSettings>();
var options = new RestClientOptions(mailgunSettings.MailgunApiUrl)
{
Authenticator = new HttpBasicAuthenticator("api", mailgunSettings.ApiKey),
};
return new RestClient(options);
});

services.AddScoped<Library.Services.v2.IPurchaseService, Library.Services.v2.PurchaseService>();
services.AddScoped<Library.Services.v2.ITicketService, Library.Services.v2.TicketService>();
services.AddMobilePayHttpClients(_configuration.GetSection("MobilePaySettingsV2").Get<MobilePaySettingsV2>());
Expand Down
Loading