constant_contact 1.3.2 → 1.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/constant_contact/activity.rb +11 -8
- data/lib/constant_contact/version.rb +1 -1
- data/test/constant_contact/activity_test.rb +48 -26
- data/test/test_helper.rb +1 -2
- metadata +6 -20
@@ -2,7 +2,7 @@
|
|
2
2
|
module ConstantContact
|
3
3
|
class Activity < Base
|
4
4
|
self.format = ActiveResource::Formats::HtmlEncodedFormat
|
5
|
-
attr_accessor :contacts, :lists, :activity_type
|
5
|
+
attr_accessor :contacts, :lists, :activity_type, :raw_data # Data is a reserved word in Rails
|
6
6
|
|
7
7
|
def self.parse_id(url)
|
8
8
|
url.to_s.split('/').last
|
@@ -29,16 +29,19 @@ module ConstantContact
|
|
29
29
|
protected
|
30
30
|
def encoded_data
|
31
31
|
result = "&data="
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
32
|
+
if self.raw_data.nil?
|
33
|
+
result += CGI.escape("Email Address,First Name,Last Name\n")
|
34
|
+
contact_strings = []
|
35
|
+
self.contacts.each do |contact|
|
36
|
+
contact_strings << "#{contact.email_address}, #{contact.first_name}, #{contact.last_name}"
|
37
|
+
end
|
38
|
+
result += CGI.escape(contact_strings.join("\n"))
|
39
|
+
else
|
40
|
+
result += CGI.escape(self.raw_data)
|
41
|
+
end
|
38
42
|
return result
|
39
43
|
end
|
40
44
|
|
41
|
-
|
42
45
|
def encoded_lists
|
43
46
|
result = ""
|
44
47
|
self.lists.each do |list|
|
@@ -3,38 +3,60 @@ require File.dirname(__FILE__) + '/../test_helper'
|
|
3
3
|
class Activity < Test::Unit::TestCase
|
4
4
|
|
5
5
|
context 'encode' do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
@
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
6
|
+
context 'with raw data' do
|
7
|
+
setup do
|
8
|
+
@data = "Email Address,Custom Field1\nemail1@domain.com,custom1\nemail2@domain.com,custom2"
|
9
|
+
@list = ConstantContact::List.new
|
10
|
+
@list.stubs(:id).returns('http://api.constantcontact.com/ws/customers/freerobby/lists/3')
|
11
|
+
@activity = ConstantContact::Activity.new(
|
12
|
+
:activity_type => "SV_ADD"
|
13
|
+
)
|
14
|
+
@activity.raw_data = @data
|
15
|
+
@activity.lists = [@list]
|
16
|
+
end
|
17
|
+
should 'use raw data, bypassing contact parsing' do
|
18
|
+
assert_match(CGI.escape(@data), @activity.encode)
|
19
|
+
end
|
20
|
+
should 'include activity type' do
|
21
|
+
assert_match('activityType=SV_ADD', @activity.encode)
|
22
|
+
end
|
23
|
+
should 'include list' do
|
24
|
+
assert_match(CGI.escape(@list.id), @activity.encode)
|
25
|
+
end
|
18
26
|
end
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
context 'with contact data' do
|
28
|
+
setup do
|
29
|
+
@contacts = []
|
30
|
+
3.times do |n|
|
31
|
+
@contacts << ConstantContact::Contact.new(:first_name => "Fred#{n}",
|
32
|
+
:last_name => "Test#{n}",
|
33
|
+
:email_address => "email#{n}@gmail.com")
|
34
|
+
end
|
35
|
+
@activity = ConstantContact::Activity.new(:activity_type => "SV_ADD")
|
36
|
+
@activity.contacts = @contacts
|
37
|
+
@list = ConstantContact::List.new
|
38
|
+
@list.stubs(:id).returns('http://api.constantcontact.com/ws/customers/joesflowers/lists/2')
|
39
|
+
@activity.lists = [@list]
|
40
|
+
end
|
41
|
+
|
42
|
+
should 'include activity type' do
|
43
|
+
assert_match(/activityType=SV_ADD/, @activity.encode)
|
44
|
+
end
|
45
|
+
|
46
|
+
should 'include contacts data' do
|
47
|
+
assert_match(/\&data\=Email\+Address\%2CFirst\+Name\%2CLast\+Name\%0A/, @activity.encode)
|
48
|
+
assert_match(/email0\%40gmail\.com\%2C\+Fred0\%2C\+Test0\%0A/, @activity.encode)
|
49
|
+
end
|
50
|
+
|
51
|
+
should 'include lists' do
|
52
|
+
assert_match(/Test2\&lists\=http\%3A\%2F\%2Fapi\.constantcontact\.com\%2Fws\%2Fcustomers\%2Fjoesflowers\%2Flists\%2F2/, @activity.encode)
|
53
|
+
end
|
31
54
|
end
|
32
|
-
|
33
55
|
end
|
34
56
|
|
35
57
|
context 'format' do
|
36
58
|
should 'be html encoded' do
|
37
|
-
assert_equal ActiveResource::Formats[:html_encoded], ConstantContact::Activity.format
|
59
|
+
assert_equal ActiveResource::Formats[:html_encoded], ConstantContact::Activity.connection.format
|
38
60
|
end
|
39
61
|
end
|
40
62
|
|
data/test/test_helper.rb
CHANGED
@@ -2,7 +2,6 @@ require 'rubygems'
|
|
2
2
|
require 'active_support/test_case'
|
3
3
|
require 'test/unit'
|
4
4
|
require 'shoulda'
|
5
|
-
require 'matchy'
|
6
5
|
require 'mocha'
|
7
6
|
require 'fakeweb'
|
8
7
|
|
@@ -16,7 +15,7 @@ class Test::Unit::TestCase
|
|
16
15
|
end
|
17
16
|
|
18
17
|
def fixture_file(filename)
|
19
|
-
return '' if filename
|
18
|
+
return '' if filename.blank?
|
20
19
|
file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/' + filename)
|
21
20
|
File.read(file_path)
|
22
21
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: constant_contact
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 1.3.
|
9
|
+
- 3
|
10
|
+
version: 1.3.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Tim Case
|
@@ -18,7 +18,7 @@ autorequire:
|
|
18
18
|
bindir: bin
|
19
19
|
cert_chain: []
|
20
20
|
|
21
|
-
date:
|
21
|
+
date: 2011-01-12 00:00:00 -05:00
|
22
22
|
default_executable:
|
23
23
|
dependencies:
|
24
24
|
- !ruby/object:Gem::Dependency
|
@@ -80,7 +80,7 @@ dependencies:
|
|
80
80
|
type: :development
|
81
81
|
version_requirements: *id004
|
82
82
|
- !ruby/object:Gem::Dependency
|
83
|
-
name:
|
83
|
+
name: mocha
|
84
84
|
prerelease: false
|
85
85
|
requirement: &id005 !ruby/object:Gem::Requirement
|
86
86
|
none: false
|
@@ -94,7 +94,7 @@ dependencies:
|
|
94
94
|
type: :development
|
95
95
|
version_requirements: *id005
|
96
96
|
- !ruby/object:Gem::Dependency
|
97
|
-
name:
|
97
|
+
name: fakeweb
|
98
98
|
prerelease: false
|
99
99
|
requirement: &id006 !ruby/object:Gem::Requirement
|
100
100
|
none: false
|
@@ -107,20 +107,6 @@ dependencies:
|
|
107
107
|
version: "0"
|
108
108
|
type: :development
|
109
109
|
version_requirements: *id006
|
110
|
-
- !ruby/object:Gem::Dependency
|
111
|
-
name: fakeweb
|
112
|
-
prerelease: false
|
113
|
-
requirement: &id007 !ruby/object:Gem::Requirement
|
114
|
-
none: false
|
115
|
-
requirements:
|
116
|
-
- - ">="
|
117
|
-
- !ruby/object:Gem::Version
|
118
|
-
hash: 3
|
119
|
-
segments:
|
120
|
-
- 0
|
121
|
-
version: "0"
|
122
|
-
type: :development
|
123
|
-
version_requirements: *id007
|
124
110
|
description: This is a very ActiveResource-like ruby wrapper to the Constant Contact API.
|
125
111
|
email:
|
126
112
|
executables: []
|