constantcontact 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +127 -136
  3. data/constantcontact.gemspec +4 -3
  4. data/lib/constantcontact.rb +63 -44
  5. data/lib/constantcontact/api.rb +932 -535
  6. data/lib/constantcontact/auth/oauth2.rb +86 -66
  7. data/lib/constantcontact/components/account/verified_email_address.rb +14 -14
  8. data/lib/constantcontact/components/activities/activity.rb +30 -30
  9. data/lib/constantcontact/components/activities/activity_error.rb +14 -14
  10. data/lib/constantcontact/components/activities/add_contacts.rb +1 -1
  11. data/lib/constantcontact/components/activities/add_contacts_import_data.rb +37 -36
  12. data/lib/constantcontact/components/component.rb +25 -0
  13. data/lib/constantcontact/components/contacts/address.rb +12 -12
  14. data/lib/constantcontact/components/contacts/contact.rb +50 -44
  15. data/lib/constantcontact/components/contacts/contact_list.rb +12 -12
  16. data/lib/constantcontact/components/contacts/custom_field.rb +14 -14
  17. data/lib/constantcontact/components/contacts/email_address.rb +14 -14
  18. data/lib/constantcontact/components/contacts/note.rb +13 -13
  19. data/lib/constantcontact/components/email_marketing/campaign.rb +41 -41
  20. data/lib/constantcontact/components/email_marketing/click_through_details.rb +14 -14
  21. data/lib/constantcontact/components/email_marketing/message_footer.rb +14 -14
  22. data/lib/constantcontact/components/email_marketing/schedule.rb +14 -15
  23. data/lib/constantcontact/components/email_marketing/test_send.rb +21 -21
  24. data/lib/constantcontact/components/event_spot/contact.rb +27 -0
  25. data/lib/constantcontact/components/event_spot/event.rb +63 -0
  26. data/lib/constantcontact/components/event_spot/event_track.rb +28 -0
  27. data/lib/constantcontact/components/event_spot/fee.rb +27 -0
  28. data/lib/constantcontact/components/event_spot/guest.rb +31 -0
  29. data/lib/constantcontact/components/event_spot/notification_option.rb +27 -0
  30. data/lib/constantcontact/components/event_spot/promo_code.rb +26 -0
  31. data/lib/constantcontact/components/event_spot/registrant.rb +54 -0
  32. data/lib/constantcontact/components/event_spot/registrant_field.rb +27 -0
  33. data/lib/constantcontact/components/event_spot/registrant_section.rb +34 -0
  34. data/lib/constantcontact/components/event_spot/sale_item.rb +27 -0
  35. data/lib/constantcontact/components/library/file/library_file.rb +27 -0
  36. data/lib/constantcontact/components/library/folder/library_folder.rb +26 -0
  37. data/lib/constantcontact/components/library/info/library_summary.rb +26 -0
  38. data/lib/constantcontact/components/library/info/move_results.rb +26 -0
  39. data/lib/constantcontact/components/library/info/upload_status.rb +26 -0
  40. data/lib/constantcontact/components/tracking/bounce_activity.rb +14 -14
  41. data/lib/constantcontact/components/tracking/click_activity.rb +14 -14
  42. data/lib/constantcontact/components/tracking/forward_activity.rb +14 -14
  43. data/lib/constantcontact/components/tracking/open_activity.rb +14 -14
  44. data/lib/constantcontact/components/tracking/send_activity.rb +14 -14
  45. data/lib/constantcontact/components/tracking/tracking_summary.rb +17 -17
  46. data/lib/constantcontact/components/tracking/unsubscribe_activity.rb +14 -14
  47. data/lib/constantcontact/services/account_service.rb +4 -3
  48. data/lib/constantcontact/services/activity_service.rb +40 -3
  49. data/lib/constantcontact/services/base_service.rb +34 -6
  50. data/lib/constantcontact/services/campaign_tracking_service.rb +20 -20
  51. data/lib/constantcontact/services/contact_service.rb +10 -12
  52. data/lib/constantcontact/services/contact_tracking_service.rb +20 -20
  53. data/lib/constantcontact/services/email_marketing_service.rb +8 -10
  54. data/lib/constantcontact/services/event_spot_service.rb +254 -0
  55. data/lib/constantcontact/services/library_service.rb +297 -0
  56. data/lib/constantcontact/services/list_service.rb +6 -5
  57. data/lib/constantcontact/util/config.rb +135 -117
  58. data/lib/constantcontact/version.rb +1 -1
  59. data/spec/constantcontact/api_spec.rb +1223 -173
  60. data/spec/constantcontact/auth/oauth2_spec.rb +60 -47
  61. data/spec/constantcontact/components/contacts/address_spec.rb +1 -1
  62. data/spec/constantcontact/components/contacts/contact_list_spec.rb +1 -1
  63. data/spec/constantcontact/components/contacts/contact_spec.rb +1 -1
  64. data/spec/constantcontact/components/contacts/email_address_spec.rb +1 -1
  65. data/spec/constantcontact/services/activity_service_spec.rb +201 -0
  66. data/spec/constantcontact/services/base_service_spec.rb +27 -0
  67. data/spec/constantcontact/services/campaign_schedule_service_spec.rb +111 -0
  68. data/spec/constantcontact/services/campaign_tracking_service_spec.rb +127 -0
  69. data/spec/constantcontact/services/contact_service_spec.rb +24 -22
  70. data/spec/constantcontact/services/contact_tracking_service_spec.rb +127 -0
  71. data/spec/constantcontact/services/email_marketing_spec.rb +72 -66
  72. data/spec/constantcontact/services/event_spot_spec.rb +217 -0
  73. data/spec/constantcontact/services/library_service_spec.rb +248 -0
  74. data/spec/constantcontact/services/list_service_spec.rb +33 -17
  75. data/spec/spec_helper.rb +3 -1
  76. metadata +63 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fbe3bbdd27400b7cabb1f7d057ddcf4cbce8af1f
4
- data.tar.gz: 5e590cbd2085adbbc074f66963f244d2b9ccf29d
3
+ metadata.gz: 0c4cc9d1ea9b203b5ca089c9da4b644f42c8ee9f
4
+ data.tar.gz: 8f618777d2131ad9e2bd55f5a97016e6d7b25849
5
5
  SHA512:
