Last active
December 23, 2015 14:51
-
-
Save smcabrera/a34d5443778bc56ec0a3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class QuoteExporter | |
| include MailerStyleHelper | |
| include LeadMailerHelper | |
| BASE = 'https://www.filepicker.io/api/store/S3' | |
| APIKEY = ENV["FILEPICKER_API_KEY"] | |
| def initialize(lead_id, current_user, message) | |
| lead = Lead.find(lead_id) | |
| @lead = LeadPresenter.new(lead, current_user) | |
| @current_user = current_user | |
| @source = SourcePresenter.new(lead.source_property_group, lead.source, lead.property.name) | |
| @group_name = @lead.booking_request_name.gsub(/&/, "&") | |
| @message = message | |
| end | |
| attr_reader :lead, :current_user, :source, :group_name | |
| def export | |
| # It should take a lead and current user and turn them into the url that will be passed to the white label | |
| # TODO: This is all very procedural so if we can, | |
| # let's try to break these into steps and move down into private methods in refactoring | |
| html_string(@message) | |
| create_static_html_file(html_string) | |
| create_quote_url(@lead.id) | |
| end | |
| def html_string(message) | |
| html = File.read('app/views/lead_mailer/quote.html.erb') | |
| ERB.new(html).result(binding) | |
| end | |
| def create_static_html_file(html_string) | |
| file_path = "tmp/static-html/quote-#{@lead.id}.html" | |
| open(file_path, 'w') do |file| | |
| file.puts html_string | |
| end | |
| file_path | |
| end | |
| def create_quote_url(id) | |
| filename = "tmp/static-html/quote-#{id}.html" | |
| cmd = %[curl -F fileUpload=@#{filename} "#{BASE}?key=#{APIKEY}&filename=#{filename}"] | |
| filepicker_response = %x[ #{cmd} ] | |
| if filepicker_response == "Invalid Application" | |
| quote_url "There was a problem with the API Key" | |
| elsif filepicker_response == "" | |
| quote_url "There was a problem making the request with the command: #{cmd}" | |
| else | |
| quote_url = filepicker_response.split(',')[1].split(" ")[1].gsub('"', "") | |
| end | |
| quote_url | |
| end | |
| def render(foo, bar) | |
| # TODO: Need to fix this, I realized that it's the partials that were calling | |
| # render. So I imagine none of the partials will be showing up... | |
| "foo" | |
| end | |
| end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment