diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-02-18 23:43:09 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-02-18 23:43:09 +0000 |
commit | 7a67d0f617db7d2962b6c3b80466e21570b244bf (patch) | |
tree | 56fa640e31f4f7f22d34a246bc1b197706a07e3a /actionwebservice/examples/googlesearch/delegated | |
parent | fdecb6843ba8c5b0f718225f343017e11fa7f711 (diff) | |
download | rails-7a67d0f617db7d2962b6c3b80466e21570b244bf.tar.gz rails-7a67d0f617db7d2962b6c3b80466e21570b244bf.tar.bz2 rails-7a67d0f617db7d2962b6c3b80466e21570b244bf.zip |
Renamed Action Service to Action Web Service
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@669 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionwebservice/examples/googlesearch/delegated')
-rw-r--r-- | actionwebservice/examples/googlesearch/delegated/google_search_service.rb | 108 | ||||
-rw-r--r-- | actionwebservice/examples/googlesearch/delegated/search_controller.rb | 7 |
2 files changed, 115 insertions, 0 deletions
diff --git a/actionwebservice/examples/googlesearch/delegated/google_search_service.rb b/actionwebservice/examples/googlesearch/delegated/google_search_service.rb new file mode 100644 index 0000000000..da7f8f4529 --- /dev/null +++ b/actionwebservice/examples/googlesearch/delegated/google_search_service.rb @@ -0,0 +1,108 @@ +class DirectoryCategory < ActionService::Struct + member :fullViewableName, :string + member :specialEncoding, :string +end + +class ResultElement < ActionService::Struct + member :summary, :string + member :URL, :string + member :snippet, :string + member :title, :string + member :cachedSize, :string + member :relatedInformationPresent, :bool + member :hostName, :string + member :directoryCategory, DirectoryCategory + member :directoryTitle, :string +end + +class GoogleSearchResult < ActionService::Struct + member :documentFiltering, :bool + member :searchComments, :string + member :estimatedTotalResultsCount, :int + member :estimateIsExact, :bool + member :resultElements, [ResultElement] + member :searchQuery, :string + member :startIndex, :int + member :endIndex, :int + member :searchTips, :string + member :directoryCategories, [DirectoryCategory] + member :searchTime, :float +end + +class GoogleSearchAPI < ActionService::API::Base + inflect_names false + + api_method :doGetCachedPage, :returns => [:string], :expects => [{:key=>:string}, {:url=>:string}] + api_method :doGetSpellingSuggestion, :returns => [:string], :expects => [{:key=>:string}, {:phrase=>:string}] + + api_method :doGoogleSearch, :returns => [GoogleSearchResult], :expects => [ + {:key=>:string}, + {:q=>:string}, + {:start=>:int}, + {:maxResults=>:int}, + {:filter=>:bool}, + {:restrict=>:string}, + {:safeSearch=>:bool}, + {:lr=>:string}, + {:ie=>:string}, + {:oe=>:string} + ] +end + +class GoogleSearchService < ActionService::Base + web_service_api GoogleSearchAPI + + def doGetCachedPage(key, url) + "<html><body>i am a cached page</body></html>" + end + + def doSpellingSuggestion(key, phrase) + "Did you mean 'teh'?" + end + + def doGoogleSearch(key, q, start, maxResults, filter, restrict, safeSearch, lr, ie, oe) + resultElement = ResultElement.new + resultElement.summary = "ONlamp.com: Rolling with Ruby on Rails" + resultElement.URL = "http://www.onlamp.com/pub/a/onlamp/2005/01/20/rails.html" + resultElement.snippet = "Curt Hibbs shows off Ruby on Rails by building a simple application that requires " + + "almost no Ruby experience. ... Rolling with Ruby on Rails. ..." + resultElement.title = "Teh Railz0r" + resultElement.cachedSize = "Almost no lines of code!" + resultElement.relatedInformationPresent = true + resultElement.hostName = "rubyonrails.com" + resultElement.directoryCategory = category("Web Development", "UTF-8") + + result = GoogleSearchResult.new + result.documentFiltering = filter + result.searchComments = "" + result.estimatedTotalResultsCount = 322000 + result.estimateIsExact = false + result.resultElements = [resultElement] + result.searchQuery = "http://www.google.com/search?q=ruby+on+rails" + result.startIndex = start + result.endIndex = start + maxResults + result.searchTips = "\"on\" is a very common word and was not included in your search [details]" + result.searchTime = 0.000001 + + # For Mono, we have to clone objects if they're referenced by more than one place, otherwise + # the Ruby SOAP collapses them into one instance and uses references all over the + # place, confusing Mono. + # + # This has recently been fixed: + # http://bugzilla.ximian.com/show_bug.cgi?id=72265 + result.directoryCategories = [ + category("Web Development", "UTF-8"), + category("Programming", "US-ASCII"), + ] + + result + end + + private + def category(name, encoding) + cat = DirectoryCategory.new + cat.fullViewableName = name.dup + cat.specialEncoding = encoding.dup + cat + end +end diff --git a/actionwebservice/examples/googlesearch/delegated/search_controller.rb b/actionwebservice/examples/googlesearch/delegated/search_controller.rb new file mode 100644 index 0000000000..6525921b5a --- /dev/null +++ b/actionwebservice/examples/googlesearch/delegated/search_controller.rb @@ -0,0 +1,7 @@ +require 'google_search_service' + +class SearchController < ApplicationController + wsdl_service_name 'GoogleSearch' + web_service_dispatching_mode :delegated + web_service :beta3, GoogleSearchService.new +end |