Skip to content
Browse files

fleshed out more wrapper classes

  • Loading branch information...
1 parent 3588790 commit db45da319d630b56c4f21466e54a40ed0949aa05 @timcase timcase committed
View
3 init.rb
@@ -1,6 +1,3 @@
require 'constant_contact'
-ConstantContact::Base.api_key = ENV['CONSTANT_CONTACT_API_KEY']
-ConstantContact::Base.user = ENV['CONSTANT_CONTACT_USER']
-ConstantContact::Base.password = ENV['CONSTANT_CONTACT_PASSWORD']
View
8 lib/constant_contact/activity.rb
@@ -2,13 +2,18 @@
module ConstantContact
class Activity < Base
self.format = ActiveResource::Formats::HtmlEncodedFormat
- attr_accessor :contacts, :lists
+ attr_accessor :contacts, :lists, :activity_type
+
def encode
post_data = "activityType=#{self.activity_type}"
post_data += self.encoded_data
post_data += self.encoded_lists
return post_data
end
+
+ def activity_type
+ @activity_type ||= "SV_ADD"
+ end
protected
def encoded_data
@@ -22,6 +27,7 @@ def encoded_data
return result
end
+
def encoded_lists
result = ""
self.lists.each do |list|
View
2 lib/constant_contact/contact.rb
@@ -1,7 +1,7 @@
module ConstantContact
class Contact < Base
attr_accessor :opt_in_source
-
+
def to_xml
xml = Builder::XmlMarkup.new
xml.tag!("Contact", :xmlns => "http://ws.constantcontact.com/ns/1.0/") do
View
9 lib/constant_contact/formats/html_encoded_format.rb
@@ -3,8 +3,15 @@ module Formats
module HtmlEncodedFormat
extend self
def mime_type
- "application/atom+xml"
+ "application/x-www-form-urlencoded"
end
+
+
+ def decode(xml)
+ {}
+ end
+
+
end
end
end
View
5 lib/constant_contact/list.rb
@@ -1,4 +1,9 @@
module ConstantContact
class List < Base
+
+ def self.find_by_name(name)
+ lists = self.find :all
+ lists.find{|list| list.Name == name}
+ end
end
end
View
7 test/constant_contact/activity_test.rb
@@ -12,9 +12,9 @@ class Activity < Test::Unit::TestCase
end
@activity = ConstantContact::Activity.new(:activity_type => "SV_ADD")
@activity.contacts = @contacts
- list = ConstantContact::List.new
- list.stubs(:id).returns('http://api.constantcontact.com/ws/customers/joesflowers/lists/2')
- @activity.lists = [list]
+ @list = ConstantContact::List.new
+ @list.stubs(:id).returns('http://api.constantcontact.com/ws/customers/joesflowers/lists/2')
+ @activity.lists = [@list]
end
should 'include activity type' do
@@ -29,6 +29,7 @@ class Activity < Test::Unit::TestCase
should 'include lists' do
assert_match(/Test2\&lists\=http\%3A\%2F\%2Fapi\.constantcontact\.com\%2Fws\%2Fcustomers\%2Fjoesflowers\%2Flists\%2F2/, @activity.encode)
end
+
end
context 'format' do
View
75 test/constant_contact/list_test.rb
@@ -2,70 +2,17 @@
class ListTest < Test::Unit::TestCase
- context 'members' do
+ context "find by name" do
+ setup do
+ ConstantContact::Base.user = "joesflowers"
+ ConstantContact::Base.password = "password"
+ ConstantContact::Base.api_key = "api_key"
+ stub_get('https://api_key%25joesflowers:password@api.constantcontact.com/ws/customers/joesflowers/lists', 'contactlistscollection.xml')
+
+ end
+ should 'find list for given name' do
+ assert_equal 'Clients', ConstantContact::List.find_by_name("Clients").name
+ end
end
-# context 'initialize' do
-# setup do
-# @xml_str_1 = <<Feed
-# <ContactList xmlns="http://ws.constantcontact.com/ns/1.0/" id="http://api.constantcontact.com/ws/customers/recordkick/lists/1">
-# <OptInDefault>true</OptInDefault>
-# <Name>General Interest</Name>
-# <ShortName>General Interest</ShortName>
-# <DisplayOnSignup>Yes</DisplayOnSignup>
-# <SortOrder>1</SortOrder>
-# <Members id="http://api.constantcontact.com/ws/customers/recordkick/lists/1/members"></Members>
-# </ContactList>
-# Feed
-#
-# @xml_str_2 = <<Feed
-# <ContactList xmlns="http://ws.constantcontact.com/ns/1.0/" id="http://api.constantcontact.com/ws/customers/recordkick/lists/active">
-# <Name>Active</Name>
-# <ShortName>Active</ShortName>
-# </ContactList
-# Feed
-# end
-#
-# should 'parse and assign attributes' do
-# l = ConstantContact::List.new(@xml_str_1)
-# assert l.opt_in_default
-# assert_equal 'General Interest', l.name
-# assert_equal 'General Interest', l.short_name
-# assert_equal 'Yes', l.display_on_signup
-# assert_equal '1', l.sort_order
-# assert_equal '/ws/customers/recordkick/lists/1/members', l.member_url
-# end
-#
-# should 'parse and assign attributes in cases where attributes are missing' do
-# l = ConstantContact::List.new(@xml_str_2)
-# assert_equal 'Active', l.name
-# assert_equal 'Active', l.short_name
-#
-# end
-# end
-#
-# context 'members' do
-# setup do
-# @constant_contact = ConstantContact::Base.new('api_key', 'joesflowers', 'password')
-# @xml_str_1 = <<Feed
-# <ContactList xmlns="http://ws.constantcontact.com/ns/1.0/" id="http://api.constantcontact.com/ws/customers/recordkick/lists/1">
-# <OptInDefault>true</OptInDefault>
-# <Name>General Interest</Name>
-# <ShortName>General Interest</ShortName>
-# <DisplayOnSignup>Yes</DisplayOnSignup>
-# <SortOrder>1</SortOrder>
-# <Members id="http://api.constantcontact.com/ws/customers/recordkick/lists/1/members"></Members>
-# </ContactList>
-# Feed
-# end
-#
-# should 'get 50 members' do
-# stub_get('https://api_key%25joesflowers:password@api.constantcontact.com/ws/customers/recordkick/lists/1/members', 'memberscollection.xml')
-# l = ConstantContact::List.new(@xml_str_1)
-# assert_equal '/ws/customers/recordkick/lists/1/members', l.member_url
-# m = l.members
-# m.size.should == 50
-# end
-# end
-
end

0 comments on commit db45da3

Please sign in to comment.
Something went wrong with that request. Please try again.