Rails Savon gem 大小写键

Rails Savon gem keys in upper and lower case

我正在使用 Savon gem 访问 SOAP API。问题是,API 需要大写的键和小写的其他键,所以我不能使用选项 convert_request_keys_to 参数。

这是 API 我需要遵守的格式:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xs="XmlServices">
   <soapenv:Header/>
   <soapenv:Body>
     <xs:GetRooms>
         <xs:request>
             <xs:Credentials> 
                 <xs:Credential1>"example1"</xs:Credential1>
                 <xs:Credential2>"example2"</xs:Credential2>
                 <xs:Credential3>"example3"</xs:Credential3>
         </xs:Credentials>
     </xs:request>
 </xs:GetRooms>

如你所见request是小写,其余的都是大写

我就是这样使用 gem:

def call(method, attributes = nil)
  attributes = { 'request': { 'Credentials': attributes } }
  response = client.call(method, message: attributes)
  #do something with response
end

我说的对吗?我有什么选择吗?我需要 fork 存储库并自己修改 gem 吗?

好吧,其实这很简单:

只需要使用选项convert_request_keys_to :none