We all started somewhere! Share your experience on the Get Advice: Let's Get Started Sweepstakes thread and be entered to win a $100 credit on your Constant Contact account.

here is my code i.e is xml form

MohanR5
Occasional Participant

here is my code i.e is xml form

hey  Dave Berard, how are you

 

this mohan form india

 

here is my code in ruby-on-rails

 

form 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 the 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("#{'username' + '%' + ' ' + ':' + ' ' }")
},
: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

 

here is the xml code


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"><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/">
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/#{'chandrareddy'}/lists/1" />)
#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

 

hey, Dave Berard please help me I think totally xml formate is wrong  

 

 

1 REPLY 1
Ryan_D
Employee

Hey,

 

I removed your crednetials for security reasons.  I am going to try to rebuild your code on my server and see if I can get it to work for you,

Ryan Davis
Quality Engineer
Developer Portal

View API documentation, code samples, get your API key.

Visit Page