constantcontact 1.0.0
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.
- checksums.yaml +7 -0
- data/.rspec +2 -0
- data/README.md +132 -0
- data/constantcontact.gemspec +32 -0
- data/lib/constantcontact.rb +75 -0
- data/lib/constantcontact/api.rb +541 -0
- data/lib/constantcontact/auth/oauth2.rb +82 -0
- data/lib/constantcontact/auth/session_data_store.rb +69 -0
- data/lib/constantcontact/components/account/verified_email_address.rb +27 -0
- data/lib/constantcontact/components/activities/activity.rb +44 -0
- data/lib/constantcontact/components/activities/activity_error.rb +27 -0
- data/lib/constantcontact/components/activities/add_contacts.rb +117 -0
- data/lib/constantcontact/components/activities/add_contacts_import_data.rb +45 -0
- data/lib/constantcontact/components/activities/export_contacts.rb +30 -0
- data/lib/constantcontact/components/component.rb +23 -0
- data/lib/constantcontact/components/contacts/address.rb +28 -0
- data/lib/constantcontact/components/contacts/contact.rb +86 -0
- data/lib/constantcontact/components/contacts/contact_list.rb +27 -0
- data/lib/constantcontact/components/contacts/custom_field.rb +27 -0
- data/lib/constantcontact/components/contacts/email_address.rb +34 -0
- data/lib/constantcontact/components/contacts/note.rb +25 -0
- data/lib/constantcontact/components/email_marketing/campaign.rb +83 -0
- data/lib/constantcontact/components/email_marketing/click_through_details.rb +28 -0
- data/lib/constantcontact/components/email_marketing/message_footer.rb +30 -0
- data/lib/constantcontact/components/email_marketing/schedule.rb +29 -0
- data/lib/constantcontact/components/email_marketing/test_send.rb +45 -0
- data/lib/constantcontact/components/result_set.rb +27 -0
- data/lib/constantcontact/components/tracking/bounce_activity.rb +29 -0
- data/lib/constantcontact/components/tracking/click_activity.rb +28 -0
- data/lib/constantcontact/components/tracking/forward_activity.rb +28 -0
- data/lib/constantcontact/components/tracking/open_activity.rb +28 -0
- data/lib/constantcontact/components/tracking/send_activity.rb +28 -0
- data/lib/constantcontact/components/tracking/tracking_activity.rb +27 -0
- data/lib/constantcontact/components/tracking/tracking_summary.rb +28 -0
- data/lib/constantcontact/components/tracking/unsubscribe_activity.rb +29 -0
- data/lib/constantcontact/exceptions/ctct_exception.rb +25 -0
- data/lib/constantcontact/exceptions/illegal_argument_exception.rb +11 -0
- data/lib/constantcontact/exceptions/oauth2_exception.rb +11 -0
- data/lib/constantcontact/services/account_service.rb +29 -0
- data/lib/constantcontact/services/activity_service.rb +107 -0
- data/lib/constantcontact/services/base_service.rb +37 -0
- data/lib/constantcontact/services/campaign_schedule_service.rb +107 -0
- data/lib/constantcontact/services/campaign_tracking_service.rb +159 -0
- data/lib/constantcontact/services/contact_service.rb +114 -0
- data/lib/constantcontact/services/contact_tracking_service.rb +159 -0
- data/lib/constantcontact/services/email_marketing_service.rb +87 -0
- data/lib/constantcontact/services/list_service.rb +85 -0
- data/lib/constantcontact/util/config.rb +140 -0
- data/lib/constantcontact/util/helpers.rb +27 -0
- data/lib/constantcontact/version.rb +12 -0
- data/spec/constantcontact/api_spec.rb +183 -0
- data/spec/constantcontact/auth/oauth2_spec.rb +48 -0
- data/spec/constantcontact/components/contacts/address_spec.rb +18 -0
- data/spec/constantcontact/components/contacts/contact_list_spec.rb +18 -0
- data/spec/constantcontact/components/contacts/contact_spec.rb +18 -0
- data/spec/constantcontact/components/contacts/custom_field_spec.rb +18 -0
- data/spec/constantcontact/components/contacts/email_address_spec.rb +18 -0
- data/spec/constantcontact/services/contact_service_spec.rb +105 -0
- data/spec/constantcontact/services/list_service_spec.rb +69 -0
- data/spec/spec_helper.rb +13 -0
- metadata +134 -0
@@ -0,0 +1,37 @@
|
|
1
|
+
#
|
2
|
+
# base_service.rb
|
3
|
+
# ConstantContact
|
4
|
+
#
|
5
|
+
# Copyright (c) 2013 Constant Contact. All rights reserved.
|
6
|
+
|
7
|
+
module ConstantContact
|
8
|
+
module Services
|
9
|
+
class BaseService
|
10
|
+
class << self
|
11
|
+
attr_accessor :api_key
|
12
|
+
|
13
|
+
protected
|
14
|
+
|
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
|
+
|
26
|
+
|
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
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
#
|
2
|
+
# campaign_schedule_service.rb
|
3
|
+
# ConstantContact
|
4
|
+
#
|
5
|
+
# Copyright (c) 2013 Constant Contact. All rights reserved.
|
6
|
+
|
7
|
+
module ConstantContact
|
8
|
+
module Services
|
9
|
+
class CampaignScheduleService < BaseService
|
10
|
+
class << self
|
11
|
+
|
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
|
+
|
26
|
+
|
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
|
+
|
38
|
+
schedules = []
|
39
|
+
body.each do |schedule|
|
40
|
+
schedules << Components::Schedule.create(schedule)
|
41
|
+
end
|
42
|
+
|
43
|
+
schedules
|
44
|
+
end
|
45
|
+
|
46
|
+
|
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
|
+
|
60
|
+
|
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
|
+
|
74
|
+
|
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
|
+
|
89
|
+
|
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
|
+
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,159 @@
|
|
1
|
+
#
|
2
|
+
# campaign_tracking_service.rb
|
3
|
+
# ConstantContact
|
4
|
+
#
|
5
|
+
# Copyright (c) 2013 Constant Contact. All rights reserved.
|
6
|
+
|
7
|
+
module ConstantContact
|
8
|
+
module Services
|
9
|
+
class CampaignTrackingService < BaseService
|
10
|
+
class << self
|
11
|
+
|
12
|
+
# Get a result set of bounces for a given campaign
|
13
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
14
|
+
# @param [String] campaign_id - Campaign id
|
15
|
+
# @param [Hash] param - query parameters to be appended to request
|
16
|
+
# @return [ResultSet<BounceActivity>] - Containing a results array of BounceActivity
|
17
|
+
def get_bounces(access_token, campaign_id, param = nil)
|
18
|
+
url = Util::Config.get('endpoints.base_url') +
|
19
|
+
sprintf(Util::Config.get('endpoints.campaign_tracking_bounces'), campaign_id)
|
20
|
+
url = build_url(url, param)
|
21
|
+
|
22
|
+
response = RestClient.get(url, get_headers(access_token))
|
23
|
+
body = JSON.parse(response.body)
|
24
|
+
|
25
|
+
bounces = []
|
26
|
+
body['results'].each do |bounce_activity|
|
27
|
+
bounces << Components::BounceActivity.create(bounce_activity)
|
28
|
+
end
|
29
|
+
|
30
|
+
Components::ResultSet.new(bounces, body['meta'])
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
# Get clicks for a given campaign
|
35
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
36
|
+
# @param [String] campaign_id - Campaign id
|
37
|
+
# @param [Hash] param - query parameters to be appended to request
|
38
|
+
# @return [ResultSet<ClickActivity>] - Containing a results array of ClickActivity
|
39
|
+
def get_clicks(access_token, campaign_id, param = nil)
|
40
|
+
url = Util::Config.get('endpoints.base_url') +
|
41
|
+
sprintf(Util::Config.get('endpoints.campaign_tracking_clicks'), campaign_id)
|
42
|
+
url = build_url(url, param)
|
43
|
+
|
44
|
+
response = RestClient.get(url, get_headers(access_token))
|
45
|
+
body = JSON.parse(response.body)
|
46
|
+
|
47
|
+
clicks = []
|
48
|
+
body['results'].each do |click_activity|
|
49
|
+
clicks << Components::ClickActivity.create(click_activity)
|
50
|
+
end
|
51
|
+
|
52
|
+
Components::ResultSet.new(clicks, body['meta'])
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
# Get forwards for a given campaign
|
57
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
58
|
+
# @param [String] campaign_id - Campaign id
|
59
|
+
# @param [Hash] param - query parameters to be appended to request
|
60
|
+
# @return [ResultSet<ForwardActivity>] - Containing a results array of ForwardActivity
|
61
|
+
def get_forwards(access_token, campaign_id, param = nil)
|
62
|
+
url = Util::Config.get('endpoints.base_url') +
|
63
|
+
sprintf(Util::Config.get('endpoints.campaign_tracking_forwards'), campaign_id)
|
64
|
+
url = build_url(url, param)
|
65
|
+
|
66
|
+
response = RestClient.get(url, get_headers(access_token))
|
67
|
+
body = JSON.parse(response.body)
|
68
|
+
|
69
|
+
forwards = []
|
70
|
+
body['results'].each do |forward_activity|
|
71
|
+
forwards << Components::ForwardActivity.create(forward_activity)
|
72
|
+
end
|
73
|
+
|
74
|
+
Components::ResultSet.new(forwards, body['meta'])
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
# Get opens for a given campaign
|
79
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
80
|
+
# @param [String] campaign_id - Campaign id
|
81
|
+
# @param [Hash] param - query parameters to be appended to request
|
82
|
+
# @return [ResultSet<OpenActivity>] - Containing a results array of OpenActivity
|
83
|
+
def get_opens(access_token, campaign_id, param = nil)
|
84
|
+
url = Util::Config.get('endpoints.base_url') +
|
85
|
+
sprintf(Util::Config.get('endpoints.campaign_tracking_opens'), campaign_id)
|
86
|
+
url = build_url(url, param)
|
87
|
+
|
88
|
+
response = RestClient.get(url, get_headers(access_token))
|
89
|
+
body = JSON.parse(response.body)
|
90
|
+
|
91
|
+
opens = []
|
92
|
+
body['results'].each do |open_activity|
|
93
|
+
opens << Components::OpenActivity.create(open_activity)
|
94
|
+
end
|
95
|
+
|
96
|
+
Components::ResultSet.new(opens, body['meta'])
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
# Get sends for a given campaign
|
101
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
102
|
+
# @param [String] campaign_id - Campaign id
|
103
|
+
# @param [Hash] param - query parameters to be appended to request
|
104
|
+
# @return [ResultSet<SendActivity>] - Containing a results array of SendActivity
|
105
|
+
def get_sends(access_token, campaign_id, param = nil)
|
106
|
+
url = Util::Config.get('endpoints.base_url') +
|
107
|
+
sprintf(Util::Config.get('endpoints.campaign_tracking_sends'), campaign_id)
|
108
|
+
url = build_url(url, param)
|
109
|
+
|
110
|
+
response = RestClient.get(url, get_headers(access_token))
|
111
|
+
body = JSON.parse(response.body)
|
112
|
+
|
113
|
+
sends = []
|
114
|
+
body['results'].each do |send_activity|
|
115
|
+
sends << Components::SendActivity.create(send_activity)
|
116
|
+
end
|
117
|
+
|
118
|
+
Components::ResultSet.new(sends, body['meta'])
|
119
|
+
end
|
120
|
+
|
121
|
+
|
122
|
+
# Get unsubscribes for a given campaign
|
123
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
124
|
+
# @param [String] campaign_id - Campaign id
|
125
|
+
# @param [Hash] param - query params to be appended to request
|
126
|
+
# @return [ResultSet<UnsubscribeActivity>] - Containing a results array of UnsubscribeActivity
|
127
|
+
def get_unsubscribes(access_token, campaign_id, param = nil)
|
128
|
+
url = Util::Config.get('endpoints.base_url') +
|
129
|
+
sprintf(Util::Config.get('endpoints.campaign_tracking_unsubscribes'), campaign_id)
|
130
|
+
url = build_url(url, param)
|
131
|
+
|
132
|
+
response = RestClient.get(url, get_headers(access_token))
|
133
|
+
body = JSON.parse(response.body)
|
134
|
+
|
135
|
+
unsubscribes = []
|
136
|
+
body['results'].each do |unsubscribe_activity|
|
137
|
+
unsubscribes[] = Components::UnsubscribeActivity.create(unsubscribe_activity)
|
138
|
+
end
|
139
|
+
|
140
|
+
Components::ResultSet.new(unsubscribes, body['meta'])
|
141
|
+
end
|
142
|
+
|
143
|
+
|
144
|
+
# Get a summary of reporting data for a given campaign
|
145
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
146
|
+
# @param [Integer] campaign_id - Campaign id
|
147
|
+
# @return [TrackingSummary]
|
148
|
+
def get_summary(access_token, campaign_id)
|
149
|
+
url = Util::Config.get('endpoints.base_url') +
|
150
|
+
sprintf(Util::Config.get('endpoints.campaign_tracking_summary'), campaign_id)
|
151
|
+
url = build_url(url)
|
152
|
+
response = RestClient.get(url, get_headers(access_token))
|
153
|
+
Components::TrackingSummary.create(JSON.parse(response.body))
|
154
|
+
end
|
155
|
+
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
#
|
2
|
+
# contact_service.rb
|
3
|
+
# ConstantContact
|
4
|
+
#
|
5
|
+
# Copyright (c) 2013 Constant Contact. All rights reserved.
|
6
|
+
|
7
|
+
module ConstantContact
|
8
|
+
module Services
|
9
|
+
class ContactService < BaseService
|
10
|
+
class << self
|
11
|
+
|
12
|
+
# Get an array of contacts
|
13
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
14
|
+
# @param [Hash] param - query parameters to be appended to the request
|
15
|
+
# @return [ResultSet<Contact>]
|
16
|
+
def get_contacts(access_token, param = nil)
|
17
|
+
url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.contacts')
|
18
|
+
url = build_url(url, param)
|
19
|
+
|
20
|
+
response = RestClient.get(url, get_headers(access_token))
|
21
|
+
body = JSON.parse(response.body)
|
22
|
+
|
23
|
+
contacts = []
|
24
|
+
body['results'].each do |contact|
|
25
|
+
contacts << Components::Contact.create(contact)
|
26
|
+
end
|
27
|
+
|
28
|
+
Components::ResultSet.new(contacts, body['meta'])
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
# Get contact details for a specific contact
|
33
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
34
|
+
# @param [Integer] contact_id - Unique contact id
|
35
|
+
# @return [Contact]
|
36
|
+
def get_contact(access_token, contact_id)
|
37
|
+
url = Util::Config.get('endpoints.base_url') +
|
38
|
+
sprintf(Util::Config.get('endpoints.contact'), contact_id)
|
39
|
+
url = build_url(url)
|
40
|
+
response = RestClient.get(url, get_headers(access_token))
|
41
|
+
Components::Contact.create(JSON.parse(response.body))
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
# Add a new contact to the Constant Contact account
|
46
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
47
|
+
# @param [Contact] contact - Contact to add
|
48
|
+
# @param [Boolean] action_by_visitor - is the action being taken by the visitor
|
49
|
+
# @return [Contact]
|
50
|
+
def add_contact(access_token, contact, action_by_visitor = false)
|
51
|
+
url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.contacts')
|
52
|
+
param = action_by_visitor ? {'action_by' => 'ACTION_BY_VISITOR'} : nil
|
53
|
+
url = build_url(url, param)
|
54
|
+
payload = contact.to_json
|
55
|
+
response = RestClient.post(url, payload, get_headers(access_token))
|
56
|
+
Components::Contact.create(JSON.parse(response.body))
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
# Delete contact details for a specific contact
|
61
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
62
|
+
# @param [Integer] contact_id - Unique contact id
|
63
|
+
# @return [Boolean]
|
64
|
+
def delete_contact(access_token, contact_id)
|
65
|
+
url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.contact'), contact_id)
|
66
|
+
url = build_url(url)
|
67
|
+
response = RestClient.delete(url, get_headers(access_token))
|
68
|
+
response.code == 204
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
# Delete a contact from all contact lists
|
73
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
74
|
+
# @param [Integer] contact_id - Contact id to be removed from lists
|
75
|
+
# @return [Boolean]
|
76
|
+
def delete_contact_from_lists(access_token, contact_id)
|
77
|
+
url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.contact_lists'), contact_id)
|
78
|
+
url = build_url(url)
|
79
|
+
response = RestClient.delete(url, get_headers(access_token))
|
80
|
+
response.code == 204
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
# Delete a contact from a specific contact list
|
85
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
86
|
+
# @param [Integer] contact_id - Contact id to be removed
|
87
|
+
# @param [Integer] list_id - ContactList to remove the contact from
|
88
|
+
# @return [Boolean]
|
89
|
+
def delete_contact_from_list(access_token, contact_id, list_id)
|
90
|
+
url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.contact_list'), contact_id, list_id)
|
91
|
+
url = build_url(url)
|
92
|
+
response = RestClient.delete(url, get_headers(access_token))
|
93
|
+
response.code == 204
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
# Update contact details for a specific contact
|
98
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
99
|
+
# @param [Contact] contact - Contact to be updated
|
100
|
+
# @param [Boolean] action_by_visitor - is the action being taken by the visitor
|
101
|
+
# @return [Contact]
|
102
|
+
def update_contact(access_token, contact, action_by_visitor = false)
|
103
|
+
url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.contact'), contact.id)
|
104
|
+
param = action_by_visitor ? {'action_by' => 'ACTION_BY_VISITOR'} : nil
|
105
|
+
url = build_url(url, param)
|
106
|
+
payload = contact.to_json
|
107
|
+
response = RestClient.put(url, payload, get_headers(access_token))
|
108
|
+
Components::Contact.create(JSON.parse(response.body))
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,159 @@
|
|
1
|
+
#
|
2
|
+
# contact_tracking_service.rb
|
3
|
+
# ConstantContact
|
4
|
+
#
|
5
|
+
# Copyright (c) 2013 Constant Contact. All rights reserved.
|
6
|
+
|
7
|
+
module ConstantContact
|
8
|
+
module Services
|
9
|
+
class ContactTrackingService < BaseService
|
10
|
+
class << self
|
11
|
+
|
12
|
+
# Get a result set of bounces for a given contact
|
13
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
14
|
+
# @param [String] contact_id - Contact id
|
15
|
+
# @param [Hash] param - query parameters to be appended to request
|
16
|
+
# @return [ResultSet<BounceActivity>] - Containing a results array of BounceActivity
|
17
|
+
def get_bounces(access_token, contact_id, param = nil)
|
18
|
+
url = Util::Config.get('endpoints.base_url') +
|
19
|
+
sprintf(Util::Config.get('endpoints.contact_tracking_bounces'), contact_id)
|
20
|
+
url = build_url(url, param)
|
21
|
+
|
22
|
+
response = RestClient.get(url, get_headers(access_token))
|
23
|
+
body = JSON.parse(response.body)
|
24
|
+
|
25
|
+
bounces = []
|
26
|
+
body['results'].each do |bounce_activity|
|
27
|
+
bounces << Components::BounceActivity.create(bounce_activity)
|
28
|
+
end
|
29
|
+
|
30
|
+
Components::ResultSet.new(bounces, body['meta'])
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
# Get clicks for a given contact
|
35
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
36
|
+
# @param [String] contact_id - Contact id
|
37
|
+
# @param [Hash] param - query parameters to be appended to request
|
38
|
+
# @return [ResultSet<ClickActivity>] - Containing a results array of ClickActivity
|
39
|
+
def get_clicks(access_token, contact_id, param = nil)
|
40
|
+
url = Util::Config.get('endpoints.base_url') +
|
41
|
+
sprintf(Util::Config.get('endpoints.contact_tracking_clicks'), contact_id)
|
42
|
+
url = build_url(url, param)
|
43
|
+
|
44
|
+
response = RestClient.get(url, get_headers(access_token))
|
45
|
+
body = JSON.parse(response.body)
|
46
|
+
|
47
|
+
clicks = []
|
48
|
+
body['results'].each do |click_activity|
|
49
|
+
clicks << Components::ClickActivity.create(click_activity)
|
50
|
+
end
|
51
|
+
|
52
|
+
Components::ResultSet.new(clicks, body['meta'])
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
# Get forwards for a given contact
|
57
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
58
|
+
# @param [String] contact_id - Contact id
|
59
|
+
# @param [Hash] param - query parameters to be appended to request
|
60
|
+
# @return [ResultSet<ForwardActivity>] - Containing a results array of ForwardActivity
|
61
|
+
def get_forwards(access_token, contact_id, param = nil)
|
62
|
+
url = Util::Config.get('endpoints.base_url') +
|
63
|
+
sprintf(Util::Config.get('endpoints.contact_tracking_forwards'), contact_id)
|
64
|
+
url = build_url(url, param)
|
65
|
+
|
66
|
+
response = RestClient.get(url, get_headers(access_token))
|
67
|
+
body = JSON.parse(response.body)
|
68
|
+
|
69
|
+
forwards = []
|
70
|
+
body['results'].each do |forward_activity|
|
71
|
+
forwards << Components::ForwardActivity.create(forward_activity)
|
72
|
+
end
|
73
|
+
|
74
|
+
Components::ResultSet.new(forwards, body['meta'])
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
# Get opens for a given contact
|
79
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
80
|
+
# @param [String] contact_id - Contact id
|
81
|
+
# @param [Hash] param - query parameters to be appended to request
|
82
|
+
# @return [ResultSet<OpenActivity>] - Containing a results array of OpenActivity
|
83
|
+
def get_opens(access_token, contact_id, param = nil)
|
84
|
+
url = Util::Config.get('endpoints.base_url') +
|
85
|
+
sprintf(Util::Config.get('endpoints.contact_tracking_opens'), contact_id)
|
86
|
+
url = build_url(url, param)
|
87
|
+
|
88
|
+
response = RestClient.get(url, get_headers(access_token))
|
89
|
+
body = JSON.parse(response.body)
|
90
|
+
|
91
|
+
opens = []
|
92
|
+
body['results'].each do |open_activity|
|
93
|
+
opens << Components::OpenActivity.create(open_activity)
|
94
|
+
end
|
95
|
+
|
96
|
+
Components::ResultSet.new(opens, body['meta'])
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
# Get sends for a given contact
|
101
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
102
|
+
# @param [String] contact_id - Contact id
|
103
|
+
# @param [Hash] param - query parameters to be appended to request
|
104
|
+
# @return [ResultSet<SendActivity>] - Containing a results array of SendActivity
|
105
|
+
def get_sends(access_token, contact_id, param = nil)
|
106
|
+
url = Util::Config.get('endpoints.base_url') +
|
107
|
+
sprintf(Util::Config.get('endpoints.contact_tracking_sends'), contact_id)
|
108
|
+
url = build_url(url, param)
|
109
|
+
|
110
|
+
response = RestClient.get(url, get_headers(access_token))
|
111
|
+
body = JSON.parse(response.body)
|
112
|
+
|
113
|
+
sends = []
|
114
|
+
body['results'].each do |send_activity|
|
115
|
+
sends << Components::SendActivity.create(send_activity)
|
116
|
+
end
|
117
|
+
|
118
|
+
Components::ResultSet.new(sends, body['meta'])
|
119
|
+
end
|
120
|
+
|
121
|
+
|
122
|
+
# Get unsubscribes for a given contact
|
123
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
124
|
+
# @param [String] contact_id - Contact id
|
125
|
+
# @param [Hash] param - query parameters to be appended to request
|
126
|
+
# @return [ResultSet<UnsubscribeActivity>] - Containing a results array of UnsubscribeActivity
|
127
|
+
def get_unsubscribes(access_token, contact_id, param = nil)
|
128
|
+
url = Util::Config.get('endpoints.base_url') +
|
129
|
+
sprintf(Util::Config.get('endpoints.contact_tracking_unsubscribes'), contact_id)
|
130
|
+
url = build_url(url, param)
|
131
|
+
|
132
|
+
response = RestClient.get(url, get_headers(access_token))
|
133
|
+
body = JSON.parse(response.body)
|
134
|
+
|
135
|
+
unsubscribes = []
|
136
|
+
body['results'].each do |unsubscribe_activity|
|
137
|
+
unsubscribes[] = Components::UnsubscribeActivity.create(unsubscribe_activity)
|
138
|
+
end
|
139
|
+
|
140
|
+
Components::ResultSet.new(unsubscribes, body['meta'])
|
141
|
+
end
|
142
|
+
|
143
|
+
|
144
|
+
# Get a summary of reporting data for a given contact
|
145
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
146
|
+
# @param [String] contact_id - Contact id
|
147
|
+
# @return [TrackingSummary]
|
148
|
+
def get_summary(access_token, contact_id)
|
149
|
+
url = Util::Config.get('endpoints.base_url') +
|
150
|
+
sprintf(Util::Config.get('endpoints.contact_tracking_summary'), contact_id)
|
151
|
+
url = build_url(url)
|
152
|
+
response = RestClient.get(url, get_headers(access_token))
|
153
|
+
Components::TrackingSummary.create(JSON.parse(response.body))
|
154
|
+
end
|
155
|
+
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|