Skip to content

Commit

Permalink
2.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Joey French committed May 11, 2016
1 parent 1f574a8 commit 798a123
Show file tree
Hide file tree
Showing 33 changed files with 865 additions and 128 deletions.
Binary file added Get Started.xlsm
Binary file not shown.
Binary file modified Intrinio_Excel_Addin.xlam
Binary file not shown.
13 changes: 12 additions & 1 deletion lib/VBA-Dictionary/Dictionary.cls
Expand Up @@ -7,8 +7,9 @@ Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Attribute VB_Description = "Drop-in replacement for Scripting.Dictionary on Mac\r\n\r\nDictionary v1.4.0\r\n(c) Tim Hall - https://github.com/timhall/VBA-Dictionary\r\nAuthor: tim.hall.engr@gmail.com\r\nLicense: MIT (http://www.opensource.org/licenses/mit-license.php)\r\n"
''
' Dictionary v1.4.0
' Dictionary v1.4.1
' (c) Tim Hall - https://github.com/timhall/VBA-Dictionary
'
' Drop-in replacement for Scripting.Dictionary on Mac
Expand Down Expand Up @@ -55,6 +56,7 @@ End Enum
' --------------------------------------------- '

Public Property Get CompareMode() As CompareMethod
Attribute CompareMode.VB_Description = "Set or get the string comparison method."
#If Mac Or Not UseScriptingDictionaryIfAvailable Then
CompareMode = dict_pCompareMode
#Else
Expand All @@ -76,6 +78,7 @@ Public Property Let CompareMode(Value As CompareMethod)
End Property

Public Property Get Count() As Long
Attribute Count.VB_Description = "Get the number of items in the dictionary.\n"
#If Mac Or Not UseScriptingDictionaryIfAvailable Then
Count = dict_pKeyValues.Count
#Else
Expand All @@ -84,6 +87,7 @@ Public Property Get Count() As Long
End Property

Public Property Get Item(Key As Variant) As Variant
Attribute Item.VB_Description = "Set or get the item for a given key."
Attribute Item.VB_UserMemId = 0
#If Mac Or Not UseScriptingDictionaryIfAvailable Then
Dim dict_KeyValue As Variant
Expand Down Expand Up @@ -130,6 +134,7 @@ Public Property Set Item(Key As Variant, Value As Variant)
End Property

Public Property Let Key(Previous As Variant, Updated As Variant)
Attribute Key.VB_Description = "Change a key to a different key."
#If Mac Or Not UseScriptingDictionaryIfAvailable Then
Dim dict_KeyValue As Variant
dict_KeyValue = dict_GetKeyValue(Previous)
Expand All @@ -153,6 +158,7 @@ End Property
' @param {Variant} Item
' --------------------------------------------- '
Public Sub Add(Key As Variant, Item As Variant)
Attribute Add.VB_Description = "Add a new key and item to the dictionary."
#If Mac Or Not UseScriptingDictionaryIfAvailable Then
If Not Me.Exists(Key) Then
dict_AddKeyValue Key, Item
Expand All @@ -172,6 +178,7 @@ End Sub
' @return {Boolean}
' --------------------------------------------- '
Public Function Exists(Key As Variant) As Boolean
Attribute Exists.VB_Description = "Determine if a given key is in the dictionary."
#If Mac Or Not UseScriptingDictionaryIfAvailable Then
Exists = Not IsEmpty(dict_GetKeyValue(Key))
#Else
Expand All @@ -185,6 +192,7 @@ End Function
' @return {Variant}
' --------------------------------------------- '
Public Function Items() As Variant
Attribute Items.VB_Description = "Get an array containing all items in the dictionary."
#If Mac Or Not UseScriptingDictionaryIfAvailable Then
If Me.Count > 0 Then
Items = dict_pItems
Expand All @@ -203,6 +211,7 @@ End Function
' @return {Variant}
' --------------------------------------------- '
Public Function Keys() As Variant
Attribute Keys.VB_Description = "Get an array containing all keys in the dictionary."
#If Mac Or Not UseScriptingDictionaryIfAvailable Then
If Me.Count > 0 Then
Keys = dict_pKeys
Expand All @@ -221,6 +230,7 @@ End Function
' @param {Variant} Key
' --------------------------------------------- '
Public Sub Remove(Key As Variant)
Attribute Remove.VB_Description = "Remove a given key from the dictionary."
#If Mac Or Not UseScriptingDictionaryIfAvailable Then
Dim dict_KeyValue As Variant
dict_KeyValue = dict_GetKeyValue(Key)
Expand All @@ -240,6 +250,7 @@ End Sub
' Remove all items
' --------------------------------------------- '
Public Sub RemoveAll()
Attribute RemoveAll.VB_Description = "Remove all information from the dictionary."
#If Mac Or Not UseScriptingDictionaryIfAvailable Then
Set dict_pKeyValues = New Collection

