Я пытаюсь преобразовать запрос Curl в мое приложение Rails.Похоже, что используемый мной онлайн-конвертер глючит.
Текущее состояние:
require 'net/http'
require 'uri'
require 'json'
class Listing < ApplicationRecord
def getit2
uri = URI.parse("https://www.somedomain.com/api/public/v1.0/markers/list")
request = Net::HTTP::Post.new(uri)
request.content_type = "application/json"
request["Origin"] = "https://www.somedomain.com"
request["Accept-Language"] = "en-US,en;q=0.9,ar;q=0.8,bg;q=0.7,de;q=0.6,es;q=0.5,fr;q=0.4,he;q=0.3,hu;q=0.2,it;q=0.1,ms;q=0.1,nl;q=0.1,nb;q=0.1,ru;q=0.1,sk;q=0.1,sv;q=0.1,tr;q=0.1,vi;q=0.1,zh-CN;q=0.1,zh;q=0.1"
request["User-Agent"] = "Mozilla/5.0 (Linux; Android 4.0; Nexus 5 Build/MRA58N) AppleWebKit/535.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Mobile Safari/537.36"
request["Accept"] = "application/json"
request["Referer"] = "https://www.google.co.uk"
request["Cookie"] = "_pxhd=2f7043c8ae569c7ddddd12207ac90cca0ef2a40d61378c41112492:46c5aca1-7401-11e9-ab6d-251d1e721a9f; _gcl_au=1.1.2102026563.1557588441; Infinite_lastSearch_key=; Infinite_user_id_key=7ba2e36f-2a47-46bf-a275-04d5b2cbe965; Infinite_ab_tests_context_key={%22context%22:{%22price_estimation%22:%22false%22%2C%22display_sold%22:%22false%22%2C%22display_sold_v2%22:%22true%22%2C%22price_estimation_v2%22:%22true%22%2C%22price_estimation_v3%22:%22false%22}%2C%22values%22:{%22price_estimation%22:%22false%22%2C%22display_sold%22:%22false%22%2C%22display_sold_v2%22:%22true%22%2C%22price_estimation_v2%22:%22true%22%2C%22price_estimation_v3%22:%22false%22}}; _pxvid=46c5aca1-7401-11e9-ab6d-251d1e721a9f; _ga=GA1.3.1522435888.1557588443; _gid=GA1.3.1336624029.1560436285; AWSELB=CD9FE1B30E32EDF52EB77EE30BE426CF7F363C127FE2A9BC2F70F9F1CDD10FF86A1B4095995C86A57A485BDD3A564FE18D63589FAE6A0457DFADBDFF864B86DAA86999D390; _sp_id.549d=457ec9d1-91b0-4e92-a50a-1d6517ccb887.1560168270.6.1560586655.1560522000.895c4b58-2ee1-45ca-bf34-b0e4716eac0d; _ud=0f90bb52e08b81cc0d5493b6de1c53b81d7a25c4-cid=116ea8bc-6bbd-4661-b5a6-f65725ec0e6d&_ts=1560595069960; _dc_gtm_UA-26019961-1=1; _px3=d331cc7dc802bed39645428247a9f83be0c89dc82d9c549bad4bc2bfe2823676:XUO7Topo8ACRMvx9jjEXR5qW+CpujeC0thydfP6jHjpGr4G0iPU2Qm4m5IDAn/Pk8qsHxJKaowm58pMULV9MIw==:1000:dqOcC/gfWU9y/hUxvT6akY2ZBKdd+M5HDrxR9UaggnszreSjIkckWJVscq59PjoRCAiNJhfIEGaHC++sor4DUOc4iwZRQgthPouxNYgqkeKCqjPXwOrsSBppi1Yh3L3AF+2Kv/msYsE+F7ol8ALbGQQp3LkYOa4ta1RIZeLhHTQ="
request["Connection"] = "keep-alive"
request.body = JSON.dump({
"sortBy" => "auto",
"areaId" => "the area",
"isStreetAreaId" => false,
"filters" => "{"dealTypes":["FOR_SALE"],"addBulletinFromPrivate":true,"addBulletinFromAgent":true,"addProjects":true,"propertyTypes":[],"conditions":[]}",
"zoom" => 11.366136034830756,
"NELat" => 1,
"NELng" => 1,
"SWLat" => 1,
"SWLng" => 1,
"slim" => true
})
req_options = {
use_ssl: uri.scheme == "https",
}
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
http.request(request)
end
end
end
И консоль выдает эту ошибку:
/ app / models / list.rb: 38: синтаксическая ошибка, неожиданный tIDENTIFIER, ожидание '}' "filters" => "{" dealTypes ": [" FOR_SALE "]," addBulletinFr ... ^
Похоже, что он не работает в точке данных filters
.Как это должно быть структурировано для создания валидного запроса?