Skip to content

Instantly share code, notes, and snippets.

@timfong888
Created July 23, 2010 12:59
Show Gist options
  • Save timfong888/487403 to your computer and use it in GitHub Desktop.
Save timfong888/487403 to your computer and use it in GitHub Desktop.
#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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment