forked from keighl/postmark
-
-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathinbound_rules_triggers.go
More file actions
69 lines (56 loc) · 2.02 KB
/
inbound_rules_triggers.go
File metadata and controls
69 lines (56 loc) · 2.02 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package postmark
import (
"context"
"fmt"
"net/url"
)
// InboundRuleTrigger represents an inbound rule trigger
type InboundRuleTrigger struct {
// ID: Unique ID of the trigger
ID int64
// Rule: Email address or domain to block
Rule string
}
// InboundRulesTriggersResponse represents the response from listing inbound rule triggers
type InboundRulesTriggersResponse struct {
// TotalCount: Total matching triggers
TotalCount int64
// InboundRules: List of inbound rules
InboundRules []InboundRuleTrigger
}
// InboundRuleTriggerCreateRequest represents the request to create an inbound rule trigger
type InboundRuleTriggerCreateRequest struct {
// Rule: Email address or domain to block (required)
Rule string `json:"Rule"`
}
// GetInboundRuleTriggers fetches a list of inbound rule triggers on the server
// It returns a slice of InboundRuleTrigger, the total trigger count, and any error that occurred
func (client *Client) GetInboundRuleTriggers(ctx context.Context, count, offset int64) ([]InboundRuleTrigger, int64, error) {
res := InboundRulesTriggersResponse{}
values := &url.Values{}
values.Add("count", fmt.Sprintf("%d", count))
values.Add("offset", fmt.Sprintf("%d", offset))
err := client.get(ctx, buildURLWithQuery("triggers/inboundrules", *values), &res)
return res.InboundRules, res.TotalCount, err
}
// CreateInboundRuleTrigger creates an inbound rule trigger to block emails
func (client *Client) CreateInboundRuleTrigger(ctx context.Context, rule string) (InboundRuleTrigger, error) {
res := InboundRuleTrigger{}
requestData := InboundRuleTriggerCreateRequest{
Rule: rule,
}
err := client.post(ctx, "triggers/inboundrules", requestData, &res)
return res, err
}
// DeleteInboundRuleTrigger deletes an inbound rule trigger by ID
func (client *Client) DeleteInboundRuleTrigger(ctx context.Context, triggerID int64) error {
res := APIError{}
err := client.delete(ctx, fmt.Sprintf("triggers/inboundrules/%d", triggerID), &res)
if err != nil {
return err
}
if res.ErrorCode != 0 {
return res
}
return nil
}