Skip to content

Instantly share code, notes, and snippets.

@nil96
Created December 10, 2021 14:55
Show Gist options
  • Save nil96/6e93979f105a9706c05fcd2baf54ac5e to your computer and use it in GitHub Desktop.
Save nil96/6e93979f105a9706c05fcd2baf54ac5e to your computer and use it in GitHub Desktop.
require "uri"
require "json"
require "net/http"
url = URI("https://staging-runner.cargoes.com/services/Default/ChargeTypes/Create")
# select concat(ChargeCode,'$',Description,'$',DefaultCost,'$',DefaultSell,'$',SellType,'$',Taxable,'$',DefaultVat,'$',TaxWithRespectToCommodity,'$',Details,'$',ChargeCodeAlt,'$',FusionIntCode,'$') FROM ChargeTypes ct where TenantId = 143 and ChargeCode in('BLRC','CLCH','CWCH','DDOC','DECH','DEDCH','DEMCH','DRCH','DTCH','DTCLCH','DTHCC','DTVAT','DUCH','ENS','FAF','FCLC','HDCH','INCD','LACH','LBCH','LCLC','MECH','MUC','OOCH','OTCH','PTCH','PUCH','SCH','SECH','SRCH','SSRC','STCH','SVCH','TCH','THC','TPCH','VDCH','VGM','WECH','WHCH');
File.foreach('missing_charge_type.csv').with_index do |line, line_num|
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
arr = line.split('$');
# puts arr[0]
# next
# Taxable = false
if(arr[5]==nil || arr[5]=="" || arr[5]=="0" || arr[5]==0)
arr[5] = false
else
arr[5] = true
end
request = Net::HTTP::Post.new(url)
request["authority"] = "staging-runner.cargoes.com"
request["sec-ch-ua"] = "\" Not A;Brand\";v=\"99\", \"Chromium\";v=\"96\", \"Google Chrome\";v=\"96\""
request["accept"] = "application/json, text/javascript, */*; q=0.01"
request["content-type"] = "application/json"
request["x-requested-with"] = "XMLHttpRequest"
request["sec-ch-ua-mobile"] = "?0"
request["user-agent"] = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Safari/537.36"
request["sec-ch-ua-platform"] = "\"macOS\""
request["origin"] = "https://staging-runner.cargoes.com"
request["sec-fetch-site"] = "same-origin"
request["sec-fetch-mode"] = "cors"
request["sec-fetch-dest"] = "empty"
request["referer"] = "https://staging-runner.cargoes.com/Default/ChargeTypes"
request["accept-language"] = "en-GB,en-US;q=0.9,en;q=0.8"
request["cookie"] ="_gcl_au=1.1.1266271950.1632407035; _ga=GA1.2.690476173.1632407039; gaconnector_GA_Client_ID=690476173.1632407039; _hjid=278a1159-0499-4c3f-a2f2-3fda1fbef722; _hjSessionUser_2326152=eyJpZCI6ImFlZTY1NGY1LWRlMTgtNTUxNS1iN2Q3LWE3Yzc5NzM5OTVkMyIsImNyZWF0ZWQiOjE2MzgxODUwNTI3NTcsImV4aXN0aW5nIjp0cnVlfQ==; gaconnector_gclid=; gaconnector_fc_source=(direct); gaconnector_lc_source=(direct); gaconnector_fc_medium=(none); gaconnector_lc_medium=(none); gaconnector_fc_campaign=(direct); gaconnector_lc_campaign=(direct); gaconnector_fc_term=(not set); gaconnector_lc_term=(not set); gaconnector_fc_content=(not set); gaconnector_lc_content=(not set); gaconnector_fc_landing=https://demo.cargoes.com/; gaconnector_lc_landing=https://demo.cargoes.com/; gaconnector_fc_referrer=(not set); gaconnector_lc_referrer=(not set); gaconnector_fc_channel=Direct; gaconnector_lc_channel=Direct; gaconnector_ip_address=-; gaconnector_OS=Mac OS 10.15.7; gaconnector_device=desktop; gaconnector_browser=Chrome 96.0.4664.55; gaconnector_city=Kolkata; gaconnector_country=India; gaconnector_country_code=IN; gaconnector_region=West Bengal; gaconnector_time_zone=Asia/Kolkata; gaconnector_latitude=22.518; gaconnector_longitude=88.3832; gaconnector_all_traffic_sources=(direct)/(none), (direct)/(none); gaconnector_pages_visited_list=/runner|/|/login|/logistics; gaconnector_page_visits=4; gaconnector_time_passed=120414263; .AspNetCore.Antiforgery.pUOXNTmQ6pM=CfDJ8MRqjtC4arRBhYRw_XNteLBEgFhzECwboSYLVIAEkHEzuydNYckgsvvQ1bHQoN6CudWJ8M4HAuiKI8Og4eCfhzw_J9B8X1OGRw9wcW9LYNHoF0g3zTSzd-6zyd8JZxMO4buDWqmT1CBAO3cJCqp-d7Q; sessionId=CfDJ8MRqjtC4arRBhYRw_XNteLBpG6fCXJ-eY4qxg3F3CAvIRhTXyjaGR_LTklBGutVV_hCCyp6Tfg2v88EpWiWkb9RlmAQozuixIzrPucGi__5-SWoxibmbWWS7gRe7IaFVf6iPgKBQbtkQk_GQMixBxKTVj4ABrQsIXvY9iS3McDq42IaGVs4BdgwTUjPq7zsvok7PM1umzeQy3PjsxVVjRgGbWD9FPXaOQ8QDLcIJJnCtfaMEU0e_yhBuUd4NmGux-1rpZZ8Yu922XY-D2I6kO7luxApW5Ck-g9YHTm6VMyJ2tfx_GgoJMI0uXuUSfL9YS6RpdwQqfmGtHxPpinEVFrw; .AspNetAuth=CfDJ8MRqjtC4arRBhYRw_XNteLA7Y7khIDiccehA7pZG_FYS62kjoGuI-SohQIJPyrzZLDnw2Gqq4aXrmGTTgO3ocxcF7H0H2uucY1DrVSelSwTV2pjjmFEyJ4nMNLxrV9-Dty1Lx9BAlovsfS4iEZbofDoMOnP_9R8qp9AtjDJGvFdxdTZPKxumtwvpxNq0ZpOtWTLQ8OEQ3En-bUSrx_lz6gSXeOa-TjCuW1bTo2msut8h2w4_kN-127vqGsKvWW2s28C-kgvPzf-jF_ysEbZJJPbiSkcmycwPOZFdV_roioOwBpwis81-2SOylOBuebjiVvJTdb9fhl1SOKWNnc8Icmg"
request.body = JSON.dump({
# (ChargeCode,'$',Description,'$',DefaultCost,'$',DefaultSell,'$',SellType,'$',DefaultVat)
"Entity": {
"ChargeCode": arr[0],
"Description": arr[1],
"DefaultCost": arr[2]=="" ? nil : arr[2].to_f,
"DefaultSell": arr[3]=="" ? nil : arr[3].to_f,
"SellType": arr[4],
"Taxable": arr[5],
"DefaultVat": arr[6]=="" ? nil : arr[6].to_f,
"TaxWithRespectToCommodity": arr[7],
"Details": arr[8],
"ChargeCodeAlt": arr[9],
"FusionIntCode": arr[10]
}
})
# return
puts request.body
# return
response = https.request(request)
puts response.read_body
# return
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment