pelle-actionwebservice 2.3.3

Sign up to get free protection for your applications and to get access to all the features.
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,183 @@
1
+ require File.dirname(__FILE__) + '/abstract_unit'
2
+ require 'webrick'
3
+ require 'webrick/log'
4
+ require 'singleton'
5
+
6
+ module ClientTest
7
+ class Person < ActionWebService::Struct
8
+ member :firstnames, [:string]
9
+ member :lastname, :string
10
+
11
+ def ==(other)
12
+ firstnames == other.firstnames && lastname == other.lastname
13
+ end
14
+ end
15
+
16
+ class Inner < ActionWebService::Struct
17
+ member :name, :string
18
+ end
19
+
20
+ class Outer < ActionWebService::Struct
21
+ member :name, :string
22
+ member :inner, Inner
23
+ end
24
+
25
+ class User < ActiveRecord::Base
26
+ end
27
+
28
+ module Accounting
29
+ class User < ActiveRecord::Base
30
+ end
31
+ end
32
+
33
+ class WithModel < ActionWebService::Struct
34
+ member :user, User
35
+ member :users, [User]
36
+ end
37
+
38
+ class WithMultiDimArray < ActionWebService::Struct
39
+ member :pref, [[:string]]
40
+ end
41
+
42
+ class API < ActionWebService::API::Base
43
+ api_method :void
44
+ api_method :normal, :expects => [:int, :int], :returns => [:int]
45
+ api_method :array_return, :returns => [[Person]]
46
+ api_method :struct_pass, :expects => [[Person]], :returns => [:bool]
47
+ api_method :nil_struct_return, :returns => [Person]
48
+ api_method :inner_nil, :returns => [Outer]
49
+ api_method :client_container, :returns => [:int]
50
+ api_method :named_parameters, :expects => [{:key=>:string}, {:id=>:int}]
51
+ api_method :thrower
52
+ api_method :user_return, :returns => [User]
53
+ api_method :with_model_return, :returns => [WithModel]
54
+ api_method :scoped_model_return, :returns => [Accounting::User]
55
+ api_method :multi_dim_return, :returns => [WithMultiDimArray]
56
+ end
57
+
58
+ class NullLogOut
59
+ def <<(*args); end
60
+ end
61
+
62
+ class Container < ActionController::Base
63
+ web_service_api API
64
+
65
+ attr_accessor :value_void
66
+ attr_accessor :value_normal
67
+ attr_accessor :value_array_return
68
+ attr_accessor :value_struct_pass
69
+ attr_accessor :value_named_parameters
70
+
71
+ def initialize
72
+ @value_void = nil
73
+ @value_normal = nil
74
+ @value_array_return = nil
75
+ @value_struct_pass = nil
76
+ @value_named_parameters = nil
77
+ end
78
+
79
+ def void
80
+ @value_void = @method_params
81
+ end
82
+
83
+ def normal
84
+ @value_normal = @method_params
85
+ 5
86
+ end
87
+
88
+ def array_return
89
+ person = Person.new
90
+ person.firstnames = ["one", "two"]
91
+ person.lastname = "last"
92
+ @value_array_return = [person]
93
+ end
94
+
95
+ def struct_pass
96
+ @value_struct_pass = @method_params
97
+ true
98
+ end
99
+
100
+ def nil_struct_return
101
+ nil
102
+ end
103
+
104
+ def inner_nil
105
+ Outer.new :name => 'outer', :inner => nil
106
+ end
107
+
108
+ def client_container
109
+ 50
110
+ end
111
+
112
+ def named_parameters
113
+ @value_named_parameters = @method_params
114
+ end
115
+
116
+ def thrower
117
+ raise "Hi"
118
+ end
119
+
120
+ def user_return
121
+ User.find(1)
122
+ end
123
+
124
+ def with_model_return
125
+ WithModel.new :user => User.find(1), :users => User.find(:all)
126
+ end
127
+
128
+ def scoped_model_return
129
+ Accounting::User.find(1)
130
+ end
131
+
132
+ def multi_dim_return
133
+ WithMultiDimArray.new :pref => [%w{pref1 value1}, %w{pref2 value2}]
134
+ end
135
+ end
136
+
137
+ class AbstractClientLet < WEBrick::HTTPServlet::AbstractServlet
138
+ def initialize(controller)
139
+ @controller = controller
140
+ end
141
+
142
+ def get_instance(*args)
143
+ self
144
+ end
145
+
146
+ def require_path_info?
147
+ false
148
+ end
149
+
150
+ def do_GET(req, res)
151
+ raise WEBrick::HTTPStatus::MethodNotAllowed, "GET request not allowed."
152
+ end
153
+
154
+ def do_POST(req, res)
155
+ raise NotImplementedError
156
+ end
157
+ end
158
+
159
+ class AbstractServer
160
+ include ClientTest
161
+ include Singleton
162
+ attr :container
163
+ def initialize
164
+ @container = Container.new
165
+ @clientlet = create_clientlet(@container)
166
+ log = WEBrick::BasicLog.new(NullLogOut.new)
167
+ @server = WEBrick::HTTPServer.new(:Port => server_port, :Logger => log, :AccessLog => [])
168
+ @server.mount('/', @clientlet)
169
+ @thr = Thread.new { @server.start }
170
+ until @server.status == :Running; end
171
+ at_exit { @server.stop; @thr.join }
172
+ end
173
+
174
+ protected
175
+ def create_clientlet
176
+ raise NotImplementedError
177
+ end
178
+
179
+ def server_port
180
+ raise NotImplementedError
181
+ end
182
+ end
183
+ end