keshav-actionwebservice 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. data/CHANGELOG +3 -0
  2. data/MIT-LICENSE +21 -0
  3. data/README +381 -0
  4. data/Rakefile +180 -0
  5. data/TODO +32 -0
  6. data/examples/googlesearch/README +143 -0
  7. data/examples/googlesearch/autoloading/google_search_api.rb +50 -0
  8. data/examples/googlesearch/autoloading/google_search_controller.rb +57 -0
  9. data/examples/googlesearch/delegated/google_search_service.rb +108 -0
  10. data/examples/googlesearch/delegated/search_controller.rb +7 -0
  11. data/examples/googlesearch/direct/google_search_api.rb +50 -0
  12. data/examples/googlesearch/direct/search_controller.rb +58 -0
  13. data/examples/metaWeblog/README +17 -0
  14. data/examples/metaWeblog/apis/blogger_api.rb +60 -0
  15. data/examples/metaWeblog/apis/blogger_service.rb +34 -0
  16. data/examples/metaWeblog/apis/meta_weblog_api.rb +67 -0
  17. data/examples/metaWeblog/apis/meta_weblog_service.rb +48 -0
  18. data/examples/metaWeblog/controllers/xmlrpc_controller.rb +16 -0
  19. data/generators/web_service/USAGE +28 -0
  20. data/generators/web_service/templates/api_definition.rb +5 -0
  21. data/generators/web_service/templates/controller.rb +8 -0
  22. data/generators/web_service/templates/functional_test.rb +19 -0
  23. data/generators/web_service/web_service_generator.rb +29 -0
  24. data/lib/action_web_service.rb +66 -0
  25. data/lib/action_web_service/api.rb +297 -0
  26. data/lib/action_web_service/base.rb +38 -0
  27. data/lib/action_web_service/casting.rb +149 -0
  28. data/lib/action_web_service/client.rb +3 -0
  29. data/lib/action_web_service/client/base.rb +28 -0
  30. data/lib/action_web_service/client/soap_client.rb +113 -0
  31. data/lib/action_web_service/client/xmlrpc_client.rb +58 -0
  32. data/lib/action_web_service/container.rb +3 -0
  33. data/lib/action_web_service/container/action_controller_container.rb +94 -0
  34. data/lib/action_web_service/container/delegated_container.rb +86 -0
  35. data/lib/action_web_service/container/direct_container.rb +69 -0
  36. data/lib/action_web_service/dispatcher.rb +2 -0
  37. data/lib/action_web_service/dispatcher/abstract.rb +207 -0
  38. data/lib/action_web_service/dispatcher/action_controller_dispatcher.rb +379 -0
  39. data/lib/action_web_service/invocation.rb +202 -0
  40. data/lib/action_web_service/protocol.rb +4 -0
  41. data/lib/action_web_service/protocol/abstract.rb +112 -0
  42. data/lib/action_web_service/protocol/discovery.rb +37 -0
  43. data/lib/action_web_service/protocol/soap_protocol.rb +176 -0
  44. data/lib/action_web_service/protocol/soap_protocol/marshaler.rb +242 -0
  45. data/lib/action_web_service/protocol/xmlrpc_protocol.rb +122 -0
  46. data/lib/action_web_service/scaffolding.rb +281 -0
  47. data/lib/action_web_service/struct.rb +64 -0
  48. data/lib/action_web_service/support/class_inheritable_options.rb +26 -0
  49. data/lib/action_web_service/support/signature_types.rb +227 -0
  50. data/lib/action_web_service/templates/scaffolds/layout.html.erb +65 -0
  51. data/lib/action_web_service/templates/scaffolds/methods.html.erb +6 -0
  52. data/lib/action_web_service/templates/scaffolds/parameters.html.erb +29 -0
  53. data/lib/action_web_service/templates/scaffolds/result.html.erb +30 -0
  54. data/lib/action_web_service/test_invoke.rb +110 -0
  55. data/lib/action_web_service/version.rb +9 -0
  56. data/lib/actionwebservice.rb +1 -0
  57. data/setup.rb +1379 -0
  58. data/test/abstract_client.rb +183 -0
  59. data/test/abstract_dispatcher.rb +548 -0
  60. data/test/abstract_unit.rb +43 -0
  61. data/test/api_test.rb +102 -0
  62. data/test/apis/auto_load_api.rb +3 -0
  63. data/test/apis/broken_auto_load_api.rb +2 -0
  64. data/test/base_test.rb +42 -0
  65. data/test/casting_test.rb +95 -0
  66. data/test/client_soap_test.rb +155 -0
  67. data/test/client_xmlrpc_test.rb +153 -0
  68. data/test/container_test.rb +73 -0
  69. data/test/dispatcher_action_controller_soap_test.rb +139 -0
  70. data/test/dispatcher_action_controller_xmlrpc_test.rb +59 -0
  71. data/test/fixtures/db_definitions/mysql.sql +8 -0
  72. data/test/fixtures/users.yml +12 -0
  73. data/test/gencov +3 -0
  74. data/test/invocation_test.rb +185 -0
  75. data/test/run +6 -0
  76. data/test/scaffolded_controller_test.rb +146 -0
  77. data/test/struct_test.rb +52 -0
  78. data/test/test_invoke_test.rb +112 -0
  79. metadata +145 -0
