mailgun dep

This commit is contained in:
Patrick Nagurny
2020-11-23 11:12:53 -05:00
parent b011b28cf5
commit ece803ec68
242 changed files with 25496 additions and 11732 deletions

View File

@@ -0,0 +1,57 @@
package events
const (
EventAccepted = "accepted"
EventRejected = "rejected"
EventDelivered = "delivered"
EventFailed = "failed"
EventOpened = "opened"
EventClicked = "clicked"
EventUnsubscribed = "unsubscribed"
EventComplained = "complained"
EventStored = "stored"
EventDropped = "dropped"
EventListMemberUploaded = "list_member_uploaded"
EventListMemberUploadError = "list_member_upload_error"
EventListUploaded = "list_uploaded"
)
const (
TransportHTTP = "http"
TransportSMTP = "smtp"
DeviceUnknown = "unknown"
DeviceMobileBrowser = "desktop"
DeviceBrowser = "mobile"
DeviceEmail = "tablet"
DeviceOther = "other"
ClientUnknown = "unknown"
ClientMobileBrowser = "mobile browser"
ClientBrowser = "browser"
ClientEmail = "email client"
ClientLibrary = "library"
ClientRobot = "robot"
ClientOther = "other"
ReasonUnknown = "unknown"
ReasonGeneric = "generic"
ReasonBounce = "bounce"
ReasonESPBlock = "espblock"
ReasonGreylisted = "greylisted"
ReasonBlacklisted = "blacklisted"
ReasonSuppressBounce = "suppress-bounce"
ReasonSuppressComplaint = "suppress-complaint"
ReasonSuppressUnsubscribe = "suppress-unsubscribe"
ReasonOld = "old"
ReasonHardFail = "hardfail"
SeverityUnknown = "unknown"
SeverityTemporary = "temporary"
SeverityPermanent = "permanent"
SeverityInternal = "internal"
MethodUnknown = "unknown"
MethodSMTP = "smtp"
MethodHTTP = "http"
)

View File

@@ -0,0 +1,265 @@
package events
import (
"strings"
"time"
)
// An EventName is a struct with the event name.
type EventName struct {
Name string `json:"event"`
}
// GetName returns the name of the event.
func (e *EventName) GetName() string {
return strings.ToLower(e.Name)
}
func (e *EventName) SetName(name string) {
e.Name = strings.ToLower(name)
}
type Generic struct {
EventName
Timestamp float64 `json:"timestamp"`
ID string `json:"id"`
}
func (g *Generic) GetTimestamp() time.Time {
return time.Unix(0, int64(g.Timestamp*float64(time.Second))).UTC()
}
func (g *Generic) SetTimestamp(t time.Time) {
// convert := fmt.Sprintf("%d.%06d", t.Unix(), t.Nanosecond()/int(time.Microsecond))
// ts, err := strconv.ParseFloat(convert, 64)
g.Timestamp = float64(t.Unix()) + (float64(t.Nanosecond()/int(time.Microsecond)) / float64(1000000))
}
func (g *Generic) GetID() string {
return g.ID
}
func (g *Generic) SetID(id string) {
g.ID = id
}
//
// Message Events
//
type Accepted struct {
Generic
Envelope Envelope `json:"envelope"`
Message Message `json:"message"`
Flags Flags `json:"flags"`
Recipient string `json:"recipient"`
RecipientDomain string `json:"recipient-domain"`
Method string `json:"method"`
OriginatingIP string `json:"originating-ip"`
Tags []string `json:"tags"`
Campaigns []Campaign `json:"campaigns"`
UserVariables interface{} `json:"user-variables"`
Storage Storage `json:"storage"`
}
type Rejected struct {
Generic
Reject struct {
Reason string `json:"reason"`
Description string `json:"description"`
} `json:"reject"`
Message Message `json:"message"`
Storage Storage `json:"storage"`
Flags Flags `json:"flags"`
Tags []string `json:"tags"`
Campaigns []Campaign `json:"campaigns"`
UserVariables interface{} `json:"user-variables"`
}
type Delivered struct {
Generic
Envelope Envelope `json:"envelope"`
Message Message `json:"message"`
Flags Flags `json:"flags"`
Recipient string `json:"recipient"`
RecipientDomain string `json:"recipient-domain"`
Method string `json:"method"`
Tags []string `json:"tags"`
Campaigns []Campaign `json:"campaigns"`
Storage Storage `json:"storage"`
DeliveryStatus DeliveryStatus `json:"delivery-status"`
UserVariables interface{} `json:"user-variables"`
}
type Failed struct {
Generic
Envelope Envelope `json:"envelope"`
Message Message `json:"message"`
Flags Flags `json:"flags"`
Recipient string `json:"recipient"`
RecipientDomain string `json:"recipient-domain"`
Method string `json:"method"`
Tags []string `json:"tags"`
Campaigns []Campaign `json:"campaigns"`
Storage Storage `json:"storage"`
DeliveryStatus DeliveryStatus `json:"delivery-status"`
Severity string `json:"severity"`
Reason string `json:"reason"`
UserVariables interface{} `json:"user-variables"`
}
type Stored struct {
Generic
Message Message `json:"message"`
Storage Storage `json:"storage"`
Flags Flags `json:"flags"`
Tags []string `json:"tags"`
Campaigns []Campaign `json:"campaigns"`
UserVariables interface{} `json:"user-variables"`
}
//
// Message Events (User)
//
type Opened struct {
Generic
Message Message `json:"message"`
Campaigns []Campaign `json:"campaigns"`
MailingList MailingList `json:"mailing-list"`
Recipient string `json:"recipient"`
RecipientDomain string `json:"recipient-domain"`
Tags []string `json:"tags"`
IP string `json:"ip"`
ClientInfo ClientInfo `json:"client-info"`
GeoLocation GeoLocation `json:"geolocation"`
UserVariables interface{} `json:"user-variables"`
}
type Clicked struct {
Generic
Url string `json:"url"`
Message Message `json:"message"`
Campaigns []Campaign `json:"campaigns"`
MailingList MailingList `json:"mailing-list"`
Recipient string `json:"recipient"`
RecipientDomain string `json:"recipient-domain"`
Tags []string `json:"tags"`
IP string `json:"ip"`
ClientInfo ClientInfo `json:"client-info"`
GeoLocation GeoLocation `json:"geolocation"`
UserVariables interface{} `json:"user-variables"`
}
type Unsubscribed struct {
Generic
Message Message `json:"message"`
Campaigns []Campaign `json:"campaigns"`
MailingList MailingList `json:"mailing-list"`
Recipient string `json:"recipient"`
RecipientDomain string `json:"recipient-domain"`
Tags []string `json:"tags"`
IP string `json:"ip"`
ClientInfo ClientInfo `json:"client-info"`
GeoLocation GeoLocation `json:"geolocation"`
UserVariables interface{} `json:"user-variables"`
}
type Complained struct {
Generic
Message Message `json:"message"`
Campaigns []Campaign `json:"campaigns"`
Recipient string `json:"recipient"`
Tags []string `json:"tags"`
UserVariables interface{} `json:"user-variables"`
}
//
// Mailing List Events
//
type MailingListMember struct {
Subscribed bool
Address string
Name string
Vars []string
}
type MailingListError struct {
Message string
}
type ListMemberUploaded struct {
Generic
MailingList MailingList `json:"mailing-list"`
Member MailingListMember `json:"member"`
TaskID string `json:"task-id"`
}
type ListMemberUploadError struct {
Generic
MailingList MailingList `json:"mailing-list"`
TaskID string `json:"task-id"`
Format string `json:"format"`
MemberDescription string `json:"member-description"`
Error MailingListError `json:"error"`
}
type ListUploaded struct {
Generic
MailingList MailingList `json:"mailing-list"`
IsUpsert bool `json:"is-upsert"`
Format string `json:"format"`
UpsertedCount int `json:"upserted-count"`
FailedCount int `json:"failed-count"`
Member MailingListMember `json:"member"`
Subscribed bool `json:"subscribed"`
TaskID string `json:"task-id"`
}
type Paging struct {
First string `json:"first,omitempty"`
Next string `json:"next,omitempty"`
Previous string `json:"previous,omitempty"`
Last string `json:"last,omitempty"`
}
type RawJSON []byte
func (v *RawJSON) UnmarshalJSON(data []byte) error {
*v = data
return nil
}
type Response struct {
Items []RawJSON `json:"items"`
Paging Paging `json:"paging"`
}

