使用HTTParty正确格式化的正文有效负载

时间:2018-07-29 12:13:13

标签: ruby-on-rails json httparty

通过跑步

orderByChild()  Order results by the value of a specified child key or nested child path.
orderByKey()    Order results by child keys.
orderByValue()  Order results by child values.

通过查询@city_numbers = [20142] @check_in = (Date.today + 25.days).strftime("%Y-%m-%d") @start = %Q|{ "requestAuditInfo": { "agentCode": "10019", "requestPassword": "passsss", "requestDateTime":\"#{Time.now.utc.iso8601}\", "requestID": 1 }, "hotelSearchCriteria": { "destination": { "cityNumbers": #{@city_numbers} }, "stayPeriod": { "checkinDate": \"#{@check_in}\", "numberOfNights": 1 }, "rooms": [ {"roomNo": 1, "guests":[{"type": "ADT"},{"type": "ADT"}]} ], "languageCode": "en", "currencyCode": "EUR", "paxNationality": "IT", "resultDetails" : { "returnDailyPrices" : true, "returnHotelInfo":1, "returnSpecialOfferDetails":1} }, "versionNumber": "1.0"}| 来获得所需的字符串作为HTTParty事务主体的有效负载:

JSON.parse(@start)

但是,我无法获得正确的语法来获取HTTParty以便在主体中发出可接受的字符串(我还没有找到调试工具来了解发送的内容)到API服务器。该呼叫已通过CLI和{"requestAuditInfo"=>{"agentCode"=>"10019", "requestPassword"=>"passsss", "requestDateTime"=>"2018-07-29T12:01:47Z", "requestID"=>1}, "hotelSearchCriteria"=>{"destination"=>{"cityNumbers"=>[20142]}, "stayPeriod"=>{"checkinDate"=>"2018-08-23", "numberOfNights"=>1}, "rooms"=>[{"roomNo"=>1, "guests"=>[{"type"=>"ADT"}, {"type"=>"ADT"}]}], "languageCode"=>"en", "currencyCode"=>"EUR", "paxNationality"=>"IT", "resultDetails"=>{"returnDailyPrices"=>true, "returnHotelInfo"=>1, "returnSpecialOfferDetails"=>1}}, "versionNumber"=>"1.0"} 进行了静态数据测试。

HTTParty.post

注意:标头块可能看起来很古怪(没有火箭),但这已通过严格的旧语法和新语法进行了测试...都可以工作

应如何编写(或建议使用更好的替代方法,例如JSON文件)?

0 个答案:

没有答案