axtro-actionwebservice 2.3.5.1.20101118142125

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. data/CHANGELOG +335 -0
  2. data/MIT-LICENSE +21 -0
  3. data/README +381 -0
  4. data/Rakefile +184 -0
  5. data/TODO +32 -0
  6. data/examples/googlesearch/README +143 -0
  7. data/examples/googlesearch/autoloading/google_search_api.rb +51 -0
  8. data/examples/googlesearch/autoloading/google_search_controller.rb +58 -0
  9. data/examples/googlesearch/delegated/google_search_service.rb +109 -0
  10. data/examples/googlesearch/delegated/search_controller.rb +8 -0
  11. data/examples/googlesearch/direct/google_search_api.rb +51 -0
  12. data/examples/googlesearch/direct/search_controller.rb +59 -0
  13. data/examples/metaWeblog/README +17 -0
  14. data/examples/metaWeblog/apis/blogger_api.rb +61 -0
  15. data/examples/metaWeblog/apis/blogger_service.rb +35 -0
  16. data/examples/metaWeblog/apis/meta_weblog_api.rb +68 -0
  17. data/examples/metaWeblog/apis/meta_weblog_service.rb +49 -0
  18. data/examples/metaWeblog/controllers/xmlrpc_controller.rb +17 -0
  19. data/generators/web_service/USAGE +28 -0
  20. data/generators/web_service/templates/api_definition.rb +6 -0
  21. data/generators/web_service/templates/controller.rb +9 -0
  22. data/generators/web_service/templates/functional_test.rb +20 -0
  23. data/generators/web_service/web_service_generator.rb +30 -0
  24. data/lib/action_web_service.rb +61 -0
  25. data/lib/action_web_service/acts_as_web_service.rb +26 -0
  26. data/lib/action_web_service/api.rb +298 -0
  27. data/lib/action_web_service/base.rb +39 -0
  28. data/lib/action_web_service/casting.rb +160 -0
  29. data/lib/action_web_service/client.rb +4 -0
  30. data/lib/action_web_service/client/base.rb +29 -0
  31. data/lib/action_web_service/client/soap_client.rb +114 -0
  32. data/lib/action_web_service/client/xmlrpc_client.rb +59 -0
  33. data/lib/action_web_service/container.rb +4 -0
  34. data/lib/action_web_service/container/action_controller_container.rb +94 -0
  35. data/lib/action_web_service/container/delegated_container.rb +87 -0
  36. data/lib/action_web_service/container/direct_container.rb +70 -0
  37. data/lib/action_web_service/dispatcher.rb +3 -0
  38. data/lib/action_web_service/dispatcher/abstract.rb +209 -0
  39. data/lib/action_web_service/dispatcher/action_controller_dispatcher.rb +397 -0
  40. data/lib/action_web_service/invocation.rb +203 -0
  41. data/lib/action_web_service/protocol.rb +5 -0
  42. data/lib/action_web_service/protocol/abstract.rb +113 -0
  43. data/lib/action_web_service/protocol/discovery.rb +38 -0
  44. data/lib/action_web_service/protocol/soap_protocol.rb +177 -0
  45. data/lib/action_web_service/protocol/soap_protocol/marshaler.rb +243 -0
  46. data/lib/action_web_service/protocol/soap_protocol/marshaler.rb~ +243 -0
  47. data/lib/action_web_service/protocol/xmlrpc_protocol.rb +124 -0
  48. data/lib/action_web_service/scaffolding.rb +282 -0
  49. data/lib/action_web_service/simple.rb +54 -0
  50. data/lib/action_web_service/string_to_datetime_for_soap.rb +17 -0
  51. data/lib/action_web_service/struct.rb +69 -0
  52. data/lib/action_web_service/support/class_inheritable_options.rb +27 -0
  53. data/lib/action_web_service/support/signature_types.rb +262 -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 +111 -0
  59. data/lib/action_web_service/version.rb +11 -0
  60. data/lib/action_web_service/version.rb~ +10 -0
  61. data/lib/actionwebservice.rb +2 -0
  62. data/setup.rb +1380 -0
  63. data/test/abstract_client.rb +185 -0
  64. data/test/abstract_dispatcher.rb +550 -0
  65. data/test/abstract_unit.rb +44 -0
  66. data/test/api_test.rb +103 -0
  67. data/test/apis/auto_load_api.rb +4 -0
  68. data/test/apis/broken_auto_load_api.rb +3 -0
  69. data/test/base_test.rb +43 -0
  70. data/test/casting_test.rb +96 -0
  71. data/test/client_soap_test.rb +157 -0
  72. data/test/client_xmlrpc_test.rb +155 -0
  73. data/test/container_test.rb +76 -0
  74. data/test/dispatcher_action_controller_soap_test.rb +147 -0
  75. data/test/dispatcher_action_controller_xmlrpc_test.rb +60 -0
  76. data/test/fixtures/db_definitions/mysql.sql +8 -0
  77. data/test/fixtures/db_definitions/sqlite3.sql +8 -0
  78. data/test/fixtures/users.yml +12 -0
  79. data/test/gencov +3 -0
  80. data/test/invocation_test.rb +187 -0
  81. data/test/run +6 -0
  82. data/test/scaffolded_controller_test.rb +148 -0
  83. data/test/struct_test.rb +85 -0
  84. data/test/test_invoke_test.rb +114 -0
  85. metadata +167 -0
