forked from mailslurp/mailslurp-client-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_form_controller.go
168 lines (152 loc) · 9.25 KB
/
api_form_controller.go
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
* MailSlurp API
*
* MailSlurp is an API for sending and receiving emails from dynamically allocated email addresses. It's designed for developers and QA teams to test applications, process inbound emails, send templated notifications, attachments, and more. ## Resources - [Homepage](https://www.mailslurp.com) - Get an [API KEY](https://app.mailslurp.com/sign-up/) - Generated [SDK Clients](https://www.mailslurp.com/docs/) - [Examples](https://github.com/mailslurp/examples) repository
*
* API version: d1659dc1567a5b62f65d0612107a50aace03e085
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
*/
package mailslurp
import (
_context "context"
_ioutil "io/ioutil"
_nethttp "net/http"
_neturl "net/url"
"github.com/antihax/optional"
)
// Linger please
var (
_ _context.Context
)
// FormControllerApiService FormControllerApi service
type FormControllerApiService service
// SubmitFormOpts Optional parameters for the method 'SubmitForm'
type SubmitFormOpts struct {
EmailAddress optional.String
RedirectTo optional.String
SpamCheck optional.String
Subject optional.String
SuccessMessage optional.String
To optional.String
ToAlias optional.String
OtherParameters optional.String
}
/*
SubmitForm Submit a form to be parsed and sent as an email to an address determined by the form fields
This endpoint allows you to submit HTML forms and receive the field values and files via email. #### Parameters The endpoint looks for special meta parameters in the form fields OR in the URL request parameters. The meta parameters can be used to specify the behaviour of the email. You must provide at-least a `_to` email address or a `_toAlias` email alias ID to tell the endpoint where the form should be emailed. These can be submitted as hidden HTML input fields with the corresponding `name` attributes or as URL query parameters such as `?_to=[email protected]` The endpoint takes all other form fields that are named and includes them in the message body of the email. Files are sent as attachments. #### Submitting This endpoint accepts form submission via POST method. It accepts `application/x-www-form-urlencoded`, and `multipart/form-data` content-types. #### HTML Example ```html <form action=\"https://api.mailslurp.com/forms\" method=\"post\" > <input name=\"_to\" type=\"hidden\" value=\"[email protected]\"/> <textarea name=\"feedback\"></textarea> <button type=\"submit\">Submit</button> </form> ``` #### URL Example ```html <form action=\"https://api.mailslurp.com/forms?_toAlias=[email protected]\" method=\"post\" > <textarea name=\"feedback\"></textarea> <button type=\"submit\">Submit</button> </form> ``` The email address is specified by a `_to` field OR is extracted from an email alias specified by a `_toAlias` field (see the alias controller for more information). Endpoint accepts . You can specify a content type in HTML forms using the `enctype` attribute, for instance: `<form enctype=\"multipart/form-data\">`.
* @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
* @param optional nil or *SubmitFormOpts - Optional Parameters:
* @param "EmailAddress" (optional.String) - Email address of the submitting user. Include this if you wish to record the submitters email address and reply to it later.
* @param "RedirectTo" (optional.String) - Optional URL to redirect form submitter to after submission. If not present user will see a success message.
* @param "SpamCheck" (optional.String) - Optional but recommended field that catches spammers out. Include as a hidden form field but LEAVE EMPTY. Spam-bots will usually fill every field. If the _spamCheck field is filled the form submission will be ignored.
* @param "Subject" (optional.String) - Optional subject of the email that will be sent.
* @param "SuccessMessage" (optional.String) - Optional success message to display if no _redirectTo present.
* @param "To" (optional.String) - The email address that submitted form should be sent to. Either this or _toAlias must be present for a form to be successfully submitted..
* @param "ToAlias" (optional.String) - ID of an email alias to that form should be sent to. Aliases must be created before submission and can be used to hide an email address and reduce spam.
* @param "OtherParameters" (optional.String) - All other parameters or fields will be accepted and attached to the sent email. This includes files and any HTML form field with a name. These fields will become the body of the email that is sent.
@return string
*/
func (a *FormControllerApiService) SubmitForm(ctx _context.Context, localVarOptionals *SubmitFormOpts) (string, *_nethttp.Response, error) {
var (
localVarHTTPMethod = _nethttp.MethodPost
localVarPostBody interface{}
localVarFormFileName string
localVarFileName string
localVarFileBytes []byte
localVarReturnValue string
)
// create path and map variables
localVarPath := a.client.cfg.BasePath + "/forms"
localVarHeaderParams := make(map[string]string)
localVarQueryParams := _neturl.Values{}
localVarFormParams := _neturl.Values{}
// to determine the Content-Type header
localVarHTTPContentTypes := []string{"multipart/form-data", "application/x-www-form-urlencoded"}
// set Content-Type header
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
if localVarHTTPContentType != "" {
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
}
// to determine the Accept header
localVarHTTPHeaderAccepts := []string{"application/json"}
// set Accept header
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
if localVarHTTPHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
}
if localVarOptionals != nil && localVarOptionals.EmailAddress.IsSet() {
localVarFormParams.Add("_emailAddress", parameterToString(localVarOptionals.EmailAddress.Value(), ""))
}
if localVarOptionals != nil && localVarOptionals.RedirectTo.IsSet() {
localVarFormParams.Add("_redirectTo", parameterToString(localVarOptionals.RedirectTo.Value(), ""))
}
if localVarOptionals != nil && localVarOptionals.SpamCheck.IsSet() {
localVarFormParams.Add("_spamCheck", parameterToString(localVarOptionals.SpamCheck.Value(), ""))
}
if localVarOptionals != nil && localVarOptionals.Subject.IsSet() {
localVarFormParams.Add("_subject", parameterToString(localVarOptionals.Subject.Value(), ""))
}
if localVarOptionals != nil && localVarOptionals.SuccessMessage.IsSet() {
localVarFormParams.Add("_successMessage", parameterToString(localVarOptionals.SuccessMessage.Value(), ""))
}
if localVarOptionals != nil && localVarOptionals.To.IsSet() {
localVarFormParams.Add("_to", parameterToString(localVarOptionals.To.Value(), ""))
}
if localVarOptionals != nil && localVarOptionals.ToAlias.IsSet() {
localVarFormParams.Add("_toAlias", parameterToString(localVarOptionals.ToAlias.Value(), ""))
}
if localVarOptionals != nil && localVarOptionals.OtherParameters.IsSet() {
localVarFormParams.Add("otherParameters", parameterToString(localVarOptionals.OtherParameters.Value(), ""))
}
if ctx != nil {
// API Key Authentication
if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok {
var key string
if auth.Prefix != "" {
key = auth.Prefix + " " + auth.Key
} else {
key = auth.Key
}
localVarHeaderParams["x-api-key"] = key
}
}
r, err := a.client.prepareRequest(ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFormFileName, localVarFileName, localVarFileBytes)
if err != nil {
return localVarReturnValue, nil, err
}
localVarHTTPResponse, err := a.client.callAPI(r)
if err != nil || localVarHTTPResponse == nil {
return localVarReturnValue, localVarHTTPResponse, err
}
localVarBody, err := _ioutil.ReadAll(localVarHTTPResponse.Body)
localVarHTTPResponse.Body.Close()
if err != nil {
return localVarReturnValue, localVarHTTPResponse, err
}
if localVarHTTPResponse.StatusCode >= 300 {
newErr := GenericOpenAPIError{
body: localVarBody,
error: localVarHTTPResponse.Status,
}
if localVarHTTPResponse.StatusCode == 200 {
var v string
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.model = v
return localVarReturnValue, localVarHTTPResponse, newErr
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr := GenericOpenAPIError{
body: localVarBody,
error: err.Error(),
}
return localVarReturnValue, localVarHTTPResponse, newErr
}
return localVarReturnValue, localVarHTTPResponse, nil
}