' simple demo of calling the Google Search API with PocketSOAP
'

dim t, key, searchRes

' You'll need to get your own account with google, and enter the key they send you here
key = "xx"

set t = CreateObject("pocketsOAP.HTTPTransport")
t.SetProxy "localhost", 7070


set res = GoogleSearch ( "pocketSOAP", 0, 10, true, "", true, "", "", "" )
wscript.echo res.ItemByName("estimatedTotalResultsCount").Value & " Estimated total results"
searchRes = res.ItemByName("resultElements").Value
for i = lbound(searchRes) to ubound(searchRes)
    wscript.echo searchRes(i).Nodes.ItemByName("title").Value & vbCRLF & vbTab & searchRes(i).Nodes.ItemByName("URL").Value & vbCRLF
next

Function GoogleSearch ( searchTerm, _
                        start, _
                        maxResults, _
                        MatchFilter, _
                        restrict,  _
                        safeSearch, _
                        languageRestrict, _
                        inputEncoding, _
                        outputEncoding )
    dim e                    
    set e = CreateObject("PocketSOAP.Envelope.2")
    e.SetMethod "doGoogleSearch", "urn:GoogleSearch"

    e.Parameters.Create "key", key
    e.Parameters.Create "q", searchTerm
    e.Parameters.Create "start", start
    e.Parameters.Create "maxResults", maxResults
    e.Parameters.Create "filter", MatchFilter
    e.Parameters.Create "restrict", restrict
    e.Parameters.Create "safeSearch", safeSearch
    e.Parameters.Create "lr", languageRestrict
    e.Parameters.Create "ie", inputEncoding
    e.Parameters.Create "oe", outputEncoding
    
    
    t.SOAPAction = "urn:GoogleSearchAction"
    
    t.send "http://api.google.com/search/beta2", e.serialize
    e.parse t
    set GoogleSearch = e.parameters.item(0).Nodes
end Function
