<commit_before>package kodingemail

import (
	"github.com/sendgrid/sendgrid-go"
	"github.com/sendgrid/smtpapi-go"
)

var (
	DefaultFromAddress = "<EMAIL>"
	DefaultFromName    = "Koding"
)

type Client interface {
	SendTemplateEmail(string, string, Options) error
}

type SenderClient interface {
	Send(*sendgrid.SGMail) error
}

type SG struct {
	FromAddress, FromName string
	SenderClient          SenderClient
}

func New(username, password string) Client {
	return New(username, password)
}

func NewSG(username, password string) *SG {
	return &SG{
		FromAddress: DefaultFromAddress, FromName: DefaultFromName,
		SenderClient: sendgrid.NewSendGridClient(username, password),
	}
}

func (s *SG) SendTemplateEmail(to, tId string, sub Options) error {
	message := sendgrid.NewMail()

	// sendgrid api requries non empty values, but I decided to put
	// all the required info in template itself since it's easier to
	// edit in sendgrid ui than to edit in code and redeploy
	message.SetSubject(" ")
	message.SetHTML(" ")

	for key, value := range sub {
		message.AddSubstitution(key, value)
	}

	filter := &smtpapi.Filter{
		Settings: map[string]string{"enabled": "1", "template_id": tId},
	}

	message.SetFilter("templates", filter)
	message.SetFrom(s.FromAddress)
	message.SetFromName(s.FromName)

	message.AddTo(to)

	return s.SenderClient.Send(message)
}
<commit_msg>paymentwebhook: add docs to kodingemail<commit_after>package kodingemail

import (
	"github.com/sendgrid/sendgrid-go"
	"github.com/sendgrid/smtpapi-go"
)

var (
	DefaultFromAddress = "<EMAIL>"
	DefaultFromName    = "Koding"
)

// The default interface to send emails.
type Client interface {
	SendTemplateEmail(string, string, Options) error
}

func New(username, password string) Client {
	return New(username, password)
}

// This interface defines the implementation of those sending emails.
type SenderClient interface {
	Send(*sendgrid.SGMail) error
}

// Sengrid implementation of `Client`.
type SG struct {
	FromAddress, FromName string
	SenderClient          SenderClient
}

func NewSG(username, password string) *SG {
	return &SG{
		FromAddress: DefaultFromAddress, FromName: DefaultFromName,
		SenderClient: sendgrid.NewSendGridClient(username, password),
	}
}

func (s *SG) SendTemplateEmail(to, tId string, sub Options) error {
	message := sendgrid.NewMail()

	// sendgrid api requries non empty values, but I decided to put
	// all the required info in template itself since it's easier to
	// edit in sendgrid ui than to edit in code and redeploy
	message.SetSubject(" ")
	message.SetHTML(" ")

	for key, value := range sub {
		message.AddSubstitution(key, value)
	}

	filter := &smtpapi.Filter{
		Settings: map[string]string{"enabled": "1", "template_id": tId},
	}

	message.SetFilter("templates", filter)
	message.SetFrom(s.FromAddress)
	message.SetFromName(s.FromName)

	message.AddTo(to)

	return s.SenderClient.Send(message)
}

{'fraction_non_alphanumeric': 0.1083676268861454, 'fraction_numerical': 0.0006858710562414266, 'mean_word_length': 4.697265625, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5615738', 'n_tokens_mistral': 957, 'n_tokens_neox': 923, 'n_words': 261}