pelle-actionwebservice 2.3.3

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 +320 -0
  2. data/MIT-LICENSE +21 -0
  3. data/README +381 -0
  4. data/Rakefile +173 -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/api.rb +297 -0
  25. data/lib/action_web_service/base.rb +38 -0
  26. data/lib/action_web_service/casting.rb +149 -0
  27. data/lib/action_web_service/client/base.rb +28 -0
  28. data/lib/action_web_service/client/soap_client.rb +113 -0
  29. data/lib/action_web_service/client/xmlrpc_client.rb +58 -0
  30. data/lib/action_web_service/client.rb +3 -0
  31. data/lib/action_web_service/container/action_controller_container.rb +93 -0
  32. data/lib/action_web_service/container/delegated_container.rb +86 -0
  33. data/lib/action_web_service/container/direct_container.rb +69 -0
  34. data/lib/action_web_service/container.rb +3 -0
  35. data/lib/action_web_service/dispatcher/abstract.rb +207 -0
  36. data/lib/action_web_service/dispatcher/action_controller_dispatcher.rb +379 -0
  37. data/lib/action_web_service/dispatcher.rb +2 -0
  38. data/lib/action_web_service/invocation.rb +202 -0
  39. data/lib/action_web_service/protocol/abstract.rb +112 -0
  40. data/lib/action_web_service/protocol/discovery.rb +37 -0
  41. data/lib/action_web_service/protocol/soap_protocol/marshaler.rb +242 -0
  42. data/lib/action_web_service/protocol/soap_protocol.rb +176 -0
  43. data/lib/action_web_service/protocol/xmlrpc_protocol.rb +122 -0
  44. data/lib/action_web_service/protocol.rb +4 -0
  45. data/lib/action_web_service/scaffolding.rb +281 -0
  46. data/lib/action_web_service/struct.rb +64 -0
  47. data/lib/action_web_service/support/class_inheritable_options.rb +26 -0
  48. data/lib/action_web_service/support/signature_types.rb +226 -0
  49. data/lib/action_web_service/templates/scaffolds/layout.html.erb +65 -0
  50. data/lib/action_web_service/templates/scaffolds/methods.html.erb +6 -0
  51. data/lib/action_web_service/templates/scaffolds/parameters.html.erb +29 -0
  52. data/lib/action_web_service/templates/scaffolds/result.html.erb +30 -0
  53. data/lib/action_web_service/test_invoke.rb +110 -0
  54. data/lib/action_web_service/version.rb +9 -0
  55. data/lib/action_web_service.rb +66 -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 +39 -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 +94 -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 +138 -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 +171 -0