Expand Down
Binary file modified lib/VBA-Dictionary/specs/VBA-Dictionary - Specs.xlsm
Binary file not shown.
1 change: 1 addition & 0 deletions lib/VBA-Web/CHANGELOG.md
Expand Up @@ -30,6 +30,7 @@ Major Changes:
- __4.0.19__ Fix installer and update VBA-JSON to v1.0.3
- __4.0.20__ Update VBA-JSON to v2.0.1 (Note: Breaking change in VBA-JSON, Solidus is no longer escaped by default)
- __4.0.21__ Fix `vbCrLf` issue in Excel for Mac 2016 and namespace internal method calls
- __4.0.22__ Add `Request.UserAgent`, sort OAuth1 querystring parameters, fix `UrlEncode` issues, and `WebClient` tweaks

Breaking Changes:

Expand Down
8 changes: 4 additions & 4 deletions lib/VBA-Web/README.md
Expand Up @@ -6,7 +6,7 @@ VBA-Web (formerly Excel-REST) makes working with complex webservices and APIs ea
Getting started
---------------

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

Expand Down Expand Up @@ -151,9 +151,9 @@ Function QueryTwitter(Query As String) As WebResponse
Request.Resource = "search/tweets.json"
Request.Format = WebFormat.Json
Request.Method = WebMethod.HttpGet
Request.AddParameter "q", Query
Request.AddParameter "lang", "en"
Request.AddParameter "count", 20
Request.AddQuerystringParam "q", Query
Request.AddQuerystringParam "lang", "en"
Request.AddQuerystringParam "count", 20

' => GET https://api.twitter.com/1.1/search/tweets.json?q=...&lang=en&count=20
' Authorization Bearer Token... (received and added automatically via TwitterAuthenticator)
Expand Down
Binary file modified lib/VBA-Web/VBA-Web - Blank.xlsm
Binary file not shown.
Binary file modified lib/VBA-Web/VBA-Web - Installer.xlsm
Binary file not shown.
59 changes: 41 additions & 18 deletions lib/VBA-Web/authenticators/OAuth1Authenticator.cls
Expand Up @@ -171,20 +171,21 @@ End Function
''
Public Function CreateBaseString(auth_Nonce As String, auth_Timestamp As String, auth_Client As WebClient, auth_Request As WebRequest) As String
Dim auth_Base As String
Dim auth_Parameters As String
Dim auth_Parameters() As String

' Check for parameters and add to auth_Base if present
auth_Parameters = GetRequestParameters(auth_Client, auth_Request)
If auth_Parameters <> "" Then
auth_Base = auth_Parameters & "&"
End If
' Add and sort parameters
auth_Parameters = VBA.Split(GetRequestParameters(auth_Client, auth_Request), "&")
ReDim Preserve auth_Parameters(UBound(auth_Parameters) + 6)

auth_Parameters(UBound(auth_Parameters) - 5) = "oauth_consumer_key=" & Me.ConsumerKey
auth_Parameters(UBound(auth_Parameters) - 4) = "oauth_nonce=" & auth_Nonce
auth_Parameters(UBound(auth_Parameters) - 3) = "oauth_signature_method=" & auth_SignatureMethod
auth_Parameters(UBound(auth_Parameters) - 2) = "oauth_timestamp=" & auth_Timestamp
auth_Parameters(UBound(auth_Parameters) - 1) = "oauth_token=" & Me.Token
auth_Parameters(UBound(auth_Parameters)) = "oauth_version=1.0"

auth_Base = auth_Base & "oauth_consumer_key" & "=" & Me.ConsumerKey
auth_Base = auth_Base & "&" & "oauth_nonce" & "=" & auth_Nonce
auth_Base = auth_Base & "&" & "oauth_signature_method" & "=" & auth_SignatureMethod
auth_Base = auth_Base & "&" & "oauth_timestamp" & "=" & auth_Timestamp
auth_Base = auth_Base & "&" & "oauth_token" & "=" & Me.Token
auth_Base = auth_Base & "&" & "oauth_version=1.0"
auth_Parameters = SortParameters(auth_Parameters)
auth_Base = VBA.Join(auth_Parameters, "&")

