Sha256: f1149233ad7525f099d12b74d176858ff85969f559ae2c06ddf1688765865c26

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
g4s_client-0.1.6 lib/g4s/headers/custom_header.rb