Guest User

Untitled

a guest
May 23rd, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. #Create client
  2. client=PostalMethods::Client.new({:api_key=>"1sekret58"})
  3. client.prepare!
  4.  
  5. @contact_postalcard = ContactPostalcard.new(params[:contact_postalcard])
  6.  
  7. @postalcard = Postalcard.find(@contact_postalcard.postalcard_id)
  8.  
  9. uploadtrue = 1
  10.  
  11. if uploadtrue
  12. #upload the file
  13. sample_data = open("#{@postalcard.postalimage.path}", "rb") {|io| io.read }
  14. puts " THE PATH IS #{@postalcard.postalimage.path}"
  15. upload_details = {
  16. :APIKey => "1esekret58" ,
  17. :MyFileName => "#{@postalcard.postalimage_file_name}",
  18. :FileBinaryData => sample_data,
  19. :Permissions => "Account",
  20. :Description => "Contact: #{@contact_postalcard.contact_id} and Postcard: #{@postalcard.title}",
  21. :Overwrite => true
  22. }
  23.  
  24. @response = client.upload_file(upload_details)
  25. puts @response
  26. end
  27. # end upload file
  28.  
  29. #send existing file
  30. filename="MyFile:" + @postalcard.postalimage_file_name
  31.  
  32. address = {:AttentionLine1 => "The President",
  33. :Address1 => "1808 Octavia St. #1",
  34. :City => "San Francisco",
  35. :State => "CA",
  36. :PostalCode => "94109",
  37. :Country => "USA" }
  38.  
  39. addr_template = open("C:/Users/Timothy/Documents/project/public/system/template.html", "r") {|io| io.read }
  40.  
  41. addr_template = addr_template.gsub(/ReplaceThisWithPostalcardMessage/, @contact_postalcard.message)
  42.  
  43. opts = {
  44. :MyDescription => "Sending #{Time.now}, Message: #{@contact_postalcard.message}",
  45. :ImageSideFileType => filename,
  46. :AddressSideFileType => "HTML",
  47. :AddressSideBinaryData => addr_template
  48. }
  49.  
  50. opts.merge! address
  51.  
  52. @response = client.send_postcard_and_address_advanced(opts)
Add Comment
Please, Sign In to add comment