View File

@@ -0,0 +1,78 @@
package events
type ClientInfo struct {
AcceptLanguage string `json:"accept-language"`
ClientName string `json:"client-name"`
ClientOS string `json:"client-os"`
ClientType string `json:"client-type"`
DeviceType string `json:"device-type"`
IP string `json:"ip"`
UserAgent string `json:"user-agent"`
}
type GeoLocation struct {
City string `json:"city"`
Country string `json:"country"`
Region string `json:"region"`
}
type MailingList struct {
Address string `json:"address"`
ListID string `json:"list-id"`
SID string `json:"sid"`
}
type Message struct {
Headers MessageHeaders `json:"headers"`
Attachments []Attachment `json:"attachments"`
Recipients []string `json:"recipients"`
Size int `json:"size"`
}
type Envelope struct {
MailFrom string `json:"mail-from"`
Sender string `json:"sender"`
Transport string `json:"transport"`
Targets string `json:"targets"`
SendingHost string `json:"sending-host"`
SendingIP string `json:"sending-ip"`
}
type Storage struct {
Key string `json:"key"`
URL string `json:"url"`
}
type Flags struct {
IsAuthenticated bool `json:"is-authenticated"`
IsBig bool `json:"is-big"`
IsSystemTest bool `json:"is-system-test"`
IsTestMode bool `json:"is-test-mode"`
IsDelayedBounce bool `json:"is-delayed-bounce"`
}
type Attachment struct {
FileName string `json:"filename"`
ContentType string `json:"content-type"`
Size int `json:"size"`
}
type MessageHeaders struct {
To string `json:"to"`
MessageID string `json:"message-id"`
From string `json:"from"`
Subject string `json:"subject"`
}
type Campaign struct {
ID string `json:"id"`
Name string `json:"name"`
}
type DeliveryStatus struct {
Code int `json:"code"`
AttemptNo int `json:"attempt-no"`
Description string `json:"description"`
Message string `json:"message"`
SessionSeconds float64 `json:"session-seconds"`
}