Passed
Push — master ( 715886...74726c )
by eval
06:41 queued 04:58
created

ses.SendBulkTemplatedEmailRequest.ToInput   D

Complexity

Conditions 13

Size

Total Lines 49
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 13
eloc 30
nop 0
dl 0
loc 49
rs 4.2
c 0
b 0
f 0

How to fix   Complexity   

Complexity

Complex classes like ses.SendBulkTemplatedEmailRequest.ToInput often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
package ses
2
3
import (
4
	"context"
5
6
	SDK "github.com/aws/aws-sdk-go-v2/service/ses"
7
8
	"github.com/evalphobia/aws-sdk-go-v2-wrapper/errors"
9
	"github.com/evalphobia/aws-sdk-go-v2-wrapper/private/pointers"
10
)
11
12
// SendBulkTemplatedEmail executes `SendBulkTemplatedEmail` operation.
13
func (svc *SES) SendBulkTemplatedEmail(ctx context.Context, r SendBulkTemplatedEmailRequest) (*SendBulkTemplatedEmailResult, error) {
14
	out, err := svc.RawSendBulkTemplatedEmail(ctx, r.ToInput())
15
	if err != nil {
16
		err = svc.errWrap(errors.ErrorData{
17
			Err:          err,
18
			AWSOperation: "SendBulkTemplatedEmail",
19
		})
20
		svc.Errorf(err.Error())
0 ignored issues
show
introduced by
can't check non-constant format in call to Errorf
Loading history...
21
		return nil, err
22
	}
23
	return NewSendBulkTemplatedEmailResult(out), nil
24
}
25
26
// SendBulkTemplatedEmailRequest has parameters for `SendBulkTemplatedEmail` operation.
27
type SendBulkTemplatedEmailRequest struct {
28
	Destinations []BulkEmailDestination
29
	Source       string
30
	Template     string
31
32
	// optional
33
	ConfigurationSetName string
34
	DefaultTags          []MessageTag
35
	DefaultTemplateData  string
36
	ReplyToAddresses     []string
37
	ReturnPath           string
38
	ReturnPathARN        string
39
	SourceARN            string
40
	TemplateARN          string
41
}
42
43
func (r SendBulkTemplatedEmailRequest) ToInput() *SDK.SendBulkTemplatedEmailInput {
0 ignored issues
show
introduced by
exported method SendBulkTemplatedEmailRequest.ToInput should have comment or be unexported
Loading history...
44
	in := &SDK.SendBulkTemplatedEmailInput{}
45
46
	if len(r.Destinations) != 0 {
47
		list := make([]SDK.BulkEmailDestination, len(r.Destinations))
48
		for i, v := range r.Destinations {
49
			list[i] = v.ToSDK()
50
		}
51
		in.Destinations = list
52
	}
53
54
	if r.Source != "" {
55
		in.Source = pointers.String(r.Source)
56
	}
57
	if r.Template != "" {
58
		in.Template = pointers.String(r.Template)
59
	}
60
61
	if r.ConfigurationSetName != "" {
62
		in.ConfigurationSetName = pointers.String(r.ConfigurationSetName)
63
	}
64
65
	if len(r.DefaultTags) != 0 {
66
		list := make([]SDK.MessageTag, len(r.DefaultTags))
67
		for i, v := range r.DefaultTags {
68
			list[i] = v.ToSDK()
69
		}
70
		in.DefaultTags = list
71
	}
72
73
	if r.DefaultTemplateData != "" {
74
		in.DefaultTemplateData = pointers.String(r.DefaultTemplateData)
75
	}
76
77
	in.ReplyToAddresses = r.ReplyToAddresses
78
79
	if r.ReturnPath != "" {
80
		in.ReturnPath = pointers.String(r.ReturnPath)
81
	}
82
	if r.ReturnPathARN != "" {
83
		in.ReturnPathArn = pointers.String(r.ReturnPathARN)
84
	}
85
	if r.SourceARN != "" {
86
		in.SourceArn = pointers.String(r.SourceARN)
87
	}
88
	if r.TemplateARN != "" {
89
		in.TemplateArn = pointers.String(r.TemplateARN)
90
	}
91
	return in
92
}
93
94
type SendBulkTemplatedEmailResult struct {
0 ignored issues
show
introduced by
exported type SendBulkTemplatedEmailResult should have comment or be unexported
Loading history...
95
	Status []BulkEmailDestinationStatus
96
}
97
98
func NewSendBulkTemplatedEmailResult(o *SDK.SendBulkTemplatedEmailResponse) *SendBulkTemplatedEmailResult {
0 ignored issues
show
introduced by
exported function NewSendBulkTemplatedEmailResult should have comment or be unexported
Loading history...
99
	result := &SendBulkTemplatedEmailResult{}
100
	if o == nil {
101
		return result
102
	}
103
104
	result.Status = newBulkEmailDestinationStatuses(o.Status)
105
	return result
106
}
107