Sha256: 6d041e32744ce16480480e35cad7e9f838e40c115cf461dca76fd6449dd461aa
Contents?: true
Size: 1.57 KB
Versions: 3
Compression:
Stored size: 1.57 KB
Contents
module Savon module Hooks # = Savon::Hooks::Hook # # A hook used somewhere in the system. class Hook HOOKS = [ # :soap_request # # Around filter wrapping the POST request executed to call a SOAP service. # See: Savon::SOAP::Request#response # # Arguments # # [callback] A block to execute the SOAP request # [request] The current <tt>Savon::SOAP::Request</tt> # # Examples # # Log the time before and after the SOAP call: # # Savon.config.hooks.define(:my_hook, :soap_request) do |callback, request| # Timer.log(:start, Time.now) # response = callback.call # Timer.log(:end, Time.now) # response # end # # Replace the SOAP call and return a custom response: # # Savon.config.hooks.define(:mock_hook, :soap_request) do |_, request| # HTTPI::Response.new(200, {}, "") # end :soap_request ] # Expects an +id+, the name of the +hook+ to use and a +block+ to be called. def initialize(id, hook, &block) unless HOOKS.include?(hook) raise ArgumentError, "No such hook: #{hook}. Expected one of: #{HOOKS.join(', ')}" end self.id = id self.hook = hook self.block = block end attr_accessor :id, :hook, :block # Calls the +block+ with the given +args+. def call(*args) block.call(*args) end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
savon-1.2.0 | lib/savon/hooks/hook.rb |
savon-1.1.0 | lib/savon/hooks/hook.rb |
savon-1.0.0 | lib/savon/hooks/hook.rb |