diff options
Diffstat (limited to 'sample/wsdl/googleSearch')
-rw-r--r-- | sample/wsdl/googleSearch/GoogleSearch.rb | 258 | ||||
-rw-r--r-- | sample/wsdl/googleSearch/GoogleSearchDriver.rb | 101 | ||||
-rw-r--r-- | sample/wsdl/googleSearch/README | 6 | ||||
-rw-r--r-- | sample/wsdl/googleSearch/httpd.rb | 15 | ||||
-rw-r--r-- | sample/wsdl/googleSearch/sampleClient.rb | 56 | ||||
-rw-r--r-- | sample/wsdl/googleSearch/sjissearch.sh | 3 | ||||
-rw-r--r-- | sample/wsdl/googleSearch/wsdlDriver.rb | 23 |
7 files changed, 462 insertions, 0 deletions
diff --git a/sample/wsdl/googleSearch/GoogleSearch.rb b/sample/wsdl/googleSearch/GoogleSearch.rb new file mode 100644 index 0000000000..e124208b91 --- /dev/null +++ b/sample/wsdl/googleSearch/GoogleSearch.rb @@ -0,0 +1,258 @@ +# urn:GoogleSearch +class GoogleSearchResult + @@schema_type = "GoogleSearchResult" + @@schema_ns = "urn:GoogleSearch" + + def documentFiltering + @documentFiltering + end + + def documentFiltering=(value) + @documentFiltering = value + end + + def searchComments + @searchComments + end + + def searchComments=(value) + @searchComments = value + end + + def estimatedTotalResultsCount + @estimatedTotalResultsCount + end + + def estimatedTotalResultsCount=(value) + @estimatedTotalResultsCount = value + end + + def estimateIsExact + @estimateIsExact + end + + def estimateIsExact=(value) + @estimateIsExact = value + end + + def resultElements + @resultElements + end + + def resultElements=(value) + @resultElements = value + end + + def searchQuery + @searchQuery + end + + def searchQuery=(value) + @searchQuery = value + end + + def startIndex + @startIndex + end + + def startIndex=(value) + @startIndex = value + end + + def endIndex + @endIndex + end + + def endIndex=(value) + @endIndex = value + end + + def searchTips + @searchTips + end + + def searchTips=(value) + @searchTips = value + end + + def directoryCategories + @directoryCategories + end + + def directoryCategories=(value) + @directoryCategories = value + end + + def searchTime + @searchTime + end + + def searchTime=(value) + @searchTime = value + end + + def initialize(documentFiltering = nil, + searchComments = nil, + estimatedTotalResultsCount = nil, + estimateIsExact = nil, + resultElements = nil, + searchQuery = nil, + startIndex = nil, + endIndex = nil, + searchTips = nil, + directoryCategories = nil, + searchTime = nil) + @documentFiltering = documentFiltering + @searchComments = searchComments + @estimatedTotalResultsCount = estimatedTotalResultsCount + @estimateIsExact = estimateIsExact + @resultElements = resultElements + @searchQuery = searchQuery + @startIndex = startIndex + @endIndex = endIndex + @searchTips = searchTips + @directoryCategories = directoryCategories + @searchTime = searchTime + end +end + +# urn:GoogleSearch +class ResultElement + @@schema_type = "ResultElement" + @@schema_ns = "urn:GoogleSearch" + + def summary + @summary + end + + def summary=(value) + @summary = value + end + + def URL + @uRL + end + + def URL=(value) + @uRL = value + end + + def snippet + @snippet + end + + def snippet=(value) + @snippet = value + end + + def title + @title + end + + def title=(value) + @title = value + end + + def cachedSize + @cachedSize + end + + def cachedSize=(value) + @cachedSize = value + end + + def relatedInformationPresent + @relatedInformationPresent + end + + def relatedInformationPresent=(value) + @relatedInformationPresent = value + end + + def hostName + @hostName + end + + def hostName=(value) + @hostName = value + end + + def directoryCategory + @directoryCategory + end + + def directoryCategory=(value) + @directoryCategory = value + end + + def directoryTitle + @directoryTitle + end + + def directoryTitle=(value) + @directoryTitle = value + end + + def initialize(summary = nil, + uRL = nil, + snippet = nil, + title = nil, + cachedSize = nil, + relatedInformationPresent = nil, + hostName = nil, + directoryCategory = nil, + directoryTitle = nil) + @summary = summary + @uRL = uRL + @snippet = snippet + @title = title + @cachedSize = cachedSize + @relatedInformationPresent = relatedInformationPresent + @hostName = hostName + @directoryCategory = directoryCategory + @directoryTitle = directoryTitle + end +end + +# urn:GoogleSearch +class ResultElementArray < Array + # Contents type should be dumped here... + @@schema_type = "ResultElementArray" + @@schema_ns = "urn:GoogleSearch" +end + +# urn:GoogleSearch +class DirectoryCategoryArray < Array + # Contents type should be dumped here... + @@schema_type = "DirectoryCategoryArray" + @@schema_ns = "urn:GoogleSearch" +end + +# urn:GoogleSearch +class DirectoryCategory + @@schema_type = "DirectoryCategory" + @@schema_ns = "urn:GoogleSearch" + + def fullViewableName + @fullViewableName + end + + def fullViewableName=(value) + @fullViewableName = value + end + + def specialEncoding + @specialEncoding + end + + def specialEncoding=(value) + @specialEncoding = value + end + + def initialize(fullViewableName = nil, + specialEncoding = nil) + @fullViewableName = fullViewableName + @specialEncoding = specialEncoding + end +end + diff --git a/sample/wsdl/googleSearch/GoogleSearchDriver.rb b/sample/wsdl/googleSearch/GoogleSearchDriver.rb new file mode 100644 index 0000000000..9901b89071 --- /dev/null +++ b/sample/wsdl/googleSearch/GoogleSearchDriver.rb @@ -0,0 +1,101 @@ +require 'GoogleSearch.rb' + +require 'soap/rpc/driver' + +class GoogleSearchPort < SOAP::RPC::Driver + MappingRegistry = ::SOAP::Mapping::Registry.new + + MappingRegistry.set( + GoogleSearchResult, + ::SOAP::SOAPStruct, + ::SOAP::Mapping::Registry::TypedStructFactory, + { :type => XSD::QName.new("urn:GoogleSearch", "GoogleSearchResult") } + ) + MappingRegistry.set( + ResultElementArray, + ::SOAP::SOAPArray, + ::SOAP::Mapping::Registry::TypedArrayFactory, + { :type => XSD::QName.new("urn:GoogleSearch", "ResultElement") } + ) + MappingRegistry.set( + DirectoryCategoryArray, + ::SOAP::SOAPArray, + ::SOAP::Mapping::Registry::TypedArrayFactory, + { :type => XSD::QName.new("urn:GoogleSearch", "DirectoryCategory") } + ) + MappingRegistry.set( + ResultElement, + ::SOAP::SOAPStruct, + ::SOAP::Mapping::Registry::TypedStructFactory, + { :type => XSD::QName.new("urn:GoogleSearch", "ResultElement") } + ) + MappingRegistry.set( + DirectoryCategory, + ::SOAP::SOAPStruct, + ::SOAP::Mapping::Registry::TypedStructFactory, + { :type => XSD::QName.new("urn:GoogleSearch", "DirectoryCategory") } + ) + + Methods = [ + ["doGetCachedPage", "doGetCachedPage", [ + ["in", "key", + [SOAP::SOAPString]], + ["in", "url", + [SOAP::SOAPString]], + ["retval", "return", + [SOAP::SOAPBase64]]], + "urn:GoogleSearchAction", "urn:GoogleSearch"], + ["doSpellingSuggestion", "doSpellingSuggestion", [ + ["in", "key", + [SOAP::SOAPString]], + ["in", "phrase", + [SOAP::SOAPString]], + ["retval", "return", + [SOAP::SOAPString]]], + "urn:GoogleSearchAction", "urn:GoogleSearch"], + ["doGoogleSearch", "doGoogleSearch", [ + ["in", "key", + [SOAP::SOAPString]], + ["in", "q", + [SOAP::SOAPString]], + ["in", "start", + [SOAP::SOAPInt]], + ["in", "maxResults", + [SOAP::SOAPInt]], + ["in", "filter", + [SOAP::SOAPBoolean]], + ["in", "restrict", + [SOAP::SOAPString]], + ["in", "safeSearch", + [SOAP::SOAPBoolean]], + ["in", "lr", + [SOAP::SOAPString]], + ["in", "ie", + [SOAP::SOAPString]], + ["in", "oe", + [SOAP::SOAPString]], + ["retval", "return", + [::SOAP::SOAPStruct, "urn:GoogleSearch", "GoogleSearchResult"]]], + "urn:GoogleSearchAction", "urn:GoogleSearch"] + ] + + DefaultEndpointUrl = "http://api.google.com/search/beta2" + + def initialize(endpoint_url = nil) + endpoint_url ||= DefaultEndpointUrl + super(endpoint_url, nil) + self.mapping_registry = MappingRegistry + init_methods + end + +private + + def init_methods + Methods.each do |name_as, name, params, soapaction, namespace| + qname = XSD::QName.new(namespace, name_as) + @proxy.add_method(qname, soapaction, name, params) + add_rpc_method_interface(name, params) + end + end +end + diff --git a/sample/wsdl/googleSearch/README b/sample/wsdl/googleSearch/README new file mode 100644 index 0000000000..461a5634dc --- /dev/null +++ b/sample/wsdl/googleSearch/README @@ -0,0 +1,6 @@ +wsdlDriver.rb: Do google search using WSDL. + +Whole files except wsdl.rb in this directory is created by wsdl2ruby.rb from +GoogleSearch.wsdl with options; + +% wsdl2ruby.rb --wsdl http://api.google.com/GoogleSearch.wsdl --classdef --client_skelton --servant_skelton --cgi_stub --standalone_server_stub --driver --force diff --git a/sample/wsdl/googleSearch/httpd.rb b/sample/wsdl/googleSearch/httpd.rb new file mode 100644 index 0000000000..ee8ab09f50 --- /dev/null +++ b/sample/wsdl/googleSearch/httpd.rb @@ -0,0 +1,15 @@ +#!/usr/bin/env ruby + +require 'webrick' +require 'getopts' + +getopts "", 'r:', 'p:8808' + +s = WEBrick::HTTPServer.new( + :BindAddress => "0.0.0.0", + :Port => $OPT_p.to_i, + :DocumentRoot => $OPT_r || ".", + :CGIPathEnv => ENV['PATH'] +) +trap(:INT){ s.shutdown } +s.start diff --git a/sample/wsdl/googleSearch/sampleClient.rb b/sample/wsdl/googleSearch/sampleClient.rb new file mode 100644 index 0000000000..38e7253ef5 --- /dev/null +++ b/sample/wsdl/googleSearch/sampleClient.rb @@ -0,0 +1,56 @@ +#!/usr/bin/env ruby + +# This file is a sample based on GoogleSearchClient.rb, which can be +# generated by WSDL file and wsdl2ruby.rb. +# +# $ wsdl2ruby.rb --type client --force \ +# --wsdl http://api.google.com/GoogleSearch.wsdl +# +# See wsdlDriver.rb to use WSDL file directly (slow). +require 'GoogleSearchDriver.rb' + +endpoint_url = ARGV.shift +obj = GoogleSearchPort.new(endpoint_url) + +# Uncomment the below line to see SOAP wiredumps. +# obj.wiredump_dev = STDERR + +# SYNOPSIS +# doGoogleSearch(key, q, start, maxResults, filter, restrict, safeSearch, lr, ie, oe) +# +# ARGS +# key - {http://www.w3.org/2001/XMLSchema}string +# q - {http://www.w3.org/2001/XMLSchema}string +# start - {http://www.w3.org/2001/XMLSchema}int +# maxResults - {http://www.w3.org/2001/XMLSchema}int +# filter - {http://www.w3.org/2001/XMLSchema}boolean +# restrict - {http://www.w3.org/2001/XMLSchema}string +# safeSearch - {http://www.w3.org/2001/XMLSchema}boolean +# lr - {http://www.w3.org/2001/XMLSchema}string +# ie - {http://www.w3.org/2001/XMLSchema}string +# oe - {http://www.w3.org/2001/XMLSchema}string +# +# RETURNS +# return GoogleSearchResult - {urn:GoogleSearch}GoogleSearchResult +# +# RAISES +# N/A +# +key = q = start = maxResults = filter = restrict = safeSearch = lr = ie = oe = nil +key = File.open(File.expand_path("~/.google_key")).read.chomp +q = "Ruby" +start = 0 +maxResults = 10 +filter = false +restrict = "" +safeSearch = false +lr = "" +ie = "utf-8" +oe = "utf-8" +result = obj.doGoogleSearch(key, q, start, maxResults, filter, restrict, safeSearch, lr, ie, oe) + +result.resultElements.each do |ele| + puts "== #{ele.title}: #{ele.URL}" + puts ele.snippet + puts +end diff --git a/sample/wsdl/googleSearch/sjissearch.sh b/sample/wsdl/googleSearch/sjissearch.sh new file mode 100644 index 0000000000..b8efb20647 --- /dev/null +++ b/sample/wsdl/googleSearch/sjissearch.sh @@ -0,0 +1,3 @@ +#!/bin/sh - + +ruby -Ks wsdlDriver.rb 'Ruby ‚È‚Ð' diff --git a/sample/wsdl/googleSearch/wsdlDriver.rb b/sample/wsdl/googleSearch/wsdlDriver.rb new file mode 100644 index 0000000000..e8b91abfe2 --- /dev/null +++ b/sample/wsdl/googleSearch/wsdlDriver.rb @@ -0,0 +1,23 @@ +#require 'uconv' +require 'soap/wsdlDriver' + +word = ARGV.shift +# You must get key from http://www.google.com/apis/ to use Google Web APIs. +key = File.open(File.expand_path("~/.google_key")).read.chomp + +GOOGLE_WSDL = 'http://api.google.com/GoogleSearch.wsdl' +# GOOGLE_WSDL = 'GoogleSearch.wsdl' + +def html2rd(str) + str.gsub(%r(<b>(.*?)</b>), '((*\\1*))').strip +end + + +google = SOAP::WSDLDriverFactory.new(GOOGLE_WSDL).create_driver +#google.wiredump_dev = STDERR +result = google.doGoogleSearch( key, word, 0, 10, false, "", false, "", 'utf-8', 'utf-8' ) +result.resultElements.each do |ele| + puts "== #{html2rd(ele.title)}: #{ele.URL}" + puts html2rd(ele.snippet) + puts +end |