Skip to content

Commit f52af78

Browse files
committed
add validating mms create request
1 parent 540e1f5 commit f52af78

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

mms/message.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package mms
22

33
import (
4+
"fmt"
45
"net/http"
56
"time"
67

@@ -48,10 +49,26 @@ func Read(c messagebird.Client, id string) (*Message, error) {
4849
// Create creates a new MMS message for one or more recipients.
4950
// Max of 50 recipients can be entered per request.
5051
func Create(c messagebird.Client, req *CreateRequest) (*Message, error) {
52+
if err := validateCreateRequest(req); err != nil {
53+
return nil, err
54+
}
55+
5156
mmsMessage := &Message{}
5257
if err := c.Request(mmsMessage, http.MethodPost, path, req); err != nil {
5358
return nil, err
5459
}
5560

5661
return mmsMessage, nil
5762
}
63+
64+
func validateCreateRequest(req *CreateRequest) error {
65+
if req == nil {
66+
return fmt.Errorf("create request should not be nil")
67+
}
68+
69+
if req.Body == "" && len(req.MediaUrls) == 0 {
70+
return fmt.Errorf("body or mediaUrls is required")
71+
}
72+
73+
return nil
74+
}

0 commit comments

Comments
 (0)