如何使用Savon向头标记添加属性?

时间:2011-07-07 04:15:00

标签: ruby soap savon

我的SOAP文档中的标题需要具有如下属性:

<soap:Header>
<eWAYHeader xmlns="https://www.eway.com.au/gateway/managedpayment">
  <eWAYCustomerID>string</eWAYCustomerID>
  <Username>string</Username>
  <Password>string</Password>
</eWAYHeader>

eWAYHeader需要xmlns属性。

我试过

    def create_customer(customer, card)
    response = @client.request(:create_customer, "xmlns" => "https://www.eway.com.au/gateway/managedpayment") do
      soap.header = header
      soap.body = create_customer_body(customer, card)
    end
  end

  private

  def header
    {
      "eWAYHeader" => {
        :attributes! => { :xmlns => 'http://www.eway.com.au/gateway/managedpayment' },
        "eWayCustomerID" => '87654321',
        "Username" => 'test@eway.com.au',
        "Password"=> 'test123'
      }
    }
  end

但属性!输入被忽略。

soap.header只接受Hash作为参数,所以我不能只使用字符串设置它的值。

我如何在Savon中实现这一目标?

感谢,

马丁

1 个答案:

答案 0 :(得分:5)

你可以通过这样做来实现

soap.header = {
  "eWAYHeader" => {
    "eWayCustomerID" => '87654321',
    "Username" => 'test@eway.com.au',
    "Password"=> 'test123'
  },
  :attributes! => {"eWAYHeader" => { :xmlns => 'http://www.eway.com.au/gateway/managedpayment' } }, }