constantcontact 1.0.0 → 1.0.1

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