How to integrate constantcontact in ruby-on-rails

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

<div id="full_width">         <div class="cream_bkg">           <h1>Suggest A Business</h1>           <div class="full_width_content center_fix">             <h2>Do you have a favourite business that you would like to see on Home Shabang? Tell us and we will invite them!!</h2>             <h3><%= flash[:error] %></h3>             <!--form method="post" action=""-->             <%= form_for :coupon,:url=> {:controller=>'coupons',:action=>'comments'},:html=>{:id=> 'cc_coupon_form'} do |f| %>               <table class="form_table suggest_business" cellpadding="0" cellspacing="0">                 <tr>                   <th></th>                   <th></th>                 </tr>                 <tr>                   <td><label for ="email"> Email:</lable></td>                   <td>                     <span class="blue_field">                     <!--input id="email" class="text_field" type="text" name="" /-->                     <%= f.text_field :email, :id =>'email',:class=>'text_field' %></span>                     <span id= "email_address" class="error_msg" style="display:none;">Please enter the Email Address.</span>                   </td>                 </tr>                 <tr>                   <td><label for="company_name">Company Name:</label></td>                   <td>                     <span class="blue_field">                     <!--input id="company_name" class="text_field" type="text" name="" /-->                     <%= f.text_field :company_name,:id =>'company',:class=>'text_field' %></span>                     <span id="name" class="error_msg" style ="display:none;"> Please enter the company name.</span>                   </td>                 </tr>                 <tr>                   <td><label for="state">State:</label></td>                   <td>                     <span class="blue_field">                     <!--input id="state" class="text_field" type="text" name="" /-->                     <%= f.text_field :state, :id =>'state',:class=>'text_field' %></span>                     <span id= "business_state" class="error_msg" style="display:none;">Please enter the state.</span>                   </td>                 </tr>                 <tr>                   <td><label for="city">City:</label></td>                   <td><span class="blue_field">                   <%= f.text_field :city, :class=> 'text_field' %>                   <!--input id="city" class="text_field" type="text" name=""/></span--></td>                 </tr>                 <tr>                   <td><label for="comment">Comment:</label></td>                   <td><span class="blue_field">                   <!--textarea id="comment" class="text_area" rows="" cols="" name=""></textarea-->                       <%= f.text_area :comment,:class=> 'text_area' %>                       </span>                   </td>                 </tr>                 <tr>                   <td></td>                   <td><!--input class="submit_btn" type="button" value="Send" /-->                       <%= f.submit "Send", :class=> "submit_btn", :id=>'send',                       :type=> 'button' %>                   </td>                 </tr>               </table>             <% end %>           </div>         </div>       </div>

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/#\{&#39;chandrareddy&#39;\}/contacts&quot;\)       response = Net::HTTP.post_form(URI.parse("https://api.constantcontact.com/ws/customers/#\{&#39;chandrareddy&#39;\}/contacts&quot;\), 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 <entry xmlns="http://www.w3.org/2005/Atom&quot;&gt;&lt;title type="text"></title><updated>#{Time.now.strftime("%Y-%m-%dT%H:%M:%S.000Z")}</updated><author></author><id>data:,none</id><summary type="text">Contact</summary><content type="application/vnd.ctct+xml"><Contact xmlns="http://ws.constantcontact.com/ns/1.0/&quot;&gt; 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(<ContactList id="http://api.constantcontact.com/ws/customers/#\{&#39;chandrareddy&#39;\}/lists/1&quot; />)           #end           xml << %Q(</ContactLists>)         else           xml << %Q(<#{node}>#{val}</#{node}>)         end       end

      xml += <<EOF <OptInSource>#{opt_in}</OptInSource></Contact></content></entry> 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

Try this...

http://rubygems.org/gems/constant_contact