Skip to content

Commit 4286a9f

Browse files
committed
v4.0.20
1 parent 254fcd1 commit 4286a9f

13 files changed

+153
-152
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Major Changes:
2828
- __4.0.17__ Add `FollowRedirects` and follow redirects by default, convert stored body to Variant, fix multiple 100 Continue bug
2929
- __4.0.18__ Add `VBA.Randomize` to `CreateNonce` and add `TodoistAuthenticator`
3030
- __4.0.19__ Fix installer and update VBA-JSON to v1.0.3
31+
- __4.0.20__ Update VBA-JSON to v2.0.1 (Note: Breaking change in VBA-JSON, Solidus is no longer escaped by default)
3132

3233
Breaking Changes:
3334

README.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ VBA-Web (formerly Excel-REST) makes working with complex webservices and APIs ea
66
Getting started
77
---------------
88

9-
- Download the [latest release (v4.0.19)](https://github.com/VBA-tools/VBA-Web/releases)
9+
- Download the [latest release (v4.0.20)](https://github.com/VBA-tools/VBA-Web/releases)
1010
- To install/upgrade in an existing file, use `VBA-Web - Installer.xlsm`
1111
- To start from scratch in Excel, `VBA-Web - Blank.xlsm` has everything setup and ready to go
1212

@@ -39,19 +39,19 @@ Function GetDirections(Origin As String, Destination As String) As String
3939
' and set a base url that all requests will be appended to
4040
Dim MapsClient As New WebClient
4141
MapsClient.BaseUrl = "https://maps.googleapis.com/maps/api/"
42-
42+
4343
' Use GetJSON helper to execute simple request and work with response
4444
Dim Resource As String
4545
Dim Response As WebResponse
46-
46+
4747
Resource = "directions/json?" & _
4848
"origin=" & Origin & _
4949
"&destination=" & Destination & _
5050
"&sensor=false"
5151
Set Response = MapsClient.GetJSON(Resource)
52-
52+
5353
' => GET https://maps.../api/directions/json?origin=...&destination=...&sensor=false
54-
54+
5555
ProcessDirections Response
5656
End Function
5757

@@ -70,13 +70,13 @@ Public Sub ProcessDirections(Response As WebResponse)
7070
End Sub
7171
```
7272

73-
There are 3 primary components in VBA-Web:
73+
There are 3 primary components in VBA-Web:
7474

7575
1. `WebRequest` for defining complex requests
7676
2. `WebClient` for executing requests
77-
3. `WebResponse` for dealing with responses.
78-
79-
In the above example, the request is fairly simple, so we can skip creating a `WebRequest` and instead use the `Client.GetJSON` helper to GET json from a specific url. In processing the response, we can look at the `StatusCode` to make sure the request succeeded and then use the parsed json in the `Data` parameter to extract complex information from the response.
77+
3. `WebResponse` for dealing with responses.
78+
79+
In the above example, the request is fairly simple, so we can skip creating a `WebRequest` and instead use the `Client.GetJSON` helper to GET json from a specific url. In processing the response, we can look at the `StatusCode` to make sure the request succeeded and then use the parsed json in the `Data` parameter to extract complex information from the response.
8080

8181
### WebRequest Example
8282

@@ -86,30 +86,30 @@ If you wish to have more control over the request, the following example uses `W
8686
Function GetDirections(Origin As String, Destination As String) As String
8787
Dim MapsClient As New WebClient
8888
MapsClient.BaseUrl = "https://maps.googleapis.com/maps/api/"
89-
89+
9090
' Create a WebRequest for getting directions
9191
Dim DirectionsRequest As New WebRequest
9292
DirectionsRequest.Resource = "directions/{format}"
9393
DirectionsRequest.Method = WebMethod.HttpGet
94-
95-
' Set the request format
94+
95+
' Set the request format
9696
' -> Sets content-type and accept headers and parses the response
9797
DirectionsRequest.Format = WebFormat.Json
98-
98+
9999
' Replace {format} segment
100100
DirectionsRequest.AddUrlSegment "format", "json"
101-
101+
102102
' Add querystring to the request
103103
DirectionsRequest.AddQuerystringParam "origin", Origin
104104
DirectionsRequest.AddQuerystringParam "destination", Destination
105105
DirectionsRequest.AddQuerystringParam "sensor", "false"
106-
106+
107107
' => GET https://maps.../api/directions/json?origin=...&destination=...&sensor=false
108-
108+
109109
' Execute the request and work with the response
110110
Dim Response As WebResponse
111111
Set Response = MapsClient.Execute(DirectionsRequest)
112-
112+
113113
ProcessDirections Response
114114
End Function
115115

@@ -138,14 +138,14 @@ The following example demonstrates using an authenticator with VBA-Web to query
138138
Function QueryTwitter(Query As String) As WebResponse
139139
Dim TwitterClient As New WebClient
140140
TwitterClient.BaseUrl = "https://api.twitter.com/1.1/"
141-
141+
142142
' Setup authenticator
143143
Dim TwitterAuth As New TwitterAuthenticator
144144
TwitterAuth.Setup _
145145
ConsumerKey:="Your consumer key", _
146146
ConsumerSecret:="Your consumer secret"
147147
Set TwitterClient.Authenticator = TwitterAuth
148-
148+
149149
' Setup query request
150150
Dim Request As New WebRequest
151151
Request.Resource = "search/tweets.json"
@@ -154,10 +154,10 @@ Function QueryTwitter(Query As String) As WebResponse
154154
Request.AddParameter "q", Query
155155
Request.AddParameter "lang", "en"
156156
Request.AddParameter "count", 20
157-
157+
158158
' => GET https://api.twitter.com/1.1/search/tweets.json?q=...&lang=en&count=20
159159
' Authorization Bearer Token... (received and added automatically via TwitterAuthenticator)
160-
160+
161161
Set QueryTwitter = TwitterClient.Execute(Request)
162162
End Function
163163
```

VBA-Web - Blank.xlsm

2.58 KB
Binary file not shown.

VBA-Web - Installer.xlsm

579 Bytes
Binary file not shown.

examples/VBA-Web - Example.xlsm

-86.3 KB
Binary file not shown.

specs/VBA-Web - Specs - Async.xlsm

9.08 KB
Binary file not shown.

specs/VBA-Web - Specs.xlsm

22.3 KB
Binary file not shown.

src/IWebAuthenticator.cls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Attribute VB_Creatable = False
88
Attribute VB_PredeclaredId = False
99
Attribute VB_Exposed = True
1010
''
11-
' IWebAuthenticator v4.0.19
11+
' IWebAuthenticator v4.0.20
1212
' (c) Tim Hall - https://github.com/VBA-tools/VBA-Web
1313
'
1414
' Interface for creating authenticators for rest client

src/WebAsyncWrapper.cls

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Attribute VB_Creatable = False
88
Attribute VB_PredeclaredId = False
99
Attribute VB_Exposed = True
1010
''
11-
' WebAsyncWrapper v4.0.19
11+
' WebAsyncWrapper v4.0.20
1212
' (c) Tim Hall - https://github.com/VBA-tools/VBA-Web
1313
'
1414
' Wrapper WebClient and WebRequest that enables callback-style async requests
@@ -84,7 +84,7 @@ Public Property Set Client(Value As WebClient)
8484
Dim web_ErrorDescription As String
8585
web_ErrorDescription = "The Client for a WebAsyncWrapper should not be changed as it may affect any currently executing Requests. " & _
8686
"A new WebAsyncWrapper should be created for each WebClient."
87-
87+
8888
WebHelpers.LogError web_ErrorDescription, "WebAsyncWrapper.Client", vbObjectError + 11050
8989
Err.Raise vbObjectError + 11050, "WebAsyncWrapper.Client", web_ErrorDescription
9090
End If
@@ -107,7 +107,7 @@ Public Sub ExecuteAsync(Request As WebRequest, Callback As String, Optional ByVa
107107
' - AsyncWrapper can only watch one WinHttpRequest's events
108108
' - Callback + CallbackArgs would need to be stored per Request
109109
Dim web_Async As WebAsyncWrapper
110-
110+
111111
Set web_Async = Me.Clone
112112
web_Async.PrepareAndExecuteRequest Request, Callback, CallbackArgs
113113
End Sub
@@ -138,19 +138,19 @@ Public Sub PrepareAndExecuteRequest(Request As WebRequest, Callback As String, O
138138

139139
Me.Callback = Callback
140140
Me.CallbackArgs = CallbackArgs
141-
141+
142142
Set Me.Request = Request.Clone
143143
Set Me.Http = Me.Client.PrepareHttpRequest(Request)
144144

145145
web_StartTimeoutTimer
146146
Me.Http.Send Request.Body
147147
Exit Sub
148-
148+
149149
web_ErrorHandling:
150-
150+
151151
Set Me.Http = Nothing
152152
Set Me.Request = Nothing
153-
153+
154154
' Rethrow error
155155
Err.Raise Err.Number, Err.Source, Err.Description
156156
End Sub
@@ -163,10 +163,10 @@ End Sub
163163
''
164164
Public Sub TimedOut()
165165
Dim web_Response As New WebResponse
166-
166+
167167
web_StopTimeoutTimer
168168
WebHelpers.LogDebug "Timed out", "WebAsyncWrapper.TimedOut"
169-
169+
170170
' Callback
171171
web_Response.StatusCode = WebStatusCode.RequestTimeout
172172
web_Response.StatusDescription = "Request Timeout"
@@ -191,9 +191,9 @@ Private Sub web_RunCallback(web_Response As WebResponse)
191191
' Debug.Print args(i) & " was passed into async execute"
192192
' Next i
193193
' End Function
194-
194+
195195
WebHelpers.LogResponse Me.Client, Me.Request, web_Response
196-
196+
197197
If Not Me.Client.Authenticator Is Nothing Then
198198
Me.Client.Authenticator.AfterExecute Me.Client, Me.Request, web_Response
199199
End If
@@ -205,7 +205,7 @@ Private Sub web_RunCallback(web_Response As WebResponse)
205205
Application.Run Me.Callback, web_Response
206206
End If
207207
End If
208-
208+
209209
Set Me.Http = Nothing
210210
Set Me.Request = Nothing
211211
End Sub
@@ -215,13 +215,13 @@ Private Sub web_StartTimeoutTimer()
215215
Dim web_TimeoutS As Long
216216

217217
If WebHelpers.AsyncRequests Is Nothing Then: Set WebHelpers.AsyncRequests = New Dictionary
218-
218+
219219
' Round ms to seconds with minimum of 1 second if ms > 0
220220
web_TimeoutS = Round(Me.Client.TimeoutMs / 1000, 0)
221221
If Me.Client.TimeoutMs > 0 And web_TimeoutS = 0 Then
222222
web_TimeoutS = 1
223223
End If
224-
224+
225225
WebHelpers.AsyncRequests.Add Me.Request.Id, Me
226226
Application.OnTime Now + TimeValue("00:00:" & web_TimeoutS), "'WebHelpers.OnTimeoutTimerExpired """ & Me.Request.Id & """'"
227227
End Sub
@@ -238,9 +238,9 @@ End Sub
238238
' Process asynchronous requests
239239
Private Sub Http_OnResponseFinished()
240240
Dim web_Response As New WebResponse
241-
241+
242242
web_StopTimeoutTimer
243-
243+
244244
' Callback
245245
web_Response.CreateFromHttp Me.Client, Me.Request, Me.Http
246246
web_RunCallback web_Response

0 commit comments

Comments
 (0)