Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Create client
- client=PostalMethods::Client.new({:api_key=>"1sekret58"})
- client.prepare!
- @contact_postalcard = ContactPostalcard.new(params[:contact_postalcard])
- @postalcard = Postalcard.find(@contact_postalcard.postalcard_id)
- uploadtrue = 1
- if uploadtrue
- #upload the file
- sample_data = open("#{@postalcard.postalimage.path}", "rb") {|io| io.read }
- puts " THE PATH IS #{@postalcard.postalimage.path}"
- upload_details = {
- :APIKey => "1esekret58" ,
- :MyFileName => "#{@postalcard.postalimage_file_name}",
- :FileBinaryData => sample_data,
- :Permissions => "Account",
- :Description => "Contact: #{@contact_postalcard.contact_id} and Postcard: #{@postalcard.title}",
- :Overwrite => true
- }
- @response = client.upload_file(upload_details)
- puts @response
- end
- # end upload file
- #send existing file
- filename="MyFile:" + @postalcard.postalimage_file_name
- address = {:AttentionLine1 => "The President",
- :Address1 => "1808 Octavia St. #1",
- :City => "San Francisco",
- :State => "CA",
- :PostalCode => "94109",
- :Country => "USA" }
- addr_template = open("C:/Users/Timothy/Documents/project/public/system/template.html", "r") {|io| io.read }
- addr_template = addr_template.gsub(/ReplaceThisWithPostalcardMessage/, @contact_postalcard.message)
- opts = {
- :MyDescription => "Sending #{Time.now}, Message: #{@contact_postalcard.message}",
- :ImageSideFileType => filename,
- :AddressSideFileType => "HTML",
- :AddressSideBinaryData => addr_template
- }
- opts.merge! address
- @response = client.send_postcard_and_address_advanced(opts)
Add Comment
Please, Sign In to add comment