6
- metadata.gz: 90c879d3fe95da598a0f2f4b9df5e6e8066e21a919a9fdfa029bff1e0fc9beaed0ffaade52e7a000a55a57285caf4d741a1d0209d5d9adb425f724cee3e99d3c
7
- data.tar.gz: aa192ef3d3440c8f4bff332df802b63b290af8eedd21847d522243a5c779e3e3e6735e27f5cb36b5f8490c084535d3f3e0092f57ec6ecdb53a385d00d9205b50
6
+ metadata.gz: 048e7ffe96661bf3941f9fa76287ad9463cf93b7eb92cbfadc00bdc526b7905c4f5ccf08615b0d4d5461e78c719fdb26468706746ebf64b1e8de89c2aac7da80
7
+ data.tar.gz: c1671514b610d40ee3cec33bad16652665ccd87a4b0b4610deb370187492ffb9c39140725297af8fbed716b6ab37c9c76ba925c46d4419620007df87a8d767e7
data/README.md CHANGED
@@ -1,139 +1,130 @@
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
- 6. Add config initializer (optional)
74
- ````ruby
75
- ConstantContact::Util::Config.configure do |config|
76
- config[:auth][:api_key] = 'foobar'
77
- config[:auth][:api_secret] = 'foobar'
1
+ Constant Contact Ruby SDK for AppConnect
2
+ ====
3
+
4
+ The Ruby SDK for AppConnect allows you to leverage the AppConnect v2 APIs.
5
+
6
+ [![Build Status](https://travis-ci.org/constantcontact/ruby-sdk.png)](https://travis-ci.org/constantcontact/ruby-sdk)
7
+
8
+ Installation
9
+ ====
10
+ Via bundler:
11
+ ```ruby
12
+ gem 'constantcontact', '~> 1.1.0'
13
+ ```
14
+ Otherwise:
15
+ ```bash
16
+ [sudo|rvm] gem install constantcontact
17
+ ```
18
+
19
+ Configuration
20
+ ====
21
+ The AppConnect SDK can be configured with some options globally or they can be specified when creating the API client:
22
+ ```ruby
23
+ ConstantContact::Util::Config.configure do |config|
24
+ config[:auth][:api_key] = 'your-access-key'
25
+ config[:auth][:api_secret] = 'your-access-secret'
26
+ config[:auth][:redirect_uri] = 'https://example.com/auth/constantcontact'
27
+ end
28
+ ```
29
+
30
+ Getting Started
31
+ ====
32
+ AppConnect requires an OAuth access token which will give your app access to Constant Contact data and services for the accout that granted that access token.
33
+
34
+ Rails
35
+ =====
36
+ Create a new controller action. The redirect_url should be the same as the one given when registering the app with Mashery. Use the following code snippet to get an access token:
37
+ ```ruby
38
+ @oauth = ConstantContact::Auth::OAuth2.new(
39
+ :api_key => 'your api key',
40
+ :api_secret => 'your secret key',
41
+ :redirect_url => 'your redirect url' # the URL given when registering your app with Mashery.
42
+ )
43
+
44
+ @error = params[:error]
45
+ @user = params[:username]
46
+ @code = params[:code]
47
+
48
+ if @code.present?
49
+ response = @oauth.get_access_token(@code)
50
+ if response.present?
51
+ token = response['access_token']
52
+ cc = ConstantContact::Api.new('your api key')
53
+ @contacts = cc.get_contacts(token)
54
+ end
55
+ else
56
+ # if not code param is provided redirect into the OAuth flow
57
+ redirect_to @oauth.get_authorization_url and return
58
+ end
59
+ ```
60
+
61
+ Create a view for the above mentioned action with the following code:
62
+ ```erb
63
+
64
+ <% if @error %>
65
+ <p><%= @error %></p>
66
+ <% end %>
67
+
68
+ <% if @contacts.present? %>
69
+ <% @contacts.each do |contact| %>
70
+ <p>Contact name: <%= "#{contact.first_name} #{contact.last_name}" %></p>
71
+ <% end %>
72
+ <% end %>
73
+ ```
74
+
75
+ The first time you access the action you will be redirected into the Constant Contact OAuth flow.
76
+ Then you will be redirected back to your action and you should see the list of contacts.
77
+
78
+ Sinatra
79
+ =====
80
+ Require AppConnect:
81
+ ```ruby
82
+ require 'constantcontact'
83
+ ```
84
+
85
+ Add the following route. The redirect_url should be the same given when registering the app with Mashery.
86
+ ```ruby
87
+ get '/my_url' do
88
+ @oauth = ConstantContact::Auth::OAuth2.new(
89
+ :api_key => 'your api key',
90
+ :api_secret => 'your secret key',
91
+ :redirect_url => 'your redirect url'
92
+ )
93
+
94
+ @error = params[:error]
95
+ @user = params[:username]
96
+ @code = params[:code]
97
+
98
+ if @code
99
+ response = @oauth.get_access_token(@code)
100
+ if response
101
+ token = response['access_token']
102
+ cc = ConstantContact::Api.new('your api key')
103
+ @contacts = cc.get_contacts(token)
78
104
  end
79
-
80
- B. Sinatra example :
81
-
82
-
83
- 1. Install the gem :
84
-
85
- gem install constantcontact
86
-
87
- 2. Add the following code in myapp.rb (just an example):
88
- require 'active_support'
89
- require 'constantcontact'
90
-
91
- get '/my_url' do
92
- @oauth = ConstantContact::Auth::OAuth2.new(
93
- :api_key => 'your api key',
94
- :api_secret => 'your secret key',
95
- :redirect_url => 'your redirect url'
96
- )
97
-
98
- @error = params[:error]
99
- @user = params[:username]
100
- @code = params[:code]
101
-
102
- if @code
103
- response = @oauth.get_access_token(@code)
104
- if response
105
- token = response['access_token']
106
- cc = ConstantContact::Api.new('your api key')
107
- @contacts = cc.get_contacts(token)
108
- end
109
- end
110
-
111
- erb :my_view
112
- end
113
-
114
-
115
- Note: 'your redirect url' is the URL of the route you just created ( get '/my_url' ).
116
-
117
- 4. Create a my_view.rhtml (or my_view.erb) with the following code:
118
-
119
- <% if @error %>
120
- <p>
121
- <%=@error%>
122
- </p>
123
- <% end %>
124
-
125
- <% if @code %>
126
- <% if @contacts %>
127
- <% for contact in @contacts %>
128
- <p>
129
- Contact name: <%= contact.first_name + contact.last_name %>
130
- </p>
131
- <% end %>
132
- <% end %>
133
- <% else %>
134
- <a href="<%=@oauth.get_authorization_url%>">Click to authorize</a>
135
- <% end %>
136
-
137
- 5. The first time you access the action in browser you should see the "Click to authorize" link.
105
+ end
106
+
107
+ erb :my_view
108
+ end
109
+ ```
110
+
111
+ Create a my_view.erb with the following code:
112
+ ```ruby
113
+ <% if @error %>
114
+ <p><%=@error%></p>
115
+ <% end %>
116
+
117
+ <% if @code %>
118
+ <% if @contacts %>
119
+ <% @contacts.each do |contact| %>
120
+ <p>\Contact name: <%= "#{contact.first_name} #{contact.last_name}" %></p>
121
+ <% end %>
122
+ <% end %>
123
+ <% else %>
124
+ <a href="<%=@oauth.get_authorization_url%>">Click to authorize</a>
125
+ <% end %>
126
+ ```
127
+
128
+ The first time you access the action in browser you should see the "Click to authorize" link.
138
129
  Follow the link, go through all the Constant Contact steps required
139
130
  and then you will be redirected back to your action and you should see the list of contacts.
@@ -21,11 +21,12 @@ Gem::Specification.new do |s|
21
21
  'README.md'
22
22
  ]
23
23
  s.files += Dir['lib/**/*.rb']
24
- s.files += Dir['spec/**/*.rb']
25
24
  s.executables = []
26
- s.require_paths = [ "lib", "spec" ]
27
-
25
+ s.require_paths = [ "lib" ]
26
+ s.test_files = Dir['spec/**/*.rb']
27
+
28
28
  s.add_dependency("rest-client")
29
29
  s.add_dependency("json")
30
+ s.add_dependency('mime-types', ['1.25.1'])
30
31
  s.add_development_dependency("rspec")
31
32
  end
@@ -13,63 +13,82 @@ require 'cgi/session/pstore'
13
13
 
14
14
 
15
15
  module ConstantContact
16
- autoload :Api, "constantcontact/api"
16
+ autoload :Api, 'constantcontact/api'
17
17
 
18
18
  module Auth
19
- autoload :OAuth2, "constantcontact/auth/oauth2"
20
- autoload :Session, "constantcontact/auth/session_data_store"
19
+ autoload :OAuth2, 'constantcontact/auth/oauth2'
20
+ autoload :Session, 'constantcontact/auth/session_data_store'
21
21
  end
22
22
 
23
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"
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 :UnsubscribeActivity, 'constantcontact/components/tracking/unsubscribe_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
+ autoload :Event, 'constantcontact/components/event_spot/event'
52
+ autoload :Fee, 'constantcontact/components/event_spot/fee'
53
+ autoload :Registrant, 'constantcontact/components/event_spot/registrant'
54
+ autoload :LibrarySummary, 'constantcontact/components/library/info/library_summary'
55
+ autoload :UploadStatus, 'constantcontact/components/library/info/upload_status'
56
+ autoload :MoveResults, 'constantcontact/components/library/info/move_results'
57
+ autoload :LibraryFolder, 'constantcontact/components/library/folder/library_folder'
58
+ autoload :LibraryFile, 'constantcontact/components/library/file/library_file'
59
+
60
+ module EventSpot
61
+ autoload :Contact, 'constantcontact/components/event_spot/contact'
62
+ autoload :NotificationOption, 'constantcontact/components/event_spot/notification_option'
63
+ autoload :Guest, 'constantcontact/components/event_spot/guest'
64
+ autoload :EventTrack, 'constantcontact/components/event_spot/event_track'
65
+ autoload :RegistrantSection, 'constantcontact/components/event_spot/registrant_section'
66
+ autoload :RegistrantField, 'constantcontact/components/event_spot/registrant_field'
67
+ end
51
68
  end
52
69
 
53
70
  module Exceptions
54
- autoload :CtctException, "constantcontact/exceptions/ctct_exception"
55
- autoload :IllegalArgumentException, "constantcontact/exceptions/illegal_argument_exception"
56
- autoload :OAuth2Exception, "constantcontact/exceptions/oauth2_exception"
71
+ autoload :CtctException, 'constantcontact/exceptions/ctct_exception'
72
+ autoload :IllegalArgumentException, 'constantcontact/exceptions/illegal_argument_exception'
73
+ autoload :OAuth2Exception, 'constantcontact/exceptions/oauth2_exception'
57
74
  end
58
75
 
59
76
  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"
77
+ autoload :BaseService, 'constantcontact/services/base_service'
78
+ autoload :ActivityService, 'constantcontact/services/activity_service'
79
+ autoload :CampaignScheduleService, 'constantcontact/services/campaign_schedule_service'
80
+ autoload :CampaignTrackingService, 'constantcontact/services/campaign_tracking_service'
81
+ autoload :ContactService, 'constantcontact/services/contact_service'
82
+ autoload :ContactTrackingService, 'constantcontact/services/contact_tracking_service'
83
+ autoload :EmailMarketingService, 'constantcontact/services/email_marketing_service'
84
+ autoload :ListService, 'constantcontact/services/list_service'
85
+ autoload :AccountService, 'constantcontact/services/account_service'
86
+ autoload :EventSpotService, 'constantcontact/services/event_spot_service'
87
+ autoload :LibraryService, 'constantcontact/services/library_service'
69
88
  end
70
89
 
71
90
  module Util
72
- autoload :Config, "constantcontact/util/config"
73
- autoload :Helpers, "constantcontact/util/helpers"
91
+ autoload :Config, 'constantcontact/util/config'
92
+ autoload :Helpers, 'constantcontact/util/helpers'
74
93
  end
75
94
  end
@@ -5,539 +5,936 @@
5
5
  # Copyright (c) 2013 Constant Contact. All rights reserved.
6
6
 
7
7
  module ConstantContact
8
- class Api
9
- # Class constructor
10
- # @param [String] api_key - Constant Contact API Key
11
- # @return
12
- def initialize(api_key = nil)
13
- Services::BaseService.api_key = api_key || Util::Config.get('auth.api_key')
14
- if Services::BaseService.api_key.nil? || Services::BaseService.api_key == ''
15
- raise ArgumentError.new("api_key required either explicitly or in configuration.")
16
- end
17
- end
18
-
19
-
20
- # Get verified addresses for the account
21
- # @param [String] access_token - Valid access token
22
- # @return [Array<VerifiedEmailAddress>] an array of email addresses
23
- def get_verified_email_addresses(access_token)
24
- Services::AccountService.get_verified_email_addresses(access_token)
25
- end
26
-
27
-
28
- # Get a set of contacts
29
- # @param [String] access_token - Valid access token
30
- # @param [Integer] param - denotes the number of results per set, limited to 50,
31
- # or a next parameter provided from a previous call
32
- # @return [ResultSet<Contact>] a ResultSet of Contacts
33
- def get_contacts(access_token, param = nil)
34
- param = determine_param(param)
35
- Services::ContactService.get_contacts(access_token, param)
36
- end
37
-
38
-
39
- # Get an individual contact
40
- # @param [String] access_token - Valid access token
41
- # @param [Integer] contact_id - Id of the contact to retrieve
42
- # @return [Contact]
43
- def get_contact(access_token, contact_id)
44
- Services::ContactService.get_contact(access_token, contact_id)
45
- end
46
-
47
-
48
- # Get contacts with a specified email eaddress
49
- # @param [String] access_token - Constant Contact OAuth2 access token
50
- # @param [String] email - contact email address to search for
51
- # @return [ResultSet<Contact>] a ResultSet of Contacts
52
- def get_contact_by_email(access_token, email)
53
- Services::ContactService.get_contacts(access_token, {'email' => email})
54
- end
55
-
56
-
57
- # Add a new contact to an account
58
- # @param [String] access_token - Valid access token
59
- # @param [Contact] contact - Contact to add
60
- # @param [Boolean] action_by_visitor - if the action is being taken by the visitor
61
- # @return [Contact]
62
- def add_contact(access_token, contact, action_by_visitor = false)
63
- Services::ContactService.add_contact(access_token, contact, action_by_visitor)
64
- end
65
-
66
-
67
- # Sets an individual contact to 'REMOVED' status
68
- # @param [String] access_token - Valid access token
69
- # @param [Mixed] contact - Either a Contact id or the Contact itself
70
- # @raise [IllegalArgumentException] If contact is not an integer or a Contact object
71
- # @return [Boolean]
72
- def delete_contact(access_token, contact)
73
- contact_id = get_argument_id(contact, 'Contact')
74
- Services::ContactService.delete_contact(access_token, contact_id)
75
- end
76
-
77
-
78
- # Delete a contact from all contact lists
79
- # @param [String] access_token - Constant Contact OAuth2 access token
80
- # @param [Mixed] contact - Contact id or the Contact object itself
81
- # @raise [IllegalArgumentException] If contact is not an integer or a Contact object
82
- # @return [Boolean]
83
- def delete_contact_from_lists(access_token, contact)
84
- contact_id = get_argument_id(contact, 'Contact')
85
- Services::ContactService.delete_contact_from_lists(access_token, contact_id)
86
- end
87
-
88
-
89
- # Delete a contact from all contact lists
90
- # @param [String] access_token - Constant Contact OAuth2 access token
91
- # @param [Mixed] contact - Contact id or a Contact object
92
- # @param [Mixed] list - ContactList id or a ContactList object
93
- # @raise [IllegalArgumentException] If contact is not an integer or a Contact object
94
- # @return [Boolean]
95
- def delete_contact_from_list(access_token, contact, list)
96
- contact_id = get_argument_id(contact, 'Contact')
97
- list_id = get_argument_id(list, 'ContactList')
98
- Services::ContactService.delete_contact_from_list(access_token, contact_id, list_id)
99
- end
100
-
101
-
102
- # Update an individual contact
103
- # @param [String] access_token - Valid access token
104
- # @param [Contact] contact - Contact to update
105
- # @param [Boolean] action_by_visitor - if the action is being taken by the visitor
106
- # @return [Contact]
107
- def update_contact(access_token, contact, action_by_visitor = false)
108
- Services::ContactService.update_contact(access_token, contact, action_by_visitor)
109
- end
110
-
111
-
112
- # Get lists
113
- # @param [String] access_token - Valid access token
114
- # @return [Array<ContactList>] Array of ContactList objects
115
- def get_lists(access_token)
116
- Services::ListService.get_lists(access_token)
117
- end
118
-
119
-
120
- # Get an individual list
121
- # @param [String] access_token - Valid access token
122
- # @param [Integer] list_id - Id of the list to retrieve
123
- # @return [ContactList]
124
- def get_list(access_token, list_id)
125
- Services::ListService.get_list(access_token, list_id)
126
- end
127
-
128
-
129
- # Add a new list to an account
130
- # @param [String] access_token - Valid access token
131
- # @param [ContactList] list - List to add
132
- # @return [ContactList]
133
- def add_list(access_token, list)
134
- Services::ListService.add_list(access_token, list)
135
- end
136
-
137
-
138
- # Update a contact list
139
- # @param [String] access_token - Valid access token
140
- # @param [ContactList] list - ContactList to update
141
- # @return [ContactList]
142
- def update_list(access_token, list)
143
- Services::ListService.update_list(access_token, list)
144
- end
145
-
146
-
147
- # Get contact that belong to a specific list
148
- # @param [String] access_token - Constant Contact OAuth2 access token
149
- # @param [Mixed] list - Integer id of the list or ContactList object
150
- # @raise [IllegalArgumentException] If contact is not an integer or contact
151
- # @return [Array<Contact>] An array of contacts
152
- def get_contacts_from_list(access_token, list)
153
- list_id = get_argument_id(list, 'ContactList')
154
- Services::ListService.get_contacts_from_list(access_token, list_id)
155
- end
156
-
157
-
158
- # Get a set of campaigns
159
- # @param [String] access_token - Constant Contact OAuth2 access token
160
- # @param [String] param - denotes the number of results per set, limited to 50, or a next parameter provided
161
- # from a previous call
162
- # @return [ResultSet<Campaign>]
163
- def get_email_campaigns(access_token, param = nil)
164
- param = determine_param(param)
165
- Services::EmailMarketingService.get_campaigns(access_token, param)
166
- end
167
-
168
-
169
- # Get an individual campaign
170
- # @param [String] access_token - Constant Contact OAuth2 access token
171
- # @param [Integer] campaign_id - Valid campaign id
172
- # @return [Campaign]
173
- def get_email_campaign(access_token, campaign_id)
174
- Services::EmailMarketingService.get_campaign(access_token, campaign_id)
175
- end
176
-
177
-
178
- # Delete an individual campaign
179
- # @param [String] access_token - Constant Contact OAuth2 access token
180
- # @param [Mixed] campaign - Id of a campaign or a Campaign object
181
- # @raise IllegalArgumentException - if a Campaign object or campaign id is not passed
182
- # @return [Boolean]
183
- def delete_email_campaign(access_token, campaign)
184
- campaign_id = get_argument_id(campaign, 'Campaign')
185
- Services::EmailMarketingService.delete_campaign(access_token, campaign_id)
186
- end
187
-
188
-
189
- # Create a new campaign
190
- # @param [String] access_token - Constant Contact OAuth2 access token
191
- # @param [Campaign] campaign - Campaign to be created
192
- # @return [Campaign] - created campaign
193
- def add_email_campaign(access_token, campaign)
194
- Services::EmailMarketingService.add_campaign(access_token, campaign)
195
- end
196
-
197
-
198
- # Update a specific campaign
199
- # @param [String] access_token - Constant Contact OAuth2 access token
200
- # @param [Campaign] campaign - Campaign to be updated
201
- # @return [Campaign] - updated campaign
202
- def update_email_campaign(access_token, campaign)
203
- Services::EmailMarketingService.update_campaign(access_token, campaign)
204
- end
205
-
206
-
207
- # Schedule a campaign to be sent
208
- # @param [String] access_token - Constant Contact OAuth2 access token
209
- # @param [Mixed] campaign - Id of a campaign or a Campaign object
210
- # @param [Schedule] schedule - Schedule to be associated with the provided campaign
211
- # @return [Campaign] - updated campaign
212
- def add_email_campaign_schedule(access_token, campaign, schedule)
213
- campaign_id = get_argument_id(campaign, 'Campaign')
214
- Services::CampaignScheduleService.add_schedule(access_token, campaign_id, schedule)
215
- end
216
-
217
-
218
- # Get an array of schedules associated with a given campaign
219
- # @param [String] access_token - Constant Contact OAuth2 access token
220
- # @param [Mixed] campaign - Campaign id or Campaign object itself
221
- # @return [Array<Schedule>]
222
- def get_email_campaign_schedules(access_token, campaign)
223
- campaign_id = get_argument_id(campaign, 'Campaign')
224
- Services::CampaignScheduleService.get_schedules(access_token, campaign_id)
225
- end
226
-
227
-
228
- # Get a specific schedule associated with a given campaign
229
- # @param [String] access_token - Constant Contact OAuth2 access token
230
- # @param [Mixed] campaign - Campaign id or Campaign object itself
231
- # @param [Mixed] schedule - Schedule id or Schedule object itself
232
- # @raise IllegalArgumentException
233
- # @return [Schedule]
234
- def get_email_campaign_schedule(access_token, campaign, schedule)
235
- campaign_id = get_argument_id(campaign, 'Campaign')
236
- schedule_id = get_argument_id(schedule, 'Schedule')
237
- Services::CampaignScheduleService.get_schedule(access_token, campaign_id, schedule_id)
238
- end
239
-
240
-
241
- # Update a specific schedule associated with a given campaign
242
- # @param [String] access_token - Constant Contact OAuth2 access token
243
- # @param [Mixed] campaign - Campaign id or Campaign object itself
244
- # @param [Schedule] schedule - Schedule to be updated
245
- # @return [Schedule]
246
- def update_email_campaign_schedule(access_token, campaign, schedule)
247
- campaign_id = get_argument_id(campaign, 'Campaign')
248
- Services::CampaignScheduleService.update_schedule(access_token, campaign_id, schedule)
249
- end
250
-
251
-
252
- # Delete a specific schedule associated with a given campaign
253
- # @param [String] access_token - Constant Contact OAuth2 access token
254
- # @param [Mixed] campaign - Campaign id or Campaign object itself
255
- # @param [Mixed] schedule - Schedule id or Schedule object itself
256
- # @raise IllegalArgumentException
257
- # @return [Boolean]
258
- def delete_email_campaign_schedule(access_token, campaign, schedule)
259
- campaign_id = get_argument_id(campaign, 'Campaign')
260
- schedule_id = get_argument_id(schedule, 'Schedule')
261
- Services::CampaignScheduleService.delete_schedule(access_token, campaign_id, schedule_id)
262
- end
263
-
264
-
265
- # Send a test send of a campaign
266
- # @param [String] access_token - Constant Contact OAuth2 access token
267
- # @param [Mixed] campaign - Campaign id or Campaign object itself
268
- # @param [TestSend] test_send - test send details
269
- # @return [TestSend]
270
- def send_email_campaign_test(access_token, campaign, test_send)
271
- campaign_id = get_argument_id(campaign, 'Campaign')
272
- Services::CampaignScheduleService.send_test(access_token, campaign_id, test_send)
273
- end
274
-
275
-
276
- # Get sends for a campaign
277
- # @param [String] access_token - Constant Contact OAuth2 access token
278
- # @param [Mixed] campaign - Campaign id or Campaign object itself
279
- # @param [String] param - next value returned from a previous request (used in pagination)
280
- # @return [ResultSet<SendActivity>]
281
- def get_email_campaign_sends(access_token, campaign, param = nil)
282
- campaign_id = get_argument_id(campaign, 'Campaign')
283
- param = determine_param(param)
284
- Services::CampaignTrackingService.get_sends(access_token, campaign_id, param)
285
- end
286
-
287
-
288
- # Get bounces for a campaign
289
- # @param [String] access_token - Constant Contact OAuth2 access token
290
- # @param [Mixed] campaign - Campaign id or Campaign object itself
291
- # @param [Mixed] param - either the next link from a previous request, or a limit or restrict the page size of
292
- # an initial request
293
- # @return [ResultSet<BounceActivity>]
294
- def get_email_campaign_bounces(access_token, campaign, param = nil)
295
- campaign_id = get_argument_id(campaign, 'Campaign')
296
- param = determine_param(param)
297
- Services::CampaignTrackingService.get_bounces(access_token, campaign_id, param)
298
- end
299
-
300
-
301
- # Get clicks for a campaign
302
- # @param [String] access_token - Constant Contact OAuth2 access token
303
- # @param [Mixed] campaign - Campaign id or Campaign object itself
304
- # @param [Mixed] param - either the next link from a previous request, or a limit or restrict the page size of
305
- # an initial request
306
- # @return [ResultSet<ClickActivity>]
307
- def get_email_campaign_clicks(access_token, campaign, param = nil)
308
- campaign_id = get_argument_id(campaign, 'Campaign')
309
- param = determine_param(param)
310
- Services::CampaignTrackingService.get_clicks(access_token, campaign_id, param)
311
- end
312
-
313
-
314
- # Get opens for a campaign
315
- # @param [String] access_token - Constant Contact OAuth2 access token
316
- # @param [Mixed] campaign - Campaign id or Campaign object itself
317
- # @param [Mixed] param - either the next link from a previous request, or a limit or restrict the page size of
318
- # an initial request
319
- # @return [ResultSet<OpenActivity>]
320
- def get_email_campaign_opens(access_token, campaign, param = nil)
321
- campaign_id = get_argument_id(campaign, 'Campaign')
322
- param = determine_param(param)
323
- Services::CampaignTrackingService.get_opens(access_token, campaign_id, param)
324
- end
325
-
326
-
327
- # Get forwards for a campaign
328
- # @param [String] access_token - Constant Contact OAuth2 access token
329
- # @param [Mixed] campaign - Campaign id or Campaign object itself
330
- # @param [Mixed] param - either the next link from a previous request, or a limit or restrict the page size of
331
- # an initial request
332
- # @return [ResultSet<ForwardActivity>]
333
- def get_email_campaign_forwards(access_token, campaign, param = nil)
334
- campaign_id = get_argument_id(campaign, 'Campaign')
335
- param = determine_param(param)
336
- Services::CampaignTrackingService.get_forwards(access_token, campaign_id, param)
337
- end
338
-
339
-
340
- # Get unsubscribes for a campaign
341
- # @param [String] access_token - Constant Contact OAuth2 access token
342
- # @param [Mixed] campaign - Campaign id or Campaign object itself
343
- # @param [Mixed] param - either the next link from a previous request, or a limit or restrict the page size of
344
- # an initial request
345
- # @return [ResultSet<UnsubscribeActivity>] - Containing a results array of UnsubscribeActivity
346
- def get_email_campaign_unsubscribes(access_token, campaign, param = nil)
347
- campaign_id = get_argument_id(campaign, 'Campaign')
348
- param = determine_param(param)
349
- Services::CampaignTrackingService.get_unsubscribes(access_token, campaign_id, param)
350
- end
351
-
352
-
353
- # Get a reporting summary for a campaign
354
- # @param [String] access_token - Constant Contact OAuth2 access token
355
- # @param [Mixed] campaign - Campaign id or Campaign object itself
356
- # @return [TrackingSummary]
357
- def get_email_campaign_summary_report(access_token, campaign)
358
- campaign_id = get_argument_id(campaign, 'Campaign')
359
- Services::CampaignTrackingService.get_summary(access_token, campaign_id)
360
- end
361
-
362
-
363
- # Get sends for a Contact
364
- # @param [String] access_token - Constant Contact OAuth2 access token
365
- # @param [Mixed] contact - Contact id or Contact object itself
366
- # @param [Mixed] param - either the next link from a previous request, or a limit or restrict the page size of
367
- # an initial request
368
- # @return [ResultSet<SendActivity>]
369
- def get_contact_sends(access_token, contact, param = nil)
370
- contact_id = get_argument_id(contact, 'Contact')
371
- Services::ContactTrackingService.get_sends(access_token, contact_id, param)
372
- end
373
-
374
-
375
- # Get bounces for a Contact
376
- # @param [String] access_token - Constant Contact OAuth2 access token
377
- # @param [Mixed] contact - Contact id or Contact object itself
378
- # @param [Mixed] param - either the next link from a previous request, or a limit or restrict the page size of
379
- # an initial request
380
- # @return [ResultSet<BounceActivity>]
381
- def get_contact_bounces(access_token, contact, param = nil)
382
- contact_id = get_argument_id(contact, 'Contact')
383
- Services::ContactTrackingService.get_bounces(access_token, contact_id, param)
384
- end
385
-
386
-
387
- # Get clicks for a Contact
388
- # @param [String] access_token - Constant Contact OAuth2 access token
389
- # @param [Mixed] contact - Contact id or Contact object itself
390
- # @param [Mixed] param - either the next link from a previous request, or a limit or restrict the page size of
391
- # an initial request
392
- # @return [ResultSet<ClickActivity>]
393
- def get_contact_clicks(access_token, contact, param = nil)
394
- contact_id = get_argument_id(contact, 'Contact')
395
- param = determine_param(param)
396
- Services::ContactTrackingService.get_clicks(access_token, contact_id, param)
397
- end
398
-
399
-
400
- # Get opens for a Contact
401
- # @param [String] access_token - Constant Contact OAuth2 access token
402
- # @param [Mixed] contact - Contact id or Contact object itself
403
- # @param [Mixed] param - either the next link from a previous request, or a limit or restrict the page size of
404
- # an initial request
405
- # @return [ResultSet<OpenActivity>]
406
- def get_contact_opens(access_token, contact, param = nil)
407
- contact_id = get_argument_id(contact, 'Contact')
408
- param = determine_param(param)
409
- Services::ContactTrackingService.get_opens(access_token, contact_id, param)
410
- end
411
-
412
-
413
- # Get forwards for a Contact
414
- # @param [String] access_token - Constant Contact OAuth2 access token
415
- # @param [Mixed] contact - Contact id or Contact object itself
416
- # @param [Mixed] param - either the next link from a previous request, or a limit or restrict the page size of
417
- # an initial request
418
- # @return [ResultSet<ForwardActivity>]
419
- def get_contact_forwards(access_token, contact, param = nil)
420
- contact_id = get_argument_id(contact, 'Contact')
421
- param = determine_param(param)
422
- Services::ContactTrackingService.get_forwards(access_token, contact_id, param)
423
- end
424
-
425
-
426
- # Get unsubscribes for a Contact
427
- # @param [String] access_token - Constant Contact OAuth2 access token
428
- # @param [Mixed] contact - Contact id or Contact object itself
429
- # @param [Hash] param - either the next link from a previous request, or a limit or restrict the page size of
430
- # an initial request
431
- # @return [UnsubscribeActivity] - Containing a results array of UnsubscribeActivity
432
- def get_contact_unsubscribes(access_token, contact, param = nil)
433
- contact_id = get_argument_id(contact, 'Contact')
434
- param = determine_param(param)
435
- Services::ContactTrackingService.get_unsubscribes(access_token, contact_id, param)
436
- end
437
-
438
-
439
- # Get a reporting summary for a Contact
440
- # @param [String] access_token - Constant Contact OAuth2 access token
441
- # @param [Mixed] contact - Contact id or Contact object itself
442
- # @return [TrackingSummary]
443
- def get_contact_summary_report(access_token, contact)
444
- contact_id = get_argument_id(contact, 'Contact')
445
- Services::ContactTrackingService.get_summary(access_token, contact_id)
446
- end
447
-
448
-
449
- # Get an array of activities
450
- # @param [String] access_token - Constant Contact OAuth2 access token
451
- # @return [Array<Activity>]
452
- def get_activities(access_token)
453
- Services::ActivityService.get_activities(access_token)
454
- end
455
-
456
-
457
- # Get a single activity by id
458
- # @param [String] access_token - Constant Contact OAuth2 access token
459
- # @param [String] activity_id - Activity id
460
- # @return [Activity]
461
- def get_activity(access_token, activity_id)
462
- Services::ActivityService.get_activity(access_token, activity_id)
463
- end
464
-
465
-
466
- # Add an AddContacts activity to add contacts in bulk
467
- # @param [String] access_token - Constant Contact OAuth2 access token
468
- # @param [AddContacts] add_contacts - Add Contacts
469
- # @return [Activity]
470
- def add_add_contacts_activity(access_token, add_contacts)
471
- Services::ActivityService.create_add_contacts_activity(access_token, add_contacts)
472
- end
473
-
474
-
475
- # Add a ClearLists Activity to remove all contacts from the provided lists
476
- # @param [String] access_token - Constant Contact OAuth2 access token
477
- # @param [Array<Lists>] lists - Add Contacts Activity
478
- # @return [Activity]
479
- def add_clear_lists_activity(access_token, lists)
480
- Services::ActivityService.add_clear_lists_activity(access_token, lists)
481
- end
482
-
483
-
484
- # Add a Remove Contacts From Lists Activity
485
- # @param [String] access_token - Constant Contact OAuth2 access token
486
- # @param [Array<EmailAddress>] email_addresses - email addresses to be removed
487
- # @param [Array<Lists>] lists - lists to remove the provided email addresses from
488
- # @return [Activity]
489
- def add_remove_contacts_from_lists_activity(access_token, email_addresses, lists)
490
- Services::ActivityService.add_remove_contacts_from_lists_activity(access_token, email_addresses, lists)
491
- end
492
-
493
-
494
- # Create an Export Contacts Activity
495
- # @param [String] access_token - Constant Contact OAuth2 access token
496
- # @param [<Array>Contacts] export_contacts - Contacts to be exported
497
- # @return [Activity]
498
- def add_export_contacts_activity(access_token, export_contacts)
499
- Services::ActivityService.add_export_contacts_activity(access_token, export_contacts)
500
- end
501
-
502
-
503
- private
504
-
505
-
506
- # Get the id of object, or attempt to convert the argument to an int
507
- # @param [Mixed] item - object or a numeric value
508
- # @param [String] class_name - class name to test the given object against
509
- # @raise IllegalArgumentException - if the item is not an instance of the class name given, or cannot be
510
- # converted to a numeric value
511
- # @return [Integer]
512
- def get_argument_id(item, class_name)
513
- item_id = nil
514
- if item.is_a?(Integer)
515
- item_id = item
516
- elsif item.class.to_s.split('::').last == class_name
517
- item_id = item.id
518
- else
519
- raise Exceptions::IllegalArgumentException.new(sprintf(Util::Config.get('errors.id_or_object'), class_name))
520
- end
521
- item_id
522
- end
523
-
524
-
525
- # Append the limit parameter, if the value is an integer
526
- # @param [String] param - parameter value
527
- # @return [Hash] the parameters as a hash object
528
- def determine_param(param)
529
- params = {}
530
- if param
531
- param = param.to_s
532
- if param[0, 1] == '?'
533
- hash_params = CGI::parse(param[1..-1])
534
- params = Hash[*hash_params.collect {|key, value| [key, value.first] }.flatten]
535
- else
536
- params['limit'] = param
537
- end
538
- end
539
- params
540
- end
541
-
542
- end
8
+ class Api
9
+ # Class constructor
10
+ # @param [String] api_key - Constant Contact API Key
11
+ # @return
12
+ def initialize(api_key = nil)
13
+ Services::BaseService.api_key = api_key || Util::Config.get('auth.api_key')
14
+ if Services::BaseService.api_key.nil? || Services::BaseService.api_key == ''
15
+ raise ArgumentError.new("api_key required either explicitly or in configuration.")
16
+ end
17
+ end
18
+
19
+
20
+ # Get verified addresses for the account
21
+ # @param [String] access_token - Valid access token
22
+ # @param [String] status - status to filter query results by
23
+ # @return [Array<VerifiedEmailAddress>] an array of email addresses
24
+ def get_verified_email_addresses(access_token, status = nil)
25
+ params = {}
26
+ params['status'] = status if status
27
+ Services::AccountService.get_verified_email_addresses(access_token, params)
28
+ end
29
+
30
+
31
+ # Get a set of contacts
32
+ # @param [String] access_token - Valid access token
33
+ # @param [Hash] params - hash of query parameters and values to append to the request.
34
+ # Allowed parameters include:
35
+ # limit - Specifies the number of results displayed per page of output, from 1 - 500, default = 50.
36
+ # modified_since - ISO-8601 formatted timestamp.
37
+ # next - the next link returned from a previous paginated call. May only be used by itself.
38
+ # email - the contact by email address to retrieve information for.
39
+ # status - a contact status to filter results by. Must be one of ACTIVE, OPTOUT, REMOVED, UNCONFIRMED.
40
+ # @return [ResultSet<Contact>] a ResultSet of Contacts
41
+ def get_contacts(access_token, params = {})
42
+ Services::ContactService.get_contacts(access_token, params)
43
+ end
44
+
45
+
46
+ # Get an individual contact
47
+ # @param [String] access_token - Valid access token
48
+ # @param [Integer] contact_id - Id of the contact to retrieve
49
+ # @return [Contact]
50
+ def get_contact(access_token, contact_id)
51
+ Services::ContactService.get_contact(access_token, contact_id)
52
+ end
53
+
54
+
55
+ # Get contacts with a specified email eaddress
56
+ # @param [String] access_token - Constant Contact OAuth2 access token
57
+ # @param [String] email - contact email address to search for
58
+ # @return [ResultSet<Contact>] a ResultSet of Contacts
59
+ def get_contact_by_email(access_token, email)
60
+ Services::ContactService.get_contacts(access_token, {'email' => email})
61
+ end
62
+
63
+
64
+ # Add a new contact to an account
65
+ # @param [String] access_token - Valid access token
66
+ # @param [Contact] contact - Contact to add
67
+ # @param [Boolean] action_by_visitor - if the action is being taken by the visitor
68
+ # @return [Contact]
69
+ def add_contact(access_token, contact, action_by_visitor = false)
70
+ params = {}
71
+ params['action_by'] = 'ACTION_BY_VISITOR' if action_by_visitor
72
+ Services::ContactService.add_contact(access_token, contact, params)
73
+ end
74
+
75
+
76
+ # Sets an individual contact to 'REMOVED' status
77
+ # @param [String] access_token - Valid access token
78
+ # @param [Mixed] contact - Either a Contact id or the Contact itself
79
+ # @raise [IllegalArgumentException] If contact is not an integer or a Contact object
80
+ # @return [Boolean]
81
+ def delete_contact(access_token, contact)
82
+ contact_id = get_argument_id(contact, 'Contact')
83
+ Services::ContactService.delete_contact(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 the Contact object itself
90
+ # @raise [IllegalArgumentException] If contact is not an integer or a Contact object
91
+ # @return [Boolean]
92
+ def delete_contact_from_lists(access_token, contact)
93
+ contact_id = get_argument_id(contact, 'Contact')
94
+ Services::ContactService.delete_contact_from_lists(access_token, contact_id)
95
+ end
96
+
97
+
98
+ # Delete a contact from all contact lists
99
+ # @param [String] access_token - Constant Contact OAuth2 access token
100
+ # @param [Mixed] contact - Contact id or a Contact object
101
+ # @param [Mixed] list - ContactList id or a ContactList object
102
+ # @raise [IllegalArgumentException] If contact is not an integer or a Contact object
103
+ # @return [Boolean]
104
+ def delete_contact_from_list(access_token, contact, list)
105
+ contact_id = get_argument_id(contact, 'Contact')
106
+ list_id = get_argument_id(list, 'ContactList')
107
+ Services::ContactService.delete_contact_from_list(access_token, contact_id, list_id)
108
+ end
109
+
110
+
111
+ # Update an individual contact
112
+ # @param [String] access_token - Valid access token
113
+ # @param [Contact] contact - Contact to update
114
+ # @param [Boolean] action_by_visitor - if the action is being taken by the visitor
115
+ # @return [Contact]
116
+ def update_contact(access_token, contact, action_by_visitor = false)
117
+ params = {}
118
+ params['action_by'] = 'ACTION_BY_VISITOR' if action_by_visitor
119
+ Services::ContactService.update_contact(access_token, contact, params)
120
+ end
121
+
122
+
123
+ # Get lists
124
+ # @param [String] access_token - Valid access token
125
+ # @param [Hash] params - hash of query parameters and values to append to the request.
126
+ # Allowed parameters include:
127
+ # - modified_since - ISO-8601 formatted timestamp.
128
+ # @return [Array<ContactList>] Array of ContactList objects
129
+ def get_lists(access_token, params = {})
130
+ Services::ListService.get_lists(access_token, params)
131
+ end
132
+
133
+
134
+ # Get an individual list
135
+ # @param [String] access_token - Valid access token
136
+ # @param [Integer] list_id - Id of the list to retrieve
137
+ # @return [ContactList]
138
+ def get_list(access_token, list_id)
139
+ Services::ListService.get_list(access_token, list_id)
140
+ end
141
+
142
+
143
+ # Add a new list to an account
144
+ # @param [String] access_token - Valid access token
145
+ # @param [ContactList] list - List to add
146
+ # @return [ContactList]
147
+ def add_list(access_token, list)
148
+ Services::ListService.add_list(access_token, list)
149
+ end
150
+
151
+
152
+ # Update a contact list
153
+ # @param [String] access_token - Valid access token
154
+ # @param [ContactList] list - ContactList to update
155
+ # @return [ContactList]
156
+ def update_list(access_token, list)
157
+ Services::ListService.update_list(access_token, list)
158
+ end
159
+
160
+
161
+ # Get contact that belong to a specific list
162
+ # @param [String] access_token - Constant Contact OAuth2 access token
163
+ # @param [Mixed] list - Integer id of the list or ContactList object
164
+ # @param [Mixed] param - denotes the number of results per set, limited to 50, or a next parameter provided
165
+ # from a previous getContactsFromList call
166
+ # @raise [IllegalArgumentException] If contact is not an integer or contact
167
+ # @return [Array<Contact>] An array of contacts
168
+ def get_contacts_from_list(access_token, list, param = nil)
169
+ list_id = get_argument_id(list, 'ContactList')
170
+ param = determine_param(param)
171
+ Services::ListService.get_contacts_from_list(access_token, list_id, param)
172
+ end
173
+
174
+
175
+ # Get a set of campaigns
176
+ # @param [String] access_token - Constant Contact OAuth2 access token
177
+ # @param [Mixed] params - hash of query parameters and values to append to the request.
178
+ # Allowed parameters include:
179
+ # limit - Specifies the number of results displayed per page of output, from 1 - 500, default = 50.
180
+ # modified_since - ISO-8601 formatted timestamp.
181
+ # next - the next link returned from a previous paginated call. May only be used by itself.
182
+ # email - the contact by email address to retrieve information for
183
+ # @return [ResultSet<Campaign>]
184
+ def get_email_campaigns(access_token, params = {})
185
+ Services::EmailMarketingService.get_campaigns(access_token, params)
186
+ end
187
+
188
+
189
+ # Get an individual campaign
190
+ # @param [String] access_token - Constant Contact OAuth2 access token
191
+ # @param [Integer] campaign_id - Valid campaign id
192
+ # @return [Campaign]
193
+ def get_email_campaign(access_token, campaign_id)
194
+ Services::EmailMarketingService.get_campaign(access_token, campaign_id)
195
+ end
196
+
197
+
198
+ # Delete an individual campaign
199
+ # @param [String] access_token - Constant Contact OAuth2 access token
200
+ # @param [Mixed] campaign - Id of a campaign or a Campaign object
201
+ # @raise IllegalArgumentException - if a Campaign object or campaign id is not passed
202
+ # @return [Boolean]
203
+ def delete_email_campaign(access_token, campaign)
204
+ campaign_id = get_argument_id(campaign, 'Campaign')
205
+ Services::EmailMarketingService.delete_campaign(access_token, campaign_id)
206
+ end
207
+
208
+
209
+ # Create a new campaign
210
+ # @param [String] access_token - Constant Contact OAuth2 access token
211
+ # @param [Campaign] campaign - Campaign to be created
212
+ # @return [Campaign] - created campaign
213
+ def add_email_campaign(access_token, campaign)
214
+ Services::EmailMarketingService.add_campaign(access_token, campaign)
215
+ end
216
+
217
+
218
+ # Update a specific campaign
219
+ # @param [String] access_token - Constant Contact OAuth2 access token
220
+ # @param [Campaign] campaign - Campaign to be updated
221
+ # @return [Campaign] - updated campaign
222
+ def update_email_campaign(access_token, campaign)
223
+ Services::EmailMarketingService.update_campaign(access_token, campaign)
224
+ end
225
+
226
+
227
+ # Schedule a campaign to be sent
228
+ # @param [String] access_token - Constant Contact OAuth2 access token
229
+ # @param [Mixed] campaign - Id of a campaign or a Campaign object
230
+ # @param [Schedule] schedule - Schedule to be associated with the provided campaign
231
+ # @return [Campaign] - updated campaign
232
+ def add_email_campaign_schedule(access_token, campaign, schedule)
233
+ campaign_id = get_argument_id(campaign, 'Campaign')
234
+ Services::CampaignScheduleService.add_schedule(access_token, campaign_id, schedule)
235
+ end
236
+
237
+
238
+ # Get an array of schedules associated with a given campaign
239
+ # @param [String] access_token - Constant Contact OAuth2 access token
240
+ # @param [Mixed] campaign - Campaign id or Campaign object itself
241
+ # @return [Array<Schedule>]
242
+ def get_email_campaign_schedules(access_token, campaign)
243
+ campaign_id = get_argument_id(campaign, 'Campaign')
244
+ Services::CampaignScheduleService.get_schedules(access_token, campaign_id)
245
+ end
246
+
247
+
248
+ # Get a specific schedule associated with a given campaign
249
+ # @param [String] access_token - Constant Contact OAuth2 access token
250
+ # @param [Mixed] campaign - Campaign id or Campaign object itself
251
+ # @param [Mixed] schedule - Schedule id or Schedule object itself
252
+ # @raise IllegalArgumentException
253
+ # @return [Schedule]
254
+ def get_email_campaign_schedule(access_token, campaign, schedule)
255
+ campaign_id = get_argument_id(campaign, 'Campaign')
256
+ schedule_id = get_argument_id(schedule, 'Schedule')
257
+ Services::CampaignScheduleService.get_schedule(access_token, campaign_id, schedule_id)
258
+ end
259
+
260
+
261
+ # Update a specific schedule associated with a given campaign
262
+ # @param [String] access_token - Constant Contact OAuth2 access token
263
+ # @param [Mixed] campaign - Campaign id or Campaign object itself
264
+ # @param [Schedule] schedule - Schedule to be updated
265
+ # @return [Schedule]
266
+ def update_email_campaign_schedule(access_token, campaign, schedule)
267
+ campaign_id = get_argument_id(campaign, 'Campaign')
268
+ Services::CampaignScheduleService.update_schedule(access_token, campaign_id, schedule)
269
+ end
270
+
271
+
272
+ # Delete a specific schedule associated with a given campaign
273
+ # @param [String] access_token - Constant Contact OAuth2 access token
274
+ # @param [Mixed] campaign - Campaign id or Campaign object itself
275
+ # @param [Mixed] schedule - Schedule id or Schedule object itself
276
+ # @raise IllegalArgumentException
277
+ # @return [Boolean]
278
+ def delete_email_campaign_schedule(access_token, campaign, schedule)
279
+ campaign_id = get_argument_id(campaign, 'Campaign')
280
+ schedule_id = get_argument_id(schedule, 'Schedule')
281
+ Services::CampaignScheduleService.delete_schedule(access_token, campaign_id, schedule_id)
282
+ end
283
+
284
+
285
+ # Send a test send of a campaign
286
+ # @param [String] access_token - Constant Contact OAuth2 access token
287
+ # @param [Mixed] campaign - Campaign id or Campaign object itself
288
+ # @param [TestSend] test_send - test send details
289
+ # @return [TestSend]
290
+ def send_email_campaign_test(access_token, campaign, test_send)
291
+ campaign_id = get_argument_id(campaign, 'Campaign')
292
+ Services::CampaignScheduleService.send_test(access_token, campaign_id, test_send)
293
+ end
294
+
295
+
296
+ # Get sends for a campaign
297
+ # @param [String] access_token - Constant Contact OAuth2 access token
298
+ # @param [Mixed] campaign - Campaign id or Campaign object itself
299
+ # @param [Hash] params - hash of query parameters and values to append to the request.
300
+ # Allowed parameters include:
301
+ # limit - Specifies the number of results displayed per page of output, from 1 - 500, default = 50.
302
+ # created_since - Used to retrieve a list of events since the date and time specified (in ISO-8601 format).
303
+ # next - the next link returned from a previous paginated call. May only be used by itself.
304
+ # @return [ResultSet<SendActivity>]
305
+ def get_email_campaign_sends(access_token, campaign, params = {})
306
+ campaign_id = get_argument_id(campaign, 'Campaign')
307
+ Services::CampaignTrackingService.get_sends(access_token, campaign_id, params)
308
+ end
309
+
310
+
311
+ # Get bounces for a campaign
312
+ # @param [String] access_token - Constant Contact OAuth2 access token
313
+ # @param [Mixed] campaign - Campaign id or Campaign object itself
314
+ # @param [Hash] params - hash of query parameters and values to append to the request.
315
+ # Allowed parameters include:
316
+ # limit - Specifies the number of results displayed per page of output, from 1 - 500, default = 50.
317
+ # created_since - Used to retrieve a list of events since the date and time specified (in ISO-8601 format).
318
+ # next - the next link returned from a previous paginated call. May only be used by itself.
319
+ # @return [ResultSet<BounceActivity>]
320
+ def get_email_campaign_bounces(access_token, campaign, params = {})
321
+ campaign_id = get_argument_id(campaign, 'Campaign')
322
+ Services::CampaignTrackingService.get_bounces(access_token, campaign_id, params)
323
+ end
324
+
325
+
326
+ # Get clicks for a campaign
327
+ # @param [String] access_token - Constant Contact OAuth2 access token
328
+ # @param [Mixed] campaign - Campaign id or Campaign object itself
329
+ # @param [Hash] params - hash of query parameters and values to append to the request.
330
+ # Allowed parameters include:
331
+ # limit - Specifies the number of results displayed per page of output, from 1 - 500, default = 50.
332
+ # created_since - Used to retrieve a list of events since the date and time specified (in ISO-8601 format).
333
+ # next - the next link returned from a previous paginated call. May only be used by itself.
334
+ # @return [ResultSet<ClickActivity>]
335
+ def get_email_campaign_clicks(access_token, campaign, params = {})
336
+ campaign_id = get_argument_id(campaign, 'Campaign')
337
+ Services::CampaignTrackingService.get_clicks(access_token, campaign_id, params)
338
+ end
339
+
340
+
341
+ # Get opens for a campaign
342
+ # @param [String] access_token - Constant Contact OAuth2 access token
343
+ # @param [Mixed] campaign - Campaign id or Campaign object itself
344
+ # @param [Hash] params - hash of query parameters and values to append to the request.
345
+ # Allowed parameters include:
346
+ # limit - Specifies the number of results displayed per page of output, from 1 - 500, default = 50.
347
+ # created_since - Used to retrieve a list of events since the date and time specified (in ISO-8601 format).
348
+ # next - the next link returned from a previous paginated call. May only be used by itself.
349
+ # @return [ResultSet<OpenActivity>]
350
+ def get_email_campaign_opens(access_token, campaign, params = {})
351
+ campaign_id = get_argument_id(campaign, 'Campaign')
352
+ Services::CampaignTrackingService.get_opens(access_token, campaign_id, params)
353
+ end
354
+
355
+
356
+ # Get forwards for a campaign
357
+ # @param [String] access_token - Constant Contact OAuth2 access token
358
+ # @param [Mixed] campaign - Campaign id or Campaign object itself
359
+ # @param [Hash] params - hash of query parameters and values to append to the request.
360
+ # Allowed parameters include:
361
+ # limit - Specifies the number of results displayed per page of output, from 1 - 500, default = 50.
362
+ # created_since - Used to retrieve a list of events since the date and time specified (in ISO-8601 format).
363
+ # next - the next link returned from a previous paginated call. May only be used by itself.
364
+ # @return [ResultSet<ForwardActivity>]
365
+ def get_email_campaign_forwards(access_token, campaign, params = {})
366
+ campaign_id = get_argument_id(campaign, 'Campaign')
367
+ Services::CampaignTrackingService.get_forwards(access_token, campaign_id, params)
368
+ end
369
+
370
+
371
+ # Get unsubscribes for a campaign
372
+ # @param [String] access_token - Constant Contact OAuth2 access token
373
+ # @param [Mixed] campaign - Campaign id or Campaign object itself
374
+ # @param [Hash] params - hash of query parameters and values to append to the request.
375
+ # Allowed parameters include:
376
+ # limit - Specifies the number of results displayed per page of output, from 1 - 500, default = 50.
377
+ # created_since - Used to retrieve a list of events since the date and time specified (in ISO-8601 format).
378
+ # next - the next link returned from a previous paginated call. May only be used by itself.
379
+ # @return [ResultSet<UnsubscribeActivity>] - Containing a results array of UnsubscribeActivity
380
+ def get_email_campaign_unsubscribes(access_token, campaign, params = {})
381
+ campaign_id = get_argument_id(campaign, 'Campaign')
382
+ Services::CampaignTrackingService.get_unsubscribes(access_token, campaign_id, params)
383
+ end
384
+
385
+
386
+ # Get a reporting summary for a campaign
387
+ # @param [String] access_token - Constant Contact OAuth2 access token
388
+ # @param [Mixed] campaign - Campaign id or Campaign object itself
389
+ # @return [TrackingSummary]
390
+ def get_email_campaign_summary_report(access_token, campaign)
391
+ campaign_id = get_argument_id(campaign, 'Campaign')
392
+ Services::CampaignTrackingService.get_summary(access_token, campaign_id)
393
+ end
394
+
395
+
396
+ # Get sends for a Contact
397
+ # @param [String] access_token - Constant Contact OAuth2 access token
398
+ # @param [Mixed] contact - Contact id or Contact object itself
399
+ # @param [Hash] params - hash of query parameters and values to append to the request.
400
+ # Allowed parameters include:
401
+ # limit - Specifies the number of results displayed per page of output, from 1 - 500, default = 50.
402
+ # created_since - Used to retrieve a list of events since the date and time specified (in ISO-8601 format).
403
+ # next - the next link returned from a previous paginated call. May only be used by itself.
404
+ # @return [ResultSet<SendActivity>]
405
+ def get_contact_sends(access_token, contact, params = {})
406
+ contact_id = get_argument_id(contact, 'Contact')
407
+ Services::ContactTrackingService.get_sends(access_token, contact_id, params)
408
+ end
409
+
410
+
411
+ # Get bounces 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 [Hash] params - hash of query parameters and values to append to the request.
415
+ # Allowed parameters include:
416
+ # limit - Specifies the number of results displayed per page of output, from 1 - 500, default = 50.
417
+ # created_since - Used to retrieve a list of events since the date and time specified (in ISO-8601 format).
418
+ # next - the next link returned from a previous paginated call. May only be used by itself.
419
+ # @return [ResultSet<BounceActivity>]
420
+ def get_contact_bounces(access_token, contact, params = {})
421
+ contact_id = get_argument_id(contact, 'Contact')
422
+ Services::ContactTrackingService.get_bounces(access_token, contact_id, params)
423
+ end
424
+
425
+
426
+ # Get clicks for a Contact
427
+ # @param [String] access_token - Constant Contact OAuth2 access token
428
+ # @param [Mixed] contact - Contact id or Contact object itself
429
+ # @param [Hash] params - hash of query parameters and values to append to the request.
430
+ # Allowed parameters include:
431
+ # limit - Specifies the number of results displayed per page of output, from 1 - 500, default = 50.
432
+ # created_since - Used to retrieve a list of events since the date and time specified (in ISO-8601 format).
433
+ # next - the next link returned from a previous paginated call. May only be used by itself.
434
+ # @return [ResultSet<ClickActivity>]
435
+ def get_contact_clicks(access_token, contact, params = {})
436
+ contact_id = get_argument_id(contact, 'Contact')
437
+ Services::ContactTrackingService.get_clicks(access_token, contact_id, params)
438
+ end
439
+
440
+
441
+ # Get opens for a Contact
442
+ # @param [String] access_token - Constant Contact OAuth2 access token
443
+ # @param [Mixed] contact - Contact id or Contact object itself
444
+ # @param [Hash] params - hash of query parameters and values to append to the request.
445
+ # Allowed parameters include:
446
+ # limit - Specifies the number of results displayed per page of output, from 1 - 500, default = 50.
447
+ # created_since - Used to retrieve a list of events since the date and time specified (in ISO-8601 format).
448
+ # next - the next link returned from a previous paginated call. May only be used by itself.
449
+ # @return [ResultSet<OpenActivity>]
450
+ def get_contact_opens(access_token, contact, params = {})
451
+ contact_id = get_argument_id(contact, 'Contact')
452
+ Services::ContactTrackingService.get_opens(access_token, contact_id, params)
453
+ end
454
+
455
+
456
+ # Get forwards for a Contact
457
+ # @param [String] access_token - Constant Contact OAuth2 access token
458
+ # @param [Mixed] contact - Contact id or Contact object itself
459
+ # @param [Hash] params - hash of query parameters and values to append to the request.
460
+ # Allowed parameters include:
461
+ # limit - Specifies the number of results displayed per page of output, from 1 - 500, default = 50.
462
+ # created_since - Used to retrieve a list of events since the date and time specified (in ISO-8601 format).
463
+ # next - the next link returned from a previous paginated call. May only be used by itself.
464
+ # @return [ResultSet<ForwardActivity>]
465
+ def get_contact_forwards(access_token, contact, params = {})
466
+ contact_id = get_argument_id(contact, 'Contact')
467
+ Services::ContactTrackingService.get_forwards(access_token, contact_id, params)
468
+ end
469
+
470
+
471
+ # Get unsubscribes for a Contact
472
+ # @param [String] access_token - Constant Contact OAuth2 access token
473
+ # @param [Mixed] contact - Contact id or Contact object itself
474
+ # @param [Hash] params - hash of query parameters and values to append to the request.
475
+ # Allowed parameters include:
476
+ # limit - Specifies the number of results displayed per page of output, from 1 - 500, default = 50.
477
+ # created_since - Used to retrieve a list of events since the date and time specified (in ISO-8601 format).
478
+ # next - the next link returned from a previous paginated call. May only be used by itself.
479
+ # @return [UnsubscribeActivity] - Containing a results array of UnsubscribeActivity
480
+ def get_contact_unsubscribes(access_token, contact, params = {})
481
+ contact_id = get_argument_id(contact, 'Contact')
482
+ Services::ContactTrackingService.get_unsubscribes(access_token, contact_id, params)
483
+ end
484
+
485
+
486
+ # Get a reporting summary for a Contact
487
+ # @param [String] access_token - Constant Contact OAuth2 access token
488
+ # @param [Mixed] contact - Contact id or Contact object itself
489
+ # @return [TrackingSummary]
490
+ def get_contact_summary_report(access_token, contact)
491
+ contact_id = get_argument_id(contact, 'Contact')
492
+ Services::ContactTrackingService.get_summary(access_token, contact_id)
493
+ end
494
+
495
+
496
+ # Get an array of activities
497
+ # @param [String] access_token - Constant Contact OAuth2 access token
498
+ # @param [Hash] params - hash of query parameters and values to append to the request.
499
+ # Allowed parameters include:
500
+ # status - Status of the activity, must be one of UNCONFIRMED, PENDING, QUEUED, RUNNING, COMPLETE, ERROR
501
+ # type - Type of activity, must be one of ADD_CONTACTS, REMOVE_CONTACTS_FROM_LISTS, CLEAR_CONTACTS_FROM_LISTS,
502
+ # EXPORT_CONTACTS
503
+ # @return [Array<Activity>]
504
+ def get_activities(access_token, params = {})
505
+ Services::ActivityService.get_activities(access_token, params)
506
+ end
507
+
508
+
509
+ # Get a single activity by id
510
+ # @param [String] access_token - Constant Contact OAuth2 access token
511
+ # @param [String] activity_id - Activity id
512
+ # @return [Activity]
513
+ def get_activity(access_token, activity_id)
514
+ Services::ActivityService.get_activity(access_token, activity_id)
515
+ end
516
+
517
+
518
+ # Add an AddContacts activity to add contacts in bulk
519
+ # @param [String] access_token - Constant Contact OAuth2 access token
520
+ # @param [AddContacts] add_contacts - Add Contacts Activity
521
+ # @return [Activity]
522
+ def add_create_contacts_activity(access_token, add_contacts)
523
+ Services::ActivityService.create_add_contacts_activity(access_token, add_contacts)
524
+ end
525
+
526
+
527
+ # Create an Add Contacts Activity from a file. Valid file types are txt, csv, xls, xlsx
528
+ # @param [String] access_token - Constant Contact OAuth2 access token
529
+ # @param [String] file_name - The name of the file (ie: contacts.csv)
530
+ # @param [String] contents - The content of the file
531
+ # @param [String] lists - Comma separated list of ContactList id's to add the contacts to
532
+ # @return [Activity]
533
+ def add_create_contacts_activity_from_file(access_token, file_name, contents, lists)
534
+ Services::ActivityService.create_add_contacts_activity_from_file(access_token, file_name, contents, lists)
535
+ end
536
+
537
+
538
+ # Add a ClearLists Activity to remove all contacts from the provided lists
539
+ # @param [String] access_token - Constant Contact OAuth2 access token
540
+ # @param [Array<Lists>] lists - Add Contacts Activity
541
+ # @return [Activity]
542
+ def add_clear_lists_activity(access_token, lists)
543
+ Services::ActivityService.add_clear_lists_activity(access_token, lists)
544
+ end
545
+
546
+
547
+ # Add a Remove Contacts From Lists Activity
548
+ # @param [String] access_token - Constant Contact OAuth2 access token
549
+ # @param [Array<EmailAddress>] email_addresses - email addresses to be removed
550
+ # @param [Array<Lists>] lists - lists to remove the provided email addresses from
551
+ # @return [Activity]
552
+ def add_remove_contacts_from_lists_activity(access_token, email_addresses, lists)
553
+ Services::ActivityService.add_remove_contacts_from_lists_activity(access_token, email_addresses, lists)
554
+ end
555
+
556
+
557
+ # Add a Remove Contacts From Lists Activity from a file. Valid file types are txt, csv, xls, xlsx
558
+ # @param [String] access_token - Constant Contact OAuth2 access token
559
+ # @param [String] file_name - The name of the file (ie: contacts.csv)
560
+ # @param [String] contents - The content of the file
561
+ # @param [String] lists - Comma separated list of ContactList id' to add the contacts too
562
+ # @return [Activity]
563
+ def add_remove_contacts_from_lists_activity_from_file(access_token, file_name, contents, lists)
564
+ Services::ActivityService.add_remove_contacts_from_lists_activity_from_file(access_token, file_name, contents, lists)
565
+ end
566
+
567
+
568
+ # Create an Export Contacts Activity
569
+ # @param [String] access_token - Constant Contact OAuth2 access token
570
+ # @param [<Array>Contacts] export_contacts - Contacts to be exported
571
+ # @return [Activity]
572
+ def add_export_contacts_activity(access_token, export_contacts)
573
+ Services::ActivityService.add_export_contacts_activity(access_token, export_contacts)
574
+ end
575
+
576
+
577
+ # Get a list of events
578
+ # @param [String] access_token - Constant Contact OAuth2 access token
579
+ # @return [ResultSet<Event>]
580
+ def get_events(access_token)
581
+ Services::EventSpotService.get_events(access_token)
582
+ end
583
+
584
+
585
+ # Get an event
586
+ # @param [String] access_token - Constant Contact OAuth2 access token
587
+ # @param [Event] event - event id or object to be retrieved
588
+ # @return [Event]
589
+ def get_event(access_token, event)
590
+ Services::EventSpotService.get_event(access_token, event)
591
+ end
592
+
593
+
594
+ # Create an event
595
+ # @param [String] access_token - Constant Contact OAuth2 access token
596
+ # @param [Hash] event - Event data stored in an object which respods to to_json
597
+ # @return [Event]
598
+ def add_event(access_token, event)
599
+ Services::EventSpotService.add_event(access_token, event)
600
+ end
601
+
602
+
603
+ # Update an event
604
+ # @param [String] access_token - Constant Contact OAuth2 access token
605
+ # @param [Event|Hash] event - Event details stored in an object that responds to to_json and has an :id attribute
606
+ # @return [Event]
607
+ def update_event(access_token, event)
608
+ Services::EventSpotService.update_event(access_token, event)
609
+ end
610
+
611
+
612
+ # Publish an event
613
+ # @param [String] access_token - Constant Contact OAuth2 access token
614
+ # @param [Event] event - Event to publish
615
+ # @return [Event]
616
+ def publish_event(access_token, event)
617
+ Services::EventSpotService.publish_event(access_token, event)
618
+ end
619
+
620
+
621
+ # Cancel an event
622
+ # @param [String] access_token - Constant Contact OAuth2 access token
623
+ # @param [Event] event - Event to cancel
624
+ # @return [Activity]
625
+ def cancel_event(access_token, event)
626
+ Services::EventSpotService.cancel_event(access_token, event)
627
+ end
628
+
629
+
630
+ # Delete an event
631
+ # @param [String] access_token - Constant Contact OAuth2 access token
632
+ # @param [Event] event - Event fee corresponds to
633
+ # @return [Activity]
634
+ def delete_event(access_token, event)
635
+ Services::EventSpotService.delete_event(access_token, event)
636
+ end
637
+
638
+
639
+ # Get a list of event fees
640
+ # @param [String] access_token - Constant Contact OAuth2 access token
641
+ # @param [Event] event - Event to get fees of
642
+ # @return [Activity]
643
+ def get_event_fees(access_token, event)
644
+ Services::EventSpotService.get_fees(access_token, event)
645
+ end
646
+
647
+
648
+ # Get an event fee
649
+ # @param [String] access_token - Constant Contact OAuth2 access token
650
+ # @param [Event] event - Event fee corresponds to
651
+ # @param [Fee] fee - Fee to retrieve
652
+ # @return [Activity]
653
+ def get_event_fee(access_token, event, fee)
654
+ Services::EventSpotService.get_fee(access_token, event, fee)
655
+ end
656
+
657
+
658
+ # Create an event fee
659
+ # @param [String] access_token - Constant Contact OAuth2 access token
660
+ # @param [Event] event - Event fee corresponds to
661
+ # @param [Hash] fee - Fee details
662
+ # @return [Activity]
663
+ def add_event_fee(access_token, event, fee)
664
+ Services::EventSpotService.add_fee(access_token, event, fee)
665
+ end
666
+
667
+
668
+ # Update an event fee
669
+ # @param [String] access_token - Constant Contact OAuth2 access token
670
+ # @param [Event] event - Event fee corresponds to
671
+ # @param [Fee] fee - Fee details
672
+ # @return [Activity]
673
+ def update_event_fee(access_token, event, fee)
674
+ Services::EventSpotService.update_fee(access_token, event, fee)
675
+ end
676
+
677
+
678
+ # Delete an event fee
679
+ # @param [String] access_token - Constant Contact OAuth2 access token
680
+ # @param [Event] event - Event fee corresponds to
681
+ # @param [Fee] fee - Fee details
682
+ # @return [Activity]
683
+ def delete_event_fee(access_token, event, fee)
684
+ Services::EventSpotService.delete_fee(access_token, event, fee)
685
+ end
686
+
687
+
688
+ # Get a list of event registrants
689
+ # @param [String] access_token - Constant Contact OAuth2 access token
690
+ # @param [Event] event - Event fee corresponds to
691
+ # @return [Activity]
692
+ def get_event_registrants(access_token, event)
693
+ Services::EventSpotService.get_registrants(access_token, event)
694
+ end
695
+
696
+
697
+ # Get an event registrant
698
+ # @param [String] access_token - Constant Contact OAuth2 access token
699
+ # @param [Event] event - Event registrant corresponds to
700
+ # @param [Registrant] registrant - registrant details
701
+ # @return [Activity]
702
+ def get_event_registrant(access_token, event, registrant)
703
+ Services::EventSpotService.get_registrant(access_token, event, registrant)
704
+ end
705
+
706
+
707
+ # Retrieve MyLibrary usage information
708
+ # @param [String] access_token - Constant Contact OAuth2 access token
709
+ # @return [LibrarySummary]
710
+ def get_library_info(access_token)
711
+ Services::LibraryService.get_library_info(access_token)
712
+ end
713
+
714
+
715
+ # Retrieve a list of MyLibrary folders
716
+ # @param [String] access_token - Constant Contact OAuth2 access token
717
+ # @param [Hash] params - hash of query parameters and values to append to the request.
718
+ # Allowed parameters include:
719
+ # sort_by - The method to sort by, valid values are :
720
+ # CREATED_DATE - sorts by date folder was added, ascending (earliest to latest)
721
+ # CREATED_DATE_DESC - (default) sorts by date folder was added, descending (latest to earliest)
722
+ # MODIFIED_DATE - sorts by date folder was last modified, ascending (earliest to latest)
723
+ # MODIFIED_DATE_DESC - sorts by date folder was last modified, descending (latest to earliest)
724
+ # NAME - sorts alphabetically by folder name, a to z
725
+ # NAME_DESC - sorts alphabetically by folder name, z to a
726
+ # limit - Specifies the number of results displayed per page of output, from 1 - 50, default = 50.
727
+ # @return [ResultSet<LibraryFolder>]
728
+ def get_library_folders(access_token, params = {})
729
+ Services::LibraryService.get_library_folders(access_token, params)
730
+ end
731
+
732
+
733
+ # Create a new MyLibrary folder
734
+ # @param [String] access_token - Constant Contact OAuth2 access token
735
+ # @param [LibraryFolder] folder - Library Folder to be created
736
+ # @return [LibraryFolder]
737
+ def add_library_folder(access_token, folder)
738
+ Services::LibraryService.add_library_folder(access_token, folder)
739
+ end
740
+
741
+
742
+ # Retrieve a specific MyLibrary folder using the folder_id path parameter
743
+ # @param [String] access_token - Constant Contact OAuth2 access token
744
+ # @param [String] folder_id - The ID for the folder to return
745
+ # @return [LibraryFolder]
746
+ def get_library_folder(access_token, folder_id)
747
+ Services::LibraryService.get_library_folder(access_token, folder_id)
748
+ end
749
+
750
+
751
+ # Update a specific MyLibrary folder
752
+ # @param [String] access_token - Constant Contact OAuth2 access token
753
+ # @param [LibraryFolder] folder - MyLibrary folder to be updated
754
+ # @return [LibraryFolder]
755
+ def update_library_folder(access_token, folder)
756
+ Services::LibraryService.update_library_folder(access_token, folder)
757
+ end
758
+
759
+
760
+ # Delete a MyLibrary folder
761
+ # @param [String] access_token - Constant Contact OAuth2 access token
762
+ # @param [String] folder_id - The ID for the MyLibrary folder to delete
763
+ # @return [Boolean]
764
+ def delete_library_folder(access_token, folder_id)
765
+ Services::LibraryService.delete_library_folder(access_token, folder_id)
766
+ end
767
+
768
+
769
+ # Retrieve all files in the Trash folder
770
+ # @param [String] access_token - Constant Contact OAuth2 access token
771
+ # @param [Hash] params - hash of query parameters and values to append to the request.
772
+ # Allowed parameters include:
773
+ # type - Specifies the type of files to retrieve, valid values are : ALL, IMAGES, or DOCUMENTS
774
+ # sort_by - The method to sort by, valid values are :
775
+ # ADDED_DATE - sorts by date folder was added, ascending (earliest to latest)
776
+ # ADDED_DATE_DESC - (default) sorts by date folder was added, descending (latest to earliest)
777
+ # MODIFIED_DATE - sorts by date folder was last modified, ascending (earliest to latest)
778
+ # MODIFIED_DATE_DESC - sorts by date folder was last modified, descending (latest to earliest)
779
+ # NAME - sorts alphabetically by file name, a to z
780
+ # NAME_DESC - sorts alphabetically by file name, z to a
781
+ # SIZE - sorts by file size, smallest to largest
782
+ # SIZE_DESC - sorts by file size, largest to smallest
783
+ # DIMENSION - sorts by file dimensions (hxw), smallest to largest
784
+ # DIMENSION_DESC - sorts by file dimensions (hxw), largest to smallest
785
+ # limit - Specifies the number of results displayed per page of output, from 1 - 50, default = 50.
786
+ # @return [ResultSet<LibraryFile>]
787
+ def get_library_trash(access_token, params = {})
788
+ Services::LibraryService.get_library_trash(access_token, params)
789
+ end
790
+
791
+
792
+ # Permanently deletes all files in the Trash folder
793
+ # @param [String] access_token - Constant Contact OAuth2 access token
794
+ # @return [Boolean]
795
+ def delete_library_trash(access_token)
796
+ Services::LibraryService.delete_library_trash(access_token)
797
+ end
798
+
799
+
800
+ # Retrieve a collection of Library files in the Constant Contact account
801
+ # @param [String] access_token - Constant Contact OAuth2 access token
802
+ # @param [Hash] params - hash of query parameters and values to append to the request.
803
+ # Allowed parameters include:
804
+ # type - Specifies the type of files to retrieve, valid values are : ALL, IMAGES, or DOCUMENTS
805
+ # source - Specifies to retrieve files from a particular source, valid values are :
806
+ # ALL - (default) files from all sources
807
+ # MyComputer
808
+ # StockImage
809
+ # Facebook
810
+ # Instagram
811
+ # Shutterstock
812
+ # Mobile
813
+ # limit - Specifies the number of results displayed per page of output, from 1 - 1000, default = 50.
814
+ # @return [ResultSet<LibraryFile>]
815
+ def get_library_files(access_token, params = {})
816
+ Services::LibraryService.get_library_files(access_token, params)
817
+ end
818
+
819
+
820
+ # Retrieves all files from a MyLibrary folder specified by the folder_id path parameter
821
+ # @param [String] access_token - Constant Contact OAuth2 access token
822
+ # @param [String] folder_id - Specifies the folder from which to retrieve files
823
+ # @param [Hash] params - hash of query parameters and values to append to the request.
824
+ # Allowed parameters include:
825
+ # limit - Specifies the number of results displayed per page of output, from 1 - 50, default = 50.
826
+ # @return [ResultSet<LibraryFile>]
827
+ def get_library_files_by_folder(access_token, folder_id, params = {})
828
+ Services::LibraryService.get_library_files_by_folder(access_token, folder_id, params)
829
+ end
830
+
831
+
832
+ # Retrieve a MyLibrary file using the file_id path parameter
833
+ # @param [String] access_token - Constant Contact OAuth2 access token
834
+ # @param [String] file_id - Specifies the MyLibrary file for which to retrieve information
835
+ # @return [LibraryFile]
836
+ def get_library_file(access_token, file_id)
837
+ Services::LibraryService.get_library_file(access_token, file_id)
838
+ end
839
+
840
+
841
+ # Adds a new MyLibrary file using the multipart content-type
842
+ # @param [String] access_token - Constant Contact OAuth2 access token
843
+ # @param [String] file_name - The name of the file (ie: dinnerplate-special.jpg)
844
+ # @param [String] folder_id - Folder id to add the file to
845
+ # @param [String] description - The description of the file provided by user
846
+ # @param [String] source - indicates the source of the original file;
847
+ # image files can be uploaded from the following sources :
848
+ # MyComputer, StockImage, Facebook - MyLibrary Plus customers only,
849
+ # Instagram - MyLibrary Plus customers only, Shutterstock, Mobile
850
+ # @param [String] file_type - Specifies the file type, valid values are: JPEG, JPG, GIF, PDF, PNG
851
+ # @param [String] contents - The content of the file
852
+ # @return [LibraryFile]
853
+ def add_library_file(access_token, file_name, folder_id, description, source, file_type, contents)
854
+ Services::LibraryService.add_library_file(access_token, file_name, folder_id, description, source, file_type, contents)
855
+ end
856
+
857
+
858
+ # Update information for a specific MyLibrary file
859
+ # @param [String] access_token - Constant Contact OAuth2 access token
860
+ # @param [LibraryFile] file - Library File to be updated
861
+ # @return [LibraryFile]
862
+ def update_library_file(access_token, file)
863
+ Services::LibraryService.update_library_file(access_token, file)
864
+ end
865
+
866
+
867
+ # Delete one or more MyLibrary files specified by the fileId path parameter;
868
+ # separate multiple file IDs with a comma.
869
+ # Deleted files are moved from their current folder into the system Trash folder, and its status is set to Deleted.
870
+ # @param [String] access_token - Constant Contact OAuth2 access token
871
+ # @param [String] file_id - Specifies the MyLibrary file to delete
872
+ # @return [Boolean]
873
+ def delete_library_file(access_token, file_id)
874
+ Services::LibraryService.delete_library_file(access_token, file_id)
875
+ end
876
+
877
+
878
+ # Retrieve the upload status for one or more MyLibrary files using the file_id path parameter;
879
+ # separate multiple file IDs with a comma
880
+ # @param [String] access_token - Constant Contact OAuth2 access token
881
+ # @param [String] file_id - Specifies the files for which to retrieve upload status information
882
+ # @return [Array<UploadStatus>]
883
+ def get_library_files_upload_status(access_token, file_id)
884
+ Services::LibraryService.get_library_files_upload_status(access_token, file_id)
885
+ end
886
+
887
+
888
+ # Move one or more MyLibrary files to a different folder in the user's account
889
+ # specify the destination folder using the folder_id path parameter.
890
+ # @param [String] access_token - Constant Contact OAuth2 access token
891
+ # @param [String] folder_id - Specifies the destination MyLibrary folder to which the files will be moved
892
+ # @param [String] file_id - Specifies the files to move, in a string of comma separated file ids (e.g. 8,9)
893
+ # @return [Array<MoveResults>]
894
+ def move_library_files(access_token, folder_id, file_id)
895
+ Services::LibraryService.move_library_files(access_token, folder_id, file_id)
896
+ end
897
+
898
+
899
+
900
+ private
901
+
902
+
903
+ # Get the id of object, or attempt to convert the argument to an int
904
+ # @param [Mixed] item - object or a numeric value
905
+ # @param [String] class_name - class name to test the given object against
906
+ # @raise IllegalArgumentException - if the item is not an instance of the class name given, or cannot be
907
+ # converted to a numeric value
908
+ # @return [Integer]
909
+ def get_argument_id(item, class_name)
910
+ item_id = nil
911
+ if item.is_a?(Integer)
912
+ item_id = item
913
+ elsif item.class.to_s.split('::').last == class_name
914
+ item_id = item.id
915
+ else
916
+ raise Exceptions::IllegalArgumentException.new(sprintf(Util::Config.get('errors.id_or_object'), class_name))
917
+ end
918
+ item_id
919
+ end
920
+
921
+
922
+ # Append the limit parameter, if the value is an integer
923
+ # @param [String] param - parameter value
924
+ # @return [Hash] the parameters as a hash object
925
+ def determine_param(param)
926
+ params = {}
927
+ if param
928
+ param = param.to_s
929
+ if param[0, 1] == '?'
930
+ hash_params = CGI::parse(param[1..-1])
931
+ params = Hash[*hash_params.collect {|key, value| [key, value.first] }.flatten]
932
+ else
933
+ params['limit'] = param
934
+ end
935
+ end
936
+ params
937
+ end
938
+
939
+ end
543
940
  end