app/controllers/medivo/labs_controller.rb in medivo-0.2.7 vs app/controllers/medivo/labs_controller.rb in medivo-0.2.8
- old
+ new
@@ -1,21 +1,35 @@
module Medivo
class LabsController < ActionController::Base
- def lab_data
+ def index
lab_data = Medivo::Lab.data_for_zip(params[:zip_code])
render :json=> lab_data
end
- def appointment_data
+ def find_appointment
data = Medivo::Appointment.find(params[:lab_code], params[:date], params[:am_pm])
render :json=> data
- rescue RestClient::RequestTimeout, RestClient::InternalServerError => te
- render :status=> te.http_code, :json=> {:message=>"Could be lab_code is wrong, or labcorp server is down"}
- rescue RestClient::Exception => br
- render :status=> br.http_code, :json=> {:message=>br.response}
+ rescue => e
+ appointment_error_handler(e)
+ end
+
+ def make_appointment
+ data = Medivo::Appointment.make(params[:lab_code], params[:time_id], params[:user])
+ render :json=> data
rescue Exception => e
- render :status=> 500, :json=> {:message=>e.message}
+ appointment_error_handler(e)
+ end
+
+ def appointment_error_handler(e)
+ case e
+ when RestClient::RequestTimeout, RestClient::InternalServerError
+ render :status=> e.http_code, json: {message: "Could be lab_code is wrong, or labcorp server is down"}
+ when RestClient::Exception
+ render :status=> e.http_code, json: {message: e.response}
+ else
+ render :status=> 500, json: {message: e.message}
+ end
end
end
end