constantcontact 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -7
- data/README.md +7 -0
- data/constantcontact.gemspec +1 -1
- data/lib/constantcontact.rb +54 -54
- data/lib/constantcontact/api.rb +5 -3
- data/lib/constantcontact/auth/oauth2.rb +7 -4
- data/lib/constantcontact/auth/session_data_store.rb +52 -52
- data/lib/constantcontact/components/account/verified_email_address.rb +17 -17
- data/lib/constantcontact/components/activities/activity.rb +34 -34
- data/lib/constantcontact/components/activities/activity_error.rb +17 -17
- data/lib/constantcontact/components/activities/add_contacts.rb +109 -109
- data/lib/constantcontact/components/activities/add_contacts_import_data.rb +37 -37
- data/lib/constantcontact/components/activities/export_contacts.rb +19 -19
- data/lib/constantcontact/components/component.rb +13 -13
- data/lib/constantcontact/components/contacts/address.rb +18 -18
- data/lib/constantcontact/components/contacts/contact.rb +69 -69
- data/lib/constantcontact/components/contacts/contact_list.rb +17 -17
- data/lib/constantcontact/components/contacts/custom_field.rb +17 -17
- data/lib/constantcontact/components/contacts/email_address.rb +23 -23
- data/lib/constantcontact/components/contacts/note.rb +16 -16
- data/lib/constantcontact/components/email_marketing/campaign.rb +67 -67
- data/lib/constantcontact/components/email_marketing/click_through_details.rb +17 -17
- data/lib/constantcontact/components/email_marketing/message_footer.rb +20 -20
- data/lib/constantcontact/components/email_marketing/schedule.rb +18 -18
- data/lib/constantcontact/components/email_marketing/test_send.rb +32 -32
- data/lib/constantcontact/components/result_set.rb +15 -15
- data/lib/constantcontact/components/tracking/bounce_activity.rb +18 -18
- data/lib/constantcontact/components/tracking/click_activity.rb +17 -17
- data/lib/constantcontact/components/tracking/forward_activity.rb +17 -17
- data/lib/constantcontact/components/tracking/open_activity.rb +17 -17
- data/lib/constantcontact/components/tracking/send_activity.rb +17 -17
- data/lib/constantcontact/components/tracking/tracking_activity.rb +15 -15
- data/lib/constantcontact/components/tracking/tracking_summary.rb +17 -17
- data/lib/constantcontact/components/tracking/unsubscribe_activity.rb +18 -18
- data/lib/constantcontact/exceptions/ctct_exception.rb +15 -15
- data/lib/constantcontact/exceptions/illegal_argument_exception.rb +3 -3
- data/lib/constantcontact/exceptions/oauth2_exception.rb +3 -3
- data/lib/constantcontact/services/account_service.rb +19 -19
- data/lib/constantcontact/services/activity_service.rb +99 -99
- data/lib/constantcontact/services/base_service.rb +24 -24
- data/lib/constantcontact/services/campaign_schedule_service.rb +85 -85
- data/lib/constantcontact/services/campaign_tracking_service.rb +151 -151
- data/lib/constantcontact/services/contact_service.rb +106 -106
- data/lib/constantcontact/services/contact_tracking_service.rb +151 -151
- data/lib/constantcontact/services/email_marketing_service.rb +66 -66
- data/lib/constantcontact/services/list_service.rb +67 -67
- data/lib/constantcontact/util/config.rb +102 -96
- data/lib/constantcontact/util/helpers.rb +18 -18
- data/lib/constantcontact/version.rb +4 -4
- data/spec/constantcontact/api_spec.rb +223 -173
- data/spec/constantcontact/auth/oauth2_spec.rb +68 -4
- data/spec/constantcontact/components/contacts/address_spec.rb +7 -7
- data/spec/constantcontact/components/contacts/contact_list_spec.rb +7 -7
- data/spec/constantcontact/components/contacts/contact_spec.rb +7 -7
- data/spec/constantcontact/components/contacts/custom_field_spec.rb +7 -7
- data/spec/constantcontact/components/contacts/email_address_spec.rb +7 -7
- data/spec/constantcontact/services/contact_service_spec.rb +95 -95
- data/spec/constantcontact/services/list_service_spec.rb +48 -48
- data/spec/spec_helper.rb +1 -1
- metadata +55 -44
@@ -5,21 +5,21 @@
|
|
5
5
|
# Copyright (c) 2013 Constant Contact. All rights reserved.
|
6
6
|
|
7
7
|
module ConstantContact
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
module Exceptions
|
9
|
+
class CtctException < Exception
|
10
|
+
attr_accessor :errors
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
# Setter
|
13
|
+
# @param [Array<String>] errors
|
14
|
+
def set_errors(errors)
|
15
|
+
@errors = errors
|
16
|
+
end
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
18
|
+
# Getter
|
19
|
+
# @return [Array<String>]
|
20
|
+
def get_errors
|
21
|
+
@errors
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
25
|
end
|
@@ -5,25 +5,25 @@
|
|
5
5
|
# Copyright (c) 2013 Constant Contact. All rights reserved.
|
6
6
|
|
7
7
|
module ConstantContact
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
module Services
|
9
|
+
class AccountService < BaseService
|
10
|
+
class << self
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
12
|
+
# Get the verified emails from account
|
13
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
14
|
+
# @return [Array<VerifiedEmailAddress>]
|
15
|
+
def get_verified_email_addresses(access_token)
|
16
|
+
url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.account_verified_addresses')
|
17
|
+
url = build_url(url)
|
18
|
+
response = RestClient.get(url, get_headers(access_token))
|
19
|
+
email_addresses = []
|
20
|
+
JSON.parse(response.body).each do |email_address|
|
21
|
+
email_addresses << Components::VerifiedEmailAddress.create(email_address)
|
22
|
+
end
|
23
|
+
email_addresses
|
24
|
+
end
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
29
|
end
|
@@ -5,103 +5,103 @@
|
|
5
5
|
# Copyright (c) 2013 Constant Contact. All rights reserved.
|
6
6
|
|
7
7
|
module ConstantContact
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
8
|
+
module Services
|
9
|
+
class ActivityService < BaseService
|
10
|
+
class << self
|
11
|
+
|
12
|
+
# Get a set of activities
|
13
|
+
# @param [String] access_token
|
14
|
+
# @return [Array<Activity>]
|
15
|
+
def get_activities(access_token)
|
16
|
+
url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.activities')
|
17
|
+
url = build_url(url)
|
18
|
+
response = RestClient.get(url, get_headers(access_token))
|
19
|
+
|
20
|
+
activities = []
|
21
|
+
JSON.parse(response.body).each do |activity|
|
22
|
+
activities << Components::Activity.create(activity)
|
23
|
+
end
|
24
|
+
|
25
|
+
activities
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
# Get an array of activities
|
30
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
31
|
+
# @param [String] activity_id - Activity id
|
32
|
+
# @return [Activity]
|
33
|
+
def get_activity(access_token, activity_id)
|
34
|
+
url = Util::Config.get('endpoints.base_url') +
|
35
|
+
sprintf(Util::Config.get('endpoints.activity'), activity_id)
|
36
|
+
url = build_url(url)
|
37
|
+
response = RestClient.get(url, get_headers(access_token))
|
38
|
+
Components::Activity.create(JSON.parse(response.body))
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
# Create an Add Contacts Activity
|
43
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
44
|
+
# @param [AddContacts] add_contacts
|
45
|
+
# @return [Activity]
|
46
|
+
def create_add_contacts_activity(access_token, add_contacts)
|
47
|
+
url = Util::Config.get('endpoints.base_url') +
|
48
|
+
Util::Config.get('endpoints.add_contacts_activity')
|
49
|
+
url = build_url(url)
|
50
|
+
payload = add_contacts.to_json
|
51
|
+
response = RestClient.post(url, payload, get_headers(access_token))
|
52
|
+
Components::Activity.create(JSON.parse(response.body))
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
# Create a Clear Lists Activity
|
57
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
58
|
+
# @param [Array<lists>] lists - array of list id's to be cleared
|
59
|
+
# @return [Activity]
|
60
|
+
def add_clear_lists_activity(access_token, lists)
|
61
|
+
url = Util::Config.get('endpoints.base_url') +
|
62
|
+
Util::Config.get('endpoints.clear_lists_activity')
|
63
|
+
url = build_url(url)
|
64
|
+
payload = {'lists' => lists}.to_json
|
65
|
+
response = RestClient.post(url, payload, get_headers(access_token))
|
66
|
+
Components::Activity.create(JSON.parse(response.body))
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
# Create an Export Contacts Activity
|
71
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
72
|
+
# @param [ExportContacts] export_contacts
|
73
|
+
# @return [Activity]
|
74
|
+
def add_export_contacts_activity(access_token, export_contacts)
|
75
|
+
url = Util::Config.get('endpoints.base_url') +
|
76
|
+
Util::Config.get('endpoints.export_contacts_activity')
|
77
|
+
url = build_url(url)
|
78
|
+
payload = export_contacts.to_json
|
79
|
+
response = RestClient.post(url, payload, get_headers(access_token))
|
80
|
+
Components::Activity.create(JSON.parse(response.body))
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
# Create a Remove Contacts From Lists Activity
|
85
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
86
|
+
# @param [<Array>EmailAddress] email_addresses
|
87
|
+
# @param [<Array>RemoveFromLists] lists
|
88
|
+
# @return [Activity]
|
89
|
+
def add_remove_contacts_from_lists_activity(access_token, email_addresses, lists)
|
90
|
+
url = Util::Config.get('endpoints.base_url') +
|
91
|
+
Util::Config.get('endpoints.remove_from_lists_activity')
|
92
|
+
url = build_url(url)
|
93
|
+
|
94
|
+
payload = { 'import_data' => [], 'lists' => lists }
|
95
|
+
email_addresses.each do |email_address|
|
96
|
+
payload['import_data'] << { 'email_addresses' => [email_address] }
|
97
|
+
end
|
98
|
+
payload = payload.to_json
|
99
|
+
|
100
|
+
response = RestClient.post(url, payload, get_headers(access_token))
|
101
|
+
Components::Activity.create(JSON.parse(response.body))
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
107
|
end
|
@@ -5,33 +5,33 @@
|
|
5
5
|
# Copyright (c) 2013 Constant Contact. All rights reserved.
|
6
6
|
|
7
7
|
module ConstantContact
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
module Services
|
9
|
+
class BaseService
|
10
|
+
class << self
|
11
|
+
attr_accessor :api_key
|
12
12
|
|
13
|
-
|
13
|
+
protected
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
15
|
+
# Helper function to return required headers for making an http request with constant contact
|
16
|
+
# @param [String] access_token - OAuth2 access token to be placed into the Authorization header
|
17
|
+
# @return [Hash] - authorization headers
|
18
|
+
def get_headers(access_token)
|
19
|
+
{
|
20
|
+
:content_type => 'application/json',
|
21
|
+
:accept => 'application/json',
|
22
|
+
:authorization => "Bearer #{access_token}"
|
23
|
+
}
|
24
|
+
end
|
25
25
|
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
27
|
+
# Build a url from the base url and query parameters hash
|
28
|
+
def build_url(url, params = nil)
|
29
|
+
params = {} if !params
|
30
|
+
params['api_key'] = BaseService.api_key
|
31
|
+
url += '?' + Util::Helpers.http_build_query(params)
|
32
|
+
end
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
37
|
end
|
@@ -5,103 +5,103 @@
|
|
5
5
|
# Copyright (c) 2013 Constant Contact. All rights reserved.
|
6
6
|
|
7
7
|
module ConstantContact
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
module Services
|
9
|
+
class CampaignScheduleService < BaseService
|
10
|
+
class << self
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
12
|
+
# Create a new schedule for a campaign
|
13
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
14
|
+
# @param [Integer] campaign_id - Campaign id to be scheduled
|
15
|
+
# @param [Schedule] schedule - Schedule to be created
|
16
|
+
# @return [Schedule]
|
17
|
+
def add_schedule(access_token, campaign_id, schedule)
|
18
|
+
url = Util::Config.get('endpoints.base_url') +
|
19
|
+
sprintf(Util::Config.get('endpoints.campaign_schedules'), campaign_id)
|
20
|
+
url = build_url(url)
|
21
|
+
payload = schedule.to_json
|
22
|
+
response = RestClient.post(url, payload, get_headers(access_token))
|
23
|
+
Components::Schedule.create(JSON.parse(response.body))
|
24
|
+
end
|
25
25
|
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
27
|
+
# Get a list of schedules for a campaign
|
28
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
29
|
+
# @param [Integer] campaign_id - Campaign id to be scheduled
|
30
|
+
# @return [Array<Schedule>]
|
31
|
+
def get_schedules(access_token, campaign_id)
|
32
|
+
url = Util::Config.get('endpoints.base_url') +
|
33
|
+
sprintf(Util::Config.get('endpoints.campaign_schedules'), campaign_id)
|
34
|
+
url = build_url(url)
|
35
|
+
response = RestClient.get(url, get_headers(access_token))
|
36
|
+
body = JSON.parse(response.body)
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
38
|
+
schedules = []
|
39
|
+
body.each do |schedule|
|
40
|
+
schedules << Components::Schedule.create(schedule)
|
41
|
+
end
|
42
42
|
|
43
|
-
|
44
|
-
|
43
|
+
schedules
|
44
|
+
end
|
45
45
|
|
46
46
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
47
|
+
# Get a specific schedule for a campaign
|
48
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
49
|
+
# @param [Integer] campaign_id - Campaign id to get a schedule for
|
50
|
+
# @param [Integer] schedule_id - Schedule id to retrieve
|
51
|
+
# @return [Schedule]
|
52
|
+
def get_schedule(access_token, campaign_id, schedule_id)
|
53
|
+
url = Util::Config.get('endpoints.base_url') +
|
54
|
+
sprintf(Util::Config.get('endpoints.campaign_schedule'), campaign_id, schedule_id)
|
55
|
+
url = build_url(url)
|
56
|
+
response = RestClient.get(url, get_headers(access_token))
|
57
|
+
Components::Schedule.create(JSON.parse(response.body))
|
58
|
+
end
|
59
59
|
|
60
60
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
61
|
+
# Delete a specific schedule for a campaign
|
62
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
63
|
+
# @param [Integer] campaign_id - Campaign id to delete a schedule for
|
64
|
+
# @param [Integer] schedule_id - Schedule id to delete
|
65
|
+
# @return [Boolean]
|
66
|
+
def delete_schedule(access_token, campaign_id, schedule_id)
|
67
|
+
url = Util::Config.get('endpoints.base_url') +
|
68
|
+
sprintf(Util::Config.get('endpoints.campaign_schedule'), campaign_id, schedule_id)
|
69
|
+
url = build_url(url)
|
70
|
+
response = RestClient.delete(url, get_headers(access_token))
|
71
|
+
response.code == 204
|
72
|
+
end
|
73
73
|
|
74
74
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
75
|
+
# Update a specific schedule for a campaign
|
76
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
77
|
+
# @param [Integer] campaign_id - Campaign id to be scheduled
|
78
|
+
# @param [Schedule] schedule - Schedule to retrieve
|
79
|
+
# @return [Schedule]
|
80
|
+
def update_schedule(access_token, campaign_id, schedule)
|
81
|
+
url = Util::Config.get('endpoints.base_url') +
|
82
|
+
sprintf(Util::Config.get('endpoints.campaign_schedule'), campaign_id, schedule.id)
|
83
|
+
url = build_url(url)
|
84
|
+
payload = schedule.to_json
|
85
|
+
response = RestClient.put(url, payload, get_headers(access_token))
|
86
|
+
Components::Schedule.create(JSON.parse(response.body))
|
87
|
+
end
|
88
88
|
|
89
89
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
90
|
+
# Send a test send of a campaign
|
91
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
92
|
+
# @param [Integer] campaign_id - Id of campaign to send test of
|
93
|
+
# @param [TestSend] test_send - Test send details
|
94
|
+
# @return [TestSend]
|
95
|
+
def send_test(access_token, campaign_id, test_send)
|
96
|
+
url = Util::Config.get('endpoints.base_url') +
|
97
|
+
sprintf(Util::Config.get('endpoints.campaign_test_sends'), campaign_id)
|
98
|
+
url = build_url(url)
|
99
|
+
payload = test_send.to_json
|
100
|
+
response = RestClient.post(url, payload, get_headers(access_token))
|
101
|
+
Components::TestSend.create(JSON.parse(response.body))
|
102
|
+
end
|
103
103
|
|
104
|
-
|
105
|
-
|
106
|
-
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
107
|
end
|