Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 

Repository files navigation

SparkPostFun is a C# Library for SparkPost

SparkPostFun is a functional style C# library using LanguageExt for SparkPost API.

Features

  • 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.

Installation

To install via NuGet, run the following command in the Package Manager Console:

PM> Install-Package SparkPostFun

Usage

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 => ...);

Idiomatic Usage (Work in progress)

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

About

Functional style C# Library for SparkPost

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages