Skip to content

Commit

Permalink
DE-1344 Add getters to Message to get the current state of the object (
Browse files Browse the repository at this point in the history
  • Loading branch information
vtopc authored Dec 2, 2024
1 parent cfbbb36 commit d6b1593
Show file tree
Hide file tree
Showing 8 changed files with 957 additions and 162 deletions.
20 changes: 10 additions & 10 deletions httphelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type keyNameBuff struct {
value []byte
}

type formDataPayload struct {
type FormDataPayload struct {
contentType string
Values []keyValuePair
Files []keyValuePair
Expand Down Expand Up @@ -146,31 +146,31 @@ func (r *httpResponse) parseFromJSON(v interface{}) error {
return json.Unmarshal(r.Data, v)
}

func newFormDataPayload() *formDataPayload {
return &formDataPayload{}
func NewFormDataPayload() *FormDataPayload {
return &FormDataPayload{}
}

func (f *formDataPayload) getValues() []keyValuePair {
func (f *FormDataPayload) getValues() []keyValuePair {
return f.Values
}

func (f *formDataPayload) addValue(key, value string) {
func (f *FormDataPayload) addValue(key, value string) {
f.Values = append(f.Values, keyValuePair{key: key, value: value})
}

func (f *formDataPayload) addFile(key, file string) {
func (f *FormDataPayload) addFile(key, file string) {
f.Files = append(f.Files, keyValuePair{key: key, value: file})
}

func (f *formDataPayload) addBuffer(key, file string, buff []byte) {
func (f *FormDataPayload) addBuffer(key, file string, buff []byte) {
f.Buffers = append(f.Buffers, keyNameBuff{key: key, name: file, value: buff})
}

func (f *formDataPayload) addReadCloser(key, name string, rc io.ReadCloser) {
func (f *FormDataPayload) addReadCloser(key, name string, rc io.ReadCloser) {
f.ReadClosers = append(f.ReadClosers, keyNameRC{key: key, name: name, value: rc})
}

func (f *formDataPayload) getPayloadBuffer() (*bytes.Buffer, error) {
func (f *FormDataPayload) getPayloadBuffer() (*bytes.Buffer, error) {
data := &bytes.Buffer{}
writer := multipart.NewWriter(data)
defer writer.Close()
Expand Down Expand Up @@ -239,7 +239,7 @@ func (f *formDataPayload) getPayloadBuffer() (*bytes.Buffer, error) {
return data, nil
}

func (f *formDataPayload) getContentType() (string, error) {
func (f *FormDataPayload) getContentType() (string, error) {
if f.contentType == "" {
_, err := f.getPayloadBuffer()
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions mailgun.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ type Mailgun interface {
AddOverrideHeader(k string, v string)
GetCurlOutput() string

// Send attempts to queue a message (see Message, NewMessage, and its methods) for delivery.
// TODO(v5): switch m to SendableMessage interface
Send(ctx context.Context, m *Message) (mes string, id string, err error)
ReSend(ctx context.Context, id string, recipients ...string) (string, string, error)
// Deprecated: use func NewMessage instead of method.
Expand Down
6 changes: 3 additions & 3 deletions members.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func (mg *MailgunImpl) CreateMember(ctx context.Context, merge bool, addr string
r := newHTTPRequest(generateMemberApiUrl(mg, listsEndpoint, addr))
r.setClient(mg.Client())
r.setBasicAuth(basicAuthUser, mg.APIKey())
p := newFormDataPayload()
p := NewFormDataPayload()
p.addValue("upsert", yesNo(merge))
p.addValue("address", prototype.Address)
p.addValue("name", prototype.Name)
Expand All @@ -197,7 +197,7 @@ func (mg *MailgunImpl) UpdateMember(ctx context.Context, s, l string, prototype
r := newHTTPRequest(generateMemberApiUrl(mg, listsEndpoint, l) + "/" + s)
r.setClient(mg.Client())
r.setBasicAuth(basicAuthUser, mg.APIKey())
p := newFormDataPayload()
p := NewFormDataPayload()
if prototype.Address != "" {
p.addValue("address", prototype.Address)
}
Expand Down Expand Up @@ -247,7 +247,7 @@ func (mg *MailgunImpl) CreateMemberList(ctx context.Context, u *bool, addr strin
r := newHTTPRequest(generateMemberApiUrl(mg, listsEndpoint, addr) + ".json")
r.setClient(mg.Client())
r.setBasicAuth(basicAuthUser, mg.APIKey())
p := newFormDataPayload()
p := NewFormDataPayload()
if u != nil {
p.addValue("upsert", yesNo(*u))
}
Expand Down
Loading

0 comments on commit d6b1593

Please sign in to comment.