github.com/mailgun/mailgun-go/v3@v3.6.4/events/events.go (about) 1 package events 2 3 import ( 4 "strings" 5 "time" 6 ) 7 8 // An EventName is a struct with the event name. 9 type EventName struct { 10 Name string `json:"event"` 11 } 12 13 // GetName returns the name of the event. 14 func (e *EventName) GetName() string { 15 return strings.ToLower(e.Name) 16 } 17 18 func (e *EventName) SetName(name string) { 19 e.Name = strings.ToLower(name) 20 } 21 22 type Generic struct { 23 EventName 24 Timestamp float64 `json:"timestamp"` 25 ID string `json:"id"` 26 } 27 28 func (g *Generic) GetTimestamp() time.Time { 29 return time.Unix(0, int64(g.Timestamp*float64(time.Second))).UTC() 30 } 31 32 func (g *Generic) SetTimestamp(t time.Time) { 33 // convert := fmt.Sprintf("%d.%06d", t.Unix(), t.Nanosecond()/int(time.Microsecond)) 34 // ts, err := strconv.ParseFloat(convert, 64) 35 g.Timestamp = float64(t.Unix()) + (float64(t.Nanosecond()/int(time.Microsecond)) / float64(1000000)) 36 } 37 38 func (g *Generic) GetID() string { 39 return g.ID 40 } 41 42 func (g *Generic) SetID(id string) { 43 g.ID = id 44 } 45 46 // 47 // Message Events 48 // 49 50 type Accepted struct { 51 Generic 52 53 Envelope Envelope `json:"envelope"` 54 Message Message `json:"message"` 55 Flags Flags `json:"flags"` 56 57 Recipient string `json:"recipient"` 58 RecipientDomain string `json:"recipient-domain"` 59 Method string `json:"method"` 60 OriginatingIP string `json:"originating-ip"` 61 Tags []string `json:"tags"` 62 Campaigns []Campaign `json:"campaigns"` 63 UserVariables map[string]interface{} `json:"user-variables"` 64 } 65 66 type Rejected struct { 67 Generic 68 69 Reject struct { 70 Reason string `json:"reason"` 71 Description string `json:"description"` 72 } `json:"reject"` 73 74 Message Message `json:"message"` 75 Storage Storage `json:"storage"` 76 Flags Flags `json:"flags"` 77 78 Tags []string `json:"tags"` 79 Campaigns []Campaign `json:"campaigns"` 80 UserVariables map[string]interface{} `json:"user-variables"` 81 } 82 83 type Delivered struct { 84 Generic 85 86 Envelope Envelope `json:"envelope"` 87 Message Message `json:"message"` 88 Flags Flags `json:"flags"` 89 90 Recipient string `json:"recipient"` 91 RecipientDomain string `json:"recipient-domain"` 92 Method string `json:"method"` 93 Tags []string `json:"tags"` 94 Campaigns []Campaign `json:"campaigns"` 95 96 DeliveryStatus DeliveryStatus `json:"delivery-status"` 97 UserVariables map[string]interface{} `json:"user-variables"` 98 } 99 100 type Failed struct { 101 Generic 102 103 Envelope Envelope `json:"envelope"` 104 Message Message `json:"message"` 105 Flags Flags `json:"flags"` 106 107 Recipient string `json:"recipient"` 108 RecipientDomain string `json:"recipient-domain"` 109 Method string `json:"method"` 110 Tags []string `json:"tags"` 111 Campaigns []Campaign `json:"campaigns"` 112 113 DeliveryStatus DeliveryStatus `json:"delivery-status"` 114 Severity string `json:"severity"` 115 Reason string `json:"reason"` 116 UserVariables map[string]interface{} `json:"user-variables"` 117 } 118 119 type Stored struct { 120 Generic 121 122 Message Message `json:"message"` 123 Storage Storage `json:"storage"` 124 Flags Flags `json:"flags"` 125 126 Tags []string `json:"tags"` 127 Campaigns []Campaign `json:"campaigns"` 128 UserVariables map[string]interface{} `json:"user-variables"` 129 } 130 131 // 132 // Message Events (User) 133 // 134 135 type Opened struct { 136 Generic 137 138 Message Message `json:"message"` 139 Campaigns []Campaign `json:"campaigns"` 140 MailingList MailingList `json:"mailing-list"` 141 142 Recipient string `json:"recipient"` 143 RecipientDomain string `json:"recipient-domain"` 144 Tags []string `json:"tags"` 145 146 IP string `json:"ip"` 147 ClientInfo ClientInfo `json:"client-info"` 148 GeoLocation GeoLocation `json:"geolocation"` 149 150 UserVariables map[string]interface{} `json:"user-variables"` 151 } 152 153 type Clicked struct { 154 Generic 155 156 Url string `json:"url"` 157 158 Message Message `json:"message"` 159 Campaigns []Campaign `json:"campaigns"` 160 MailingList MailingList `json:"mailing-list"` 161 162 Recipient string `json:"recipient"` 163 RecipientDomain string `json:"recipient-domain"` 164 Tags []string `json:"tags"` 165 166 IP string `json:"ip"` 167 ClientInfo ClientInfo `json:"client-info"` 168 GeoLocation GeoLocation `json:"geolocation"` 169 170 UserVariables map[string]interface{} `json:"user-variables"` 171 } 172 173 type Unsubscribed struct { 174 Generic 175 176 Message Message `json:"message"` 177 Campaigns []Campaign `json:"campaigns"` 178 MailingList MailingList `json:"mailing-list"` 179 180 Recipient string `json:"recipient"` 181 RecipientDomain string `json:"recipient-domain"` 182 Tags []string `json:"tags"` 183 184 IP string `json:"ip"` 185 ClientInfo ClientInfo `json:"client-info"` 186 GeoLocation GeoLocation `json:"geolocation"` 187 188 UserVariables map[string]interface{} `json:"user-variables"` 189 } 190 191 type Complained struct { 192 Generic 193 194 Message Message `json:"message"` 195 Campaigns []Campaign `json:"campaigns"` 196 197 Recipient string `json:"recipient"` 198 Tags []string `json:"tags"` 199 UserVariables map[string]interface{} `json:"user-variables"` 200 } 201 202 // 203 // Mailing List Events 204 // 205 206 type MailingListMember struct { 207 Subscribed bool 208 Address string 209 Name string 210 Vars []string 211 } 212 213 type MailingListError struct { 214 Message string 215 } 216 217 type ListMemberUploaded struct { 218 Generic 219 MailingList MailingList `json:"mailing-list"` 220 Member MailingListMember `json:"member"` 221 TaskID string `json:"task-id"` 222 } 223 224 type ListMemberUploadError struct { 225 Generic 226 MailingList MailingList `json:"mailing-list"` 227 TaskID string `json:"task-id"` 228 Format string `json:"format"` 229 MemberDescription string `json:"member-description"` 230 Error MailingListError `json:"error"` 231 } 232 233 type ListUploaded struct { 234 Generic 235 MailingList MailingList `json:"mailing-list"` 236 IsUpsert bool `json:"is-upsert"` 237 Format string `json:"format"` 238 UpsertedCount int `json:"upserted-count"` 239 FailedCount int `json:"failed-count"` 240 Member MailingListMember `json:"member"` 241 Subscribed bool `json:"subscribed"` 242 TaskID string `json:"task-id"` 243 } 244 245 type Paging struct { 246 First string `json:"first,omitempty"` 247 Next string `json:"next,omitempty"` 248 Previous string `json:"previous,omitempty"` 249 Last string `json:"last,omitempty"` 250 } 251 252 type RawJSON []byte 253 254 func (v *RawJSON) UnmarshalJSON(data []byte) error { 255 *v = data 256 return nil 257 } 258 259 type Response struct { 260 Items []RawJSON `json:"items"` 261 Paging Paging `json:"paging"` 262 }