Skip to content

Commit

Permalink
cleanup: credentials: remove old code
Browse files Browse the repository at this point in the history
  • Loading branch information
grokify committed Jul 30, 2021
1 parent 48f243e commit 813fe7e
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions sparkpost/examples/send_ics/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"github.com/grokify/oauth2more/sparkpost"
)

const DefaultExampleEmail = "[email protected]"

type appConfig struct {
SparkPostApiKey string `env:"SPARKPOST_API_KEY"`
SparkPostEmailSender string `env:"SPARKPOST_EMAIL_SENDER"`
Expand All @@ -31,6 +33,10 @@ func sendTestEmail(cfg appConfig, client sp.Client) {
day := 811 // Change this to set the day. This currently uses single digit month + 2 digit day
seq := 0 // Sequence index. Start with 0 and increment. This demo doesn't support changing the day when changing sequence.

if len(strings.TrimSpace(cfg.SparkPostEmailRecipientDemo)) == 0 {
cfg.SparkPostEmailRecipientDemo = DefaultExampleEmail
}

format := `BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//MY COMPANY//Calendar//EN
Expand Down Expand Up @@ -72,6 +78,7 @@ END:VCALENDAR`
attendee, uid2, day, day, dtNow, seq)

fmt.Println(data)
panic("z")
attach := sp.Attachment{
MIMEType: hum.ContentTypeTextCalendarUtf8Request,
B64Data: base64.StdEncoding.EncodeToString([]byte(data))}
Expand All @@ -97,6 +104,56 @@ END:VCALENDAR`
Str("email-id", id)
}

func buildExampleIcs(recipientSmtpAddr string, dtStart, dtEnd time.Time, seq uint) string {
if len(strings.TrimSpace(recipientSmtpAddr)) == 0 {
recipientSmtpAddr = DefaultExampleEmail
}
// seq = Sequence index. Start with 0 and increment. This demo doesn't support changing the day when changing sequence.

day := 811 // Change this to set the day. This currently uses single digit month + 2 digit day

format := `BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//MY COMPANY//Calendar//EN
CALSCALE:GREGORIAN
METHOD:%v
BEGIN:VEVENT
%vUID:shift-%[email protected]
DTSTART:20180%vT010000
DTEND:20180%vT020000
DTSTAMP:%v
SEQUENCE:%v
SUMMARY:Morning shift
LOCATION:Morning Location
DESCRIPTION:Morning shift
END:VEVENT
BEGIN:VEVENT
%vUID:shift-%[email protected]
DTSTART:20180%vT130000
DTEND:20180%vT140000
DTSTAMP:%v
SEQUENCE:%v
SUMMARY:Night shift
LOCATION:Night Location
DESCRIPTION:Night
END:VEVENT
END:VCALENDAR`

//attenddee needed for both events
attendee := fmt.Sprintf(
"ATTENDEE;ROLE=REQ-PARTICIPANT;CN=%s:MAILTO:%s\n",
recipientSmtpAddr, recipientSmtpAddr)

uid1 := day + 1000
uid2 := uid1 + 1
dtNow := time.Now().Format(tu.ISO8601CompactNoTZ)
icsData := fmt.Sprintf(
format, "REQUEST",
attendee, uid1, day, day, dtNow, seq,
attendee, uid2, day, day, dtNow, seq)
return icsData
}

func main() {
envFiles := []string{os.Getenv("ENV_PATH"), "./.env"}
if err := config.LoadDotEnvSkipEmpty(envFiles...); err != nil {
Expand Down

0 comments on commit 813fe7e

Please sign in to comment.