CreateBaseString = WebHelpers.MethodToName(auth_Request.Method) & "&" & _
WebHelpers.UrlEncode(GetRequestUrl(auth_Client, auth_Request), EncodeUnsafe:=False) & "&" & _
Expand Down Expand Up @@ -251,16 +252,38 @@ End Function
' @return {String}
''
Public Function GetRequestParameters(auth_Client As WebClient, auth_Request As WebRequest) As String
' TODO Sort parameters by key then value

Dim auth_Parts As Dictionary
Set auth_Parts = WebHelpers.GetUrlParts(auth_Client.GetFullUrl(auth_Request))

' Remove leading ?
GetRequestParameters = auth_Parts("Querystring")

' Replace + for spaces with %20
GetRequestParameters = Replace(GetRequestParameters, "+", "%20")
GetRequestParameters = VBA.Replace(auth_Parts("Querystring"), "+", "%20")
End Function

''
' Sort parameters (by value then key)
'
' @internal
' @param {Variant} Parameters
' @return {Variant}
''
Public Function SortParameters(auth_Parameters As Variant) As Variant
' Sort by key then value = sort by combined key-value
' (shouldn't be too many parameters, use naive selection sort
Dim auth_Temp As String
Dim auth_i As Long
Dim auth_j As Long

For auth_i = LBound(auth_Parameters) To UBound(auth_Parameters)
For auth_j = auth_i To UBound(auth_Parameters)
If auth_Parameters(auth_j) < auth_Parameters(auth_i) Then
auth_Temp = auth_Parameters(auth_i)
auth_Parameters(auth_i) = auth_Parameters(auth_j)
auth_Parameters(auth_j) = auth_Temp
End If
Next auth_j
Next auth_i

SortParameters = auth_Parameters
End Function

' ============================================= '
Expand Down
Binary file modified lib/VBA-Web/examples/VBA-Web - Example.xlsm
Binary file not shown.
30 changes: 28 additions & 2 deletions lib/VBA-Web/examples/gmail/Gmail.bas
@@ -1,6 +1,32 @@
Attribute VB_Name = "Gmail"
' Setup client and authenticator (cached between requests)
Private pGmailClientId As String
Private pGmailClientSecret As String
Private pGmailClient As WebClient

Private Property Get GmailClientId() As String
If pGmailClientId = "" Then
If Credentials.Loaded Then
pGmailClientId = Credentials.Values("Google")("id")
Else
pGmailClientId = InputBox("Please Enter Google API Client Id")
End If
End If

GmailClientId = pGmailClientId
End Property
Private Property Get GmailClientSecret() As String
If pGmailClientSecret = "" Then
If Credentials.Loaded Then
pGmailClientSecret = Credentials.Values("Google")("secret")
Else
pGmailClientSecret = InputBox("Please Enter Google API Client Secret")
End If
End If

GmailClientSecret = pGmailClientSecret
End Property

' Setup client and authenticator (cached between requests)
Private Property Get GmailClient() As WebClient
If pGmailClient Is Nothing Then
' Create client with base url that is appended to all requests
Expand All @@ -12,7 +38,7 @@ Private Property Get GmailClient() As WebClient
' - Get API client id and secret from https://console.developers.google.com/
' - https://github.com/VBA-tools/VBA-Web/wiki/Google-APIs for more info
Dim Auth As New GoogleAuthenticator
Auth.Setup CStr(Credentials.Values("Google")("id")), CStr(Credentials.Values("Google")("secret"))
Auth.Setup CStr(GmailClientId), CStr(GmailClientSecret)
Auth.AddScope "https://www.googleapis.com/auth/gmail.readonly"
Auth.Login
Set pGmailClient.Authenticator = Auth
Expand Down
12 changes: 11 additions & 1 deletion lib/VBA-Web/specs/Specs_OAuth1Authenticator.bas
Expand Up @@ -43,7 +43,7 @@ Public Function Specs() As SpecSuite
.Expect(Auth.GetRequestUrl(Client, Request)).ToEqual "http://localhost:3000/a/b/c"
End With

With Specs.It("should property format request parameters")
With Specs.It("should properly format request parameters")
Set Request = New WebRequest
Request.Resource = "resource"
Request.AddQuerystringParam "a", True
Expand Down Expand Up @@ -73,6 +73,16 @@ Public Function Specs() As SpecSuite
.Expect(Client.GetFullUrl(Request)).ToEqual "http://localhost:3000/testing?a=a+b"
End With

