@@ -279,18 +279,28 @@ Public Function ConvertToUrlEncoded(Obj As Variant) As String
279279 ConvertToUrlEncoded = Encoded
280280End Function
281281
282- Public Function DictionariesToUrlEncodedString (ParamArray Dictionaries() As Variant ) As String
283- Debug.Print "Excel-REST: DEPRECATED DictionariesToUrlEncodedString has been deprecated in favor of ConvertToUrlEncoded. It will be removed in Excel-REST v4"
284-
285- Dim i As Integer
286- Dim Combined As Dictionary
287-
288- Set Combined = Dictionaries(LBound(Dictionaries))
289- For i = LBound(Dictionaries) + 1 To UBound(Dictionaries)
290- Set Combined = CombineObjects(Combined, Dictionaries(i))
291- Next i
292-
293- DictionariesToUrlEncodedString = ConvertToUrlEncoded(Combined)
282+ ''
283+ ' Parse XML string to XML
284+ '
285+ ' @param {String} Encoded
286+ ' @return {Object} XML
287+ ' --------------------------------------------- '
288+ Public Function ParseXML (Encoded As String ) As Object
289+ Set ParseXML = New MSXML2.DOMDocument
290+ ParseXML.async = False
291+ ParseXML.LoadXML Encoded
292+ End Function
293+
294+ ''
295+ ' Convert MSXML2.DomDocument to string
296+ '
297+ ' @param {Object: MSXML2.DomDocument} XML
298+ ' @return {String} XML string
299+ ' --------------------------------------------- '
300+
301+ Public Function ConvertToXML (Obj As Variant ) As String
302+ On Error Resume Next
303+ ConvertToXML = Trim(Replace(Obj.xml, vbCrLf, "" ))
294304End Function
295305
296306''
@@ -306,6 +316,8 @@ Public Function ParseByFormat(Value As String, Format As AvailableFormats) As Ob
306316 Set ParseByFormat = ParseJSON(Value)
307317 Case AvailableFormats.formurlencoded
308318 Set ParseByFormat = ParseUrlEncoded(Value)
319+ Case AvailableFormats.xml
320+ Set ParseByFormat = ParseXML(Value)
309321 End Select
310322End Function
311323
@@ -322,6 +334,8 @@ Public Function ConvertToFormat(Obj As Variant, Format As AvailableFormats) As S
322334 ConvertToFormat = ConvertToJSON(Obj)
323335 Case AvailableFormats.formurlencoded
324336 ConvertToFormat = ConvertToUrlEncoded(Obj)
337+ Case AvailableFormats.xml
338+ ConvertToFormat = ConvertToXML(Obj)
325339 End Select
326340End Function
327341
@@ -603,7 +617,7 @@ End Function
603617' --------------------------------------------- '
604618Public Function IsArray (Obj As Variant ) As Boolean
605619 If Not IsEmpty(Obj) Then
606- If VarType (Obj) = vbObject Then
620+ If IsObject (Obj) Then
607621 If TypeOf Obj Is Collection Then
608622 IsArray = True
609623 End If
@@ -614,6 +628,21 @@ Public Function IsArray(Obj As Variant) As Boolean
614628 End If
615629End Function
616630
631+ ''
632+ ' Add or update key/value in dictionary
633+ '
634+ ' @param {Dictionary} Dict
635+ ' @param {String} Key
636+ ' @param {Variant} Value
637+ ' --------------------------------------------- '
638+ Public Sub AddToDictionary (ByRef Dict As Dictionary , Key As String , Value As Variant )
639+ If Not Dict.Exists(Key) Then
640+ Dict.Add Key, Value
641+ Else
642+ Dict(Key) = Value
643+ End If
644+ End Sub
645+
617646' ============================================= '
618647' 5. Request preparation / handling
619648' ============================================= '
@@ -790,7 +819,9 @@ Public Function CreateResponseFromHttp(ByRef Http As Object, Optional Format As
790819 CreateResponseFromHttp.Content = Http.ResponseText
791820
792821 ' Convert content to data by format
793- Set CreateResponseFromHttp.Data = RestHelpers.ParseByFormat(Http.ResponseText, Format)
822+ If Format <> AvailableFormats.plaintext Then
823+ Set CreateResponseFromHttp.Data = RestHelpers.ParseByFormat(Http.ResponseText, Format)
824+ End If
794825
795826 ' Extract headers
796827 Set CreateResponseFromHttp.Headers = ExtractHeadersFromResponseHeaders(Http.getAllResponseHeaders)
@@ -924,7 +955,7 @@ Public Function UpdateResponse(ByRef Original As RestResponse, Updated As RestRe
924955 Set Original.Cookies = Updated.Cookies
925956
926957 If Not IsEmpty(Updated.Data) Then
927- If VarType (Updated.Data) = vbObject Then
958+ If IsObject (Updated.Data) Then
928959 Set Original.Data = Updated.Data
929960 Else
930961 Original.Data = Updated.Data
@@ -946,6 +977,10 @@ Public Function FormatToName(Format As AvailableFormats) As String
946977 FormatToName = "form-urlencoded"
947978 Case AvailableFormats.json
948979 FormatToName = "json"
980+ Case AvailableFormats.xml
981+ FormatToName = "xml"
982+ Case AvailableFormats.plaintext
983+ FormatToName = "txt"
949984 End Select
950985End Function
951986
@@ -961,6 +996,10 @@ Public Function FormatToContentType(Format As AvailableFormats) As String
961996 FormatToContentType = "application/x-www-form-urlencoded;charset=UTF-8"
962997 Case AvailableFormats.json
963998 FormatToContentType = "application/json"
999+ Case AvailableFormats.xml
1000+ FormatToContentType = "application/xml"
1001+ Case AvailableFormats.plaintext
1002+ FormatToContentType = "text/plain"
9641003 End Select
9651004End Function
9661005
@@ -1090,18 +1129,18 @@ Public Function BytesToHex(Bytes() As Byte) As String
10901129End Function
10911130
10921131Public Function BytesToBase64 (Bytes() As Byte ) As String
1093- Dim XML As Object
1132+ Dim xml As Object
10941133 Dim Node As Object
1095- Set XML = CreateObject("MSXML2.DOMDocument" )
1134+ Set xml = CreateObject("MSXML2.DOMDocument" )
10961135
10971136 ' byte array to base64
1098- Set Node = XML .createElement("b64" )
1137+ Set Node = xml .createElement("b64" )
10991138 Node.DataType = "bin.base64"
11001139 Node.nodeTypedValue = Bytes
11011140 BytesToBase64 = Node.Text
11021141
11031142 Set Node = Nothing
1104- Set XML = Nothing
1143+ Set xml = Nothing
11051144End Function
11061145
11071146''
0 commit comments