@@ -49,6 +49,7 @@ Public Enum AvailableMethods
4949End Enum
5050Public Enum AvailableFormats
5151 json
52+ formurlencoded
5253End Enum
5354
5455' --------------------------------------------- '
@@ -136,7 +137,7 @@ Public Property Get FormattedResource() As String
136137
137138 ' Only load parameters to querystring if GET request (otherwise they are added to the body)
138139 If Me.Method = httpGET Then
139- FormattedResource = FormattedResource & RestHelpers.DictionariesToUrlEncodedString(Me.QuerystringParams , Me.Parameters )
140+ FormattedResource = FormattedResource & RestHelpers.DictionariesToUrlEncodedString(Me.Parameters , Me.QuerystringParams )
140141 Else
141142 FormattedResource = FormattedResource & RestHelpers.DictionariesToUrlEncodedString(Me.QuerystringParams)
142143 End If
@@ -147,24 +148,30 @@ End Property
147148Public Property Get Body() As String
148149 ' Add body if it's defined or parameters have been set and it is not a GET request
149150 If Not pBody Is Nothing Or pBodyString <> "" Or (Me.Parameters.count > 0 And Me.Method <> httpGET) Then
150- Select Case Me.Format
151- ' (Currently only JSON is supported)
152- Case Else
153- If pBodyString <> "" Then
154- If Me.Parameters.count > 0 And Me.Method <> httpGET Then
155- Err.Raise vbObjectError + 1 , "RestRequest.Body" , "Unable to combine body string and parameters"
151+ If pBodyString <> "" Then
152+ If Me.Parameters.count > 0 And Me.Method <> httpGET Then
153+ Err.Raise vbObjectError + 1 , "RestRequest.Body" , "Unable to combine body string and parameters"
154+ Else
155+ Body = pBodyString
156+ End If
157+ Else
158+ Select Case Me.Format
159+ Case AvailableFormats.formurlencoded
160+ If Me.Method <> httpGET Then
161+ ' Combine defined body and parameters and convert to JSON
162+ Body = RestHelpers.DictionariesToUrlEncodedString(Me.Parameters, pBody)
156163 Else
157- Body = pBodyString
164+ Body = RestHelpers.DictionariesToUrlEncodedString(pBody)
158165 End If
159- Else
166+ Case AvailableFormats.json
160167 If Me.Method <> httpGET Then
161168 ' Combine defined body and parameters and convert to JSON
162- Body = RestHelpers.ConvertToJSON(CombineObjects(pBody, Me.Parameters))
169+ Body = RestHelpers.ConvertToJSON(CombineObjects(Me.Parameters, pBody ))
163170 Else
164171 Body = RestHelpers.ConvertToJSON(pBody)
165172 End If
166- End If
167- End Select
173+ End Select
174+ End If
168175 End If
169176End Property
170177
@@ -200,7 +207,9 @@ End Property
200207
201208Public Property Get FormatName() As String
202209 Select Case Me.Format
203- Case Else
210+ Case AvailableFormats.formurlencoded
211+ FormatName = "form-urlencoded"
212+ Case AvailableFormats.json
204213 FormatName = "json"
205214 End Select
206215End Property
@@ -210,12 +219,10 @@ Public Property Get ContentType() As String
210219 ContentType = pContentType
211220 Else
212221 Select Case Me.Format
213- Case Else
214- If Me.Method <> httpGET And Me.Parameters.count > 0 Then
215- ContentType = "application/x-www-form-urlencoded;charset=UTF-8"
216- Else
217- ContentType = "application/json"
218- End If
222+ Case AvailableFormats.formurlencoded
223+ ContentType = "application/x-www-form-urlencoded;charset=UTF-8"
224+ Case AvailableFormats.json
225+ ContentType = "application/json"
219226 End Select
220227 End If
221228End Property
0 commit comments