valdemaximus-actionwebservice 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. data/.gitignore +2 -0
  2. data/CHANGELOG +320 -0
  3. data/MIT-LICENSE +21 -0
  4. data/README +381 -0
  5. data/Rakefile +190 -0
  6. data/TODO +32 -0
  7. data/VERSION +1 -0
  8. data/actionwebservice.gemspec +29 -0
  9. data/examples/googlesearch/README +143 -0
  10. data/examples/googlesearch/autoloading/google_search_api.rb +50 -0
  11. data/examples/googlesearch/autoloading/google_search_controller.rb +57 -0
  12. data/examples/googlesearch/delegated/google_search_service.rb +108 -0
  13. data/examples/googlesearch/delegated/search_controller.rb +7 -0
  14. data/examples/googlesearch/direct/google_search_api.rb +50 -0
  15. data/examples/googlesearch/direct/search_controller.rb +58 -0
  16. data/examples/metaWeblog/README +17 -0
  17. data/examples/metaWeblog/apis/blogger_api.rb +60 -0
  18. data/examples/metaWeblog/apis/blogger_service.rb +34 -0
  19. data/examples/metaWeblog/apis/meta_weblog_api.rb +67 -0
  20. data/examples/metaWeblog/apis/meta_weblog_service.rb +48 -0
  21. data/examples/metaWeblog/controllers/xmlrpc_controller.rb +16 -0
  22. data/generators/web_service/USAGE +28 -0
  23. data/generators/web_service/templates/api_definition.rb +5 -0
  24. data/generators/web_service/templates/controller.rb +8 -0
  25. data/generators/web_service/templates/functional_test.rb +19 -0
  26. data/generators/web_service/web_service_generator.rb +29 -0
  27. data/install.rb +30 -0
  28. data/lib/action_web_service.rb +66 -0
  29. data/lib/action_web_service/api.rb +297 -0
  30. data/lib/action_web_service/base.rb +38 -0
  31. data/lib/action_web_service/casting.rb +149 -0
  32. data/lib/action_web_service/client.rb +3 -0
  33. data/lib/action_web_service/client/base.rb +28 -0
  34. data/lib/action_web_service/client/soap_client.rb +113 -0
  35. data/lib/action_web_service/client/xmlrpc_client.rb +58 -0
  36. data/lib/action_web_service/container.rb +3 -0
  37. data/lib/action_web_service/container/action_controller_container.rb +93 -0
  38. data/lib/action_web_service/container/delegated_container.rb +86 -0
  39. data/lib/action_web_service/container/direct_container.rb +69 -0
  40. data/lib/action_web_service/dispatcher.rb +2 -0
  41. data/lib/action_web_service/dispatcher/abstract.rb +207 -0
  42. data/lib/action_web_service/dispatcher/action_controller_dispatcher.rb +379 -0
  43. data/lib/action_web_service/invocation.rb +202 -0
  44. data/lib/action_web_service/protocol.rb +4 -0
  45. data/lib/action_web_service/protocol/abstract.rb +112 -0
  46. data/lib/action_web_service/protocol/discovery.rb +37 -0
  47. data/lib/action_web_service/protocol/soap_protocol.rb +176 -0
  48. data/lib/action_web_service/protocol/soap_protocol/marshaler.rb +242 -0
  49. data/lib/action_web_service/protocol/xmlrpc_protocol.rb +122 -0
  50. data/lib/action_web_service/scaffolding.rb +281 -0
  51. data/lib/action_web_service/struct.rb +64 -0
  52. data/lib/action_web_service/support/class_inheritable_options.rb +26 -0
  53. data/lib/action_web_service/support/signature_types.rb +226 -0
  54. data/lib/action_web_service/templates/scaffolds/layout.html.erb +65 -0
  55. data/lib/action_web_service/templates/scaffolds/methods.html.erb +6 -0
  56. data/lib/action_web_service/templates/scaffolds/parameters.html.erb +29 -0
  57. data/lib/action_web_service/templates/scaffolds/result.html.erb +30 -0
  58. data/lib/action_web_service/test_invoke.rb +110 -0
  59. data/lib/action_web_service/version.rb +9 -0
  60. data/lib/actionwebservice.rb +1 -0
  61. data/setup.rb +1379 -0
  62. data/test/abstract_client.rb +183 -0
  63. data/test/abstract_dispatcher.rb +548 -0
  64. data/test/abstract_unit.rb +44 -0
  65. data/test/api_test.rb +102 -0
  66. data/test/apis/auto_load_api.rb +3 -0
  67. data/test/apis/broken_auto_load_api.rb +2 -0
  68. data/test/base_test.rb +42 -0
  69. data/test/casting_test.rb +94 -0
  70. data/test/client_soap_test.rb +155 -0
  71. data/test/client_xmlrpc_test.rb +153 -0
  72. data/test/container_test.rb +73 -0
  73. data/test/dispatcher_action_controller_soap_test.rb +138 -0
  74. data/test/dispatcher_action_controller_xmlrpc_test.rb +59 -0
  75. data/test/fixtures/db_definitions/mysql.sql +8 -0
  76. data/test/fixtures/db_definitions/sqlite-schema.sql +8 -0
  77. data/test/fixtures/users.yml +12 -0
  78. data/test/gencov +3 -0
  79. data/test/invocation_test.rb +185 -0
  80. data/test/run +6 -0
  81. data/test/scaffolded_controller_test.rb +146 -0
  82. data/test/struct_test.rb +52 -0
  83. data/test/test_invoke_test.rb +112 -0
  84. data/valdemaximus-actionwebservice.gemspec +150 -0
  85. metadata +165 -0
