constantcontact 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +127 -136
- data/constantcontact.gemspec +4 -3
- data/lib/constantcontact.rb +63 -44
- data/lib/constantcontact/api.rb +932 -535
- data/lib/constantcontact/auth/oauth2.rb +86 -66
- data/lib/constantcontact/components/account/verified_email_address.rb +14 -14
- data/lib/constantcontact/components/activities/activity.rb +30 -30
- data/lib/constantcontact/components/activities/activity_error.rb +14 -14
- data/lib/constantcontact/components/activities/add_contacts.rb +1 -1
- data/lib/constantcontact/components/activities/add_contacts_import_data.rb +37 -36
- data/lib/constantcontact/components/component.rb +25 -0
- data/lib/constantcontact/components/contacts/address.rb +12 -12
- data/lib/constantcontact/components/contacts/contact.rb +50 -44
- data/lib/constantcontact/components/contacts/contact_list.rb +12 -12
- data/lib/constantcontact/components/contacts/custom_field.rb +14 -14
- data/lib/constantcontact/components/contacts/email_address.rb +14 -14
- data/lib/constantcontact/components/contacts/note.rb +13 -13
- data/lib/constantcontact/components/email_marketing/campaign.rb +41 -41
- data/lib/constantcontact/components/email_marketing/click_through_details.rb +14 -14
- data/lib/constantcontact/components/email_marketing/message_footer.rb +14 -14
- data/lib/constantcontact/components/email_marketing/schedule.rb +14 -15
- data/lib/constantcontact/components/email_marketing/test_send.rb +21 -21
- data/lib/constantcontact/components/event_spot/contact.rb +27 -0
- data/lib/constantcontact/components/event_spot/event.rb +63 -0
- data/lib/constantcontact/components/event_spot/event_track.rb +28 -0
- data/lib/constantcontact/components/event_spot/fee.rb +27 -0
- data/lib/constantcontact/components/event_spot/guest.rb +31 -0
- data/lib/constantcontact/components/event_spot/notification_option.rb +27 -0
- data/lib/constantcontact/components/event_spot/promo_code.rb +26 -0
- data/lib/constantcontact/components/event_spot/registrant.rb +54 -0
- data/lib/constantcontact/components/event_spot/registrant_field.rb +27 -0
- data/lib/constantcontact/components/event_spot/registrant_section.rb +34 -0
- data/lib/constantcontact/components/event_spot/sale_item.rb +27 -0
- data/lib/constantcontact/components/library/file/library_file.rb +27 -0
- data/lib/constantcontact/components/library/folder/library_folder.rb +26 -0
- data/lib/constantcontact/components/library/info/library_summary.rb +26 -0
- data/lib/constantcontact/components/library/info/move_results.rb +26 -0
- data/lib/constantcontact/components/library/info/upload_status.rb +26 -0
- data/lib/constantcontact/components/tracking/bounce_activity.rb +14 -14
- data/lib/constantcontact/components/tracking/click_activity.rb +14 -14
- data/lib/constantcontact/components/tracking/forward_activity.rb +14 -14
- data/lib/constantcontact/components/tracking/open_activity.rb +14 -14
- data/lib/constantcontact/components/tracking/send_activity.rb +14 -14
- data/lib/constantcontact/components/tracking/tracking_summary.rb +17 -17
- data/lib/constantcontact/components/tracking/unsubscribe_activity.rb +14 -14
- data/lib/constantcontact/services/account_service.rb +4 -3
- data/lib/constantcontact/services/activity_service.rb +40 -3
- data/lib/constantcontact/services/base_service.rb +34 -6
- data/lib/constantcontact/services/campaign_tracking_service.rb +20 -20
- data/lib/constantcontact/services/contact_service.rb +10 -12
- data/lib/constantcontact/services/contact_tracking_service.rb +20 -20
- data/lib/constantcontact/services/email_marketing_service.rb +8 -10
- data/lib/constantcontact/services/event_spot_service.rb +254 -0
- data/lib/constantcontact/services/library_service.rb +297 -0
- data/lib/constantcontact/services/list_service.rb +6 -5
- data/lib/constantcontact/util/config.rb +135 -117
- data/lib/constantcontact/version.rb +1 -1
- data/spec/constantcontact/api_spec.rb +1223 -173
- data/spec/constantcontact/auth/oauth2_spec.rb +60 -47
- data/spec/constantcontact/components/contacts/address_spec.rb +1 -1
- data/spec/constantcontact/components/contacts/contact_list_spec.rb +1 -1
- data/spec/constantcontact/components/contacts/contact_spec.rb +1 -1
- data/spec/constantcontact/components/contacts/email_address_spec.rb +1 -1
- data/spec/constantcontact/services/activity_service_spec.rb +201 -0
- data/spec/constantcontact/services/base_service_spec.rb +27 -0
- data/spec/constantcontact/services/campaign_schedule_service_spec.rb +111 -0
- data/spec/constantcontact/services/campaign_tracking_service_spec.rb +127 -0
- data/spec/constantcontact/services/contact_service_spec.rb +24 -22
- data/spec/constantcontact/services/contact_tracking_service_spec.rb +127 -0
- data/spec/constantcontact/services/email_marketing_spec.rb +72 -66
- data/spec/constantcontact/services/event_spot_spec.rb +217 -0
- data/spec/constantcontact/services/library_service_spec.rb +248 -0
- data/spec/constantcontact/services/list_service_spec.rb +33 -17
- data/spec/spec_helper.rb +3 -1
- metadata +63 -7
@@ -0,0 +1,26 @@
|
|
1
|
+
#
|
2
|
+
# library_summary.rb
|
3
|
+
# ConstantContact
|
4
|
+
#
|
5
|
+
# Copyright (c) 2013 Constant Contact. All rights reserved.
|
6
|
+
|
7
|
+
module ConstantContact
|
8
|
+
module Components
|
9
|
+
class LibrarySummary < Component
|
10
|
+
attr_accessor :max_free_file_num, :max_premium_space_limit, :max_upload_size_limit, :image_root, :usage_summary
|
11
|
+
|
12
|
+
# Factory method to create a LibrarySummary object from a json string
|
13
|
+
# @param [Hash] props - properties to create object from
|
14
|
+
# @return [LibrarySummary]
|
15
|
+
def self.create(props)
|
16
|
+
obj = LibrarySummary.new
|
17
|
+
if props
|
18
|
+
props.each do |key, value|
|
19
|
+
obj.send("#{key}=", value) if obj.respond_to?("#{key}=")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
obj
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
#
|
2
|
+
# move_results.rb
|
3
|
+
# ConstantContact
|
4
|
+
#
|
5
|
+
# Copyright (c) 2013 Constant Contact. All rights reserved.
|
6
|
+
|
7
|
+
module ConstantContact
|
8
|
+
module Components
|
9
|
+
class MoveResults < Component
|
10
|
+
attr_accessor :id, :uri
|
11
|
+
|
12
|
+
# Factory method to create a MoveResults object from a json string
|
13
|
+
# @param [Hash] props - properties to create object from
|
14
|
+
# @return [MoveResults]
|
15
|
+
def self.create(props)
|
16
|
+
obj = MoveResults.new
|
17
|
+
if props
|
18
|
+
props.each do |key, value|
|
19
|
+
obj.send("#{key}=", value) if obj.respond_to?("#{key}=")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
obj
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
#
|
2
|
+
# upload_status.rb
|
3
|
+
# ConstantContact
|
4
|
+
#
|
5
|
+
# Copyright (c) 2013 Constant Contact. All rights reserved.
|
6
|
+
|
7
|
+
module ConstantContact
|
8
|
+
module Components
|
9
|
+
class UploadStatus < Component
|
10
|
+
attr_accessor :status, :description, :file_id
|
11
|
+
|
12
|
+
# Factory method to create an UploadStatus object from a json string
|
13
|
+
# @param [Hash] props - properties to create object from
|
14
|
+
# @return [UploadStatus]
|
15
|
+
def self.create(props)
|
16
|
+
obj = UploadStatus.new
|
17
|
+
if props
|
18
|
+
props.each do |key, value|
|
19
|
+
obj.send("#{key}=", value) if obj.respond_to?("#{key}=")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
obj
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -11,18 +11,18 @@ module ConstantContact
|
|
11
11
|
:contact_id, :email_address, :campaign_id
|
12
12
|
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
14
|
+
# Factory method to create a BounceActivity object from an array
|
15
|
+
# @param [Hash] props - properties to create object from
|
16
|
+
# @return [BounceActivity]
|
17
|
+
def self.create(props)
|
18
|
+
obj = BounceActivity.new
|
19
|
+
if props
|
20
|
+
props.each do |key, value|
|
21
|
+
obj.send("#{key}=", value) if obj.respond_to? key
|
22
|
+
end
|
23
|
+
end
|
24
|
+
obj
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
28
|
end
|
@@ -9,18 +9,18 @@ module ConstantContact
|
|
9
9
|
class ClickActivity < Component
|
10
10
|
attr_accessor :activity_type, :campaign_id, :contact_id, :email_address, :link_id, :click_date
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
12
|
+
# Factory method to create a ClickActivity object from an array
|
13
|
+
# @param [Hash] props - properties to create object from
|
14
|
+
# @return [ClickActivity]
|
15
|
+
def self.create(props)
|
16
|
+
obj = ClickActivity.new
|
17
|
+
if props
|
18
|
+
props.each do |key, value|
|
19
|
+
obj.send("#{key}=", value) if obj.respond_to? key
|
20
|
+
end
|
21
|
+
end
|
22
|
+
obj
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
26
|
end
|
@@ -9,18 +9,18 @@ module ConstantContact
|
|
9
9
|
class ForwardActivity < Component
|
10
10
|
attr_accessor :activity_type, :campaign_id, :contact_id, :email_address, :forward_date
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
12
|
+
# Factory method to create a ForwardActivity object from an array
|
13
|
+
# @param [Hash] props - properties to create object from
|
14
|
+
# @return [ForwardActivity]
|
15
|
+
def self.create(props)
|
16
|
+
obj = ForwardActivity.new
|
17
|
+
if props
|
18
|
+
props.each do |key, value|
|
19
|
+
obj.send("#{key}=", value) if obj.respond_to? key
|
20
|
+
end
|
21
|
+
end
|
22
|
+
obj
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
26
|
end
|
@@ -9,18 +9,18 @@ module ConstantContact
|
|
9
9
|
class OpenActivity < Component
|
10
10
|
attr_accessor :activity_type, :campaign_id, :email_address, :open_date, :contact_id
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
12
|
+
# Factory method to create an OpenActivity object from an array
|
13
|
+
# @param [Hash] props - properties to create object from
|
14
|
+
# @return [OpenActivity]
|
15
|
+
def self.create(props)
|
16
|
+
obj = OpenActivity.new
|
17
|
+
if props
|
18
|
+
props.each do |key, value|
|
19
|
+
obj.send("#{key}=", value) if obj.respond_to? key
|
20
|
+
end
|
21
|
+
end
|
22
|
+
obj
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
26
|
end
|
@@ -10,18 +10,18 @@ module ConstantContact
|
|
10
10
|
attr_accessor :activity_type, :campaign_id, :email_address, :contact_id, :send_date
|
11
11
|
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
13
|
+
# Factory method to create a SendActivity object from an array
|
14
|
+
# @param [Hash] props - properties to create object from
|
15
|
+
# @return [SendActivity]
|
16
|
+
def self.create(props)
|
17
|
+
obj = SendActivity.new
|
18
|
+
if props
|
19
|
+
props.each do |key, value|
|
20
|
+
obj.send("#{key}=", value)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
obj
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
27
|
end
|
@@ -5,23 +5,23 @@
|
|
5
5
|
# Copyright (c) 2013 Constant Contact. All rights reserved.
|
6
6
|
|
7
7
|
module ConstantContact
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
module Components
|
9
|
+
class TrackingSummary < Component
|
10
|
+
attr_accessor :sends, :opens, :clicks, :forwards, :unsubscribes, :bounces, :spam_count
|
11
11
|
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
13
|
+
# Factory method to create a TrackingSummary object from an array
|
14
|
+
# @param [Hash] props - properties to create object from
|
15
|
+
# @return [TrackingSummary]
|
16
|
+
def self.create(props)
|
17
|
+
obj = TrackingSummary.new
|
18
|
+
if props
|
19
|
+
props.each do |key, value|
|
20
|
+
obj.send("#{key}=", value) if obj.respond_to? key
|
21
|
+
end
|
22
|
+
end
|
23
|
+
obj
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
27
|
end
|
@@ -10,18 +10,18 @@ module ConstantContact
|
|
10
10
|
attr_accessor :activity_type, :campaign_id, :contact_id, :email_address, :unsubscribe_date,
|
11
11
|
:unsubscribe_source, :unsubscribe_reason
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
13
|
+
# Factory method to create an UnsubscribeActivity object from an array
|
14
|
+
# @param [Hash] props - properties to create object from
|
15
|
+
# @return [UnsubscribeActivity]
|
16
|
+
def self.create(props)
|
17
|
+
obj = UnsubscribeActivity.new
|
18
|
+
if props
|
19
|
+
props.each do |key, value|
|
20
|
+
obj.send("#{key}=", value) if obj.respond_to? key
|
21
|
+
end
|
22
|
+
end
|
23
|
+
obj
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
27
|
end
|
@@ -9,12 +9,13 @@ module ConstantContact
|
|
9
9
|
class AccountService < BaseService
|
10
10
|
class << self
|
11
11
|
|
12
|
-
# Get
|
12
|
+
# Get all verified email addresses associated with an account
|
13
13
|
# @param [String] access_token - Constant Contact OAuth2 access token
|
14
|
+
# @param [Hash] params - hash of query parameters/values to append to the request
|
14
15
|
# @return [Array<VerifiedEmailAddress>]
|
15
|
-
def get_verified_email_addresses(access_token)
|
16
|
+
def get_verified_email_addresses(access_token, params)
|
16
17
|
url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.account_verified_addresses')
|
17
|
-
url = build_url(url)
|
18
|
+
url = build_url(url, params)
|
18
19
|
response = RestClient.get(url, get_headers(access_token))
|
19
20
|
email_addresses = []
|
20
21
|
JSON.parse(response.body).each do |email_address|
|
@@ -10,11 +10,12 @@ module ConstantContact
|
|
10
10
|
class << self
|
11
11
|
|
12
12
|
# Get a set of activities
|
13
|
-
# @param [String] access_token
|
13
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
14
|
+
# @param [Hash] params - query parameters to be appended to the url
|
14
15
|
# @return [Array<Activity>]
|
15
|
-
def get_activities(access_token)
|
16
|
+
def get_activities(access_token, params = {})
|
16
17
|
url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.activities')
|
17
|
-
url = build_url(url)
|
18
|
+
url = build_url(url, params)
|
18
19
|
response = RestClient.get(url, get_headers(access_token))
|
19
20
|
|
20
21
|
activities = []
|
@@ -53,6 +54,24 @@ module ConstantContact
|
|
53
54
|
end
|
54
55
|
|
55
56
|
|
57
|
+
# Create an Add Contacts Activity from a file. Valid file types are txt, csv, xls, xlsx
|
58
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
59
|
+
# @param [String] file_name - The name of the file (ie: contacts.csv)
|
60
|
+
# @param [String] contents - The content of the file
|
61
|
+
# @param [String] lists - Comma separated list of ContactList id's to add the contacts to
|
62
|
+
# @return [Activity]
|
63
|
+
def create_add_contacts_activity_from_file(access_token, file_name, contents, lists)
|
64
|
+
url = Util::Config.get('endpoints.base_url') +
|
65
|
+
Util::Config.get('endpoints.add_contacts_activity')
|
66
|
+
url = build_url(url)
|
67
|
+
|
68
|
+
payload = { :file_name => file_name, :lists => lists, :data => contents, :multipart => true }
|
69
|
+
|
70
|
+
response = RestClient.post(url, payload, get_headers(access_token))
|
71
|
+
Components::Activity.create(JSON.parse(response.body))
|
72
|
+
end
|
73
|
+
|
74
|
+
|
56
75
|
# Create a Clear Lists Activity
|
57
76
|
# @param [String] access_token - Constant Contact OAuth2 access token
|
58
77
|
# @param [Array<lists>] lists - array of list id's to be cleared
|
@@ -101,6 +120,24 @@ module ConstantContact
|
|
101
120
|
Components::Activity.create(JSON.parse(response.body))
|
102
121
|
end
|
103
122
|
|
123
|
+
|
124
|
+
# Create an Remove Contacts Activity from a file. Valid file types are txt, csv, xls, xlsx
|
125
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
126
|
+
# @param [String] file_name - The name of the file (ie: contacts.csv)
|
127
|
+
# @param [String] contents - The content of the file
|
128
|
+
# @param [String] lists - Comma separated list of ContactList id' to add the contacts too
|
129
|
+
# @return [Activity]
|
130
|
+
def add_remove_contacts_from_lists_activity_from_file(access_token, file_name, contents, lists)
|
131
|
+
url = Util::Config.get('endpoints.base_url') +
|
132
|
+
Util::Config.get('endpoints.remove_from_lists_activity')
|
133
|
+
url = build_url(url)
|
134
|
+
|
135
|
+
payload = { :file_name => file_name, :lists => lists, :data => contents, :multipart => true }
|
136
|
+
|
137
|
+
response = RestClient.post(url, payload, get_headers(access_token))
|
138
|
+
Components::Activity.create(JSON.parse(response.body))
|
139
|
+
end
|
140
|
+
|
104
141
|
end
|
105
142
|
end
|
106
143
|
end
|
@@ -12,21 +12,49 @@ module ConstantContact
|
|
12
12
|
|
13
13
|
protected
|
14
14
|
|
15
|
-
#
|
15
|
+
# Return required headers for making an http request with constant contact
|
16
16
|
# @param [String] access_token - OAuth2 access token to be placed into the Authorization header
|
17
|
+
# @param [String] content_type - The MIME type of the body of the request, default is 'application/json'
|
17
18
|
# @return [Hash] - authorization headers
|
18
|
-
def get_headers(access_token)
|
19
|
+
def get_headers(access_token, content_type = 'application/json')
|
19
20
|
{
|
20
|
-
:content_type =>
|
21
|
+
:content_type => content_type,
|
21
22
|
:accept => 'application/json',
|
22
|
-
:authorization => "Bearer #{access_token}"
|
23
|
+
:authorization => "Bearer #{access_token}",
|
24
|
+
:user_agent => "AppConnect Ruby SDK v#{ConstantContact::SDK::VERSION} (#{RUBY_DESCRIPTION})"
|
23
25
|
}
|
24
26
|
end
|
25
27
|
|
26
28
|
|
27
|
-
#
|
29
|
+
# returns the id of a ConstantContact component
|
30
|
+
def get_id_for(obj)
|
31
|
+
if obj.kind_of? ConstantContact::Components::Component
|
32
|
+
obj.id
|
33
|
+
elsif obj.kind_of? Hash
|
34
|
+
obj["id"]
|
35
|
+
else
|
36
|
+
obj
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
# Build a url from the base url and query parameters hash. Query parameters
|
42
|
+
# should not be URL encoded because this method will handle that
|
43
|
+
# @param [String] url - The base url
|
44
|
+
# @param [Hash] params - A hash with query parameters
|
45
|
+
# @return [String] - the url with query parameters hash
|
28
46
|
def build_url(url, params = nil)
|
29
|
-
|
47
|
+
if params.respond_to? :each
|
48
|
+
params.each do |key, value|
|
49
|
+
# Convert dates to CC date format
|
50
|
+
if value.respond_to? :iso8601
|
51
|
+
params[key] = value.iso8601
|
52
|
+
end
|
53
|
+
end
|
54
|
+
else
|
55
|
+
params ||= {}
|
56
|
+
end
|
57
|
+
|
30
58
|
params['api_key'] = BaseService.api_key
|
31
59
|
url += '?' + Util::Helpers.http_build_query(params)
|
32
60
|
end
|