@@ -0,0 +1,109 @@
1
+ # encoding: UTF-8
2
+ class DirectoryCategory < ActionWebService::Struct
3
+ member :fullViewableName, :string
4
+ member :specialEncoding, :string
5
+ end
6
+
7
+ class ResultElement < ActionWebService::Struct
8
+ member :summary, :string
9
+ member :URL, :string
10
+ member :snippet, :string
11
+ member :title, :string
12
+ member :cachedSize, :string
13
+ member :relatedInformationPresent, :bool
14
+ member :hostName, :string
15
+ member :directoryCategory, DirectoryCategory
16
+ member :directoryTitle, :string
17
+ end
18
+
19
+ class GoogleSearchResult < ActionWebService::Struct
20
+ member :documentFiltering, :bool
21
+ member :searchComments, :string
22
+ member :estimatedTotalResultsCount, :int
23
+ member :estimateIsExact, :bool
24
+ member :resultElements, [ResultElement]
25
+ member :searchQuery, :string
26
+ member :startIndex, :int
27
+ member :endIndex, :int
28
+ member :searchTips, :string
29
+ member :directoryCategories, [DirectoryCategory]
30
+ member :searchTime, :float
31
+ end
32
+
33
+ class GoogleSearchAPI < ActionWebService::API::Base
34
+ inflect_names false
35
+
36
+ api_method :doGetCachedPage, :returns => [:string], :expects => [{:key=>:string}, {:url=>:string}]
37
+ api_method :doGetSpellingSuggestion, :returns => [:string], :expects => [{:key=>:string}, {:phrase=>:string}]
38
+
39
+ api_method :doGoogleSearch, :returns => [GoogleSearchResult], :expects => [
40
+ {:key=>:string},
41
+ {:q=>:string},
42
+ {:start=>:int},
43
+ {:maxResults=>:int},
44
+ {:filter=>:bool},
45
+ {:restrict=>:string},
46
+ {:safeSearch=>:bool},
47
+ {:lr=>:string},
48
+ {:ie=>:string},
49
+ {:oe=>:string}
50
+ ]
51
+ end
52
+
53
+ class GoogleSearchService < ActionWebService::Base
54
+ web_service_api GoogleSearchAPI
55
+
56
+ def doGetCachedPage(key, url)
57
+ "<html><body>i am a cached page</body></html>"
58
+ end
59
+
60
+ def doSpellingSuggestion(key, phrase)
61
+ "Did you mean 'teh'?"
62
+ end
63
+
64
+ def doGoogleSearch(key, q, start, maxResults, filter, restrict, safeSearch, lr, ie, oe)
65
+ resultElement = ResultElement.new
66
+ resultElement.summary = "ONlamp.com: Rolling with Ruby on Rails"
67
+ resultElement.URL = "http://www.onlamp.com/pub/a/onlamp/2005/01/20/rails.html"
68
+ resultElement.snippet = "Curt Hibbs shows off Ruby on Rails by building a simple application that requires " +
69
+ "almost no Ruby experience. ... Rolling with Ruby on Rails. ..."
70
+ resultElement.title = "Teh Railz0r"
71
+ resultElement.cachedSize = "Almost no lines of code!"
72
+ resultElement.relatedInformationPresent = true
73
+ resultElement.hostName = "rubyonrails.com"
74
+ resultElement.directoryCategory = category("Web Development", "UTF-8")
75
+
76
+ result = GoogleSearchResult.new
77
+ result.documentFiltering = filter
78
+ result.searchComments = ""
79
+ result.estimatedTotalResultsCount = 322000
80
+ result.estimateIsExact = false
81
+ result.resultElements = [resultElement]
82
+ result.searchQuery = "http://www.google.com/search?q=ruby+on+rails"
83
+ result.startIndex = start
84
+ result.endIndex = start + maxResults
85
+ result.searchTips = "\"on\" is a very common word and was not included in your search [details]"
86
+ result.searchTime = 0.000001
87
+
88
+ # For Mono, we have to clone objects if they're referenced by more than one place, otherwise
89
+ # the Ruby SOAP collapses them into one instance and uses references all over the
90
+ # place, confusing Mono.
91
+ #
92
+ # This has recently been fixed:
93
+ # http://bugzilla.ximian.com/show_bug.cgi?id=72265
94
+ result.directoryCategories = [
95
+ category("Web Development", "UTF-8"),
96
+ category("Programming", "US-ASCII"),
97
+ ]
98
+
99
+ result
100
+ end
101
+
102
+ private
103
+ def category(name, encoding)
104
+ cat = DirectoryCategory.new
105
+ cat.fullViewableName = name.dup
106
+ cat.specialEncoding = encoding.dup
107
+ cat
108
+ end
109
+ end
@@ -0,0 +1,8 @@
1
+ # encoding: UTF-8
2
+ require 'google_search_service'
3
+
4
+ class SearchController < ApplicationController
5
+ wsdl_service_name 'GoogleSearch'
6
+ web_service_dispatching_mode :delegated
7
+ web_service :beta3, GoogleSearchService.new
8
+ end
@@ -0,0 +1,51 @@
1
+ # encoding: UTF-8
2
+ class DirectoryCategory < ActionWebService::Struct
3
+ member :fullViewableName, :string
4
+ member :specialEncoding, :string
5
+ end
6
+
7
+ class ResultElement < ActionWebService::Struct
8
+ member :summary, :string
9
+ member :URL, :string
10
+ member :snippet, :string
11
+ member :title, :string
12
+ member :cachedSize, :string
13
+ member :relatedInformationPresent, :bool
14
+ member :hostName, :string
15
+ member :directoryCategory, DirectoryCategory
16
+ member :directoryTitle, :string
17
+ end
18
+
19
+ class GoogleSearchResult < ActionWebService::Struct
20
+ member :documentFiltering, :bool
21
+ member :searchComments, :string
22
+ member :estimatedTotalResultsCount, :int
23
+ member :estimateIsExact, :bool
24
+ member :resultElements, [ResultElement]
25
+ member :searchQuery, :string
26
+ member :startIndex, :int
27
+ member :endIndex, :int
28
+ member :searchTips, :string
29
+ member :directoryCategories, [DirectoryCategory]
30
+ member :searchTime, :float
31
+ end
32
+
33
+ class GoogleSearchAPI < ActionWebService::API::Base
34
+ inflect_names false
35
+
36
+ api_method :doGetCachedPage, :returns => [:string], :expects => [{:key=>:string}, {:url=>:string}]
37
+ api_method :doGetSpellingSuggestion, :returns => [:string], :expects => [{:key=>:string}, {:phrase=>:string}]
38
+
39
+ api_method :doGoogleSearch, :returns => [GoogleSearchResult], :expects => [
40
+ {:key=>:string},
41
+ {:q=>:string},
42
+ {:start=>:int},
43
+ {:maxResults=>:int},
44
+ {:filter=>:bool},
45
+ {:restrict=>:string},
46
+ {:safeSearch=>:bool},
47
+ {:lr=>:string},
48
+ {:ie=>:string},
49
+ {:oe=>:string}
50
+ ]
51
+ end
@@ -0,0 +1,59 @@
1
+ # encoding: UTF-8
2
+ class SearchController < ApplicationController
3
+ web_service_api :google_search
4
+ wsdl_service_name 'GoogleSearch'
5
+
6
+ def doGetCachedPage
7
+ "<html><body>i am a cached page. my key was %s, url was %s</body></html>" % [@params['key'], @params['url']]
8
+ end
9
+
10
+ def doSpellingSuggestion
11
+ "%s: Did you mean '%s'?" % [@params['key'], @params['phrase']]
12
+ end
13
+
14
+ def doGoogleSearch
15
+ resultElement = ResultElement.new
16
+ resultElement.summary = "ONlamp.com: Rolling with Ruby on Rails"
17
+ resultElement.URL = "http://www.onlamp.com/pub/a/onlamp/2005/01/20/rails.html"
18
+ resultElement.snippet = "Curt Hibbs shows off Ruby on Rails by building a simple application that requires " +
19
+ "almost no Ruby experience. ... Rolling with Ruby on Rails. ..."
20
+ resultElement.title = "Teh Railz0r"
21
+ resultElement.cachedSize = "Almost no lines of code!"
22
+ resultElement.relatedInformationPresent = true
23
+ resultElement.hostName = "rubyonrails.com"
24
+ resultElement.directoryCategory = category("Web Development", "UTF-8")
25
+
26
+ result = GoogleSearchResult.new
27
+ result.documentFiltering = @params['filter']
28
+ result.searchComments = ""
29
+ result.estimatedTotalResultsCount = 322000
30
+ result.estimateIsExact = false
31
+ result.resultElements = [resultElement]
32
+ result.searchQuery = "http://www.google.com/search?q=ruby+on+rails"
33
+ result.startIndex = @params['start']
34
+ result.endIndex = @params['start'] + @params['maxResults']
35
+ result.searchTips = "\"on\" is a very common word and was not included in your search [details]"
36
+ result.searchTime = 0.000001
37
+
38
+ # For Mono, we have to clone objects if they're referenced by more than one place, otherwise
39
+ # the Ruby SOAP collapses them into one instance and uses references all over the
40
+ # place, confusing Mono.
41
+ #
42
+ # This has recently been fixed:
43
+ # http://bugzilla.ximian.com/show_bug.cgi?id=72265
44
+ result.directoryCategories = [
45
+ category("Web Development", "UTF-8"),
46
+ category("Programming", "US-ASCII"),
47
+ ]
48
+
49
+ result
50
+ end
51
+
52
+ private
53
+ def category(name, encoding)
54
+ cat = DirectoryCategory.new
55
+ cat.fullViewableName = name.dup
56
+ cat.specialEncoding = encoding.dup
57
+ cat
58
+ end
59
+ 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,61 @@
1
+ # encoding: UTF-8
2
+ #
3
+ # see the blogger API spec at http://www.blogger.com/developers/api/1_docs/
4
+ # note that the method signatures are subtly different to metaWeblog, they
5
+ # are not identical. take care to ensure you handle the different semantics
6
+ # properly if you want to support blogger API too, to get maximum compatibility.
7
+ #
8
+
9
+ module Blog
10
+ class Blog < ActionWebService::Struct
11
+ member :url, :string
12
+ member :blogid, :string
13
+ member :blogName, :string
14
+ end
15
+
16
+ class User < ActionWebService::Struct
17
+ member :nickname, :string
18
+ member :userid, :string
19
+ member :url, :string
20
+ member :email, :string
21
+ member :lastname, :string
22
+ member :firstname, :string
23
+ end
24
+ end
25
+
26
+ #
27
+ # blogger
28
+ #
29
+ class BloggerAPI < ActionWebService::API::Base
30
+ inflect_names false
31
+
32
+ api_method :newPost, :returns => [:string], :expects => [
33
+ {:appkey=>:string},
34
+ {:blogid=>:string},
35
+ {:username=>:string},
36
+ {:password=>:string},
37
+ {:content=>:string},
38
+ {:publish=>:bool}
39
+ ]
40
+
41
+ api_method :editPost, :returns => [:bool], :expects => [
42
+ {:appkey=>:string},
43
+ {:postid=>:string},
44
+ {:username=>:string},
45
+ {:password=>:string},
46
+ {:content=>:string},
47
+ {:publish=>:bool}
48
+ ]
49
+
50
+ api_method :getUsersBlogs, :returns => [[Blog::Blog]], :expects => [
51
+ {:appkey=>:string},
52
+ {:username=>:string},
53
+ {:password=>:string}
54
+ ]
55
+
56
+ api_method :getUserInfo, :returns => [Blog::User], :expects => [
57
+ {:appkey=>:string},
58
+ {:username=>:string},
59
+ {:password=>:string}
60
+ ]
61
+ end
@@ -0,0 +1,35 @@
1
+ # encoding: UTF-8
2
+ require 'blogger_api'
3
+
4
+ class BloggerService < ActionWebService::Base
5
+ web_service_api BloggerAPI
6
+
7
+ def initialize
8
+ @postid = 0
9
+ end
10
+
11
+ def newPost(key, id, user, pw, content, publish)
12
+ $stderr.puts "id=#{id} user=#{user} pw=#{pw}, content=#{content.inspect} [#{publish}]"
13
+ (@postid += 1).to_s
14
+ end
15
+
16
+ def editPost(key, post_id, user, pw, content, publish)
17
+ $stderr.puts "id=#{post_id} user=#{user} pw=#{pw} content=#{content.inspect} [#{publish}]"
18
+ true
19
+ end
20
+
21
+ def getUsersBlogs(key, user, pw)
22
+ $stderr.puts "getting blogs for #{user}"
23
+ blog = Blog::Blog.new(
24
+ :url =>'http://blog',
25
+ :blogid => 'myblog',
26
+ :blogName => 'My Blog'
27
+ )
28
+ [blog]
29
+ end
30
+
31
+ def getUserInfo(key, user, pw)
32
+ $stderr.puts "getting user info for #{user}"
33
+ Blog::User.new(:nickname => 'user', :email => 'user@test.com')
34
+ end
35
+ end
@@ -0,0 +1,68 @@
1
+ # encoding: UTF-8
2
+ #
3
+ # here lie structures, cousins of those on http://www.xmlrpc.com/metaWeblog
4
+ # but they don't necessarily the real world reflect
5
+ # so if you do, find that your client complains:
6
+ # please tell, of problems you suffered through
7
+ #
8
+
9
+ module Blog
10
+ class Post < ActionWebService::Struct
11
+ member :title, :string
12
+ member :link, :string
13
+ member :description, :string
14
+ member :author, :string
15
+ member :category, :string
16
+ member :comments, :string
17
+ member :guid, :string
18
+ member :pubDate, :string
19
+ end
20
+
21
+ class Category < ActionWebService::Struct
22
+ member :description, :string
23
+ member :htmlUrl, :string
24
+ member :rssUrl, :string
25
+ end
26
+ end
27
+
28
+ #
29
+ # metaWeblog
30
+ #
31
+ class MetaWeblogAPI < ActionWebService::API::Base
32
+ inflect_names false
33
+
34
+ api_method :newPost, :returns => [:string], :expects => [
35
+ {:blogid=>:string},
36
+ {:username=>:string},
37
+ {:password=>:string},
38
+ {:struct=>Blog::Post},
39
+ {:publish=>:bool}
40
+ ]
41
+
42
+ api_method :editPost, :returns => [:bool], :expects => [
43
+ {:postid=>:string},
44
+ {:username=>:string},
45
+ {:password=>:string},
46
+ {:struct=>Blog::Post},
47
+ {:publish=>:bool},
48
+ ]
49
+
50
+ api_method :getPost, :returns => [Blog::Post], :expects => [
51
+ {:postid=>:string},
52
+ {:username=>:string},
53
+ {:password=>:string},
54
+ ]
55
+
56
+ api_method :getCategories, :returns => [[Blog::Category]], :expects => [
57
+ {:blogid=>:string},
58
+ {:username=>:string},
59
+ {:password=>:string},
60
+ ]
61
+
62
+ api_method :getRecentPosts, :returns => [[Blog::Post]], :expects => [
63
+ {:blogid=>:string},
64
+ {:username=>:string},
65
+ {:password=>:string},
66
+ {:numberOfPosts=>:int},
67
+ ]
68
+ end
@@ -0,0 +1,49 @@
1
+ # encoding: UTF-8
2
+ require 'meta_weblog_api'
3
+
4
+ class MetaWeblogService < ActionWebService::Base
5
+ web_service_api MetaWeblogAPI
6
+
7
+ def initialize
8
+ @postid = 0
9
+ end
10
+
11
+ def newPost(id, user, pw, struct, publish)
12
+ $stderr.puts "id=#{id} user=#{user} pw=#{pw}, struct=#{struct.inspect} [#{publish}]"
13
+ (@postid += 1).to_s
14
+ end
15
+
16
+ def editPost(post_id, user, pw, struct, publish)
17
+ $stderr.puts "id=#{post_id} user=#{user} pw=#{pw} struct=#{struct.inspect} [#{publish}]"
18
+ true
19
+ end
20
+
21
+ def getPost(post_id, user, pw)
22
+ $stderr.puts "get post #{post_id}"
23
+ Blog::Post.new(:title => 'hello world', :description => 'first post!')
24
+ end
25
+
26
+ def getCategories(id, user, pw)
27
+ $stderr.puts "categories for #{user}"
28
+ cat = Blog::Category.new(
29
+ :description => 'Tech',
30
+ :htmlUrl => 'http://blog/tech',
31
+ :rssUrl => 'http://blog/tech.rss')
32
+ [cat]
33
+ end
34
+
35
+ def getRecentPosts(id, user, pw, num)
36
+ $stderr.puts "recent #{num} posts for #{user} on blog #{id}"
37
+ post1 = Blog::Post.new(
38
+ :title => 'first post!',
39
+ :link => 'http://blog.xeraph.org/testOne.html',
40
+ :description => 'this is the first post'
41
+ )
42
+ post2 = Blog::Post.new(
43
+ :title => 'second post!',
44
+ :link => 'http://blog.xeraph.org/testTwo.html',
45
+ :description => 'this is the second post'
46
+ )
47
+ [post1, post2]
48
+ end
49
+ end