constantcontact 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +2 -0
  3. data/README.md +132 -0
  4. data/constantcontact.gemspec +32 -0
  5. data/lib/constantcontact.rb +75 -0
  6. data/lib/constantcontact/api.rb +541 -0
  7. data/lib/constantcontact/auth/oauth2.rb +82 -0
  8. data/lib/constantcontact/auth/session_data_store.rb +69 -0
  9. data/lib/constantcontact/components/account/verified_email_address.rb +27 -0
  10. data/lib/constantcontact/components/activities/activity.rb +44 -0
  11. data/lib/constantcontact/components/activities/activity_error.rb +27 -0
  12. data/lib/constantcontact/components/activities/add_contacts.rb +117 -0
  13. data/lib/constantcontact/components/activities/add_contacts_import_data.rb +45 -0
  14. data/lib/constantcontact/components/activities/export_contacts.rb +30 -0
  15. data/lib/constantcontact/components/component.rb +23 -0
  16. data/lib/constantcontact/components/contacts/address.rb +28 -0
  17. data/lib/constantcontact/components/contacts/contact.rb +86 -0
  18. data/lib/constantcontact/components/contacts/contact_list.rb +27 -0
  19. data/lib/constantcontact/components/contacts/custom_field.rb +27 -0
  20. data/lib/constantcontact/components/contacts/email_address.rb +34 -0
  21. data/lib/constantcontact/components/contacts/note.rb +25 -0
  22. data/lib/constantcontact/components/email_marketing/campaign.rb +83 -0
  23. data/lib/constantcontact/components/email_marketing/click_through_details.rb +28 -0
  24. data/lib/constantcontact/components/email_marketing/message_footer.rb +30 -0
  25. data/lib/constantcontact/components/email_marketing/schedule.rb +29 -0
  26. data/lib/constantcontact/components/email_marketing/test_send.rb +45 -0
  27. data/lib/constantcontact/components/result_set.rb +27 -0
  28. data/lib/constantcontact/components/tracking/bounce_activity.rb +29 -0
  29. data/lib/constantcontact/components/tracking/click_activity.rb +28 -0
  30. data/lib/constantcontact/components/tracking/forward_activity.rb +28 -0
  31. data/lib/constantcontact/components/tracking/open_activity.rb +28 -0
  32. data/lib/constantcontact/components/tracking/send_activity.rb +28 -0
  33. data/lib/constantcontact/components/tracking/tracking_activity.rb +27 -0
  34. data/lib/constantcontact/components/tracking/tracking_summary.rb +28 -0
  35. data/lib/constantcontact/components/tracking/unsubscribe_activity.rb +29 -0
  36. data/lib/constantcontact/exceptions/ctct_exception.rb +25 -0
  37. data/lib/constantcontact/exceptions/illegal_argument_exception.rb +11 -0
  38. data/lib/constantcontact/exceptions/oauth2_exception.rb +11 -0
  39. data/lib/constantcontact/services/account_service.rb +29 -0
  40. data/lib/constantcontact/services/activity_service.rb +107 -0
  41. data/lib/constantcontact/services/base_service.rb +37 -0
  42. data/lib/constantcontact/services/campaign_schedule_service.rb +107 -0
  43. data/lib/constantcontact/services/campaign_tracking_service.rb +159 -0
  44. data/lib/constantcontact/services/contact_service.rb +114 -0
  45. data/lib/constantcontact/services/contact_tracking_service.rb +159 -0
  46. data/lib/constantcontact/services/email_marketing_service.rb +87 -0
  47. data/lib/constantcontact/services/list_service.rb +85 -0
  48. data/lib/constantcontact/util/config.rb +140 -0
  49. data/lib/constantcontact/util/helpers.rb +27 -0
  50. data/lib/constantcontact/version.rb +12 -0
  51. data/spec/constantcontact/api_spec.rb +183 -0
  52. data/spec/constantcontact/auth/oauth2_spec.rb +48 -0
  53. data/spec/constantcontact/components/contacts/address_spec.rb +18 -0
  54. data/spec/constantcontact/components/contacts/contact_list_spec.rb +18 -0
  55. data/spec/constantcontact/components/contacts/contact_spec.rb +18 -0
  56. data/spec/constantcontact/components/contacts/custom_field_spec.rb +18 -0
  57. data/spec/constantcontact/components/contacts/email_address_spec.rb +18 -0
  58. data/spec/constantcontact/services/contact_service_spec.rb +105 -0
  59. data/spec/constantcontact/services/list_service_spec.rb +69 -0
  60. data/spec/spec_helper.rb +13 -0
  61. metadata +134 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA512:
