SparkPostFun is a functional style C# library using LanguageExt for SparkPost API.
- All client calls returns
Task<Either<TError, TResponse>>monad. - Invalid states unrepresentable - required fields are obvious when constructing requests.
- Immutable data.
- Doesn't throw exceptions.
To install via NuGet, run the following command in the Package Manager Console:
PM> Install-Package SparkPostFun
var content = new StoredTemplateContent("black_friday")
{
UseDraftTemplate = true
};
var substitutionData = new Dictionary<string, object>
{
["discount"] = "25%"
};
var recipient = new Recipient(new Address("wilma@flintstone.com") { Name = "Wilma Flintstone" })
{
SubstitutionData = new Dictionary<string, object>
{
["first_name"] = "Wilma",
["last_name"] = "Flintstone"
}
};
var transmission = TransmissionExtensions.CreateTransmission(recipient, content)
.WithSubstitutionData(substitutionData);
var response = await client.CreateTransmission(transmission);
response.Match(
success => ...,
fail => ...);There are extension method helpers that can wrap the client return type if you prefer a more idiomatic approach.
var response = await ResponseExtensions.Wrap(client.CreateTransmission(transmission));
if(response.StatusCode == HttpStatusCode.OK) {
...
}To use this extension method helpers, you also need to install the SparkPostFun.ResponseWrappers NuGet package.
Completed Wrappers
- Sending
- Transmission
- Sending Domains
- Tracking Domains
- Templates
- A/B Testing
- Snippets
- Recipient Lists
- Recipient Validation
- Suppression List
- Sending IPs
- IP Pools
- Accounts
- Account
- Subaccounts
- Data Privacy