VERSION 1.0 CLASS BEGIN MultiUse = -1 'True END Attribute VB_Name = "Endpoint" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False '@Folder("SeleniumVBA") '@PredeclaredId 'See https://w3c.github.io/webdriver/#endpoints Option Explicit Private Const DELIMITER_START As String = "{" Private Const DELIMITER_END As String = "}" '=============================================' 'Types '=============================================' Private Type TEndpoint Method As String uriTemplate As String 'Uniform Resource Identifier (URI) Template End Type '=============================================' 'Private Variables '=============================================' Private this As TEndpoint '=============================================' 'Constructors and destructors '=============================================' Public Function Create(ByVal Method As String, ByVal sURITemplate As String) As Endpoint With New Endpoint .RequestMethod = Method .uriTemplate = sURITemplate Set Create = .Self End With End Function '=============================================' 'Properties '=============================================' Public Property Get RequestMethod() As String RequestMethod = this.Method End Property Public Property Let RequestMethod(ByVal Method As String) this.Method = Method End Property Public Property Get uriTemplate() As String uriTemplate = this.uriTemplate End Property Public Property Let uriTemplate(ByVal strURITemplate As String) this.uriTemplate = strURITemplate End Property Public Property Get Self() As Endpoint Set Self = Me End Property '=============================================' 'Public Methods '=============================================' Public Function ParseURI(Optional ByVal uriParameters As Scripting.Dictionary = Nothing) As String Dim Path As String Path = this.uriTemplate If Not uriParameters Is Nothing Then ' Replace url parameters with user defined values. ' {session id}, {element id}, etc.. Dim paramKey As Variant For Each paramKey In uriParameters Path = Replace(Path, paramKey, uriParameters.Item(paramKey)) Next End If ParseURI = Path End Function '@TODO Remove just for testing 'Obtains a list of strings found between two delimiters eg (variable name) Private Function ParseParameters(ByVal strMain As String, delimiterStart As String, delimiterEnd As String) As Scripting.Dictionary Dim i As Integer Dim j As Integer Dim startPos As Integer Dim foundDelimeters As Boolean Dim strParamater As String Dim dictParmaters As Scripting.Dictionary Set dictParmaters = New Scripting.Dictionary startPos = 1 Do i = InStr(startPos, strMain, delimiterStart) If i <> 0 Then j = InStr(i, strMain, delimiterEnd) End If If i = 0 Or j = 0 Then foundDelimeters = False Else foundDelimeters = True i = i + Len(delimiterStart) strParamater = Mid(strMain, i, j - i) dictParmaters.Add strParamater, strParamater Debug.Print dictParmaters.Item(strParamater) startPos = j + Len(delimiterEnd) - 1 End If Loop While foundDelimeters = True And startPos < Len(strMain) If dictParmaters.Count = 0 Then Set dictParmaters = Nothing End If Set ParseParameters = dictParmaters End Function