sync data record

This commit is contained in:
Zoey
2019-06-12 18:03:31 +06:30
parent ddc65d7b35
commit e1bb948a3d
11 changed files with 178 additions and 48 deletions

View File

@@ -69,5 +69,48 @@ authorize_resource :class => false
format.json { render json: out }
end
end
def sync_data
@orders, @order_items = Booking.get_sync_data(params[:sale_id])
# Here comes to call the sync api
url = "http://192.168.1.187:3000/api/sync_records"
begin
@result = HTTParty.post(url.to_str,
:body => { :orders => @orders,
:order_items => @order_items
}.to_json,
:headers => {
'Content-Type' => 'application/json',
'Authorization' => 'bearer 88fa8a47ba8b52a43cbc'
}, :timeout => 10,
:verify_ssl => OpenSSL::SSL::VERIFY_NONE,
:verify => false )
rescue HTTParty::Error
response = { status: false, message: "Can't open membership server "}
rescue Net::OpenTimeout
response = { status: false, message: "Can't open membership server "}
rescue OpenURI::HTTPError
puts "Fire in here"
response = { status: false, message: "Can't open membership server "}
rescue SocketError
response = { status: false, message: "Can't open server "}
rescue Errno::EHOSTDOWN
response = { status: false, message: "Can't open server "}
rescue Errno::ECONNREFUSED, Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError
response = { status: false, message: "Can't open membership server"}
end
puts url
puts response
puts '########################'
puts @result
respond_to do |format|
format.html { redirect_to '/en/reports/receipt_no/', notice: 'Sync Record Completed.'}
end
end
end