3
+ metadata.gz: ce4ab04068029132c0a484c8de77cdffa0a4eda24eeb8e42806266f0935151255a3d270b5c133aba9e337c87788597386cec2b5de64c1e81fe33c9a473d02076
4
+ data.tar.gz: 19c32b1028d217e47bc65a3e145d666b5b57b67a9b58692e75ca6f25fb8f16daecb6e43f8392038a51eb2324f4907db5398884c9746270b3eeb422048904b214
5
+ SHA1:
6
+ metadata.gz: e6944720fbf8a0b247595feb9676859612b53376
7
+ data.tar.gz: d2294f919b1f9d7292618c7a817ff29e0bc09987
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format nested
2
+ --color
data/README.md ADDED
@@ -0,0 +1,132 @@
1
+ Constant Contact Ruby SDK
2
+ =========================
3
+
4
+ In order to use the Constant Contact SDK you have to follow these steps:
5
+
6
+ A. Rails example :
7
+
8
+ 1. Install the gem :
9
+
10
+ gem install constantcontact
11
+
12
+ 2. Configure Rails to load the gem :
13
+
14
+ Rails::Initializer.run do |config|
15
+ ...
16
+ config.gem "constantcontact"
17
+ ...
18
+ end
19
+
20
+ or add the following in your .Gemfile :
21
+
22
+ gem 'constantcontact'
23
+
24
+ 3. Create a new action and add the following code:
25
+
26
+ @oauth = ConstantContact::Auth::OAuth2.new(
27
+ :api_key => 'your api key',
28
+ :api_secret => 'your secret key',
29
+ :redirect_url => 'your redirect url'
30
+ )
31
+
32
+ @error = params[:error]
33
+ @user = params[:username]
34
+ @code = params[:code]
35
+
36
+ if @code
37
+ response = @oauth.get_access_token(@code)
38
+ if response
39
+ token = response['access_token']
40
+ cc = ConstantContact::Api.new('your api key')
41
+ @contacts = cc.get_contacts(token)
42
+ end
43
+ end
44
+
45
+
46
+ Note: 'your redirect url' is the URL of the action you just created.
47
+
48
+ 4. Create a view for the above mentioned action with the following code:
49
+
50
+ <% if @error %>
51
+ <p>
52
+ <%=@error%>
53
+ </p>
54
+ <% end %>
55
+
56
+ <% if @code %>
57
+ <% if @contacts %>
58
+ <% for contact in @contacts %>
59
+ <p>
60
+ Contact name: <%= contact.first_name + contact.last_name %>
61
+ </p>
62
+ <% end %>
63
+ <% end %>
64
+ <% else %>
65
+ <a href="<%=@oauth.get_authorization_url%>">Click to authorize</a>
66
+ <% end %>
67
+
68
+ 5. The first time you access the action in browser you should see the "Click to authorize" link.
69
+ Follow the link, go through all the Constant Contact steps required
70
+ and then you will be redirected back to your action and you should see the list of contacts.
71
+
72
+
73
+ B. Sinatra example :
74
+
75
+
76
+ 1. Install the gem :
77
+
78
+ gem install constantcontact
79
+
80
+ 2. Add the following code in myapp.rb (just an example):
81
+ require 'active_support'
82
+ require 'constantcontact'
83
+
84
+ get '/my_url' do
85
+ @oauth = ConstantContact::Auth::OAuth2.new(
86
+ :api_key => 'your api key',
87
+ :api_secret => 'your secret key',
88
+ :redirect_url => 'your redirect url'
89
+ )
90
+
91
+ @error = params[:error]
92
+ @user = params[:username]
93
+ @code = params[:code]
94
+
95
+ if @code
96
+ response = @oauth.get_access_token(@code)
97
+ if response
98
+ token = response['access_token']
99
+ cc = ConstantContact::Api.new('your api key')
100
+ @contacts = cc.get_contacts(token)
101
+ end
102
+ end
103
+
104
+ erb :my_view
105
+ end
106
+
107
+
108
+ Note: 'your redirect url' is the URL of the route you just created ( get '/my_url' ).
109
+
110
+ 4. Create a my_view.rhtml (or my_view.erb) with the following code:
111
+
112
+ <% if @error %>
113
+ <p>
114
+ <%=@error%>
115
+ </p>
116
+ <% end %>
117
+
118
+ <% if @code %>
119
+ <% if @contacts %>
120
+ <% for contact in @contacts %>
121
+ <p>
122
+ Contact name: <%= contact.first_name + contact.last_name %>
123
+ </p>
124
+ <% end %>
125
+ <% end %>
126
+ <% else %>
127
+ <a href="<%=@oauth.get_authorization_url%>">Click to authorize</a>
128
+ <% end %>
129
+
130
+ 5. The first time you access the action in browser you should see the "Click to authorize" link.
131
+ Follow the link, go through all the Constant Contact steps required
132
+ and then you will be redirected back to your action and you should see the list of contacts.
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'constantcontact/version'
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "constantcontact"
9
+ s.version = ConstantContact::SDK::VERSION
10
+ s.platform = Gem::Platform::RUBY
11
+ s.authors = ["ConstantContact"]
12
+ s.homepage = "http://www.constantcontact.com"
13
+ s.summary = %q{Constant Contact SDK for Ruby}
14
+ s.email = "apisupport@constantcontact.com"
15
+ s.description = "Ruby library for interactions with Constant Contact v2 API"
16
+ s.version = "1.0.0"
17
+ s.license = "MIT"
18
+
19
+ s.files = [
20
+ '.rspec',
21
+ 'constantcontact.gemspec',
22
+ 'README.md'
23
+ ]
24
+ s.files += Dir['lib/**/*.rb']
25
+ s.files += Dir['spec/**/*.rb']
26
+ s.executables = []
27
+ s.require_paths = [ "lib", "spec" ]
28
+
29
+ s.add_dependency("rest-client")
30
+ s.add_dependency("json")
31
+ s.add_development_dependency("rspec")
32
+ end
@@ -0,0 +1,75 @@
1
+ #
2
+ # constantcontact.rb
3
+ # ConstantContact
4
+ #
5
+ # Copyright (c) 2013 Constant Contact. All rights reserved.
6
+
7
+ require 'rubygems'
8
+ require 'rest_client'
9
+ require 'json'
10
+ require 'cgi'
11
+ require 'cgi/session'
12
+ require 'cgi/session/pstore'
13
+
14
+
15
+ module ConstantContact
16
+ autoload :Api, "constantcontact/api"
17
+
18
+ module Auth
19
+ autoload :OAuth2, "constantcontact/auth/oauth2"
20
+ autoload :Session, "constantcontact/auth/session_data_store"
21
+ end
22
+
23
+ module Components
24
+ autoload :Component, "constantcontact/components/component"
25
+ autoload :ResultSet, "constantcontact/components/result_set"
26
+ autoload :Activity, "constantcontact/components/activities/activity"
27
+ autoload :ActivityError, "constantcontact/components/activities/activity_error"
28
+ autoload :AddContacts, "constantcontact/components/activities/add_contacts"
29
+ autoload :AddContactsImportData, "constantcontact/components/activities/add_contacts_import_data"
30
+ autoload :ExportContacts, "constantcontact/components/activities/export_contacts"
31
+ autoload :Address, "constantcontact/components/contacts/address"
32
+ autoload :Contact, "constantcontact/components/contacts/contact"
33
+ autoload :ContactList, "constantcontact/components/contacts/contact_list"
34
+ autoload :CustomField, "constantcontact/components/contacts/custom_field"
35
+ autoload :EmailAddress, "constantcontact/components/contacts/email_address"
36
+ autoload :Note, "constantcontact/components/contacts/note"
37
+ autoload :ClickThroughDetails, "constantcontact/components/email_marketing/click_through_details"
38
+ autoload :Campaign, "constantcontact/components/email_marketing/campaign"
39
+ autoload :MessageFooter, "constantcontact/components/email_marketing/message_footer"
40
+ autoload :Schedule, "constantcontact/components/email_marketing/schedule"
41
+ autoload :TestSend, "constantcontact/components/email_marketing/test_send"
42
+ autoload :BounceActivity, "constantcontact/components/tracking/bounce_activity"
43
+ autoload :ClickActivity, "constantcontact/components/tracking/click_activity"
44
+ autoload :ForwardActivity, "constantcontact/components/tracking/forward_activity"
45
+ autoload :OpenActivity, "constantcontact/components/tracking/open_activity"
46
+ autoload :OptOutActivity, "constantcontact/components/tracking/opt_out_activity"
47
+ autoload :SendActivity, "constantcontact/components/tracking/send_activity"
48
+ autoload :TrackingActivity, "constantcontact/components/tracking/tracking_activity"
49
+ autoload :TrackingSummary, "constantcontact/components/tracking/tracking_summary"
50
+ autoload :VerifiedEmailAddress, "constantcontact/components/account/verified_email_address"
51
+ end
52
+
53
+ module Exceptions
54
+ autoload :CtctException, "constantcontact/exceptions/ctct_exception"
55
+ autoload :IllegalArgumentException, "constantcontact/exceptions/illegal_argument_exception"
56
+ autoload :OAuth2Exception, "constantcontact/exceptions/oauth2_exception"
57
+ end
58
+
59
+ module Services
60
+ autoload :BaseService, "constantcontact/services/base_service"
61
+ autoload :ActivityService, "constantcontact/services/activity_service"
62
+ autoload :CampaignScheduleService, "constantcontact/services/campaign_schedule_service"
63
+ autoload :CampaignTrackingService, "constantcontact/services/campaign_tracking_service"
64
+ autoload :ContactService, "constantcontact/services/contact_service"
65
+ autoload :ContactTrackingService, "constantcontact/services/contact_tracking_service"
66
+ autoload :EmailMarketingService, "constantcontact/services/email_marketing_service"
67
+ autoload :ListService, "constantcontact/services/list_service"
68
+ autoload :AccountService, "constantcontact/services/account_service"
69
+ end
70
+
71
+ module Util
72
+ autoload :Config, "constantcontact/util/config"
73
+ autoload :Helpers, "constantcontact/util/helpers"
74
+ end
75
+ end
@@ -0,0 +1,541 @@
1
+ #
2
+ # api.rb
3
+ # ConstantContact
4
+ #
5
+ # Copyright (c) 2013 Constant Contact. All rights reserved.
6
+
7
+ module ConstantContact
8
+ class Api
9
+
10
+ # Class constructor
11
+ # @param [String] api_key - Constant Contact API Key
12
+ # @return
13
+ def initialize(api_key)
14
+ Services::BaseService.api_key = api_key
15
+ end
16
+
17
+
18
+ # Get verified addresses for the account
19
+ # @param [String] access_token - Valid access token
20
+ # @return [Array<VerifiedEmailAddress>] an array of email addresses
21
+ def get_verified_email_addresses(access_token)
22
+ Services::AccountService.get_verified_email_addresses(access_token)
23
+ end
24
+
25
+
26
+ # Get a set of contacts
27
+ # @param [String] access_token - Valid access token
28
+ # @param [Integer] param - denotes the number of results per set, limited to 50,
29
+ # or a next parameter provided from a previous call
30
+ # @return [ResultSet<Contact>] a ResultSet of Contacts
31
+ def get_contacts(access_token, param = nil)
32
+ param = determine_param(param)
33
+ Services::ContactService.get_contacts(access_token, param)
34
+ end
35
+
36
+
37
+ # Get an individual contact
38
+ # @param [String] access_token - Valid access token
39
+ # @param [Integer] contact_id - Id of the contact to retrieve
40
+ # @return [Contact]
41
+ def get_contact(access_token, contact_id)
42
+ Services::ContactService.get_contact(access_token, contact_id)
43
+ end
44
+
45
+
46
+ # Get contacts with a specified email eaddress
47
+ # @param [String] access_token - Constant Contact OAuth2 access token
48
+ # @param [String] email - contact email address to search for
49
+ # @return [ResultSet<Contact>] a ResultSet of Contacts
50
+ def get_contact_by_email(access_token, email)
51
+ Services::ContactService.get_contacts(access_token, {'email' => email})
52
+ end
53
+
54
+
55
+ # Add a new contact to an account
56
+ # @param [String] access_token - Valid access token
57
+ # @param [Contact] contact - Contact to add
58
+ # @param [Boolean] action_by_visitor - if the action is being taken by the visitor
59
+ # @return [Contact]
60
+ def add_contact(access_token, contact, action_by_visitor = false)
61
+ Services::ContactService.add_contact(access_token, contact, action_by_visitor)
62
+ end
63
+
64
+
65
+ # Sets an individual contact to 'REMOVED' status
66
+ # @param [String] access_token - Valid access token
67
+ # @param [Mixed] contact - Either a Contact id or the Contact itself
68
+ # @raise [IllegalArgumentException] If contact is not an integer or a Contact object
69
+ # @return [Boolean]
70
+ def delete_contact(access_token, contact)
71
+ contact_id = get_argument_id(contact, 'Contact')
72
+ Services::ContactService.delete_contact(access_token, contact_id)
73
+ end
74
+
75
+
76
+ # Delete a contact from all contact lists
77
+ # @param [String] access_token - Constant Contact OAuth2 access token
78
+ # @param [Mixed] contact - Contact id or the Contact object itself
79
+ # @raise [IllegalArgumentException] If contact is not an integer or a Contact object
80
+ # @return [Boolean]
81
+ def delete_contact_from_lists(access_token, contact)
82
+ contact_id = get_argument_id(contact, 'Contact')
83
+ Services::ContactService.delete_contact_from_lists(access_token, contact_id)
84
+ end
85
+
86
+
87
+ # Delete a contact from all contact lists
88
+ # @param [String] access_token - Constant Contact OAuth2 access token
89
+ # @param [Mixed] contact - Contact id or a Contact object
90
+ # @param [Mixed] list - ContactList id or a ContactList object
91
+ # @raise [IllegalArgumentException] If contact is not an integer or a Contact object
92
+ # @return [Boolean]
93
+ def delete_contact_from_list(access_token, contact, list)
94
+ contact_id = get_argument_id(contact, 'Contact')
95
+ list_id = get_argument_id(list, 'ContactList')
96
+ Services::ContactService.delete_contact_from_list(access_token, contact_id, list_id)
97
+ end
98
+
99
+
100
+ # Update an individual contact
101
+ # @param [String] access_token - Valid access token
102
+ # @param [Contact] contact - Contact to update
103
+ # @param [Boolean] action_by_visitor - if the action is being taken by the visitor
104
+ # @return [Contact]
105
+ def update_contact(access_token, contact, action_by_visitor = false)
106
+ Services::ContactService.update_contact(access_token, contact, action_by_visitor)
107
+ end
108
+
109
+
110
+ # Get lists
111
+ # @param [String] access_token - Valid access token
112
+ # @return [Array<ContactList>] Array of ContactList objects
113
+ def get_lists(access_token)
114
+ Services::ListService.get_lists(access_token)
115
+ end
116
+
117
+
118
+ # Get an individual list
119
+ # @param [String] access_token - Valid access token
120
+ # @param [Integer] list_id - Id of the list to retrieve
121
+ # @return [ContactList]
122
+ def get_list(access_token, list_id)
123
+ Services::ListService.get_list(access_token, list_id)
124
+ end
125
+
126
+
127
+ # Add a new list to an account
128
+ # @param [String] access_token - Valid access token
129
+ # @param [ContactList] list - List to add
130
+ # @return [ContactList]
131
+ def add_list(access_token, list)
132
+ Services::ListService.add_list(access_token, list)
133
+ end
134
+
135
+
136
+ # Update a contact list
137
+ # @param [String] access_token - Valid access token
138
+ # @param [ContactList] list - ContactList to update
139
+ # @return [ContactList]
140
+ def update_list(access_token, list)
141
+ Services::ListService.update_list(access_token, list)
142
+ end
143
+
144
+
145
+ # Get contact that belong to a specific list
146
+ # @param [String] access_token - Constant Contact OAuth2 access token
147
+ # @param [Mixed] list - Integer id of the list or ContactList object
148
+ # @raise [IllegalArgumentException] If contact is not an integer or contact
149
+ # @return [Array<Contact>] An array of contacts
150
+ def get_contacts_from_list(access_token, list)
151
+ list_id = get_argument_id(list, 'ContactList')
152
+ Services::ListService.get_contacts_from_list(access_token, list_id)
153
+ end
154
+
155
+
156
+ # Get a set of campaigns
157
+ # @param [String] access_token - Constant Contact OAuth2 access token
158
+ # @param [String] param - denotes the number of results per set, limited to 50, or a next parameter provided
159
+ # from a previous call
160
+ # @return [ResultSet<Campaign>]
161
+ def get_email_campaigns(access_token, param = nil)
162
+ param = determine_param(param)
163
+ Services::EmailMarketingService.get_campaigns(access_token, param)
164
+ end
165
+
166
+
167
+ # Get an individual campaign
168
+ # @param [String] access_token - Constant Contact OAuth2 access token
169
+ # @param [Integer] campaign_id - Valid campaign id
170
+ # @return [Campaign]
171
+ def get_email_campaign(access_token, campaign_id)
172
+ Services::EmailMarketingService.get_campaign(access_token, campaign_id)
173
+ end
174
+
175
+
176
+ # Delete an individual campaign
177
+ # @param [String] access_token - Constant Contact OAuth2 access token
178
+ # @param [Mixed] campaign - Id of a campaign or a Campaign object
179
+ # @raise IllegalArgumentException - if a Campaign object or campaign id is not passed
180
+ # @return [Boolean]
181
+ def delete_email_campaign(access_token, campaign)
182
+ campaign_id = get_argument_id(campaign, 'Campaign')
183
+ Services::EmailMarketingService.delete_campaign(access_token, campaign_id)
184
+ end
185
+
186
+
187
+ # Create a new campaign
188
+ # @param [String] access_token - Constant Contact OAuth2 access token
189
+ # @param [Campaign] campaign - Campaign to be created
190
+ # @return [Campaign] - created campaign
191
+ def add_email_campaign(access_token, campaign)
192
+ Services::EmailMarketingService.add_campaign(access_token, campaign)
193
+ end
194
+
195
+
196
+ # Update a specific campaign
197
+ # @param [String] access_token - Constant Contact OAuth2 access token
198
+ # @param [Campaign] campaign - Campaign to be updated
199
+ # @return [Campaign] - updated campaign
200
+ def update_email_campaign(access_token, campaign)
201
+ Services::EmailMarketingService.update_campaign(access_token, campaign)
202
+ end
203
+
204
+
205
+ # Schedule a campaign to be sent
206
+ # @param [String] access_token - Constant Contact OAuth2 access token
207
+ # @param [Mixed] campaign - Id of a campaign or a Campaign object
208
+ # @param [Schedule] schedule - Schedule to be associated with the provided campaign
209
+ # @return [Campaign] - updated campaign
210
+ def add_email_campaign_schedule(access_token, campaign, schedule)
211
+ campaign_id = get_argument_id(campaign, 'Campaign')
212
+ Services::CampaignScheduleService.add_schedule(access_token, campaign_id, schedule)
213
+ end
214
+
215
+
216
+ # Get an array of schedules associated with a given campaign
217
+ # @param [String] access_token - Constant Contact OAuth2 access token
218
+ # @param [Mixed] campaign - Campaign id or Campaign object itself
219
+ # @return [Array<Schedule>]
220
+ def get_email_campaign_schedules(access_token, campaign)
221
+ campaign_id = get_argument_id(campaign, 'Campaign')
222
+ Services::CampaignScheduleService.get_schedules(access_token, campaign_id)
223
+ end
224
+
225
+
226
+ # Get a specific schedule associated with a given campaign
227
+ # @param [String] access_token - Constant Contact OAuth2 access token
228
+ # @param [Mixed] campaign - Campaign id or Campaign object itself
229
+ # @param [Mixed] schedule - Schedule id or Schedule object itself
230
+ # @raise IllegalArgumentException
231
+ # @return [Schedule]
232
+ def get_email_campaign_schedule(access_token, campaign, schedule)
233
+ campaign_id = get_argument_id(campaign, 'Campaign')
234
+ schedule_id = get_argument_id(schedule, 'Schedule')
235
+ Services::CampaignScheduleService.get_schedule(access_token, campaign_id, schedule_id)
236
+ end
237
+
238
+
239
+ # Update a specific schedule associated with a given campaign
240
+ # @param [String] access_token - Constant Contact OAuth2 access token
241
+ # @param [Mixed] campaign - Campaign id or Campaign object itself
242
+ # @param [Schedule] schedule - Schedule to be updated
243
+ # @return [Schedule]
244
+ def update_email_campaign_schedule(access_token, campaign, schedule)
245
+ campaign_id = get_argument_id(campaign, 'Campaign')
246
+ Services::CampaignScheduleService.update_schedule(access_token, campaign_id, schedule)
247
+ end
248
+
249
+
250
+ # Delete a specific schedule associated with a given campaign
251
+ # @param [String] access_token - Constant Contact OAuth2 access token
252
+ # @param [Mixed] campaign - Campaign id or Campaign object itself
253
+ # @param [Mixed] schedule - Schedule id or Schedule object itself
254
+ # @raise IllegalArgumentException
255
+ # @return [Boolean]
256
+ def delete_email_campaign_schedule(access_token, campaign, schedule)
257
+ campaign_id = get_argument_id(campaign, 'Campaign')
258
+ schedule_id = get_argument_id(schedule, 'Schedule')
259
+ Services::CampaignScheduleService.delete_schedule(access_token, campaign_id, schedule_id)
260
+ end
261
+
262
+
263
+ # Send a test send of a campaign
264
+ # @param [String] access_token - Constant Contact OAuth2 access token
265
+ # @param [Mixed] campaign - Campaign id or Campaign object itself
266
+ # @param [TestSend] test_send - test send details
267
+ # @return [TestSend]
268
+ def send_email_campaign_test(access_token, campaign, test_send)
269
+ campaign_id = get_argument_id(campaign, 'Campaign')
270
+ Services::CampaignScheduleService.send_test(access_token, campaign_id, test_send)
271
+ end
272
+
273
+
274
+ # Get sends for a campaign
275
+ # @param [String] access_token - Constant Contact OAuth2 access token
276
+ # @param [Mixed] campaign - Campaign id or Campaign object itself
277
+ # @param [String] param - next value returned from a previous request (used in pagination)
278
+ # @return [ResultSet<SendActivity>]
279
+ def get_email_campaign_sends(access_token, campaign, param = nil)
280
+ campaign_id = get_argument_id(campaign, 'Campaign')
281
+ param = determine_param(param)
282
+ Services::CampaignTrackingService.get_sends(access_token, campaign_id, param)
283
+ end
284
+
285
+
286
+ # Get bounces for a campaign
287
+ # @param [String] access_token - Constant Contact OAuth2 access token
288
+ # @param [Mixed] campaign - Campaign id or Campaign object itself
289
+ # @param [Mixed] param - either the next link from a previous request, or a limit or restrict the page size of
290
+ # an initial request
291
+ # @return [ResultSet<BounceActivity>]
292
+ def get_email_campaign_bounces(access_token, campaign, param = nil)
293
+ campaign_id = get_argument_id(campaign, 'Campaign')
294
+ param = determine_param(param)
295
+ Services::CampaignTrackingService.get_bounces(access_token, campaign_id, param)
296
+ end
297
+
298
+
299
+ # Get clicks for a campaign
300
+ # @param [String] access_token - Constant Contact OAuth2 access token
301
+ # @param [Mixed] campaign - Campaign id or Campaign object itself
302
+ # @param [Mixed] param - either the next link from a previous request, or a limit or restrict the page size of
303
+ # an initial request
304
+ # @return [ResultSet<ClickActivity>]
305
+ def get_email_campaign_clicks(access_token, campaign, param = nil)
306
+ campaign_id = get_argument_id(campaign, 'Campaign')
307
+ param = determine_param(param)
308
+ Services::CampaignTrackingService.get_clicks(access_token, campaign_id, param)
309
+ end
310
+
311
+
312
+ # Get opens for a campaign
313
+ # @param [String] access_token - Constant Contact OAuth2 access token
314
+ # @param [Mixed] campaign - Campaign id or Campaign object itself
315
+ # @param [Mixed] param - either the next link from a previous request, or a limit or restrict the page size of
316
+ # an initial request
317
+ # @return [ResultSet<OpenActivity>]
318
+ def get_email_campaign_opens(access_token, campaign, param = nil)
319
+ campaign_id = get_argument_id(campaign, 'Campaign')
320
+ param = determine_param(param)
321
+ Services::CampaignTrackingService.get_opens(access_token, campaign_id, param)
322
+ end
323
+
324
+
325
+ # Get forwards for a campaign
326
+ # @param [String] access_token - Constant Contact OAuth2 access token
327
+ # @param [Mixed] campaign - Campaign id or Campaign object itself
328
+ # @param [Mixed] param - either the next link from a previous request, or a limit or restrict the page size of
329
+ # an initial request
330
+ # @return [ResultSet<ForwardActivity>]
331
+ def get_email_campaign_forwards(access_token, campaign, param = nil)
332
+ campaign_id = get_argument_id(campaign, 'Campaign')
333
+ param = determine_param(param)
334
+ Services::CampaignTrackingService.get_forwards(access_token, campaign_id, param)
335
+ end
336
+
337
+
338
+ # Get unsubscribes for a campaign
339
+ # @param [String] access_token - Constant Contact OAuth2 access token
340
+ # @param [Mixed] campaign - Campaign id or Campaign object itself
341
+ # @param [Mixed] param - either the next link from a previous request, or a limit or restrict the page size of
342
+ # an initial request
343
+ # @return [ResultSet<UnsubscribeActivity>] - Containing a results array of UnsubscribeActivity
344
+ def get_email_campaign_unsubscribes(access_token, campaign, param = nil)
345
+ campaign_id = get_argument_id(campaign, 'Campaign')
346
+ param = determine_param(param)
347
+ Services::CampaignTrackingService.get_unsubscribes(access_token, campaign_id, param)
348
+ end
349
+
350
+
351
+ # Get a reporting summary for a campaign
352
+ # @param [String] access_token - Constant Contact OAuth2 access token
353
+ # @param [Mixed] campaign - Campaign id or Campaign object itself
354
+ # @return [TrackingSummary]
355
+ def get_email_campaign_summary_report(access_token, campaign)
356
+ campaign_id = get_argument_id(campaign, 'Campaign')
357
+ Services::CampaignTrackingService.get_summary(access_token, campaign_id)
358
+ end
359
+
360
+
361
+ # Get sends for a Contact
362
+ # @param [String] access_token - Constant Contact OAuth2 access token
363
+ # @param [Mixed] contact - Contact id or Contact object itself
364
+ # @param [Mixed] param - either the next link from a previous request, or a limit or restrict the page size of
365
+ # an initial request
366
+ # @return [ResultSet<SendActivity>]
367
+ def get_contact_sends(access_token, contact, param = nil)
368
+ contact_id = get_argument_id(contact, 'Contact')
369
+ Services::ContactTrackingService.get_sends(access_token, contact_id, param)
370
+ end
371
+
372
+
373
+ # Get bounces for a Contact
374
+ # @param [String] access_token - Constant Contact OAuth2 access token
375
+ # @param [Mixed] contact - Contact id or Contact object itself
376
+ # @param [Mixed] param - either the next link from a previous request, or a limit or restrict the page size of
377
+ # an initial request
378
+ # @return [ResultSet<BounceActivity>]
379
+ def get_contact_bounces(access_token, contact, param = nil)
380
+ contact_id = get_argument_id(contact, 'Contact')
381
+ Services::ContactTrackingService.get_bounces(access_token, contact_id, param)
382
+ end
383
+
384
+
385
+ # Get clicks for a Contact
386
+ # @param [String] access_token - Constant Contact OAuth2 access token
387
+ # @param [Mixed] contact - Contact id or Contact object itself
388
+ # @param [Mixed] param - either the next link from a previous request, or a limit or restrict the page size of
389
+ # an initial request
390
+ # @return [ResultSet<ClickActivity>]
391
+ def get_contact_clicks(access_token, contact, param = nil)
392
+ contact_id = get_argument_id(contact, 'Contact')
393
+ param = determine_param(param)
394
+ Services::ContactTrackingService.get_clicks(access_token, contact_id, param)
395
+ end
396
+
397
+
398
+ # Get opens for a Contact
399
+ # @param [String] access_token - Constant Contact OAuth2 access token
400
+ # @param [Mixed] contact - Contact id or Contact object itself
401
+ # @param [Mixed] param - either the next link from a previous request, or a limit or restrict the page size of
402
+ # an initial request
403
+ # @return [ResultSet<OpenActivity>]
404
+ def get_contact_opens(access_token, contact, param = nil)
405
+ contact_id = get_argument_id(contact, 'Contact')
406
+ param = determine_param(param)
407
+ Services::ContactTrackingService.get_opens(access_token, contact_id, param)
408
+ end
409
+
410
+
411
+ # Get forwards for a Contact
412
+ # @param [String] access_token - Constant Contact OAuth2 access token
413
+ # @param [Mixed] contact - Contact id or Contact object itself
414
+ # @param [Mixed] param - either the next link from a previous request, or a limit or restrict the page size of
415
+ # an initial request
416
+ # @return [ResultSet<ForwardActivity>]
417
+ def get_contact_forwards(access_token, contact, param = nil)
418
+ contact_id = get_argument_id(contact, 'Contact')
419
+ param = determine_param(param)
420
+ Services::ContactTrackingService.get_forwards(access_token, contact_id, param)
421
+ end
422
+
423
+
424
+ # Get unsubscribes for a Contact
425
+ # @param [String] access_token - Constant Contact OAuth2 access token
426
+ # @param [Mixed] contact - Contact id or Contact object itself
427
+ # @param [Hash] param - either the next link from a previous request, or a limit or restrict the page size of
428
+ # an initial request
429
+ # @return [UnsubscribeActivity] - Containing a results array of UnsubscribeActivity
430
+ def get_contact_unsubscribes(access_token, contact, param = nil)
431
+ contact_id = get_argument_id(contact, 'Contact')
432
+ param = determine_param(param)
433
+ Services::ContactTrackingService.get_unsubscribes(access_token, contact_id, param)
434
+ end
435
+
436
+
437
+ # Get a reporting summary for a Contact
438
+ # @param [String] access_token - Constant Contact OAuth2 access token
439
+ # @param [Mixed] contact - Contact id or Contact object itself
440
+ # @return [TrackingSummary]
441
+ def get_contact_summary_report(access_token, contact)
442
+ contact_id = get_argument_id(contact, 'Contact')
443
+ Services::ContactTrackingService.get_summary(access_token, contact_id)
444
+ end
445
+
446
+
447
+ # Get an array of activities
448
+ # @param [String] access_token - Constant Contact OAuth2 access token
449
+ # @return [Array<Activity>]
450
+ def get_activities(access_token)
451
+ Services::ActivityService.get_activities(access_token)
452
+ end
453
+
454
+
455
+ # Get a single activity by id
456
+ # @param [String] access_token - Constant Contact OAuth2 access token
457
+ # @param [String] activity_id - Activity id
458
+ # @return [Activity]
459
+ def get_activity(access_token, activity_id)
460
+ Services::ActivityService.get_activity(access_token, activity_id)
461
+ end
462
+
463
+
464
+ # Add an AddContacts activity to add contacts in bulk
465
+ # @param [String] access_token - Constant Contact OAuth2 access token
466
+ # @param [AddContacts] add_contacts - Add Contacts
467
+ # @return [Activity]
468
+ def add_add_contacts_activity(access_token, add_contacts)
469
+ Services::ActivityService.create_add_contacts_activity(access_token, add_contacts)
470
+ end
471
+
472
+
473
+ # Add a ClearLists Activity to remove all contacts from the provided lists
474
+ # @param [String] access_token - Constant Contact OAuth2 access token
475
+ # @param [Array<Lists>] lists - Add Contacts Activity
476
+ # @return [Activity]
477
+ def add_clear_lists_activity(access_token, lists)
478
+ Services::ActivityService.add_clear_lists_activity(access_token, lists)
479
+ end
480
+
481
+
482
+ # Add a Remove Contacts From Lists Activity
483
+ # @param [String] access_token - Constant Contact OAuth2 access token
484
+ # @param [Array<EmailAddress>] email_addresses - email addresses to be removed
485
+ # @param [Array<Lists>] lists - lists to remove the provided email addresses from
486
+ # @return [Activity]
487
+ def add_remove_contacts_from_lists_activity(access_token, email_addresses, lists)
488
+ Services::ActivityService.add_remove_contacts_from_lists_activity(access_token, email_addresses, lists)
489
+ end
490
+
491
+
492
+ # Create an Export Contacts Activity
493
+ # @param [String] access_token - Constant Contact OAuth2 access token
494
+ # @param [<Array>Contacts] export_contacts - Contacts to be exported
495
+ # @return [Activity]
496
+ def add_export_contacts_activity(access_token, export_contacts)
497
+ Services::ActivityService.add_export_contacts_activity(access_token, export_contacts)
498
+ end
499
+
500
+
501
+ private
502
+
503
+
504
+ # Get the id of object, or attempt to convert the argument to an int
505
+ # @param [Mixed] item - object or a numeric value
506
+ # @param [String] class_name - class name to test the given object against
507
+ # @raise IllegalArgumentException - if the item is not an instance of the class name given, or cannot be
508
+ # converted to a numeric value
509
+ # @return [Integer]
510
+ def get_argument_id(item, class_name)
511
+ item_id = nil
512
+ if item.is_a?(Integer)
513
+ item_id = item
514
+ elsif item.class.to_s.split('::').last == class_name
515
+ item_id = item.id
516
+ else
517
+ raise Exceptions::IllegalArgumentException.new(sprintf(Util::Config.get('errors.id_or_object'), class_name))
518
+ end
519
+ item_id
520
+ end
521
+
522
+
523
+ # Append the limit parameter, if the value is an integer
524
+ # @param [String] param - parameter value
525
+ # @return [Hash] the parameters as a hash object
526
+ def determine_param(param)
527
+ params = {}
528
+ if param
529
+ param = param.to_s
530
+ if param[0, 1] == '?'
531
+ hash_params = CGI::parse(param[1..-1])
532
+ params = Hash[*hash_params.collect {|key, value| [key, value.first] }.flatten]
533
+ else
534
+ params['limit'] = param
535
+ end
536
+ end
537
+ params
538
+ end
539
+
540
+ end
541
+ end