Hi, All
Please help me how to integrate constantcontact in ruby-on-rails
I have implemented but it is showing me 400 error in development log
Here is my code
Suggest A Business
Do you have a favourite business that you would like to see on Home Shabang? Tell us and we will invite them!!
<%= flash[:error] %>
<%= form_for :coupon,:url=> {:controller=>'coupons',:action=>'comments'},:html=>{:id=> 'cc_coupon_form'} do |f| %>Email: | <%= f.text_field :email, :id =>'email',:class=>'text_field' %> Please enter the Email Address. |
Company Name: | <%= f.text_field :company_name,:id =>'company',:class=>'text_field' %> Please enter the company name. |
State: | <%= f.text_field :state, :id =>'state',:class=>'text_field' %> Please enter the state. |
City: | <%= f.text_field :city, :class=> 'text_field' %> |
Comment: | <%= f.text_area :comment,:class=> 'text_area' %> |
<%= f.submit "Send", :class=> "submit_btn", :id=>'send', :type=> 'button' %> |
Here is my method in my controller
def comments
unless params[:coupon].blank?
unless params[:coupon][:email].blank?
unless params[:coupon][:company_name].blank?
create_contact_on_constant_contact(params[:coupon])
else
flash[:error] = “Comapny Name is a mandatory field”
redirect_to static_suggest_business_path
end
else
flash[:error] = “Email is a mandatory field”
redirect_to static_suggest_business_path
end
else
flash[:error] = “Email is a mandatory field”
redirect_to static_suggest_business_path
end
end
def create_contact_on_constant_contact(coupon)
logger.debug “\n\n Coupon: #{coupon.inspect}\n\n”
unless coupon.blank?
#require ‘httparty’
require ‘net/http’
require ‘uri’
xml_string_response = xml_string(coupon)
logger.debug “\n\n XML string: #{xml_string_response.inspect}\n\n”
options = {
:headers => {
“Content-Type” => “application/atom+xml”,
“HTTP_AUTHORIZATION” =>
Base64.encode64(“#{‘chandrareddy’ + ‘%’ +
‘f6040a9e45484dbaabeab8f0e1da6726’ + ‘:’ +
‘605a8e068b654ca098a32a81f8cb2ef2’ }”)
},
:body => xml_string_response,
}
#url =
URI.parse(“https://api.constantcontact.com/ws/customers/#{‘chandrareddy’}/contacts”)
response =
Net::HTTP.post_form(URI.parse(“https://api.constantcontact.com/ws/customers/#{‘chandrareddy’}/contacts”),
options)
logger.debug “\n\n Response1: #{response.inspect}\n\n”
logger.debug “\n\n Response2: #{response.body.inspect}\n\n”
end
end
def xml_string( coupon )
opt_in=‘ACTION_BY_CUSTOMER’
data = {:email_address => “#{coupon[:email]}”, :company_name =>
“#{coupon[:company_name]}”, :contact_lists => ‘’}
xml = <<EOF
#{Time.now.strftime(“%Y-%m-%dT%H:%M:%S.000Z”)}data:,none
EOF
data.each do |key, val|
node = camelize(key.to_s)
if key == :contact_lists
xml << %Q(<ContactLists>)
#val.each do |list_id|
# xml<< %Q( <ContactList id="#{ContactList.url_for(
list_id )}" />\n)
xml << %Q()
#end
xml << %Q()
else
xml << %Q(<#{node}>#{val}</#{node}>)
end
end
xml += <<EOF
#{opt_in}
EOF
xml
end
def camelize( string )
string.split( /[^a-z0-9]/i ).map{ |w| w.capitalize }.join
end
I think the xml is totally wrong code, Please can any one help me how to
code right xml formate