class String def strip_space gsub(/\s|\n|\r/, '') end end module Medivo::Spec def pdf_to_text(file) pdf = PDF::Toolkit.open(file) pdf.to_text.read.force_encoding('ascii-8bit') end def pdf_stream_to_text(bytes) pdf = Tempfile.new('pdf', :encoding => 'ascii-8bit') pdf.write bytes pdf.close text = pdf_to_text pdf pdf.unlink text end ## # For seeing the pdf yourself. writes to file so you can open it. # All the pdf's are created with tempfiles so you have to write to # a real file to see it. def show_me_the_pdf(pdf_file, file_name) # tmp files usually are kept closed, so reopen again to read it pdf_file.open open(file_name, 'wb+') { |f| f.write pdf_file.read } end def show_me_the_pdf_stream(bytes, file_name) open(file_name, 'wb+') { |f| f.write bytes } end FIXTURE_PATH = File.expand_path('../../fixtures', __FILE__) unless defined? FIXTURE_PATH def medivo_fixture_path(file_name) "#{FIXTURE_PATH}/#{file_name}" end def medivo_pdf_fixture_path(file_name) "#{FIXTURE_PATH}/pdfs/#{file_name}" end def medivo_img_fixture_path(file_name) "#{FIXTURE_PATH}/images/#{file_name}" end def medivo_xml_fixture_path(file_name) "#{FIXTURE_PATH}/xml/#{file_name}" end ## # requisition_id Number id of the Medivo::Order you are stubbing # file_path String points to the path to xml file with order info which contains # requisition that includes requisition pdf def stub_order(requisition_id, file_path) stub_request(:get, "test:test@test.medivo.com/customers/#{requisition_id}.xml"). to_return(:body => File.read(file_path)) end ## # requisition_id Number id of the Medivo::Order you are stubbing # file_path String points to the path to xml file with order info which contains # requisition that includes requisition pdf def stub_order_requisition(requisition_id, file_path) stub_request(:get, "test:test@test.medivo.com/customers/#{requisition_id}.xml?include=requisition"). to_return(:body => File.read(file_path)) end ## # requisition_id Number id of the Medivo::Order you are stubbing # file_path String points to the path to xml file with order info which contains # result info that includes result pdf def stub_order_result(requisition_id, file_path) stub_request(:get, "test:test@test.medivo.com/customers/#{requisition_id}.xml?include=reconciled_results"). to_return(:body => File.read(file_path)) end def stub_appointment_request(lab_code, date, am_pm, body, status= 200) body = body.is_a?(String) ? body : body.to_json stub_request(:get, "http://test.medivo.com/?labcorp_id=#{lab_code}&appointment_date=#{date}"). to_return(:body => body, :status=>status) end def stub_appointment_confirmation(lab_code, time, user, return_body, status= 200) return_body = return_body.is_a?(String) ? return_body : return_body.to_json time_id = time.strftime(Medivo::Appointment::LABCORP_FORMAT) stub_request(:post, "http://test.medivo.com"). with( body: { labcorp_id: lab_code, time_id: time_id, user: user } ). to_return(:body => return_body, :status=>status) end def stub_appointment_cancelation(confirmation, user, return_body, status= 200) return_body = return_body.is_a?(String) ? return_body : return_body.to_json stub_request(:delete, "http://test.medivo.com"). with( body: { confirmation: confirmation, user: user } ). to_return(:body => return_body, :status=>status) end end