@@ -0,0 +1,30 @@
1
+ <h4>Method Invocation Result for <em><%= @scaffold_service %>#<%= @scaffold_method.public_name %></em></h4>
2
+
3
+ <p>
4
+ Invocation took <tt><%= '%f' % @method_elapsed %></tt> seconds
5
+ </p>
6
+
7
+ <p>
8
+ <strong>Return Value:</strong><br />
9
+ <pre>
10
+ <%= h @method_return_value.inspect %>
11
+ </pre>
12
+ </p>
13
+
14
+ <p>
15
+ <strong>Request XML:</strong><br />
16
+ <pre>
17
+ <%= h @method_request_xml %>
18
+ </pre>
19
+ </p>
20
+
21
+ <p>
22
+ <strong>Response XML:</strong><br />
23
+ <pre>
24
+ <%= h @method_response_xml %>
25
+ </pre>
26
+ </p>
27
+
28
+ <p>
29
+ <%= link_to "Back", :action => @scaffold_action_name + '_method_params', :method => @scaffold_method.public_name, :service => @scaffold_service.name %>
30
+ </p>
@@ -0,0 +1,110 @@
1
+ require 'test/unit'
2
+
3
+ module Test # :nodoc:
4
+ module Unit # :nodoc:
5
+ class TestCase # :nodoc:
6
+ private
7
+ # invoke the specified API method
8
+ def invoke_direct(method_name, *args)
9
+ prepare_request('api', 'api', method_name, *args)
10
+ @controller.process(@request, @response)
11
+ decode_rpc_response
12
+ end
13
+ alias_method :invoke, :invoke_direct
14
+
15
+ # invoke the specified API method on the specified service
16
+ def invoke_delegated(service_name, method_name, *args)
17
+ prepare_request(service_name.to_s, service_name, method_name, *args)
18
+ @controller.process(@request, @response)
19
+ decode_rpc_response
20
+ end
21
+
22
+ # invoke the specified layered API method on the correct service
23
+ def invoke_layered(service_name, method_name, *args)
24
+ prepare_request('api', service_name, method_name, *args)
25
+ @controller.process(@request, @response)
26
+ decode_rpc_response
27
+ end
28
+
29
+ # ---------------------- internal ---------------------------
30
+
31
+ def prepare_request(action, service_name, api_method_name, *args)
32
+ @request.recycle!
33
+ @request.request_parameters['action'] = action
34
+ @request.env['REQUEST_METHOD'] = 'POST'
35
+ @request.env['HTTP_CONTENT_TYPE'] = 'text/xml'
36
+ @request.env['RAW_POST_DATA'] = encode_rpc_call(service_name, api_method_name, *args)
37
+ case protocol
38
+ when ActionWebService::Protocol::Soap::SoapProtocol
39
+ soap_action = "/#{@controller.controller_name}/#{service_name}/#{public_method_name(service_name, api_method_name)}"
40
+ @request.env['HTTP_SOAPACTION'] = soap_action
41
+ when ActionWebService::Protocol::XmlRpc::XmlRpcProtocol
42
+ @request.env.delete('HTTP_SOAPACTION')
43
+ end
44
+ end
45
+
46
+ def encode_rpc_call(service_name, api_method_name, *args)
47
+ case @controller.web_service_dispatching_mode
48
+ when :direct
49
+ api = @controller.class.web_service_api
50
+ when :delegated, :layered
51
+ api = @controller.web_service_object(service_name.to_sym).class.web_service_api
52
+ end
53
+ protocol.register_api(api)
54
+ method = api.api_methods[api_method_name.to_sym]
55
+ raise ArgumentError, "wrong number of arguments for rpc call (#{args.length} for #{method.expects.length})" if method && method.expects && args.length != method.expects.length
56
+ protocol.encode_request(public_method_name(service_name, api_method_name), args.dup, method.expects)
57
+ end
58
+
59
+ def decode_rpc_response
60
+ public_method_name, return_value = protocol.decode_response(@response.body)
61
+ exception = is_exception?(return_value)
62
+ raise exception if exception
63
+ return_value
64
+ end
65
+
66
+ def public_method_name(service_name, api_method_name)
67
+ public_name = service_api(service_name).public_api_method_name(api_method_name)
68
+ if @controller.web_service_dispatching_mode == :layered && protocol.is_a?(ActionWebService::Protocol::XmlRpc::XmlRpcProtocol)
69
+ '%s.%s' % [service_name.to_s, public_name]
70
+ else
71
+ public_name
72
+ end
73
+ end
74
+
75
+ def service_api(service_name)
76
+ case @controller.web_service_dispatching_mode
77
+ when :direct
78
+ @controller.class.web_service_api
79
+ when :delegated, :layered
80
+ @controller.web_service_object(service_name.to_sym).class.web_service_api
81
+ end
82
+ end
83
+
84
+ def protocol
85
+ if @protocol.nil?
86
+ @protocol ||= ActionWebService::Protocol::Soap::SoapProtocol.create(@controller)
87
+ else
88
+ case @protocol
89
+ when :xmlrpc
90
+ @protocol = ActionWebService::Protocol::XmlRpc::XmlRpcProtocol.create(@controller)
91
+ when :soap
92
+ @protocol = ActionWebService::Protocol::Soap::SoapProtocol.create(@controller)
93
+ else
94
+ @protocol
95
+ end
96
+ end
97
+ end
98
+
99
+ def is_exception?(obj)
100
+ case protocol
101
+ when :soap, ActionWebService::Protocol::Soap::SoapProtocol
102
+ (obj.respond_to?(:detail) && obj.detail.respond_to?(:cause) && \
103
+ obj.detail.cause.is_a?(Exception)) ? obj.detail.cause : nil
104
+ when :xmlrpc, ActionWebService::Protocol::XmlRpc::XmlRpcProtocol
105
+ obj.is_a?(XMLRPC::FaultException) ? obj : nil
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,9 @@
1
+ module ActionWebService
2
+ module VERSION #:nodoc:
3
+ MAJOR = 2
4
+ MINOR = 3
5
+ TINY = 2
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ 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
@@ -0,0 +1 @@
1
+ require 'action_web_service'