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,17 @@
1
+ # encoding: UTF-8
2
+ module StringToDatetimeForSoap
3
+ def to_datetime
4
+ begin
5
+ if /^([+\-]?\d{4,})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d(?:\.(\d*))?)(Z|(?:[+\-]\d\d:\d\d)?)?$/ =~ self.strip
6
+ return Time.xmlschema(self).localtime
7
+ end
8
+ super
9
+ rescue
10
+ # If a invalid date is supplied, it will automatically turn it into the first Julian Day
11
+ # Jan/01 - 4712 BC - This is a simple solution, until a better one appear :)
12
+ return Date.new
13
+ end
14
+ end
15
+ end
16
+
17
+ String.send :include, StringToDatetimeForSoap
@@ -0,0 +1,69 @@
1
+ # encoding: UTF-8
2
+ module ActionWebService
3
+ # To send structured types across the wire, derive from ActionWebService::Struct,
4
+ # and use +member+ to declare structure members.
5
+ #
6
+ # ActionWebService::Struct should be used in method signatures when you want to accept or return
7
+ # structured types that have no Active Record model class representations, or you don't
8
+ # want to expose your entire Active Record model to remote callers.
9
+ #
10
+ # === Example
11
+ #
12
+ # class Person < ActionWebService::Struct
13
+ # member :id, :int
14
+ # member :firstnames, [:string]
15
+ # member :lastname, :string
16
+ # member :email, :string, :nillable => true
17
+ # end
18
+ # person = Person.new(:id => 5, :firstname => 'john', :lastname => 'doe')
19
+ #
20
+ # Active Record model classes are already implicitly supported in method
21
+ # signatures.
22
+ class Struct
23
+ # If a Hash is given as argument to an ActionWebService::Struct constructor,
24
+ # it can contain initial values for the structure member.
25
+ # Values passed within the Hash that do not reflect member within the Struct will raise
26
+ # a NoMethodError unless the optional check_hash boolean is true.
27
+ def initialize(values={}, check_hash = false)
28
+ if values.is_a?(Hash)
29
+ values.map { |k,v| __send__("#{k}=", v) unless (check_hash && !self.respond_to?("#{k}=") ) }
30
+ end
31
+ end
32
+
33
+ # The member with the given name
34
+ def [](name)
35
+ send(name.to_s)
36
+ end
37
+
38
+ # Iterates through each member
39
+ def each_pair(&block)
40
+ self.class.members.each do |name, type|
41
+ yield name, self.__send__(name)
42
+ end
43
+ end
44
+
45
+ class << self
46
+ # Creates a structure member with the specified +name+ and +type+. Additional wsdl
47
+ # schema properties may be specified in the optional hash +options+. Generates
48
+ # accessor methods for reading and writing the member value.
49
+ def member(name, type, options={})
50
+ name = name.to_sym
51
+ type = ActionWebService::SignatureTypes.canonical_signature_entry({ name => type }, 0)
52
+ write_inheritable_hash("struct_members", name => [type, options])
53
+ class_eval <<-END
54
+ def #{name}; @#{name}; end
55
+ def #{name}=(value); @#{name} = value; end
56
+ END
57
+ end
58
+
59
+ def members # :nodoc:
60
+ read_inheritable_attribute("struct_members") || {}
61
+ end
62
+
63
+ def member_type(name) # :nodoc:
64
+ type, options = members[name.to_sym]
65
+ type
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,27 @@
1
+ # encoding: UTF-8
2
+ class Class # :nodoc:
3
+ def class_inheritable_option(sym, default_value=nil)
4
+ write_inheritable_attribute sym, default_value
5
+ class_eval <<-EOS
6
+ def self.#{sym}(value=nil)
7
+ if !value.nil?
8
+ write_inheritable_attribute(:#{sym}, value)
9
+ else
10
+ read_inheritable_attribute(:#{sym})
11
+ end
12
+ end
13
+
14
+ def self.#{sym}=(value)
15
+ write_inheritable_attribute(:#{sym}, value)
16
+ end
17
+
18
+ def #{sym}
19
+ self.class.#{sym}
20
+ end
21
+
22
+ def #{sym}=(value)
23
+ self.class.#{sym} = value
24
+ end
25
+ EOS
26
+ end
27
+ end
@@ -0,0 +1,262 @@
1
+ # encoding: UTF-8
2
+ module ActionWebService # :nodoc:
3
+ # Action Web Service supports the following base types in a signature:
4
+ #
5
+ # [<tt>:int</tt>] Represents an integer value, will be cast to an integer using <tt>Integer(value)</tt>
6
+ # [<tt>:string</tt>] Represents a string value, will be cast to an string using the <tt>to_s</tt> method on an object
7
+ # [<tt>:base64</tt>] Represents a Base 64 value, will contain the binary bytes of a Base 64 value sent by the caller
8
+ # [<tt>:bool</tt>] Represents a boolean value, whatever is passed will be cast to boolean (<tt>true</tt>, '1', 'true', 'y', 'yes' are taken to represent true; <tt>false</tt>, '0', 'false', 'n', 'no' and <tt>nil</tt> represent false)
9
+ # [<tt>:float</tt>] Represents a floating point value, will be cast to a float using <tt>Float(value)</tt>
10
+ # [<tt>:time</tt>] Represents a timestamp, will be cast to a <tt>Time</tt> object
11
+ # [<tt>:datetime</tt>] Represents a timestamp, will be cast to a <tt>DateTime</tt> object
12
+ # [<tt>:date</tt>] Represents a date, will be cast to a <tt>Date</tt> object
13
+ #
14
+ # For structured types, you'll need to pass in the Class objects of
15
+ # ActionWebService::Struct and ActiveRecord::Base derivatives.
16
+ module SignatureTypes
17
+ def canonical_signature(signature) # :nodoc:
18
+ return nil if signature.nil?
19
+ unless signature.is_a?(Array)
20
+ raise(ActionWebServiceError, "Expected signature to be an Array")
21
+ end
22
+ i = -1
23
+ signature.map{ |spec| canonical_signature_entry(spec, i += 1) }
24
+ end
25
+
26
+ def canonical_signature_entry(spec, i) # :nodoc:
27
+ orig_spec = spec
28
+ name = "param#{i}"
29
+ if spec.is_a?(Hash)
30
+ name, spec = spec.keys.first, spec.values.first
31
+ end
32
+ type = spec
33
+ if spec.is_a?(Array)
34
+ ArrayType.new(orig_spec, canonical_signature_entry(spec[0], 0), name)
35
+ else
36
+ type = canonical_type(type)
37
+ if type.is_a?(Symbol)
38
+ BaseType.new(orig_spec, type, name)
39
+ else
40
+ if type.is_a?(Hash)
41
+ complexity, type = type.keys.first.to_sym, type.values.first
42
+ end
43
+ element = complexity || :complex
44
+ element == :simple ? SimpleType.new(orig_spec, type, name) : StructuredType.new(orig_spec, type, name)
45
+ end
46
+ end
47
+ end
48
+
49
+ def canonical_type(type) # :nodoc:
50
+ type_name = symbol_name(type) || class_to_type_name(type)
51
+ type = type_name || type
52
+ return canonical_type_name(type) if type.is_a?(Symbol)
53
+ type
54
+ end
55
+
56
+ def canonical_type_name(name) # :nodoc:
57
+ name = name.to_sym
58
+ case name
59
+ when :int, :integer, :fixnum, :bignum
60
+ :int
61
+ when :string, :text
62
+ :string
63
+ when :base64, :binary
64
+ :base64
65
+ when :bool, :boolean
66
+ :bool
67
+ when :float, :double
68
+ :float
69
+ when :decimal
70
+ :decimal
71
+ when :time, :timestamp
72
+ :time
73
+ when :datetime
74
+ :datetime
75
+ when :date
76
+ :date
77
+ else
78
+ raise(TypeError, "#{name} is not a valid base type")
79
+ end
80
+ end
81
+
82
+ def canonical_type_class(type) # :nodoc:
83
+ type = canonical_type(type)
84
+ type.is_a?(Symbol) ? type_name_to_class(type) : type
85
+ end
86
+
87
+ def symbol_name(name) # :nodoc:
88
+ return name.to_sym if name.is_a?(Symbol) || name.is_a?(String)
89
+ nil
90
+ end
91
+
92
+ def class_to_type_name(klass) # :nodoc:
93
+ klass = klass.class unless klass.is_a?(Class)
94
+ if derived_from?(Integer, klass) || derived_from?(Fixnum, klass) || derived_from?(Bignum, klass)
95
+ :int
96
+ elsif klass == String
97
+ :string
98
+ elsif klass == Base64
99
+ :base64
100
+ elsif klass == TrueClass || klass == FalseClass
101
+ :bool
102
+ elsif derived_from?(Float, klass)
103
+ :float
104
+ elsif RUBY_VERSION < '1.9' && derived_from?(Precision, klass)
105
+ :float
106
+ elsif derived_from?(Numeric, klass)
107
+ :float
108
+ elsif klass == Time
109
+ :time
110
+ elsif klass == DateTime
111
+ :datetime
112
+ elsif klass == Date
113
+ :date
114
+ else
115
+ nil
116
+ end
117
+ end
118
+
119
+ def type_name_to_class(name) # :nodoc:
120
+ case canonical_type_name(name)
121
+ when :int
122
+ Integer
123
+ when :string
124
+ String
125
+ when :base64
126
+ Base64
127
+ when :bool
128
+ TrueClass
129
+ when :float
130
+ Float
131
+ when :decimal
132
+ BigDecimal
133
+ when :time
134
+ Time
135
+ when :date
136
+ Date
137
+ when :datetime
138
+ DateTime
139
+ else
140
+ nil
141
+ end
142
+ end
143
+
144
+ def derived_from?(ancestor, child) # :nodoc:
145
+ child.ancestors.include?(ancestor)
146
+ end
147
+
148
+ module_function :type_name_to_class
149
+ module_function :class_to_type_name
150
+ module_function :symbol_name
151
+ module_function :canonical_type_class
152
+ module_function :canonical_type_name
153
+ module_function :canonical_type
154
+ module_function :canonical_signature_entry
155
+ module_function :canonical_signature
156
+ module_function :derived_from?
157
+ end
158
+
159
+ class BaseType # :nodoc:
160
+ include SignatureTypes
161
+
162
+ attr :spec
163
+ attr :type
164
+ attr :type_class
165
+ attr :name
166
+
167
+ def initialize(spec, type, name)
168
+ @spec = spec
169
+ @type = canonical_type(type)
170
+ @type_class = canonical_type_class(@type)
171
+ @name = name
172
+ end
173
+
174
+ def custom?
175
+ false
176
+ end
177
+
178
+ def array?
179
+ false
180
+ end
181
+
182
+ def structured?
183
+ false
184
+ end
185
+
186
+ def simple?
187
+ false
188
+ end
189
+
190
+ def human_name(show_name=true)
191
+ type_type = array? ? element_type.type.to_s : self.type.to_s
192
+ str = array? ? (type_type + '[]') : type_type
193
+ show_name ? (str + " " + name.to_s) : str
194
+ end
195
+ end
196
+
197
+ class ArrayType < BaseType # :nodoc:
198
+ attr :element_type
199
+
200
+ def initialize(spec, element_type, name)
201
+ super(spec, Array, name)
202
+ @element_type = element_type
203
+ end
204
+
205
+ def custom?
206
+ true
207
+ end
208
+
209
+ def array?
210
+ true
211
+ end
212
+ end
213
+
214
+ class StructuredType < BaseType # :nodoc:
215
+ def each_member
216
+ if @type_class.respond_to?(:members)
217
+ @type_class.members.each do |name, type_options|
218
+ type, options = type_options
219
+ yield name, type, options
220
+ end
221
+ elsif @type_class.respond_to?(:columns)
222
+ i = -1
223
+ @type_class.columns.each do |column|
224
+ yield column.name, canonical_signature_entry(column.type, i += 1)
225
+ end
226
+ end
227
+ end
228
+
229
+ def custom?
230
+ true
231
+ end
232
+
233
+ def structured?
234
+ true
235
+ end
236
+ end
237
+
238
+ class SimpleType < BaseType # :nodoc:
239
+ def base
240
+ @type_class.restriction_base if @type_class.respond_to?(:restriction_base)
241
+ end
242
+
243
+ def restrictions
244
+ if @type_class.respond_to?(:restrictions)
245
+ @type_class.restrictions.each do |name, value|
246
+ yield name, value
247
+ end
248
+ end
249
+ end
250
+
251
+ def custom?
252
+ true
253
+ end
254
+
255
+ def simple?
256
+ true
257
+ end
258
+ end
259
+
260
+ class Base64 < String # :nodoc:
261
+ end
262
+ end
@@ -0,0 +1,65 @@
1
+ <html>
2
+ <head>
3
+ <title><%= @scaffold_class.wsdl_service_name %> Web Service</title>
4
+ <style>
5
+ body { background-color: #fff; color: #333; }
6
+
7
+ body, p, ol, ul, td {
8
+ font-family: verdana, arial, helvetica, sans-serif;
9
+ font-size: 13px;
10
+ line-height: 18px;
11
+ }
12
+
13
+ pre {
14
+ background-color: #eee;
15
+ padding: 10px;
16
+ font-size: 11px;
17
+ }
18
+
19
+ a { color: #000; }
20
+ a:visited { color: #666; }
21
+ a:hover { color: #fff; background-color:#000; }
22
+
23
+ .fieldWithErrors {
24
+ padding: 2px;
25
+ background-color: red;
26
+ display: table;
27
+ }
28
+
29
+ #errorExplanation {
30
+ width: 400px;
31
+ border: 2px solid red;
32
+ padding: 7px;
33
+ padding-bottom: 12px;
34
+ margin-bottom: 20px;
35
+ background-color: #f0f0f0;
36
+ }
37
+
38
+ #errorExplanation h2 {
39
+ text-align: left;
40
+ font-weight: bold;
41
+ padding: 5px 5px 5px 15px;
42
+ font-size: 12px;
43
+ margin: -7px;
44
+ background-color: #c00;
45
+ color: #fff;
46
+ }
47
+
48
+ #errorExplanation p {
49
+ color: #333;
50
+ margin-bottom: 0;
51
+ padding: 5px;
52
+ }
53
+
54
+ #errorExplanation ul li {
55
+ font-size: 12px;
56
+ list-style: square;
57
+ }
58
+ </style>
59
+ </head>
60
+ <body>
61
+
62
+ <%= @content_for_layout %>
63
+
64
+ </body>
65
+ </html>
@@ -0,0 +1,6 @@
1
+ <% @scaffold_container.services.each do |service| %>
2
+
3
+ <h4>API Methods for <%= service %></h4>
4
+ <%= service_method_list(service) %>
5
+
6
+ <% end %>