git.sr.ht/~pingoo/stdx@v0.0.0-20240218134121-094174641f6e/postmark/message_streams.go (about) 1 package postmark 2 3 import ( 4 "context" 5 "fmt" 6 "net/http" 7 ) 8 9 const ( 10 DefaultBroadcastStreamID = "broadcast" 11 DefaultInboundStreamID = "inbound" 12 DefaultTransactionalStreamID = "outbound" 13 ) 14 15 type MessageStreamType string 16 17 const ( 18 MessageStreamTypeInbound MessageStreamType = "Inbound" 19 MessageStreamTypeBroadcasts MessageStreamType = "Broadcasts" 20 MessageStreamTypeTransactional MessageStreamType = "Transactional" 21 ) 22 23 type MessageStreamUnsubscribeHandlingType string 24 25 const ( 26 MessageStreamUnsubscribeHandlingPostmark MessageStreamUnsubscribeHandlingType = "Postmark" 27 MessageStreamUnsubscribeHandlingCustom MessageStreamUnsubscribeHandlingType = "Custom" 28 MessageStreamUnsubscribeHandlingNone MessageStreamUnsubscribeHandlingType = "none" 29 ) 30 31 type MessageStreamSubscriptionManagementConfiguration struct { 32 UnsubscribeHandlingType MessageStreamUnsubscribeHandlingType `json:"UnsubscribeHandlingType"` 33 } 34 35 // See https://postmarkapp.com/developer/api/message-streams-api 36 type MessageStream struct { 37 ID string `json:"ID"` 38 ServerID int64 `json:"ServerID"` 39 Name string `json:"Name"` 40 Description string `json:"Description"` 41 MessageStreamType MessageStreamType `json:"MessageStreamType"` 42 // "CreatedAt": "2020-07-02T00:00:00-04:00", 43 // "UpdatedAt": "2020-07-03T00:00:00-04:00", 44 // "ArchivedAt": null, 45 // "ExpectedPurgeDate": null, 46 SubscriptionManagementConfiguration MessageStreamSubscriptionManagementConfiguration `json:"SubscriptionManagementConfiguration"` 47 } 48 49 type UpdateMessageStreamInput struct { 50 Name string `json:"Name,omitempty"` 51 Description string `json:"Description,omitempty"` 52 SubscriptionManagementConfiguration MessageStreamSubscriptionManagementConfiguration `json:"SubscriptionManagementConfiguration,omitempty"` 53 } 54 55 func (client *Client) UpdateMessageStream(ctx context.Context, serverToken, messageStreamID string, input UpdateMessageStreamInput) (res MessageStream, err error) { 56 err = client.request(ctx, requestParams{ 57 Method: http.MethodPatch, 58 URL: fmt.Sprintf("/message-streams/%s", messageStreamID), 59 Payload: input, 60 ServerToken: &serverToken, 61 }, &res) 62 63 return 64 }