REBOL [
author: "chl"
date: [2002-04-13 2002-04-14]
version: 0.2
]
context [
xml-head: join {}
soap-head: {}
soap-tail: {}
encode-xsd: func [type name value] [
rejoin ["<" name { xsi:type="xsd:} type {">} value "" name ">"]
]
key: none
set-key: func [key] [
self/key: key
]
encode-call: func [procedure ns encoded-params] [
rejoin [
xml-head soap-head
"<" ns/1 ":" procedure " xmlns:"
ns/1 {="} ns/2 {" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">}
encoded-params
"" ns/1 ":" procedure ">"
soap-tail
]
]
soap-endpoint: ["api.google.com" 80 "/search/beta2"]
call: func [procedure ns encoded-params /local soap-req req data conn res] [
soap-req: encode-call procedure ns encoded-params
req: copy ""
append req rejoin ["POST " soap-endpoint/3 " HTTP/1.0" newline]
append req rejoin ["Host: " soap-endpoint/1 newline]
append req rejoin ["User-Agent: sySOAP 0.1/goo" newline]
append req rejoin ["Content-Type: text/xml" newline]
append req rejoin ["Content-Length: " (length? soap-req) newline]
append req rejoin ["SOAPAction: " newline]
append req newline
append req soap-req
conn: open to-url rejoin ["tcp://" soap-endpoint/1 ":" soap-endpoint/2]
insert conn req ; probe here
res: copy ""
while [data: copy conn] [append res data]
close conn
res
]
search: func [term start max /local params res results url title snippet n] [
params: rejoin [
encode-xsd 'string "key" key
encode-xsd 'string "q" term
encode-xsd 'int "start" start
encode-xsd 'int "maxResults" max
encode-xsd 'boolean "filter" "false"
encode-xsd 'string "restrict" ""
encode-xsd 'boolean "safeSearch" false
encode-xsd 'string "lr" ""
encode-xsd 'string "ie" "latin-1"
encode-xsd 'string "oe" "latin-1"
]
res: find call "doGoogleSearch" [ns1 "urn:GoogleSearch"] params ""
results: copy []
parse res [any [
(url: title: snippet: none)
to "} copy snippet to ""
thru {} copy url to ""
thru {
} copy title to ""
(repend/only results [url title snippet])
] to end
]
n: 0
parse res [thru {} copy n to {}]
context compose/deep [n: (n) results: [(results)]]
]
spellcheck: func [phrase /local params res result] [
params: rejoin [
encode-xsd 'string "key" key
encode-xsd 'string "phrase" phrase
]
res: find call "doSpellingSuggestion" [ns1 "urn:GoogleSearch"] params ""
either found? find res "xsi:null" [
return none
] [
result: none
parse res [to "" copy result to ""]
return result
]
]
]