require 'soap/header/simplehandler' class CustomHeader < SOAP::Header::SimpleHandler NAMESPACE = 'http://tempuri.org' # def initialize(shipment_request) # @shipment_request = shipment_request # super(XSD::QName.new(NAMESPACE, 'ShipmentRequest')) # end # # def on_simple_outbound # to_hash(@shipment_request) # # {"Username" => @username, "Password" => @password, "AccessKey"=>@accessKey} # end protected # Transform a object into a hash of its instance variables def to_hash(object) return {} unless object result = {} object.instance_variables.each do |var| value = object.instance_variable_get(var) var.gsub!('@','') var = capitalize_first_letter(var) result[var] = value #TODO: NESTING: some things like Address will need to result[var] = to_hash(object.instance_variable_get(var)) end result end def capitalize_first_letter(string) return nil unless string.is_a?(String) string[0].chr.capitalize + string[1, string.size] end end