constantcontact-ruby 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +2 -0
- data/README.md +136 -0
- data/constantcontact-ruby.gemspec +31 -0
- data/lib/constantcontact/api.rb +1012 -0
- data/lib/constantcontact/auth/oauth2.rb +105 -0
- data/lib/constantcontact/auth/session_data_store.rb +69 -0
- data/lib/constantcontact/components/account/account_address.rb +26 -0
- data/lib/constantcontact/components/account/account_info.rb +38 -0
- data/lib/constantcontact/components/account/verified_email_address.rb +26 -0
- data/lib/constantcontact/components/activities/activity.rb +43 -0
- data/lib/constantcontact/components/activities/activity_error.rb +26 -0
- data/lib/constantcontact/components/activities/add_contacts.rb +127 -0
- data/lib/constantcontact/components/activities/add_contacts_import_data.rb +46 -0
- data/lib/constantcontact/components/activities/export_contacts.rb +30 -0
- data/lib/constantcontact/components/component.rb +48 -0
- data/lib/constantcontact/components/contacts/address.rb +27 -0
- data/lib/constantcontact/components/contacts/contact.rb +92 -0
- data/lib/constantcontact/components/contacts/contact_list.rb +26 -0
- data/lib/constantcontact/components/contacts/custom_field.rb +26 -0
- data/lib/constantcontact/components/contacts/email_address.rb +33 -0
- data/lib/constantcontact/components/contacts/note.rb +26 -0
- data/lib/constantcontact/components/email_marketing/campaign.rb +83 -0
- data/lib/constantcontact/components/email_marketing/campaign_preview.rb +29 -0
- data/lib/constantcontact/components/email_marketing/click_through_details.rb +27 -0
- data/lib/constantcontact/components/email_marketing/message_footer.rb +29 -0
- data/lib/constantcontact/components/email_marketing/schedule.rb +27 -0
- data/lib/constantcontact/components/email_marketing/test_send.rb +45 -0
- data/lib/constantcontact/components/event_spot/contact.rb +27 -0
- data/lib/constantcontact/components/event_spot/event.rb +69 -0
- data/lib/constantcontact/components/event_spot/event_address.rb +29 -0
- data/lib/constantcontact/components/event_spot/event_fee.rb +27 -0
- data/lib/constantcontact/components/event_spot/event_item.rb +36 -0
- data/lib/constantcontact/components/event_spot/event_item_attribute.rb +26 -0
- data/lib/constantcontact/components/event_spot/event_track.rb +31 -0
- data/lib/constantcontact/components/event_spot/guest.rb +31 -0
- data/lib/constantcontact/components/event_spot/guest_section.rb +34 -0
- data/lib/constantcontact/components/event_spot/notification_option.rb +27 -0
- data/lib/constantcontact/components/event_spot/online_meeting.rb +28 -0
- data/lib/constantcontact/components/event_spot/payment_address.rb +29 -0
- data/lib/constantcontact/components/event_spot/payment_summary.rb +33 -0
- data/lib/constantcontact/components/event_spot/promocode.rb +25 -0
- data/lib/constantcontact/components/event_spot/registrant.rb +52 -0
- data/lib/constantcontact/components/event_spot/registrant_fee.rb +29 -0
- data/lib/constantcontact/components/event_spot/registrant_field.rb +27 -0
- data/lib/constantcontact/components/event_spot/registrant_order.rb +39 -0
- data/lib/constantcontact/components/event_spot/registrant_promo_code.rb +31 -0
- data/lib/constantcontact/components/event_spot/registrant_promo_code_info.rb +27 -0
- data/lib/constantcontact/components/event_spot/registrant_section.rb +34 -0
- data/lib/constantcontact/components/event_spot/sale_item.rb +29 -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/result_set.rb +50 -0
- data/lib/constantcontact/components/tracking/bounce_activity.rb +28 -0
- data/lib/constantcontact/components/tracking/click_activity.rb +26 -0
- data/lib/constantcontact/components/tracking/forward_activity.rb +26 -0
- data/lib/constantcontact/components/tracking/open_activity.rb +26 -0
- data/lib/constantcontact/components/tracking/send_activity.rb +27 -0
- data/lib/constantcontact/components/tracking/tracking_activity.rb +26 -0
- data/lib/constantcontact/components/tracking/tracking_summary.rb +27 -0
- data/lib/constantcontact/components/tracking/unsubscribe_activity.rb +27 -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/exceptions/webhooks_exception.rb +11 -0
- data/lib/constantcontact/services/account_service.rb +39 -0
- data/lib/constantcontact/services/activity_service.rb +136 -0
- data/lib/constantcontact/services/base_service.rb +68 -0
- data/lib/constantcontact/services/campaign_schedule_service.rb +101 -0
- data/lib/constantcontact/services/campaign_tracking_service.rb +152 -0
- data/lib/constantcontact/services/contact_service.rb +105 -0
- data/lib/constantcontact/services/contact_tracking_service.rb +152 -0
- data/lib/constantcontact/services/email_marketing_service.rb +94 -0
- data/lib/constantcontact/services/event_spot_service.rb +448 -0
- data/lib/constantcontact/services/library_service.rb +281 -0
- data/lib/constantcontact/services/list_service.rb +81 -0
- data/lib/constantcontact/util/config.rb +180 -0
- data/lib/constantcontact/util/helpers.rb +27 -0
- data/lib/constantcontact/version.rb +12 -0
- data/lib/constantcontact/webhooks/helpers/validator.rb +30 -0
- data/lib/constantcontact/webhooks/models/billing_change_notification.rb +27 -0
- data/lib/constantcontact/webhooks/webhooks_util.rb +45 -0
- data/lib/constantcontact.rb +124 -0
- data/spec/constantcontact/api_spec.rb +1560 -0
- data/spec/constantcontact/auth/oauth2_spec.rb +125 -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/sdk_spec.rb +24 -0
- data/spec/constantcontact/services/account_service_spec.rb +46 -0
- data/spec/constantcontact/services/activity_service_spec.rb +244 -0
- data/spec/constantcontact/services/base_service_spec.rb +50 -0
- data/spec/constantcontact/services/campaign_schedule_service_spec.rb +115 -0
- data/spec/constantcontact/services/campaign_tracking_service_spec.rb +131 -0
- data/spec/constantcontact/services/contact_service_spec.rb +111 -0
- data/spec/constantcontact/services/contact_tracking_service_spec.rb +131 -0
- data/spec/constantcontact/services/email_marketing_spec.rb +100 -0
- data/spec/constantcontact/services/event_spot_spec.rb +423 -0
- data/spec/constantcontact/services/library_service_spec.rb +252 -0
- data/spec/constantcontact/services/list_service_spec.rb +89 -0
- data/spec/constantcontact/webhooks/webhooks_spec.rb +26 -0
- metadata +243 -0
@@ -0,0 +1,152 @@
|
|
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 bounces for a given campaign
|
13
|
+
# @param [String] campaign_id - Campaign id
|
14
|
+
# @param [Hash] params - query parameters to be appended to request
|
15
|
+
# @return [ResultSet<BounceActivity>] - Containing a results array of BounceActivity
|
16
|
+
def get_bounces(campaign_id, params = {})
|
17
|
+
url = Util::Config.get('endpoints.base_url') +
|
18
|
+
sprintf(Util::Config.get('endpoints.campaign_tracking_bounces'), campaign_id)
|
19
|
+
url = build_url(url, params)
|
20
|
+
|
21
|
+
response = RestClient.get(url, get_headers())
|
22
|
+
body = JSON.parse(response.body)
|
23
|
+
|
24
|
+
bounces = []
|
25
|
+
body['results'].each do |bounce_activity|
|
26
|
+
bounces << Components::BounceActivity.create(bounce_activity)
|
27
|
+
end
|
28
|
+
|
29
|
+
Components::ResultSet.new(bounces, body['meta'])
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
# Get clicks for a given campaign
|
34
|
+
# @param [String] campaign_id - Campaign id
|
35
|
+
# @param [Hash] params - query parameters to be appended to request
|
36
|
+
# @return [ResultSet<ClickActivity>] - Containing a results array of ClickActivity
|
37
|
+
def get_clicks(campaign_id, params = {})
|
38
|
+
url = Util::Config.get('endpoints.base_url') +
|
39
|
+
sprintf(Util::Config.get('endpoints.campaign_tracking_clicks'), campaign_id)
|
40
|
+
url = build_url(url, params)
|
41
|
+
|
42
|
+
response = RestClient.get(url, get_headers())
|
43
|
+
body = JSON.parse(response.body)
|
44
|
+
|
45
|
+
clicks = []
|
46
|
+
body['results'].each do |click_activity|
|
47
|
+
clicks << Components::ClickActivity.create(click_activity)
|
48
|
+
end
|
49
|
+
|
50
|
+
Components::ResultSet.new(clicks, body['meta'])
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
# Get forwards for a given campaign
|
55
|
+
# @param [String] campaign_id - Campaign id
|
56
|
+
# @param [Hash] params - query parameters to be appended to request
|
57
|
+
# @return [ResultSet<ForwardActivity>] - Containing a results array of ForwardActivity
|
58
|
+
def get_forwards(campaign_id, params = {})
|
59
|
+
url = Util::Config.get('endpoints.base_url') +
|
60
|
+
sprintf(Util::Config.get('endpoints.campaign_tracking_forwards'), campaign_id)
|
61
|
+
url = build_url(url, params)
|
62
|
+
|
63
|
+
response = RestClient.get(url, get_headers())
|
64
|
+
body = JSON.parse(response.body)
|
65
|
+
|
66
|
+
forwards = []
|
67
|
+
body['results'].each do |forward_activity|
|
68
|
+
forwards << Components::ForwardActivity.create(forward_activity)
|
69
|
+
end
|
70
|
+
|
71
|
+
Components::ResultSet.new(forwards, body['meta'])
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
# Get opens for a given campaign
|
76
|
+
# @param [String] campaign_id - Campaign id
|
77
|
+
# @param [Hash] params - query parameters to be appended to request
|
78
|
+
# @return [ResultSet<OpenActivity>] - Containing a results array of OpenActivity
|
79
|
+
def get_opens(campaign_id, params = {})
|
80
|
+
url = Util::Config.get('endpoints.base_url') +
|
81
|
+
sprintf(Util::Config.get('endpoints.campaign_tracking_opens'), campaign_id)
|
82
|
+
url = build_url(url, params)
|
83
|
+
|
84
|
+
response = RestClient.get(url, get_headers())
|
85
|
+
body = JSON.parse(response.body)
|
86
|
+
|
87
|
+
opens = []
|
88
|
+
body['results'].each do |open_activity|
|
89
|
+
opens << Components::OpenActivity.create(open_activity)
|
90
|
+
end
|
91
|
+
|
92
|
+
Components::ResultSet.new(opens, body['meta'])
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
# Get sends for a given campaign
|
97
|
+
# @param [String] campaign_id - Campaign id
|
98
|
+
# @param [Hash] params - query parameters to be appended to request
|
99
|
+
# @return [ResultSet<SendActivity>] - Containing a results array of SendActivity
|
100
|
+
def get_sends(campaign_id, params = {})
|
101
|
+
url = Util::Config.get('endpoints.base_url') +
|
102
|
+
sprintf(Util::Config.get('endpoints.campaign_tracking_sends'), campaign_id)
|
103
|
+
url = build_url(url, params)
|
104
|
+
|
105
|
+
response = RestClient.get(url, get_headers())
|
106
|
+
body = JSON.parse(response.body)
|
107
|
+
|
108
|
+
sends = []
|
109
|
+
body['results'].each do |send_activity|
|
110
|
+
sends << Components::SendActivity.create(send_activity)
|
111
|
+
end
|
112
|
+
|
113
|
+
Components::ResultSet.new(sends, body['meta'])
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
# Get unsubscribes for a given campaign
|
118
|
+
# @param [String] campaign_id - Campaign id
|
119
|
+
# @param [Hash] params - query params to be appended to request
|
120
|
+
# @return [ResultSet<UnsubscribeActivity>] - Containing a results array of UnsubscribeActivity
|
121
|
+
def get_unsubscribes(campaign_id, params = {})
|
122
|
+
url = Util::Config.get('endpoints.base_url') +
|
123
|
+
sprintf(Util::Config.get('endpoints.campaign_tracking_unsubscribes'), campaign_id)
|
124
|
+
url = build_url(url, params)
|
125
|
+
|
126
|
+
response = RestClient.get(url, get_headers())
|
127
|
+
body = JSON.parse(response.body)
|
128
|
+
|
129
|
+
unsubscribes = []
|
130
|
+
body['results'].each do |unsubscribe_activity|
|
131
|
+
unsubscribes << Components::UnsubscribeActivity.create(unsubscribe_activity)
|
132
|
+
end
|
133
|
+
|
134
|
+
Components::ResultSet.new(unsubscribes, body['meta'])
|
135
|
+
end
|
136
|
+
|
137
|
+
|
138
|
+
# Get a summary of reporting data for a given campaign
|
139
|
+
# @param [Integer] campaign_id - Campaign id
|
140
|
+
# @return [TrackingSummary]
|
141
|
+
def get_summary(campaign_id)
|
142
|
+
url = Util::Config.get('endpoints.base_url') +
|
143
|
+
sprintf(Util::Config.get('endpoints.campaign_tracking_summary'), campaign_id)
|
144
|
+
url = build_url(url)
|
145
|
+
response = RestClient.get(url, get_headers())
|
146
|
+
Components::TrackingSummary.create(JSON.parse(response.body))
|
147
|
+
end
|
148
|
+
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
@@ -0,0 +1,105 @@
|
|
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 [Hash] params - query parameters to be appended to the request
|
14
|
+
# @return [ResultSet<Contact>]
|
15
|
+
def get_contacts(params = {})
|
16
|
+
url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.contacts')
|
17
|
+
url = build_url(url, params)
|
18
|
+
|
19
|
+
response = RestClient.get(url, get_headers())
|
20
|
+
body = JSON.parse(response.body)
|
21
|
+
|
22
|
+
contacts = []
|
23
|
+
body['results'].each do |contact|
|
24
|
+
contacts << Components::Contact.create(contact)
|
25
|
+
end
|
26
|
+
|
27
|
+
Components::ResultSet.new(contacts, body['meta'])
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
# Get contact details for a specific contact
|
32
|
+
# @param [Integer] contact_id - Unique contact id
|
33
|
+
# @return [Contact]
|
34
|
+
def get_contact(contact_id)
|
35
|
+
url = Util::Config.get('endpoints.base_url') +
|
36
|
+
sprintf(Util::Config.get('endpoints.contact'), contact_id)
|
37
|
+
url = build_url(url)
|
38
|
+
response = RestClient.get(url, get_headers())
|
39
|
+
Components::Contact.create(JSON.parse(response.body))
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
# Add a new contact to the Constant Contact account
|
44
|
+
# @param [Contact] contact - Contact to add
|
45
|
+
# @param [Boolean] params - query params to be appended to the request
|
46
|
+
# @return [Contact]
|
47
|
+
def add_contact(contact, params = {})
|
48
|
+
url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.contacts')
|
49
|
+
url = build_url(url, params)
|
50
|
+
payload = contact.to_json
|
51
|
+
response = RestClient.post(url, payload, get_headers())
|
52
|
+
Components::Contact.create(JSON.parse(response.body))
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
# Delete contact details for a specific contact
|
57
|
+
# @param [Integer] contact_id - Unique contact id
|
58
|
+
# @return [Boolean]
|
59
|
+
def delete_contact(contact_id)
|
60
|
+
url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.contact'), contact_id)
|
61
|
+
url = build_url(url)
|
62
|
+
response = RestClient.delete(url, get_headers())
|
63
|
+
response.code == 204
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
# Delete a contact from all contact lists
|
68
|
+
# @param [Integer] contact_id - Contact id to be removed from lists
|
69
|
+
# @return [Boolean]
|
70
|
+
def delete_contact_from_lists(contact_id)
|
71
|
+
url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.contact_lists'), contact_id)
|
72
|
+
url = build_url(url)
|
73
|
+
response = RestClient.delete(url, get_headers())
|
74
|
+
response.code == 204
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
# Delete a contact from a specific contact list
|
79
|
+
# @param [Integer] contact_id - Contact id to be removed
|
80
|
+
# @param [Integer] list_id - ContactList id to remove the contact from
|
81
|
+
# @return [Boolean]
|
82
|
+
def delete_contact_from_list(contact_id, list_id)
|
83
|
+
url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.contact_list'), contact_id, list_id)
|
84
|
+
url = build_url(url)
|
85
|
+
response = RestClient.delete(url, get_headers())
|
86
|
+
response.code == 204
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
# Update contact details for a specific contact
|
91
|
+
# @param [Contact] contact - Contact to be updated
|
92
|
+
# @param [Hash] params - query params to be appended to the request
|
93
|
+
# @return [Contact]
|
94
|
+
def update_contact(contact, params = {})
|
95
|
+
url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.contact'), contact.id)
|
96
|
+
url = build_url(url, params)
|
97
|
+
payload = contact.to_json
|
98
|
+
response = RestClient.put(url, payload, get_headers())
|
99
|
+
Components::Contact.create(JSON.parse(response.body))
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,152 @@
|
|
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 bounces for a given contact
|
13
|
+
# @param [String] contact_id - Contact id
|
14
|
+
# @param [Hash] params - query parameters to be appended to request
|
15
|
+
# @return [ResultSet<BounceActivity>] - Containing a results array of BounceActivity
|
16
|
+
def get_bounces(contact_id, params = {})
|
17
|
+
url = Util::Config.get('endpoints.base_url') +
|
18
|
+
sprintf(Util::Config.get('endpoints.contact_tracking_bounces'), contact_id)
|
19
|
+
url = build_url(url, params)
|
20
|
+
|
21
|
+
response = RestClient.get(url, get_headers())
|
22
|
+
body = JSON.parse(response.body)
|
23
|
+
|
24
|
+
bounces = []
|
25
|
+
body['results'].each do |bounce_activity|
|
26
|
+
bounces << Components::BounceActivity.create(bounce_activity)
|
27
|
+
end
|
28
|
+
|
29
|
+
Components::ResultSet.new(bounces, body['meta'])
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
# Get clicks for a given contact
|
34
|
+
# @param [String] contact_id - Contact id
|
35
|
+
# @param [Hash] params - query parameters to be appended to request
|
36
|
+
# @return [ResultSet<ClickActivity>] - Containing a results array of ClickActivity
|
37
|
+
def get_clicks(contact_id, params = {})
|
38
|
+
url = Util::Config.get('endpoints.base_url') +
|
39
|
+
sprintf(Util::Config.get('endpoints.contact_tracking_clicks'), contact_id)
|
40
|
+
url = build_url(url, params)
|
41
|
+
|
42
|
+
response = RestClient.get(url, get_headers())
|
43
|
+
body = JSON.parse(response.body)
|
44
|
+
|
45
|
+
clicks = []
|
46
|
+
body['results'].each do |click_activity|
|
47
|
+
clicks << Components::ClickActivity.create(click_activity)
|
48
|
+
end
|
49
|
+
|
50
|
+
Components::ResultSet.new(clicks, body['meta'])
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
# Get forwards for a given contact
|
55
|
+
# @param [String] contact_id - Contact id
|
56
|
+
# @param [Hash] params - query parameters to be appended to request
|
57
|
+
# @return [ResultSet<ForwardActivity>] - Containing a results array of ForwardActivity
|
58
|
+
def get_forwards(contact_id, params = {})
|
59
|
+
url = Util::Config.get('endpoints.base_url') +
|
60
|
+
sprintf(Util::Config.get('endpoints.contact_tracking_forwards'), contact_id)
|
61
|
+
url = build_url(url, params)
|
62
|
+
|
63
|
+
response = RestClient.get(url, get_headers())
|
64
|
+
body = JSON.parse(response.body)
|
65
|
+
|
66
|
+
forwards = []
|
67
|
+
body['results'].each do |forward_activity|
|
68
|
+
forwards << Components::ForwardActivity.create(forward_activity)
|
69
|
+
end
|
70
|
+
|
71
|
+
Components::ResultSet.new(forwards, body['meta'])
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
# Get opens for a given contact
|
76
|
+
# @param [String] contact_id - Contact id
|
77
|
+
# @param [Hash] params - query parameters to be appended to request
|
78
|
+
# @return [ResultSet<OpenActivity>] - Containing a results array of OpenActivity
|
79
|
+
def get_opens(contact_id, params = {})
|
80
|
+
url = Util::Config.get('endpoints.base_url') +
|
81
|
+
sprintf(Util::Config.get('endpoints.contact_tracking_opens'), contact_id)
|
82
|
+
url = build_url(url, params)
|
83
|
+
|
84
|
+
response = RestClient.get(url, get_headers())
|
85
|
+
body = JSON.parse(response.body)
|
86
|
+
|
87
|
+
opens = []
|
88
|
+
body['results'].each do |open_activity|
|
89
|
+
opens << Components::OpenActivity.create(open_activity)
|
90
|
+
end
|
91
|
+
|
92
|
+
Components::ResultSet.new(opens, body['meta'])
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
# Get sends for a given contact
|
97
|
+
# @param [String] contact_id - Contact id
|
98
|
+
# @param [Hash] params - query parameters to be appended to request
|
99
|
+
# @return [ResultSet<SendActivity>] - Containing a results array of SendActivity
|
100
|
+
def get_sends(contact_id, params = {})
|
101
|
+
url = Util::Config.get('endpoints.base_url') +
|
102
|
+
sprintf(Util::Config.get('endpoints.contact_tracking_sends'), contact_id)
|
103
|
+
url = build_url(url, params)
|
104
|
+
|
105
|
+
response = RestClient.get(url, get_headers())
|
106
|
+
body = JSON.parse(response.body)
|
107
|
+
|
108
|
+
sends = []
|
109
|
+
body['results'].each do |send_activity|
|
110
|
+
sends << Components::SendActivity.create(send_activity)
|
111
|
+
end
|
112
|
+
|
113
|
+
Components::ResultSet.new(sends, body['meta'])
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
# Get unsubscribes for a given contact
|
118
|
+
# @param [String] contact_id - Contact id
|
119
|
+
# @param [Hash] params - query parameters to be appended to request
|
120
|
+
# @return [ResultSet<UnsubscribeActivity>] - Containing a results array of UnsubscribeActivity
|
121
|
+
def get_unsubscribes(contact_id, params = {})
|
122
|
+
url = Util::Config.get('endpoints.base_url') +
|
123
|
+
sprintf(Util::Config.get('endpoints.contact_tracking_unsubscribes'), contact_id)
|
124
|
+
url = build_url(url, params)
|
125
|
+
|
126
|
+
response = RestClient.get(url, get_headers())
|
127
|
+
body = JSON.parse(response.body)
|
128
|
+
|
129
|
+
unsubscribes = []
|
130
|
+
body['results'].each do |unsubscribe_activity|
|
131
|
+
unsubscribes << Components::UnsubscribeActivity.create(unsubscribe_activity)
|
132
|
+
end
|
133
|
+
|
134
|
+
Components::ResultSet.new(unsubscribes, body['meta'])
|
135
|
+
end
|
136
|
+
|
137
|
+
|
138
|
+
# Get a summary of reporting data for a given contact
|
139
|
+
# @param [String] contact_id - Contact id
|
140
|
+
# @return [TrackingSummary]
|
141
|
+
def get_summary(contact_id)
|
142
|
+
url = Util::Config.get('endpoints.base_url') +
|
143
|
+
sprintf(Util::Config.get('endpoints.contact_tracking_summary'), contact_id)
|
144
|
+
url = build_url(url)
|
145
|
+
response = RestClient.get(url, get_headers())
|
146
|
+
Components::TrackingSummary.create(JSON.parse(response.body))
|
147
|
+
end
|
148
|
+
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
#
|
2
|
+
# email_marketing_service.rb
|
3
|
+
# ConstantContact
|
4
|
+
#
|
5
|
+
# Copyright (c) 2013 Constant Contact. All rights reserved.
|
6
|
+
|
7
|
+
module ConstantContact
|
8
|
+
module Services
|
9
|
+
class EmailMarketingService < BaseService
|
10
|
+
class << self
|
11
|
+
|
12
|
+
# Create a new campaign
|
13
|
+
# @param [Campaign] campaign - Campaign to be created
|
14
|
+
# @return [Campaign]
|
15
|
+
def add_campaign(campaign)
|
16
|
+
url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.campaigns')
|
17
|
+
url = build_url(url)
|
18
|
+
payload = campaign.to_json
|
19
|
+
response = RestClient.post(url, payload, get_headers())
|
20
|
+
Components::Campaign.create(JSON.parse(response.body))
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
# Get a set of campaigns
|
25
|
+
# @param [Hash] params - query parameters to be appended to the request
|
26
|
+
# @return [ResultSet<Campaign>]
|
27
|
+
def get_campaigns(params = {})
|
28
|
+
url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.campaigns')
|
29
|
+
url = build_url(url, params)
|
30
|
+
|
31
|
+
response = RestClient.get(url, get_headers())
|
32
|
+
body = JSON.parse(response.body)
|
33
|
+
|
34
|
+
campaigns = []
|
35
|
+
body['results'].each do |campaign|
|
36
|
+
campaigns << Components::Campaign.create_summary(campaign)
|
37
|
+
end
|
38
|
+
|
39
|
+
Components::ResultSet.new(campaigns, body['meta'])
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
# Get campaign details for a specific campaign
|
44
|
+
# @param [Integer] campaign_id - Valid campaign id
|
45
|
+
# @return [Campaign]
|
46
|
+
def get_campaign(campaign_id)
|
47
|
+
url = Util::Config.get('endpoints.base_url') +
|
48
|
+
sprintf(Util::Config.get('endpoints.campaign'), campaign_id)
|
49
|
+
url = build_url(url)
|
50
|
+
response = RestClient.get(url, get_headers())
|
51
|
+
Components::Campaign.create(JSON.parse(response.body))
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
# Get the preview of the given campaign
|
56
|
+
# @param [Integer] campaign_id - Valid campaign id
|
57
|
+
# @return [CampaignPreview]
|
58
|
+
def get_campaign_preview(campaign_id)
|
59
|
+
url = Util::Config.get('endpoints.base_url') +
|
60
|
+
sprintf(Util::Config.get('endpoints.campaign_preview'), campaign_id)
|
61
|
+
url = build_url(url)
|
62
|
+
response = RestClient.get(url, get_headers())
|
63
|
+
Components::CampaignPreview.create(JSON.parse(response.body))
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
# Delete an email campaign
|
68
|
+
# @param [Integer] campaign_id - Valid campaign id
|
69
|
+
# @return [Boolean]
|
70
|
+
def delete_campaign(campaign_id)
|
71
|
+
url = Util::Config.get('endpoints.base_url') +
|
72
|
+
sprintf(Util::Config.get('endpoints.campaign'), campaign_id)
|
73
|
+
url = build_url(url)
|
74
|
+
response = RestClient.delete(url, get_headers())
|
75
|
+
response.code == 204
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
# Update a specific email campaign
|
80
|
+
# @param [Campaign] campaign - Campaign to be updated
|
81
|
+
# @return [Campaign]
|
82
|
+
def update_campaign(campaign)
|
83
|
+
url = Util::Config.get('endpoints.base_url') +
|
84
|
+
sprintf(Util::Config.get('endpoints.campaign'), campaign.id)
|
85
|
+
url = build_url(url)
|
86
|
+
payload = campaign.to_json
|
87
|
+
response = RestClient.put(url, payload, get_headers())
|
88
|
+
Components::Campaign.create(JSON.parse(response.body))
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|