1 class DirectoryCategory < ActionWebService::Struct
2 member :fullViewableName, :string
3 member :specialEncoding, :string
6 class ResultElement < ActionWebService::Struct
7 member :summary, :string
9 member :snippet, :string
10 member :title, :string
11 member :cachedSize, :string
12 member :relatedInformationPresent, :bool
13 member :hostName, :string
14 member :directoryCategory, DirectoryCategory
15 member :directoryTitle, :string
18 class GoogleSearchResult < ActionWebService::Struct
19 member :documentFiltering, :bool
20 member :searchComments, :string
21 member :estimatedTotalResultsCount, :int
22 member :estimateIsExact, :bool
23 member :resultElements, [ResultElement]
24 member :searchQuery, :string
25 member :startIndex, :int
26 member :endIndex, :int
27 member :searchTips, :string
28 member :directoryCategories, [DirectoryCategory]
29 member :searchTime, :float
32 class GoogleSearchAPI < ActionWebService::API::Base
35 api_method :doGetCachedPage, :returns => [:string], :expects => [{:key=>:string}, {:url=>:string}]
36 api_method :doGetSpellingSuggestion, :returns => [:string], :expects => [{:key=>:string}, {:phrase=>:string}]
38 api_method :doGoogleSearch, :returns => [GoogleSearchResult], :expects => [
52 class GoogleSearchService < ActionWebService::Base
53 web_service_api GoogleSearchAPI
55 def doGetCachedPage(key, url)
56 "<html><body>i am a cached page</body></html>"
59 def doSpellingSuggestion(key, phrase)
63 def doGoogleSearch(key, q, start, maxResults, filter, restrict, safeSearch, lr, ie, oe)
64 resultElement = ResultElement.new
65 resultElement.summary = "ONlamp.com: Rolling with Ruby on Rails"
66 resultElement.URL = "http://www.onlamp.com/pub/a/onlamp/2005/01/20/rails.html"
67 resultElement.snippet = "Curt Hibbs shows off Ruby on Rails by building a simple application that requires " +
68 "almost no Ruby experience. ... Rolling with Ruby on Rails. ..."
69 resultElement.title = "Teh Railz0r"
70 resultElement.cachedSize = "Almost no lines of code!"
71 resultElement.relatedInformationPresent = true
72 resultElement.hostName = "rubyonrails.com"
73 resultElement.directoryCategory = category("Web Development", "UTF-8")
75 result = GoogleSearchResult.new
76 result.documentFiltering = filter
77 result.searchComments = ""
78 result.estimatedTotalResultsCount = 322000
79 result.estimateIsExact = false
80 result.resultElements = [resultElement]
81 result.searchQuery = "http://www.google.com/search?q=ruby+on+rails"
82 result.startIndex = start
83 result.endIndex = start + maxResults
84 result.searchTips = "\"on\" is a very common word and was not included in your search [details]"
85 result.searchTime = 0.000001
87 # For Mono, we have to clone objects if they're referenced by more than one place, otherwise
88 # the Ruby SOAP collapses them into one instance and uses references all over the
89 # place, confusing Mono.
91 # This has recently been fixed:
92 # http://bugzilla.ximian.com/show_bug.cgi?id=72265
93 result.directoryCategories = [
94 category("Web Development", "UTF-8"),
95 category("Programming", "US-ASCII"),
102 def category(name, encoding)
103 cat = DirectoryCategory.new
104 cat.fullViewableName = name.dup
105 cat.specialEncoding = encoding.dup