forked from customerio/go-customerio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransactional.go
39 lines (34 loc) · 960 Bytes
/
transactional.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package customerio
import (
"encoding/json"
"time"
)
// TransactionalResponse is a response to the send of a transactional message.
type TransactionalResponse struct {
// DeliveryID is a unique id for the given message.
DeliveryID string `json:"delivery_id"`
// QueuedAt is when the message was queued.
QueuedAt time.Time `json:"queued_at"`
}
func (t *TransactionalResponse) UnmarshalJSON(b []byte) error {
var r struct {
DeliveryID string `json:"delivery_id"`
QueuedAt int64 `json:"queued_at"`
}
if err := json.Unmarshal(b, &r); err != nil {
return err
}
t.DeliveryID = r.DeliveryID
t.QueuedAt = time.Unix(r.QueuedAt, 0)
return nil
}
// TransactionalError is returned if a transactional message fails to send.
type TransactionalError struct {
// Err is a more specific error message.
Err string
// StatusCode is the http status code for the error.
StatusCode int
}
func (e *TransactionalError) Error() string {
return e.Err
}