With Specs.It("should sort querystring parameters")
Client.BaseUrl = "HTTP://localhost:3000/testing"
Set Request = New WebRequest
Request.Resource = "?c=Howdy!&b=456"
Request.AddQuerystringParam "d", 789
Request.AddQuerystringParam "a", 123

.Expect(VBA.Join(Auth.SortParameters(VBA.Split(Auth.GetRequestParameters(Client, Request), "&")), "&")).ToEqual "a=123&b=456&c=Howdy!&d=789"
End With

Set Client = New WebClient
Set Request = New WebRequest

Expand Down
5 changes: 3 additions & 2 deletions lib/VBA-Web/specs/Specs_WebHelpers.bas
Expand Up @@ -194,9 +194,10 @@ Public Function Specs() As SpecSuite
' UrlEncode
' --------------------------------------------- '
With Specs.It("should url-encode string (with space as plus and encode unsafe options)")
.Expect(WebHelpers.UrlEncode("$&+,/:;=?@", EncodeUnsafe:=False)).ToEqual "%24%26%2B%2C%2F%3A%3B%3D%3F%40"
.Expect(WebHelpers.UrlEncode("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890$-_.+!*'(),")).ToEqual "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890$-_.+!*'(),"
.Expect(WebHelpers.UrlEncode("&/:;=?@")).ToEqual "%26%2F%3A%3B%3D%3F%40"
.Expect(WebHelpers.UrlEncode(" ""<>#%{}|\^~[]`")).ToEqual "%20%22%3C%3E%23%25%7B%7D%7C%5C%5E%7E%5B%5D%60"
.Expect(WebHelpers.UrlEncode("A + B")).ToEqual "A%20%2B%20B"
.Expect(WebHelpers.UrlEncode("A + B")).ToEqual "A%20+%20B"
.Expect(WebHelpers.UrlEncode("A + B", SpaceAsPlus:=True)).ToEqual "A+%2B+B"
End With

Expand Down
9 changes: 5 additions & 4 deletions lib/VBA-Web/specs/Specs_WebRequest.bas
Expand Up @@ -228,9 +228,9 @@ Public Function Specs() As SpecSuite
Set Request = New WebRequest

Request.Resource = "{segment}"
Request.AddUrlSegment "segment", "$&+,/:;=?@"
Request.AddUrlSegment "segment", "&/:;=?@"

.Expect(Request.FormattedResource).ToEqual "%24%26%2B%2C%2F%3A%3B%3D%3F%40"
.Expect(Request.FormattedResource).ToEqual "%26%2F%3A%3B%3D%3F%40"
End With

With Specs.It("FormattedResource should include querystring parameters")
Expand Down Expand Up @@ -266,11 +266,12 @@ Public Function Specs() As SpecSuite
With Specs.It("FormattedResource should URL encode querystring")
Set Request = New WebRequest

Request.AddQuerystringParam "A B", "$&+,/:;=?@"
Request.AddQuerystringParam "A B", "&/:;=?@"

.Expect(Request.FormattedResource).ToEqual "?A+B=%24%26%2B%2C%2F%3A%3B%3D%3F%40"
.Expect(Request.FormattedResource).ToEqual "?A+B=%26%2F%3A%3B%3D%3F%40"
End With

' UserAgent
' Cookies
' Headers
' QuerystringParams
Expand Down
Binary file modified lib/VBA-Web/specs/VBA-Web - Specs - Async.xlsm
Binary file not shown.
Binary file modified lib/VBA-Web/specs/VBA-Web - Specs.xlsm
Binary file not shown.
2 changes: 1 addition & 1 deletion lib/VBA-Web/src/IWebAuthenticator.cls
Expand Up @@ -8,7 +8,7 @@ Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
''
' IWebAuthenticator v4.0.21
' IWebAuthenticator v4.0.22
' (c) Tim Hall - https://github.com/VBA-tools/VBA-Web
'
' Interface for creating authenticators for rest client
Expand Down
2 changes: 1 addition & 1 deletion lib/VBA-Web/src/WebAsyncWrapper.cls
Expand Up @@ -8,7 +8,7 @@ Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
''
' WebAsyncWrapper v4.0.21
' WebAsyncWrapper v4.0.22
' (c) Tim Hall - https://github.com/VBA-tools/VBA-Web
'
' Wrapper WebClient and WebRequest that enables callback-style async requests
Expand Down

0 comments on commit 798a123

Please sign in to comment.