Skip to content

Commit

Permalink
fleshed out more wrapper classes
Browse files Browse the repository at this point in the history
  • Loading branch information
timcase committed Aug 14, 2009
1 parent 3588790 commit db45da3
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 73 deletions.
3 changes: 0 additions & 3 deletions init.rb
Original file line number Diff line number Diff line change
@@ -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']

8 changes: 7 additions & 1 deletion lib/constant_contact/activity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,6 +27,7 @@ def encoded_data
return result
end


def encoded_lists
result = ""
self.lists.each do |list|
Expand Down
2 changes: 1 addition & 1 deletion lib/constant_contact/contact.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 8 additions & 1 deletion lib/constant_contact/formats/html_encoded_format.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions lib/constant_contact/list.rb
Original file line number Diff line number Diff line change
@@ -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
7 changes: 4 additions & 3 deletions test/constant_contact/activity_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
75 changes: 11 additions & 64 deletions test/constant_contact/list_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.