-
Notifications
You must be signed in to change notification settings - Fork 8
/
unsubscribe_confirmation.go
44 lines (37 loc) · 1.11 KB
/
unsubscribe_confirmation.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
40
41
42
43
44
package snshttp
import (
"context"
"fmt"
"net/http"
"time"
)
// UnsubscribeConfirmation events are received when a subscription is canceled
// via the API. No unsubscribe event is fired when deleting a subscription
// through the AWS web console.
type UnsubscribeConfirmation struct {
MessageID string `json:"MessageId"`
TopicARN string `json:"TopicArn"`
Timestamp time.Time `json:"Timestamp"`
Token string `json:"Token"`
Message string `json:"Message"`
SubscribeURL string `json:"SubscribeURL"`
}
// Resubscribe notifies Amazon to reinstate the subscription. A request is made
// to the SubscribeURL.
func (e *UnsubscribeConfirmation) Resubscribe(ctx context.Context) error {
req, err := http.NewRequest("GET", e.SubscribeURL, nil)
if err != nil {
return err
}
resp, err := http.DefaultClient.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
// Server is expected to return 200 OK but we can treat any 200 level code as
// success.
if !(200 <= resp.StatusCode && resp.StatusCode < 300) {
return fmt.Errorf("server returned error status=%d", resp.StatusCode)
}
return nil
}