data/Rakefile ADDED
@@ -0,0 +1,190 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+ require 'rake/rdoctask'
5
+ require 'rake/packagetask'
6
+ require 'rake/gempackagetask'
7
+ require 'rake/contrib/rubyforgepublisher'
8
+ require 'fileutils'
9
+ require File.join(File.dirname(__FILE__), 'lib', 'action_web_service', 'version')
10
+
11
+ PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
12
+ PKG_NAME = 'actionwebservice'
13
+ PKG_VERSION = ActionWebService::VERSION::STRING + PKG_BUILD
14
+ PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
15
+ PKG_DESTINATION = ENV["RAILS_PKG_DESTINATION"] || "../#{PKG_NAME}"
16
+
17
+ RELEASE_NAME = "REL #{PKG_VERSION}"
18
+
19
+ RUBY_FORGE_PROJECT = "aws"
20
+ RUBY_FORGE_USER = "webster132"
21
+
22
+ desc "Default Task"
23
+ task :default => [ :test ]
24
+
25
+
26
+ # Run the unit tests
27
+ Rake::TestTask.new { |t|
28
+ t.libs << "test"
29
+ t.test_files = Dir['test/*_test.rb']
30
+ t.verbose = true
31
+ }
32
+
33
+ SCHEMA_PATH = File.join(File.dirname(__FILE__), *%w(test fixtures db_definitions))
34
+
35
+ desc 'Build the MySQL test database'
36
+ task :build_database do
37
+ # %x( mysql create actionwebservice_unittest )
38
+ # %x( mysql actionwebservice_unittest < #{File.join(SCHEMA_PATH, 'mysql.sql')} )
39
+ %x( sqlite3 actionwebservice_unittest < #{File.join(SCHEMA_PATH, 'sqlite-schema.sql')} )
40
+ end
41
+
42
+
43
+ # Generate the RDoc documentation
44
+ Rake::RDocTask.new { |rdoc|
45
+ rdoc.rdoc_dir = 'doc'
46
+ rdoc.title = "Action Web Service -- Web services for Action Pack"
47
+ rdoc.options << '--line-numbers' << '--inline-source'
48
+ rdoc.options << '--charset' << 'utf-8'
49
+ rdoc.template = "#{ENV['template']}.rb" if ENV['template']
50
+ rdoc.rdoc_files.include('README')
51
+ rdoc.rdoc_files.include('CHANGELOG')
52
+ rdoc.rdoc_files.include('lib/action_web_service.rb')
53
+ rdoc.rdoc_files.include('lib/action_web_service/*.rb')
54
+ rdoc.rdoc_files.include('lib/action_web_service/api/*.rb')
55
+ rdoc.rdoc_files.include('lib/action_web_service/client/*.rb')
56
+ rdoc.rdoc_files.include('lib/action_web_service/container/*.rb')
57
+ rdoc.rdoc_files.include('lib/action_web_service/dispatcher/*.rb')
58
+ rdoc.rdoc_files.include('lib/action_web_service/protocol/*.rb')
59
+ rdoc.rdoc_files.include('lib/action_web_service/support/*.rb')
60
+ }
61
+
62
+
63
+ # Create compressed packages
64
+ spec = Gem::Specification.new do |s|
65
+ s.platform = Gem::Platform::RUBY
66
+ s.name = PKG_NAME
67
+ s.summary = "Web service support for Action Pack."
68
+ s.description = %q{Adds WSDL/SOAP and XML-RPC web service support to Action Pack}
69
+ s.version = PKG_VERSION
70
+
71
+ s.author = "Leon Breedt, Kent Sibilev"
72
+ s.email = "bitserf@gmail.com, ksibilev@yahoo.com"
73
+ s.rubyforge_project = "aws"
74
+ s.homepage = "http://www.rubyonrails.org"
75
+
76
+ s.add_dependency('actionpack', '= 2.3.2' + PKG_BUILD)
77
+ s.add_dependency('activerecord', '= 2.3.2' + PKG_BUILD)
78
+
79
+ s.has_rdoc = true
80
+ s.requirements << 'none'
81
+ s.require_path = 'lib'
82
+ s.autorequire = 'actionwebservice'
83
+
84
+ s.files = [ "Rakefile", "setup.rb", "README", "TODO", "CHANGELOG", "MIT-LICENSE" ]
85
+ s.files = s.files + Dir.glob( "examples/**/*" ).delete_if { |item| item.match( /\.(svn|git)/ ) }
86
+ s.files = s.files + Dir.glob( "lib/**/*" ).delete_if { |item| item.match( /\.(svn|git)/ ) }
87
+ s.files = s.files + Dir.glob( "test/**/*" ).delete_if { |item| item.match( /\.(svn|git)/ ) }
88
+ s.files = s.files + Dir.glob( "generators/**/*" ).delete_if { |item| item.match( /\.(svn|git)/ ) }
89
+ end
90
+ Rake::GemPackageTask.new(spec) do |p|
91
+ p.gem_spec = spec
92
+ p.need_tar = true
93
+ p.need_zip = true
94
+ end
95
+
96
+
97
+ # Publish beta gem
98
+ desc "Publish the API documentation"
99
+ task :pgem => [:package] do
100
+ Rake::SshFilePublisher.new("davidhh@wrath.rubyonrails.org", "public_html/gems/gems", "pkg", "#{PKG_FILE_NAME}.gem").upload
101
+ `ssh davidhh@wrath.rubyonrails.org './gemupdate.sh'`
102
+ end
103
+
104
+ # Publish documentation
105
+ desc "Publish the API documentation"
106
+ task :pdoc => [:rdoc] do
107
+ Rake::SshDirPublisher.new("davidhh@wrath.rubyonrails.org", "public_html/aws", "doc").upload
108
+ end
109
+
110
+
111
+ def each_source_file(*args)
112
+ prefix, includes, excludes, open_file = args
113
+ prefix ||= File.dirname(__FILE__)
114
+ open_file = true if open_file.nil?
115
+ includes ||= %w[lib\/action_web_service\.rb$ lib\/action_web_service\/.*\.rb$]
116
+ excludes ||= %w[lib\/action_web_service\/vendor]
117
+ Find.find(prefix) do |file_name|
118
+ next if file_name =~ /\.svn/
119
+ file_name.gsub!(/^\.\//, '')
120
+ continue = false
121
+ includes.each do |inc|
122
+ if file_name.match(/#{inc}/)
123
+ continue = true
124
+ break
125
+ end
126
+ end
127
+ next unless continue
128
+ excludes.each do |exc|
129
+ if file_name.match(/#{exc}/)
130
+ continue = false
131
+ break
132
+ end
133
+ end
134
+ next unless continue
135
+ if open_file
136
+ File.open(file_name) do |f|
137
+ yield file_name, f
138
+ end
139
+ else
140
+ yield file_name
141
+ end
142
+ end
143
+ end
144
+
145
+ desc "Count lines of the AWS source code"
146
+ task :lines do
147
+ total_lines = total_loc = 0
148
+ puts "Per File:"
149
+ each_source_file do |file_name, f|
150
+ file_lines = file_loc = 0
151
+ while line = f.gets
152
+ file_lines += 1
153
+ next if line =~ /^\s*$/
154
+ next if line =~ /^\s*#/
155
+ file_loc += 1
156
+ end
157
+ puts " #{file_name}: Lines #{file_lines}, LOC #{file_loc}"
158
+ total_lines += file_lines
159
+ total_loc += file_loc
160
+ end
161
+ puts "Total:"
162
+ puts " Lines #{total_lines}, LOC #{total_loc}"
163
+ end
164
+
165
+ desc "Publish the release files to RubyForge."
166
+ task :release => [ :package ] do
167
+ require 'rubyforge'
168
+
169
+ packages = %w( gem tgz zip ).collect{ |ext| "pkg/#{PKG_NAME}-#{PKG_VERSION}.#{ext}" }
170
+
171
+ rubyforge = RubyForge.new
172
+ rubyforge.login
173
+ rubyforge.add_release(PKG_NAME, PKG_NAME, "REL #{PKG_VERSION}", *packages)
174
+ end
175
+
176
+
177
+ begin
178
+ require 'jeweler'
179
+ Jeweler::Tasks.new do |gemspec|
180
+ gemspec.name = "valdemaximus-actionwebservice"
181
+ gemspec.summary = "create wsdl and soap apis"
182
+ gemspec.description = "A Library to programmatically create wsdl and soap apis in a rails project"
183
+ gemspec.email = "valde.maximus@gmail.com"
184
+ gemspec.homepage = "http://tomonrails.com/conduit"
185
+ gemspec.authors = ["Tom Johnson"]
186
+ end
187
+ Jeweler::GemcutterTasks.new
188
+ rescue LoadError
189
+ puts "Jeweler not available. Install it with: sudo gem install jeweler"
190
+ end
data/TODO ADDED
@@ -0,0 +1,32 @@
1
+ = Post-1.0
2
+ - Document/Literal SOAP support
3
+ - URL-based dispatching, URL identifies method
4
+
5
+ - Add :rest dispatching mode, a.l.a. Backpack API. Clean up dispatching
6
+ in general. Support vanilla XML-format as a "Rails" protocol?
7
+ XML::Simple deserialization into params?
8
+
9
+ web_service_dispatching_mode :rest
10
+
11
+ def method1(params)
12
+ end
13
+
14
+ def method2(params)
15
+ end
16
+
17
+
18
+ /ws/method1
19
+ <xml>
20
+ /ws/method2
21
+ <yaml>
22
+
23
+ - Allow locking down a controller to only accept messages for a particular
24
+ protocol. This will allow us to generate fully conformant error messages
25
+ in cases where we currently fudge it if we don't know the protocol.
26
+
27
+ - Allow AWS user to participate in typecasting, so they can centralize
28
+ workarounds for buggy input in one place
29
+
30
+ = Refactoring
31
+ - Don't have clean way to go from SOAP Class object to the xsd:NAME type
32
+ string -- NaHi possibly looking at remedying this situation
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,29 @@
1
+ Gem::Specification.new do |s|
2
+ s.platform = Gem::Platform::RUBY
3
+ s.name = 'actionwebservice'
4
+ s.summary = "Web service support for Action Pack."
5
+ s.description = %q{Adds WSDL/SOAP and XML-RPC web service support to Action Pack}
6
+ s.version = '2.3.2'
7
+
8
+ s.author = "Leon Breedt, Kent Sibilev"
9
+ s.email = "bitserf@gmail.com, ksibilev@yahoo.com"
10
+ s.rubyforge_project = "aws"
11
+ s.homepage = "http://www.rubyonrails.org"
12
+
13
+ s.add_dependency('actionpack', '= 2.3.2')
14
+ s.add_dependency('activerecord', '= 2.3.2')
15
+
16
+ s.has_rdoc = true
17
+ s.requirements << 'none'
18
+ s.require_path = 'lib'
19
+
20
+ s.files = [ "Rakefile", "setup.rb", "README", "TODO", "CHANGELOG", "MIT-LICENSE" ]
21
+ s.files = s.files +
22
+ ["examples/googlesearch", "examples/googlesearch/autoloading", "examples/googlesearch/autoloading/google_search_api.rb", "examples/googlesearch/autoloading/google_search_controller.rb", "examples/googlesearch/delegated", "examples/googlesearch/delegated/google_search_service.rb", "examples/googlesearch/delegated/search_controller.rb", "examples/googlesearch/direct", "examples/googlesearch/direct/google_search_api.rb", "examples/googlesearch/direct/search_controller.rb", "examples/googlesearch/README", "examples/metaWeblog", "examples/metaWeblog/apis", "examples/metaWeblog/apis/blogger_api.rb", "examples/metaWeblog/apis/blogger_service.rb", "examples/metaWeblog/apis/meta_weblog_api.rb", "examples/metaWeblog/apis/meta_weblog_service.rb", "examples/metaWeblog/controllers", "examples/metaWeblog/controllers/xmlrpc_controller.rb", "examples/metaWeblog/README"]
23
+ s.files = s.files +
24
+ ["lib/action_web_service", "lib/action_web_service/api.rb", "lib/action_web_service/base.rb", "lib/action_web_service/casting.rb", "lib/action_web_service/client", "lib/action_web_service/client/base.rb", "lib/action_web_service/client/soap_client.rb", "lib/action_web_service/client/xmlrpc_client.rb", "lib/action_web_service/client.rb", "lib/action_web_service/container", "lib/action_web_service/container/action_controller_container.rb", "lib/action_web_service/container/delegated_container.rb", "lib/action_web_service/container/direct_container.rb", "lib/action_web_service/container.rb", "lib/action_web_service/dispatcher", "lib/action_web_service/dispatcher/abstract.rb", "lib/action_web_service/dispatcher/action_controller_dispatcher.rb", "lib/action_web_service/dispatcher.rb", "lib/action_web_service/invocation.rb", "lib/action_web_service/protocol", "lib/action_web_service/protocol/abstract.rb", "lib/action_web_service/protocol/discovery.rb", "lib/action_web_service/protocol/soap_protocol", "lib/action_web_service/protocol/soap_protocol/marshaler.rb", "lib/action_web_service/protocol/soap_protocol.rb", "lib/action_web_service/protocol/xmlrpc_protocol.rb", "lib/action_web_service/protocol.rb", "lib/action_web_service/scaffolding.rb", "lib/action_web_service/struct.rb", "lib/action_web_service/support", "lib/action_web_service/support/class_inheritable_options.rb", "lib/action_web_service/support/signature_types.rb", "lib/action_web_service/templates", "lib/action_web_service/templates/scaffolds", "lib/action_web_service/templates/scaffolds/layout.html.erb", "lib/action_web_service/templates/scaffolds/methods.html.erb", "lib/action_web_service/templates/scaffolds/parameters.html.erb", "lib/action_web_service/templates/scaffolds/result.html.erb", "lib/action_web_service/test_invoke.rb", "lib/action_web_service/version.rb", "lib/action_web_service.rb", "lib/actionwebservice.rb"]
25
+ s.files = s.files +
26
+ ["test/abstract_client.rb", "test/abstract_dispatcher.rb", "test/abstract_unit.rb", "test/api_test.rb", "test/apis", "test/apis/auto_load_api.rb", "test/apis/broken_auto_load_api.rb", "test/base_test.rb", "test/casting_test.rb", "test/client_soap_test.rb", "test/client_xmlrpc_test.rb", "test/container_test.rb", "test/dispatcher_action_controller_soap_test.rb", "test/dispatcher_action_controller_xmlrpc_test.rb", "test/fixtures", "test/fixtures/db_definitions", "test/fixtures/db_definitions/mysql.sql", "test/fixtures/users.yml", "test/gencov", "test/invocation_test.rb", "test/run", "test/scaffolded_controller_test.rb", "test/struct_test.rb", "test/test_invoke_test.rb"]
27
+ s.files = s.files +
28
+ ["generators/web_service", "generators/web_service/templates", "generators/web_service/templates/api_definition.rb", "generators/web_service/templates/controller.rb", "generators/web_service/templates/functional_test.rb", "generators/web_service/USAGE", "generators/web_service/web_service_generator.rb"]
29
+ end
@@ -0,0 +1,143 @@
1
+ = Google Service example
2
+
3
+ This example shows how one would implement an API like Google
4
+ Search that uses lots of structured types.
5
+
6
+ There are examples for "Direct" and "Delegated" dispatching
7
+ modes.
8
+
9
+ There is also an example for API definition file autoloading.
10
+
11
+
12
+ = Running the examples
13
+
14
+ 1. Add the files to an Action Web Service enabled Rails project.
15
+
16
+ "Direct" example:
17
+
18
+ * Copy direct/search_controller.rb to "app/controllers"
19
+ in a Rails project.
20
+ * Copy direct/google_search_api.rb to "app/apis"
21
+ in a Rails project
22
+
23
+ "Delegated" example:
24
+
25
+ * Copy delegated/search_controller.rb to "app/controllers"
26
+ in a Rails project.
27
+ * Copy delegated/google_search_service.rb to "lib"
28
+ in a Rails project.
29
+
30
+ "Autoloading" example:
31
+
32
+ * Copy autoloading/google_search_api.rb to "app/apis" (create the directory
33
+ if it doesn't exist) in a Rails project.
34
+
35
+ * Copy autoloading/google_search_controller.rb "app/controllers"
36
+ in a Rails project.
37
+
38
+
39
+ 2. Go to the WSDL url in a browser, and check that it looks correct.
40
+
41
+ "Direct" and "Delegated" examples:
42
+ http://url_to_project/search/wsdl
43
+
44
+ "Autoloading" example:
45
+ http://url_to_project/google_search/wsdl
46
+
47
+ You can compare it to Google's hand-coded WSDL at http://api.google.com/GoogleSearch.wsdl
48
+ and see how close (or not) the generated version is.
49
+
50
+ Note that I used GoogleSearch as the canonical "best practice"
51
+ interoperable example when implementing WSDL/SOAP support, which might
52
+ explain extreme similarities :)
53
+
54
+
55
+ 3. Test that it works with .NET (Mono in this example):
56
+
57
+ $ wget WSDL_URL
58
+ $ mv wsdl GoogleSearch.wsdl
59
+ $ wsdl -out:GoogleSearch.cs GoogleSearch.wsdl
60
+
61
+ Add these lines to the GoogleSearchService class body (be mindful of the
62
+ wrapping):
63
+
64
+ public static void Main(string[] args)
65
+ {
66
+ GoogleSearchResult result;
67
+ GoogleSearchService service;
68
+
69
+ service = new GoogleSearchService();
70
+ result = service.doGoogleSearch("myApiKey", "my query", 10, 30, true, "restrict", false, "lr", "ie", "oe");
71
+ System.Console.WriteLine("documentFiltering: {0}", result.documentFiltering);
72
+ System.Console.WriteLine("searchComments: {0}", result.searchComments);
73
+ System.Console.WriteLine("estimatedTotalResultsCount: {0}", result.estimatedTotalResultsCount);
74
+ System.Console.WriteLine("estimateIsExact: {0}", result.estimateIsExact);
75
+ System.Console.WriteLine("resultElements:");
76
+ foreach (ResultElement element in result.resultElements) {
77
+ System.Console.WriteLine("\tsummary: {0}", element.summary);
78
+ System.Console.WriteLine("\tURL: {0}", element.URL);
79
+ System.Console.WriteLine("\tsnippet: {0}", element.snippet);
80
+ System.Console.WriteLine("\ttitle: {0}", element.title);
81
+ System.Console.WriteLine("\tcachedSize: {0}", element.cachedSize);
82
+ System.Console.WriteLine("\trelatedInformationPresent: {0}", element.relatedInformationPresent);
83
+ System.Console.WriteLine("\thostName: {0}", element.hostName);
84
+ System.Console.WriteLine("\tdirectoryCategory: {0}", element.directoryCategory.fullViewableName);
85
+ System.Console.WriteLine("\tdirectoryTitle: {0}", element.directoryTitle);
86
+ }
87
+ System.Console.WriteLine("searchQuery: {0}", result.searchQuery);
88
+ System.Console.WriteLine("startIndex: {0}", result.startIndex);
89
+ System.Console.WriteLine("endIndex: {0}", result.endIndex);
90
+ System.Console.WriteLine("searchTips: {0}", result.searchTips);
91
+ System.Console.WriteLine("directoryCategories:");
92
+ foreach (DirectoryCategory cat in result.directoryCategories) {
93
+ System.Console.WriteLine("\t{0} ({1})", cat.fullViewableName, cat.specialEncoding);
94
+ }
95
+ System.Console.WriteLine("searchTime: {0}", result.searchTime);
96
+ }
97
+
98
+ Now compile and run:
99
+
100
+ $ mcs -reference:System.Web.Services GoogleSearch.cs
101
+ $ mono GoogleSearch.exe
102
+
103
+
104
+ If you had the application running (on the same host you got
105
+ the WSDL from), you should see something like this:
106
+
107
+
108
+ documentFiltering: True
109
+ searchComments:
110
+ estimatedTotalResultsCount: 322000
111
+ estimateIsExact: False
112
+ resultElements:
113
+ summary: ONlamp.com: Rolling with Ruby on Rails
114
+ URL: http://www.onlamp.com/pub/a/onlamp/2005/01/20/rails.html
115
+ snippet: Curt Hibbs shows off Ruby on Rails by building a simple ...
116
+ title: Teh Railz0r
117
+ cachedSize: Almost no lines of code!
118
+ relatedInformationPresent: True
119
+ hostName: rubyonrails.com
120
+ directoryCategory: Web Development
121
+ directoryTitle:
122
+ searchQuery: http://www.google.com/search?q=ruby+on+rails
123
+ startIndex: 10
124
+ endIndex: 40
125
+ searchTips: "on" is a very common word and was not included in your search [details]
126
+ directoryCategories:
127
+ Web Development (UTF-8)
128
+ Programming (US-ASCII)
129
+ searchTime: 1E-06
130
+
131
+
132
+ Also, if an API method throws an exception, it will be sent back to the
133
+ caller in the protocol's exception format, so they should get an exception
134
+ thrown on their side with a meaningful error message.
135
+
136
+ If you don't like this behaviour, you can do:
137
+
138
+ class MyController < ActionController::Base
139
+ web_service_exception_reporting false
140
+ end
141
+
142
+ 4. Crack open a beer. Publishing APIs for working with the same model as
143
+ your Rails web app should be easy from now on :)
@@ -0,0 +1,50 @@
1
+ class DirectoryCategory < ActionWebService::Struct
2
+ member :fullViewableName, :string
3
+ member :specialEncoding, :string
4
+ end
5
+
6
+ class ResultElement < ActionWebService::Struct
7
+ member :summary, :string
8
+ member :URL, :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
16
+ end
17
+
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
30
+ end
31
+
32
+ class GoogleSearchAPI < ActionWebService::API::Base
33
+ inflect_names false
34
+
35
+ api_method :doGetCachedPage, :returns => [:string], :expects => [{:key=>:string}, {:url=>:string}]
36
+ api_method :doGetSpellingSuggestion, :returns => [:string], :expects => [{:key=>:string}, {:phrase=>:string}]
37
+
38
+ api_method :doGoogleSearch, :returns => [GoogleSearchResult], :expects => [
39
+ {:key=>:string},
40
+ {:q=>:string},
41
+ {:start=>:int},
42
+ {:maxResults=>:int},
43
+ {:filter=>:bool},
44
+ {:restrict=>:string},
45
+ {:safeSearch=>:bool},
46
+ {:lr=>:string},
47
+ {:ie=>:string},
48
+ {:oe=>:string}
49
+ ]
50
+ end