Skip to content

Commit 44bd554

Browse files
authored
feat(tem): generate blocklist sdk (scaleway#2384)
1 parent ef7be5a commit 44bd554

File tree

1 file changed

+312
-0
lines changed

1 file changed

+312
-0
lines changed

api/tem/v1alpha1/tem_sdk.go

Lines changed: 312 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,48 @@ var (
3939
_ = namegenerator.GetRandomName
4040
)
4141

42+
type BlocklistType string
43+
44+
const (
45+
// If unspecified, the type of blocklist is unknown by default.
46+
BlocklistTypeUnknownType = BlocklistType("unknown_type")
47+
// The recipient's mailbox is full and cannot receive any new email.
48+
BlocklistTypeMailboxFull = BlocklistType("mailbox_full")
49+
// The recipient's mailbox does not exist.
50+
BlocklistTypeMailboxNotFound = BlocklistType("mailbox_not_found")
51+
)
52+
53+
func (enum BlocklistType) String() string {
54+
if enum == "" {
55+
// return default value if empty
56+
return "unknown_type"
57+
}
58+
return string(enum)
59+
}
60+
61+
func (enum BlocklistType) Values() []BlocklistType {
62+
return []BlocklistType{
63+
"unknown_type",
64+
"mailbox_full",
65+
"mailbox_not_found",
66+
}
67+
}
68+
69+
func (enum BlocklistType) MarshalJSON() ([]byte, error) {
70+
return []byte(fmt.Sprintf(`"%s"`, enum)), nil
71+
}
72+
73+
func (enum *BlocklistType) UnmarshalJSON(data []byte) error {
74+
tmp := ""
75+
76+
if err := json.Unmarshal(data, &tmp); err != nil {
77+
return err
78+
}
79+
80+
*enum = BlocklistType(BlocklistType(tmp).String())
81+
return nil
82+
}
83+
4284
type DomainLastStatusAutoconfigStateReason string
4385

4486
const (
@@ -384,6 +426,51 @@ func (enum *EmailStatus) UnmarshalJSON(data []byte) error {
384426
return nil
385427
}
386428

429+
type ListBlocklistsRequestOrderBy string
430+
431+
const (
432+
// Order by creation date (descending chronological order).
433+
ListBlocklistsRequestOrderByCreatedAtDesc = ListBlocklistsRequestOrderBy("created_at_desc")
434+
// Order by creation date (ascending chronological order).
435+
ListBlocklistsRequestOrderByCreatedAtAsc = ListBlocklistsRequestOrderBy("created_at_asc")
436+
// Order by blocklist ends date (descending chronological order).
437+
ListBlocklistsRequestOrderByEndsAtDesc = ListBlocklistsRequestOrderBy("ends_at_desc")
438+
// Order by blocklist ends date (ascending chronological order).
439+
ListBlocklistsRequestOrderByEndsAtAsc = ListBlocklistsRequestOrderBy("ends_at_asc")
440+
)
441+
442+
func (enum ListBlocklistsRequestOrderBy) String() string {
443+
if enum == "" {
444+
// return default value if empty
445+
return "created_at_desc"
446+
}
447+
return string(enum)
448+
}
449+
450+
func (enum ListBlocklistsRequestOrderBy) Values() []ListBlocklistsRequestOrderBy {
451+
return []ListBlocklistsRequestOrderBy{
452+
"created_at_desc",
453+
"created_at_asc",
454+
"ends_at_desc",
455+
"ends_at_asc",
456+
}
457+
}
458+
459+
func (enum ListBlocklistsRequestOrderBy) MarshalJSON() ([]byte, error) {
460+
return []byte(fmt.Sprintf(`"%s"`, enum)), nil
461+
}
462+
463+
func (enum *ListBlocklistsRequestOrderBy) UnmarshalJSON(data []byte) error {
464+
tmp := ""
465+
466+
if err := json.Unmarshal(data, &tmp); err != nil {
467+
return err
468+
}
469+
470+
*enum = ListBlocklistsRequestOrderBy(ListBlocklistsRequestOrderBy(tmp).String())
471+
return nil
472+
}
473+
387474
type ListEmailsRequestOrderBy string
388475

389476
const (
@@ -737,6 +824,37 @@ type DomainStatistics struct {
737824
CanceledCount uint32 `json:"canceled_count"`
738825
}
739826

827+
// Blocklist: blocklist.
828+
type Blocklist struct {
829+
// ID: ID of the blocklist.
830+
ID string `json:"id"`
831+
832+
// DomainID: domain ID linked to the blocklist.
833+
DomainID string `json:"domain_id"`
834+
835+
// CreatedAt: date and time of the blocklist creation.
836+
CreatedAt *time.Time `json:"created_at"`
837+
838+
// UpdatedAt: date and time of the blocklist's last update.
839+
UpdatedAt *time.Time `json:"updated_at"`
840+
841+
// EndsAt: date and time when the blocklist ends. Empty if the blocklist has no end.
842+
EndsAt *time.Time `json:"ends_at"`
843+
844+
// Email: email blocked by the blocklist.
845+
Email string `json:"email"`
846+
847+
// Type: type of block for this email.
848+
// Default value: unknown_type
849+
Type BlocklistType `json:"type"`
850+
851+
// Reason: reason to block this email.
852+
Reason string `json:"reason"`
853+
854+
// Custom: true if this blocklist was created manually. False for an automatic Transactional Email blocklist.
855+
Custom bool `json:"custom"`
856+
}
857+
740858
// CreateEmailRequestAddress: create email request address.
741859
type CreateEmailRequestAddress struct {
742860
// Email: email address.
@@ -1024,6 +1142,31 @@ type UpdateProjectSettingsRequestUpdatePeriodicReport struct {
10241142
SendingDay *uint32 `json:"sending_day"`
10251143
}
10261144

1145+
// BulkCreateBlocklistsRequest: bulk create blocklists request.
1146+
type BulkCreateBlocklistsRequest struct {
1147+
// Region: region to target. If none is passed will use default region from the config.
1148+
Region scw.Region `json:"-"`
1149+
1150+
// DomainID: domain ID linked to the blocklist.
1151+
DomainID string `json:"domain_id"`
1152+
1153+
// Emails: email blocked by the blocklist.
1154+
Emails []string `json:"emails"`
1155+
1156+
// Type: type of blocklist.
1157+
// Default value: unknown_type
1158+
Type BlocklistType `json:"type"`
1159+
1160+
// Reason: reason to block the email.
1161+
Reason *string `json:"reason,omitempty"`
1162+
}
1163+
1164+
// BulkCreateBlocklistsResponse: bulk create blocklists response.
1165+
type BulkCreateBlocklistsResponse struct {
1166+
// Blocklists: list of blocklist created.
1167+
Blocklists []*Blocklist `json:"blocklists"`
1168+
}
1169+
10271170
// CancelEmailRequest: cancel email request.
10281171
type CancelEmailRequest struct {
10291172
// Region: region to target. If none is passed will use default region from the config.
@@ -1126,6 +1269,15 @@ type CreateWebhookRequest struct {
11261269
SnsArn string `json:"sns_arn"`
11271270
}
11281271

1272+
// DeleteBlocklistRequest: delete blocklist request.
1273+
type DeleteBlocklistRequest struct {
1274+
// Region: region to target. If none is passed will use default region from the config.
1275+
Region scw.Region `json:"-"`
1276+
1277+
// BlocklistID: ID of the blocklist to delete.
1278+
BlocklistID string `json:"-"`
1279+
}
1280+
11291281
// DeleteWebhookRequest: delete webhook request.
11301282
type DeleteWebhookRequest struct {
11311283
// Region: region to target. If none is passed will use default region from the config.
@@ -1222,6 +1374,63 @@ type GetWebhookRequest struct {
12221374
WebhookID string `json:"-"`
12231375
}
12241376

1377+
// ListBlocklistsRequest: list blocklists request.
1378+
type ListBlocklistsRequest struct {
1379+
// Region: region to target. If none is passed will use default region from the config.
1380+
Region scw.Region `json:"-"`
1381+
1382+
// OrderBy: (Optional) List blocklist corresponding to specific criteria.
1383+
// Default value: created_at_desc
1384+
OrderBy ListBlocklistsRequestOrderBy `json:"-"`
1385+
1386+
// Page: (Optional) Requested page number. Value must be greater or equal to 1.
1387+
Page *int32 `json:"-"`
1388+
1389+
// PageSize: (Optional) Requested page size. Value must be between 1 and 100.
1390+
PageSize *uint32 `json:"-"`
1391+
1392+
// DomainID: (Optional) Filter by a domain ID.
1393+
DomainID string `json:"-"`
1394+
1395+
// Email: (Optional) Filter by an email address.
1396+
Email *string `json:"-"`
1397+
1398+
// Type: (Optional) Filter by a blocklist type.
1399+
// Default value: unknown_type
1400+
Type *BlocklistType `json:"-"`
1401+
1402+
// Custom: (Optional) Filter by custom blocklist (true) or automatic Transactional Email blocklist (false).
1403+
Custom *bool `json:"-"`
1404+
}
1405+
1406+
// ListBlocklistsResponse: list blocklists response.
1407+
type ListBlocklistsResponse struct {
1408+
// TotalCount: number of blocklists matching the requested criteria.
1409+
TotalCount uint64 `json:"total_count"`
1410+
1411+
// Blocklists: single page of blocklists matching the requested criteria.
1412+
Blocklists []*Blocklist `json:"blocklists"`
1413+
}
1414+
1415+
// UnsafeGetTotalCount should not be used
1416+
// Internal usage only
1417+
func (r *ListBlocklistsResponse) UnsafeGetTotalCount() uint64 {
1418+
return r.TotalCount
1419+
}
1420+
1421+
// UnsafeAppend should not be used
1422+
// Internal usage only
1423+
func (r *ListBlocklistsResponse) UnsafeAppend(res interface{}) (uint64, error) {
1424+
results, ok := res.(*ListBlocklistsResponse)
1425+
if !ok {
1426+
return 0, errors.New("%T type cannot be appended to type %T", res, r)
1427+
}
1428+
1429+
r.Blocklists = append(r.Blocklists, results.Blocklists...)
1430+
r.TotalCount += uint64(len(results.Blocklists))
1431+
return uint64(len(results.Blocklists)), nil
1432+
}
1433+
12251434
// ListDomainsRequest: list domains request.
12261435
type ListDomainsRequest struct {
12271436
// Region: region to target. If none is passed will use default region from the config.
@@ -2298,3 +2507,106 @@ func (s *API) UpdateProjectSettings(req *UpdateProjectSettingsRequest, opts ...s
22982507
}
22992508
return &resp, nil
23002509
}
2510+
2511+
// ListBlocklists: Retrieve the list of blocklists.
2512+
func (s *API) ListBlocklists(req *ListBlocklistsRequest, opts ...scw.RequestOption) (*ListBlocklistsResponse, error) {
2513+
var err error
2514+
2515+
if req.Region == "" {
2516+
defaultRegion, _ := s.client.GetDefaultRegion()
2517+
req.Region = defaultRegion
2518+
}
2519+
2520+
defaultPageSize, exist := s.client.GetDefaultPageSize()
2521+
if (req.PageSize == nil || *req.PageSize == 0) && exist {
2522+
req.PageSize = &defaultPageSize
2523+
}
2524+
2525+
query := url.Values{}
2526+
parameter.AddToQuery(query, "order_by", req.OrderBy)
2527+
parameter.AddToQuery(query, "page", req.Page)
2528+
parameter.AddToQuery(query, "page_size", req.PageSize)
2529+
parameter.AddToQuery(query, "domain_id", req.DomainID)
2530+
parameter.AddToQuery(query, "email", req.Email)
2531+
parameter.AddToQuery(query, "type", req.Type)
2532+
parameter.AddToQuery(query, "custom", req.Custom)
2533+
2534+
if fmt.Sprint(req.Region) == "" {
2535+
return nil, errors.New("field Region cannot be empty in request")
2536+
}
2537+
2538+
scwReq := &scw.ScalewayRequest{
2539+
Method: "GET",
2540+
Path: "/transactional-email/v1alpha1/regions/" + fmt.Sprint(req.Region) + "/blocklists",
2541+
Query: query,
2542+
}
2543+
2544+
var resp ListBlocklistsResponse
2545+
2546+
err = s.client.Do(scwReq, &resp, opts...)
2547+
if err != nil {
2548+
return nil, err
2549+
}
2550+
return &resp, nil
2551+
}
2552+
2553+
// BulkCreateBlocklists: Create multiple blocklists in a specific Project or Organization using the `region` parameter.
2554+
func (s *API) BulkCreateBlocklists(req *BulkCreateBlocklistsRequest, opts ...scw.RequestOption) (*BulkCreateBlocklistsResponse, error) {
2555+
var err error
2556+
2557+
if req.Region == "" {
2558+
defaultRegion, _ := s.client.GetDefaultRegion()
2559+
req.Region = defaultRegion
2560+
}
2561+
2562+
if fmt.Sprint(req.Region) == "" {
2563+
return nil, errors.New("field Region cannot be empty in request")
2564+
}
2565+
2566+
scwReq := &scw.ScalewayRequest{
2567+
Method: "POST",
2568+
Path: "/transactional-email/v1alpha1/regions/" + fmt.Sprint(req.Region) + "/blocklists",
2569+
}
2570+
2571+
err = scwReq.SetBody(req)
2572+
if err != nil {
2573+
return nil, err
2574+
}
2575+
2576+
var resp BulkCreateBlocklistsResponse
2577+
2578+
err = s.client.Do(scwReq, &resp, opts...)
2579+
if err != nil {
2580+
return nil, err
2581+
}
2582+
return &resp, nil
2583+
}
2584+
2585+
// DeleteBlocklist: You must specify the blocklist you want to delete by the `region` and `blocklist_id`.
2586+
func (s *API) DeleteBlocklist(req *DeleteBlocklistRequest, opts ...scw.RequestOption) error {
2587+
var err error
2588+
2589+
if req.Region == "" {
2590+
defaultRegion, _ := s.client.GetDefaultRegion()
2591+
req.Region = defaultRegion
2592+
}
2593+
2594+
if fmt.Sprint(req.Region) == "" {
2595+
return errors.New("field Region cannot be empty in request")
2596+
}
2597+
2598+
if fmt.Sprint(req.BlocklistID) == "" {
2599+
return errors.New("field BlocklistID cannot be empty in request")
2600+
}
2601+
2602+
scwReq := &scw.ScalewayRequest{
2603+
Method: "DELETE",
2604+
Path: "/transactional-email/v1alpha1/regions/" + fmt.Sprint(req.Region) + "/blocklists/" + fmt.Sprint(req.BlocklistID) + "",
2605+
}
2606+
2607+
err = s.client.Do(scwReq, nil, opts...)
2608+
if err != nil {
2609+
return err
2610+
}
2611+
return nil
2612+
}

0 commit comments

Comments
 (0)