@@ -0,0 +1,58 @@
1
+ class SearchController < ApplicationController
2
+ web_service_api :google_search
3
+ wsdl_service_name 'GoogleSearch'
4
+
5
+ def doGetCachedPage
6
+ "<html><body>i am a cached page. my key was %s, url was %s</body></html>" % [@params['key'], @params['url']]
7
+ end
8
+
9
+ def doSpellingSuggestion
10
+ "%s: Did you mean '%s'?" % [@params['key'], @params['phrase']]
11
+ end
12
+
13
+ def doGoogleSearch
14
+ resultElement = ResultElement.new
15
+ resultElement.summary = "ONlamp.com: Rolling with Ruby on Rails"
16
+ resultElement.URL = "http://www.onlamp.com/pub/a/onlamp/2005/01/20/rails.html"
17
+ resultElement.snippet = "Curt Hibbs shows off Ruby on Rails by building a simple application that requires " +
18
+ "almost no Ruby experience. ... Rolling with Ruby on Rails. ..."
19
+ resultElement.title = "Teh Railz0r"
20
+ resultElement.cachedSize = "Almost no lines of code!"
21
+ resultElement.relatedInformationPresent = true
22
+ resultElement.hostName = "rubyonrails.com"
23
+ resultElement.directoryCategory = category("Web Development", "UTF-8")
24
+
25
+ result = GoogleSearchResult.new
26
+ result.documentFiltering = @params['filter']
27
+ result.searchComments = ""
28
+ result.estimatedTotalResultsCount = 322000
29
+ result.estimateIsExact = false
30
+ result.resultElements = [resultElement]
31
+ result.searchQuery = "http://www.google.com/search?q=ruby+on+rails"
32
+ result.startIndex = @params['start']
33
+ result.endIndex = @params['start'] + @params['maxResults']
34
+ result.searchTips = "\"on\" is a very common word and was not included in your search [details]"
35
+ result.searchTime = 0.000001
36
+
37
+ # For Mono, we have to clone objects if they're referenced by more than one place, otherwise
38
+ # the Ruby SOAP collapses them into one instance and uses references all over the
39
+ # place, confusing Mono.
40
+ #
41
+ # This has recently been fixed:
42
+ # http://bugzilla.ximian.com/show_bug.cgi?id=72265
43
+ result.directoryCategories = [
44
+ category("Web Development", "UTF-8"),
45
+ category("Programming", "US-ASCII"),
46
+ ]
47
+
48
+ result
49
+ end
50
+
51
+ private
52
+ def category(name, encoding)
53
+ cat = DirectoryCategory.new
54
+ cat.fullViewableName = name.dup
55
+ cat.specialEncoding = encoding.dup
56
+ cat
57
+ end
58
+ end
@@ -0,0 +1,17 @@
1
+ = metaWeblog example
2
+
3
+ This example shows how one might begin to go about adding metaWeblog
4
+ (http://www.xmlrpc.com/metaWeblogApi) API support to a Rails-based
5
+ blogging application.
6
+
7
+ The example APIs are more verbose than you may want to make them, for documentation
8
+ reasons.
9
+
10
+ = Running
11
+
12
+ 1. Copy the "apis" directory and its files into "app" in a Rails project.
13
+
14
+ 2. Copy the "controllers" directory and its files into "app" in a Rails project
15
+
16
+ 3. Fire up a desktop blogging application (such as w.bloggar, MarsEdit, or BloGTK),
17
+ point it at http://localhost:3000/xmlrpc/api, and try creating or editing blog posts.
@@ -0,0 +1,60 @@
1
+ #
2
+ # see the blogger API spec at http://www.blogger.com/developers/api/1_docs/
3
+ # note that the method signatures are subtly different to metaWeblog, they
4
+ # are not identical. take care to ensure you handle the different semantics
5
+ # properly if you want to support blogger API too, to get maximum compatibility.
6
+ #
7
+
8
+ module Blog
9
+ class Blog < ActionWebService::Struct
10
+ member :url, :string
11
+ member :blogid, :string
12
+ member :blogName, :string
13
+ end
14
+
15
+ class User < ActionWebService::Struct
16
+ member :nickname, :string
17
+ member :userid, :string
18
+ member :url, :string
19
+ member :email, :string
20
+ member :lastname, :string
21
+ member :firstname, :string
22
+ end
23
+ end
24
+
25
+ #
26
+ # blogger
27
+ #
28
+ class BloggerAPI < ActionWebService::API::Base
29
+ inflect_names false
30
+
31
+ api_method :newPost, :returns => [:string], :expects => [
32
+ {:appkey=>:string},
33
+ {:blogid=>:string},
34
+ {:username=>:string},
35
+ {:password=>:string},
36
+ {:content=>:string},
37
+ {:publish=>:bool}
38
+ ]
39
+
40
+ api_method :editPost, :returns => [:bool], :expects => [
41
+ {:appkey=>:string},
42
+ {:postid=>:string},
43
+ {:username=>:string},
44
+ {:password=>:string},
45
+ {:content=>:string},
46
+ {:publish=>:bool}
47
+ ]
48
+
49
+ api_method :getUsersBlogs, :returns => [[Blog::Blog]], :expects => [
50
+ {:appkey=>:string},
51
+ {:username=>:string},
52
+ {:password=>:string}
53
+ ]
54
+
55
+ api_method :getUserInfo, :returns => [Blog::User], :expects => [
56
+ {:appkey=>:string},
57
+ {:username=>:string},
58
+ {:password=>:string}
59
+ ]
60
+ end
@@ -0,0 +1,34 @@
1
+ require 'blogger_api'
2
+
3
+ class BloggerService < ActionWebService::Base
4
+ web_service_api BloggerAPI
5
+
6
+ def initialize
7
+ @postid = 0
8
+ end
9
+
10
+ def newPost(key, id, user, pw, content, publish)
11
+ $stderr.puts "id=#{id} user=#{user} pw=#{pw}, content=#{content.inspect} [#{publish}]"
12
+ (@postid += 1).to_s
13
+ end
14
+
15
+ def editPost(key, post_id, user, pw, content, publish)
16
+ $stderr.puts "id=#{post_id} user=#{user} pw=#{pw} content=#{content.inspect} [#{publish}]"
17
+ true
18
+ end
19
+
20
+ def getUsersBlogs(key, user, pw)
21
+ $stderr.puts "getting blogs for #{user}"
22
+ blog = Blog::Blog.new(
23
+ :url =>'http://blog',
24
+ :blogid => 'myblog',
25
+ :blogName => 'My Blog'
26
+ )
27
+ [blog]
28
+ end
29
+
30
+ def getUserInfo(key, user, pw)
31
+ $stderr.puts "getting user info for #{user}"
32
+ Blog::User.new(:nickname => 'user', :email => 'user@test.com')
33
+ end
34
+ end
@@ -0,0 +1,67 @@
1
+ #
2
+ # here lie structures, cousins of those on http://www.xmlrpc.com/metaWeblog
3
+ # but they don't necessarily the real world reflect
4
+ # so if you do, find that your client complains:
5
+ # please tell, of problems you suffered through
6
+ #
7
+
8
+ module Blog
9
+ class Post < ActionWebService::Struct
10
+ member :title, :string
11
+ member :link, :string
12
+ member :description, :string
13
+ member :author, :string
14
+ member :category, :string
15
+ member :comments, :string
16
+ member :guid, :string
17
+ member :pubDate, :string
18
+ end
19
+
20
+ class Category < ActionWebService::Struct
21
+ member :description, :string
22
+ member :htmlUrl, :string
23
+ member :rssUrl, :string
24
+ end
25
+ end
26
+
27
+ #
28
+ # metaWeblog
29
+ #
30
+ class MetaWeblogAPI < ActionWebService::API::Base
31
+ inflect_names false
32
+
33
+ api_method :newPost, :returns => [:string], :expects => [
34
+ {:blogid=>:string},
35
+ {:username=>:string},
36
+ {:password=>:string},
37
+ {:struct=>Blog::Post},
38
+ {:publish=>:bool}
39
+ ]
40
+
41
+ api_method :editPost, :returns => [:bool], :expects => [
42
+ {:postid=>:string},
43
+ {:username=>:string},
44
+ {:password=>:string},
45
+ {:struct=>Blog::Post},
46
+ {:publish=>:bool},
47
+ ]
48
+
49
+ api_method :getPost, :returns => [Blog::Post], :expects => [
50
+ {:postid=>:string},
51
+ {:username=>:string},
52
+ {:password=>:string},
53
+ ]
54
+
55
+ api_method :getCategories, :returns => [[Blog::Category]], :expects => [
56
+ {:blogid=>:string},
57
+ {:username=>:string},
58
+ {:password=>:string},
59
+ ]
60
+
61
+ api_method :getRecentPosts, :returns => [[Blog::Post]], :expects => [
62
+ {:blogid=>:string},
63
+ {:username=>:string},
64
+ {:password=>:string},
65
+ {:numberOfPosts=>:int},
66
+ ]
67
+ end
@@ -0,0 +1,48 @@
1
+ require 'meta_weblog_api'
2
+
3
+ class MetaWeblogService < ActionWebService::Base
4
+ web_service_api MetaWeblogAPI
5
+
6
+ def initialize
7
+ @postid = 0
8
+ end
9
+
10
+ def newPost(id, user, pw, struct, publish)
11
+ $stderr.puts "id=#{id} user=#{user} pw=#{pw}, struct=#{struct.inspect} [#{publish}]"
12
+ (@postid += 1).to_s
13
+ end
14
+
15
+ def editPost(post_id, user, pw, struct, publish)
16
+ $stderr.puts "id=#{post_id} user=#{user} pw=#{pw} struct=#{struct.inspect} [#{publish}]"
17
+ true
18
+ end
19
+
20
+ def getPost(post_id, user, pw)
21
+ $stderr.puts "get post #{post_id}"
22
+ Blog::Post.new(:title => 'hello world', :description => 'first post!')
23
+ end
24
+
25
+ def getCategories(id, user, pw)
26
+ $stderr.puts "categories for #{user}"
27
+ cat = Blog::Category.new(
28
+ :description => 'Tech',
29
+ :htmlUrl => 'http://blog/tech',
30
+ :rssUrl => 'http://blog/tech.rss')
31
+ [cat]
32
+ end
33
+
34
+ def getRecentPosts(id, user, pw, num)
35
+ $stderr.puts "recent #{num} posts for #{user} on blog #{id}"
36
+ post1 = Blog::Post.new(
37
+ :title => 'first post!',
38
+ :link => 'http://blog.xeraph.org/testOne.html',
39
+ :description => 'this is the first post'
40
+ )
41
+ post2 = Blog::Post.new(
42
+ :title => 'second post!',
43
+ :link => 'http://blog.xeraph.org/testTwo.html',
44
+ :description => 'this is the second post'
45
+ )
46
+ [post1, post2]
47
+ end
48
+ end
@@ -0,0 +1,16 @@
1
+ #
2
+ # example controller implementing both blogger and metaWeblog APIs
3
+ # in a way that should be compatible with clients supporting both/either.
4
+ #
5
+ # test by pointing your client at http://URL/xmlrpc/api
6
+ #
7
+
8
+ require 'meta_weblog_service'
9
+ require 'blogger_service'
10
+
11
+ class XmlrpcController < ApplicationController
12
+ web_service_dispatching_mode :layered
13
+
14
+ web_service :metaWeblog, MetaWeblogService.new
15
+ web_service :blogger, BloggerService.new
16
+ end
@@ -0,0 +1,28 @@
1
+ Description:
2
+ The web service generator creates the controller and API definition for
3
+ a web service.
4
+
5
+ The generator takes a web service name and a list of API methods as arguments.
6
+ The web service name may be given in CamelCase or under_score and should
7
+ contain no extra suffixes. To create a web service within a
8
+ module, specify the web service name as 'module/webservice'.
9
+
10
+ The generator creates a controller class in app/controllers, an API definition
11
+ in app/apis, and a functional test suite in test/functional.
12
+
13
+ Example:
14
+ ./script/generate web_service User add edit list remove
15
+
16
+ User web service.
17
+ Controller: app/controllers/user_controller.rb
18
+ API: app/apis/user_api.rb
19
+ Test: test/functional/user_api_test.rb
20
+
21
+ Modules Example:
22
+ ./script/generate web_service 'api/registration' register renew
23
+
24
+ Registration web service.
25
+ Controller: app/controllers/api/registration_controller.rb
26
+ API: app/apis/api/registration_api.rb
27
+ Test: test/functional/api/registration_api_test.rb
28
+
@@ -0,0 +1,5 @@
1
+ class <%= class_name %>Api < ActionWebService::API::Base
2
+ <% for method_name in args -%>
3
+ api_method :<%= method_name %>
4
+ <% end -%>
5
+ end
@@ -0,0 +1,8 @@
1
+ class <%= class_name %>Controller < ApplicationController
2
+ wsdl_service_name '<%= class_name %>'
3
+ <% for method_name in args -%>
4
+
5
+ def <%= method_name %>
6
+ end
7
+ <% end -%>
8
+ end
@@ -0,0 +1,19 @@
1
+ require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../test_helper'
2
+ require '<%= file_path %>_controller'
3
+
4
+ class <%= class_name %>Controller; def rescue_action(e) raise e end; end
5
+
6
+ class <%= class_name %>ControllerApiTest < Test::Unit::TestCase
7
+ def setup
8
+ @controller = <%= class_name %>Controller.new
9
+ @request = ActionController::TestRequest.new
10
+ @response = ActionController::TestResponse.new
11
+ end
12
+ <% for method_name in args -%>
13
+
14
+ def test_<%= method_name %>
15
+ result = invoke :<%= method_name %>
16
+ assert_equal nil, result
17
+ end
18
+ <% end -%>
19
+ end
@@ -0,0 +1,29 @@
1
+ class WebServiceGenerator < Rails::Generator::NamedBase
2
+ def manifest
3
+ record do |m|
4
+ # Check for class naming collisions.
5
+ m.class_collisions class_path, "#{class_name}Api", "#{class_name}Controller", "#{class_name}ApiTest"
6
+
7
+ # API and test directories.
8
+ m.directory File.join('app/services', class_path)
9
+ m.directory File.join('app/controllers', class_path)
10
+ m.directory File.join('test/functional', class_path)
11
+
12
+ # API definition, controller, and functional test.
13
+ m.template 'api_definition.rb',
14
+ File.join('app/services',
15
+ class_path,
16
+ "#{file_name}_api.rb")
17
+
18
+ m.template 'controller.rb',
19
+ File.join('app/controllers',
20
+ class_path,
21
+ "#{file_name}_controller.rb")
22
+
23
+ m.template 'functional_test.rb',
24
+ File.join('test/functional',
25
+ class_path,
26
+ "#{file_name}_api_test.rb")
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,66 @@
1
+ #--
2
+ # Copyright (C) 2005 Leon Breedt
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ begin
25
+ require 'active_support'
26
+ require 'action_controller'
27
+ require 'active_record'
28
+ rescue LoadError
29
+ require 'rubygems'
30
+ gem 'activesupport', '>= 2.3.0'
31
+ gem 'actionpack', '>= 2.3.0'
32
+ gem 'activerecord', '>= 2.3.0'
33
+ end
34
+
35
+ $:.unshift(File.dirname(__FILE__) + "/action_web_service/vendor/")
36
+
37
+ require 'action_web_service/support/class_inheritable_options'
38
+ require 'action_web_service/support/signature_types'
39
+ require 'action_web_service/base'
40
+ require 'action_web_service/client'
41
+ require 'action_web_service/invocation'
42
+ require 'action_web_service/api'
43
+ require 'action_web_service/casting'
44
+ require 'action_web_service/struct'
45
+ require 'action_web_service/container'
46
+ require 'action_web_service/protocol'
47
+ require 'action_web_service/dispatcher'
48
+ require 'action_web_service/scaffolding'
49
+
50
+ ActionWebService::Base.class_eval do
51
+ include ActionWebService::Container::Direct
52
+ include ActionWebService::Invocation
53
+ end
54
+
55
+ ActionController::Base.class_eval do
56
+ include ActionWebService::Protocol::Discovery
57
+ include ActionWebService::Protocol::Soap
58
+ include ActionWebService::Protocol::XmlRpc
59
+ include ActionWebService::Container::Direct
60
+ include ActionWebService::Container::Delegated
61
+ include ActionWebService::Container::ActionController
62
+ include ActionWebService::Invocation
63
+ include ActionWebService::Dispatcher
64
+ include ActionWebService::Dispatcher::ActionController
65
+ include ActionWebService::Scaffolding
66
+ end