Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdanRada committed Nov 20, 2013
1 parent 5ce8564 commit 7e76894
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/washout_builder.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'wash_out'
require 'washout_builder/soap_fault'
require 'washout_builder/soap'
#require 'washout_doc/param'
require 'washout_builder/param'
require 'washout_builder/engine'
require 'washout_builder/dispatcher'
require 'washout_builder/type'
Expand Down Expand Up @@ -30,6 +30,7 @@ def wash_out(controller_name, options={})

Mime::Type.register "application/soap+xml", :soap
ActiveRecord::Base.send :extend, WashOut::Model if defined?(ActiveRecord)
WashOut::Param.send :include, WashoutBuilder::Param if defined?(WashoutBuilder::Param)

ActionController::Renderers.add :soap do |what, options|
_render_soap(what, options)
Expand Down
65 changes: 65 additions & 0 deletions lib/washout_builder/param.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
module WashoutBuilder
module Param

attr_accessor :source_class_name
attr_accessor :timestamp

def initialize(soap_config, name, type, class_name, multiplied = false)
type ||= {}
@soap_config = soap_config
@name = name.to_s
@raw_name = name.to_s
@map = {}
@multiplied = multiplied
@source_class_name = class_name

if soap_config.camelize_wsdl.to_s == 'lower'
@name = @name.camelize(:lower)
elsif soap_config.camelize_wsdl
@name = @name.camelize
end

if type.is_a?(Symbol)
@type = type.to_s
elsif type.is_a?(Class)
@type = 'struct'
@map = self.class.parse_def(soap_config, type.wash_out_param_map)
@source_class = type
else
@type = 'struct'
@map = self.class.parse_def(soap_config, type)
end
end

def self.parse_def(soap_config, definition)
raise RuntimeError, "[] should not be used in your params. Use nil if you want to mark empty set." if definition == []
return [] if definition == nil

definition_class_name = nil
if definition.is_a?(Class) && definition.ancestors.include?(WashOut::Type)
definition_class_name = definition.to_s.demodulize.classify
definition = definition.wash_out_param_map
end

if [Array, Symbol].include?(definition.class)
definition = { :value => definition }
end

if definition.is_a? Hash
definition.map do |name, opt|
if opt.is_a? WashOut::Param
opt
elsif opt.is_a? Array
WashOut::Param.new(soap_config, name, opt[0],definition_class_name, true)
else
WashOut::Param.new(soap_config, name, opt, definition_class_name)
end
end
else
raise RuntimeError, "Wrong definition: #{definition.inspect}"
end
end


end
end
36 changes: 36 additions & 0 deletions lib/washout_builder/soap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,43 @@ module WashoutBuilder
module SOAP
extend ActiveSupport::Concern
include WashOut::SOAP


module ClassMethods
attr_accessor :soap_actions

# Define a SOAP action +action+. The function has two required +options+:
# :args and :return. Each is a type +definition+ of format described in
# WashOut::Param#parse_def.
#
# An optional option :to can be passed to allow for names of SOAP actions
# which are not valid Ruby function names.
def soap_action(action, options={})
if action.is_a?(Symbol)
if soap_config.camelize_wsdl.to_s == 'lower'
options[:to] ||= action.to_s
action = action.to_s.camelize(:lower)
elsif soap_config.camelize_wsdl
options[:to] ||= action.to_s
action = action.to_s.camelize
end

end

default_response_tag = soap_config.camelize_wsdl ? 'Response' : '_response'
default_response_tag = "tns:#{action}#{default_response_tag}"

self.soap_actions[action] = {
:in => WashOut::Param.parse_def(soap_config, options[:args]),
:out => WashOut::Param.parse_def(soap_config, options[:return]),
:description => options[:description],
:raises => options[:raises],
:to => options[:to] || action,
:response_tag => options[:response_tag] || default_response_tag
}
end
end


included do
include WashOut::Configurable
Expand Down

0 comments on commit 7e76894

Please sign in to comment.