constantcontact 1.3.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +5 -5
  3. data/constantcontact.gemspec +2 -2
  4. data/lib/constantcontact/api.rb +223 -307
  5. data/lib/constantcontact/services/account_service.rb +5 -7
  6. data/lib/constantcontact/services/activity_service.rb +16 -24
  7. data/lib/constantcontact/services/base_service.rb +3 -4
  8. data/lib/constantcontact/services/campaign_schedule_service.rb +12 -18
  9. data/lib/constantcontact/services/campaign_tracking_service.rb +14 -21
  10. data/lib/constantcontact/services/contact_service.rb +14 -21
  11. data/lib/constantcontact/services/contact_tracking_service.rb +14 -21
  12. data/lib/constantcontact/services/email_marketing_service.rb +10 -15
  13. data/lib/constantcontact/services/event_spot_service.rb +56 -85
  14. data/lib/constantcontact/services/library_service.rb +32 -48
  15. data/lib/constantcontact/services/list_service.rb +10 -15
  16. data/lib/constantcontact/util/config.rb +5 -3
  17. data/lib/constantcontact/version.rb +3 -3
  18. data/spec/constantcontact/api_spec.rb +121 -103
  19. data/spec/constantcontact/services/account_service_spec.rb +15 -1
  20. data/spec/constantcontact/services/activity_service_spec.rb +9 -14
  21. data/spec/constantcontact/services/base_service_spec.rb +2 -1
  22. data/spec/constantcontact/services/campaign_schedule_service_spec.rb +6 -6
  23. data/spec/constantcontact/services/campaign_tracking_service_spec.rb +7 -7
  24. data/spec/constantcontact/services/contact_service_spec.rb +7 -7
  25. data/spec/constantcontact/services/contact_tracking_service_spec.rb +7 -7
  26. data/spec/constantcontact/services/email_marketing_spec.rb +5 -5
  27. data/spec/constantcontact/services/event_spot_spec.rb +27 -27
  28. data/spec/constantcontact/services/library_service_spec.rb +16 -16
  29. data/spec/constantcontact/services/list_service_spec.rb +5 -5
  30. metadata +2 -2
@@ -10,24 +10,22 @@ module ConstantContact
10
10
  class << self
11
11
 
12
12
  # Get a summary of account information
13
- # @param [String] access_token
14
- # @return
15
- def get_account_info(access_token)
13
+ # @return [AccountInfo]
14
+ def get_account_info()
16
15
  url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.account_info')
17
16
  url = build_url(url)
18
- response = RestClient.get(url, get_headers(access_token))
17
+ response = RestClient.get(url, get_headers())
19
18
  Components::AccountInfo.create(JSON.parse(response.body))
20
19
  end
21
20
 
22
21
 
23
22
  # Get all verified email addresses associated with an account
24
- # @param [String] access_token - Constant Contact OAuth2 access token
25
23
  # @param [Hash] params - hash of query parameters/values to append to the request
26
24
  # @return [Array<VerifiedEmailAddress>]
27
- def get_verified_email_addresses(access_token, params)
25
+ def get_verified_email_addresses(params)
28
26
  url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.account_verified_addresses')
29
27
  url = build_url(url, params)
30
- response = RestClient.get(url, get_headers(access_token))
28
+ response = RestClient.get(url, get_headers())
31
29
  email_addresses = []
32
30
  JSON.parse(response.body).each do |email_address|
33
31
  email_addresses << Components::VerifiedEmailAddress.create(email_address)
@@ -10,13 +10,12 @@ module ConstantContact
10
10
  class << self
11
11
 
12
12
  # Get a set of activities
13
- # @param [String] access_token - Constant Contact OAuth2 access token
14
13
  # @param [Hash] params - query parameters to be appended to the url
15
14
  # @return [Array<Activity>]
16
- def get_activities(access_token, params = {})
15
+ def get_activities(params = {})
17
16
  url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.activities')
18
17
  url = build_url(url, params)
19
- response = RestClient.get(url, get_headers(access_token))
18
+ response = RestClient.get(url, get_headers())
20
19
 
21
20
  activities = []
22
21
  JSON.parse(response.body).each do |activity|
@@ -28,84 +27,78 @@ module ConstantContact
28
27
 
29
28
 
30
29
  # Get an array of activities
31
- # @param [String] access_token - Constant Contact OAuth2 access token
32
30
  # @param [String] activity_id - Activity id
33
31
  # @return [Activity]
34
- def get_activity(access_token, activity_id)
32
+ def get_activity(activity_id)
35
33
  url = Util::Config.get('endpoints.base_url') +
36
34
  sprintf(Util::Config.get('endpoints.activity'), activity_id)
37
35
  url = build_url(url)
38
- response = RestClient.get(url, get_headers(access_token))
36
+ response = RestClient.get(url, get_headers())
39
37
  Components::Activity.create(JSON.parse(response.body))
40
38
  end
41
39
 
42
40
 
43
41
  # Create an Add Contacts Activity
44
- # @param [String] access_token - Constant Contact OAuth2 access token
45
42
  # @param [AddContacts] add_contacts
46
43
  # @return [Activity]
47
- def create_add_contacts_activity(access_token, add_contacts)
44
+ def create_add_contacts_activity(add_contacts)
48
45
  url = Util::Config.get('endpoints.base_url') +
49
46
  Util::Config.get('endpoints.add_contacts_activity')
50
47
  url = build_url(url)
51
48
  payload = add_contacts.to_json
52
- response = RestClient.post(url, payload, get_headers(access_token))
49
+ response = RestClient.post(url, payload, get_headers())
53
50
  Components::Activity.create(JSON.parse(response.body))
54
51
  end
55
52
 
56
53
 
57
54
  # Create an Add Contacts Activity from a file. Valid file types are txt, csv, xls, xlsx
58
- # @param [String] access_token - Constant Contact OAuth2 access token
59
55
  # @param [String] file_name - The name of the file (ie: contacts.csv)
60
56
  # @param [String] contents - The content of the file
61
57
  # @param [String] lists - Comma separated list of ContactList id's to add the contacts to
62
58
  # @return [Activity]
63
- def create_add_contacts_activity_from_file(access_token, file_name, contents, lists)
59
+ def create_add_contacts_activity_from_file(file_name, contents, lists)
64
60
  url = Util::Config.get('endpoints.base_url') +
65
61
  Util::Config.get('endpoints.add_contacts_activity')
66
62
  url = build_url(url)
67
63
 
68
64
  payload = { :file_name => file_name, :lists => lists, :data => contents, :multipart => true }
69
65
 
70
- response = RestClient.post(url, payload, get_headers(access_token))
66
+ response = RestClient.post(url, payload, get_headers())
71
67
  Components::Activity.create(JSON.parse(response.body))
72
68
  end
73
69
 
74
70
 
75
71
  # Create a Clear Lists Activity
76
- # @param [String] access_token - Constant Contact OAuth2 access token
77
72
  # @param [Array<lists>] lists - array of list id's to be cleared
78
73
  # @return [Activity]
79
- def add_clear_lists_activity(access_token, lists)
74
+ def add_clear_lists_activity(lists)
80
75
  url = Util::Config.get('endpoints.base_url') +
81
76
  Util::Config.get('endpoints.clear_lists_activity')
82
77
  url = build_url(url)
83
78
  payload = {'lists' => lists}.to_json
84
- response = RestClient.post(url, payload, get_headers(access_token))
79
+ response = RestClient.post(url, payload, get_headers())
85
80
  Components::Activity.create(JSON.parse(response.body))
86
81
  end
87
82
 
88
83
 
89
84
  # Create an Export Contacts Activity
90
- # @param [String] access_token - Constant Contact OAuth2 access token
91
85
  # @param [ExportContacts] export_contacts
92
86
  # @return [Activity]
93
- def add_export_contacts_activity(access_token, export_contacts)
87
+ def add_export_contacts_activity(export_contacts)
94
88
  url = Util::Config.get('endpoints.base_url') +
95
89
  Util::Config.get('endpoints.export_contacts_activity')
96
90
  url = build_url(url)
97
91
  payload = export_contacts.to_json
98
- response = RestClient.post(url, payload, get_headers(access_token))
92
+ response = RestClient.post(url, payload, get_headers())
99
93
  Components::Activity.create(JSON.parse(response.body))
100
94
  end
101
95
 
102
96
 
103
97
  # Create a Remove Contacts From Lists Activity
104
- # @param [String] access_token - Constant Contact OAuth2 access token
105
98
  # @param [<Array>EmailAddress] email_addresses
106
99
  # @param [<Array>RemoveFromLists] lists
107
100
  # @return [Activity]
108
- def add_remove_contacts_from_lists_activity(access_token, email_addresses, lists)
101
+ def add_remove_contacts_from_lists_activity(email_addresses, lists)
109
102
  url = Util::Config.get('endpoints.base_url') +
110
103
  Util::Config.get('endpoints.remove_from_lists_activity')
111
104
  url = build_url(url)
@@ -116,25 +109,24 @@ module ConstantContact
116
109
  end
117
110
  payload = payload.to_json
118
111
 
119
- response = RestClient.post(url, payload, get_headers(access_token))
112
+ response = RestClient.post(url, payload, get_headers())
120
113
  Components::Activity.create(JSON.parse(response.body))
121
114
  end
122
115
 
123
116
 
124
117
  # Create an Remove Contacts Activity from a file. Valid file types are txt, csv, xls, xlsx
125
- # @param [String] access_token - Constant Contact OAuth2 access token
126
118
  # @param [String] file_name - The name of the file (ie: contacts.csv)
127
119
  # @param [String] contents - The content of the file
128
120
  # @param [String] lists - Comma separated list of ContactList id' to add the contacts too
129
121
  # @return [Activity]
130
- def add_remove_contacts_from_lists_activity_from_file(access_token, file_name, contents, lists)
122
+ def add_remove_contacts_from_lists_activity_from_file(file_name, contents, lists)
131
123
  url = Util::Config.get('endpoints.base_url') +
132
124
  Util::Config.get('endpoints.remove_from_lists_activity')
133
125
  url = build_url(url)
134
126
 
135
127
  payload = { :file_name => file_name, :lists => lists, :data => contents, :multipart => true }
136
128
 
137
- response = RestClient.post(url, payload, get_headers(access_token))
129
+ response = RestClient.post(url, payload, get_headers())
138
130
  Components::Activity.create(JSON.parse(response.body))
139
131
  end
140
132
 
@@ -8,19 +8,18 @@ module ConstantContact
8
8
  module Services
9
9
  class BaseService
10
10
  class << self
11
- attr_accessor :api_key
11
+ attr_accessor :api_key, :access_token
12
12
 
13
13
  protected
14
14
 
15
15
  # Return required headers for making an http request with Constant Contact
16
- # @param [String] access_token - OAuth2 access token to be placed into the Authorization header
17
16
  # @param [String] content_type - The MIME type of the body of the request, default is 'application/json'
18
17
  # @return [Hash] - authorization headers
19
- def get_headers(access_token, content_type = 'application/json')
18
+ def get_headers(content_type = 'application/json')
20
19
  {
21
20
  :content_type => content_type,
22
21
  :accept => 'application/json',
23
- :authorization => "Bearer #{access_token}",
22
+ :authorization => "Bearer #{BaseService.access_token}",
24
23
  :user_agent => "AppConnect Ruby SDK v#{ConstantContact::SDK::VERSION} (#{RUBY_DESCRIPTION})",
25
24
  :x_ctct_request_source => "sdk.ruby.#{ConstantContact::SDK::VERSION}"
26
25
  }
@@ -10,29 +10,27 @@ module ConstantContact
10
10
  class << self
11
11
 
12
12
  # Create a new schedule for a campaign
13
- # @param [String] access_token - Constant Contact OAuth2 access token
14
13
  # @param [Integer] campaign_id - Campaign id to be scheduled
15
14
  # @param [Schedule] schedule - Schedule to be created
16
15
  # @return [Schedule]
17
- def add_schedule(access_token, campaign_id, schedule)
16
+ def add_schedule(campaign_id, schedule)
18
17
  url = Util::Config.get('endpoints.base_url') +
19
18
  sprintf(Util::Config.get('endpoints.campaign_schedules'), campaign_id)
20
19
  url = build_url(url)
21
20
  payload = schedule.to_json
22
- response = RestClient.post(url, payload, get_headers(access_token))
21
+ response = RestClient.post(url, payload, get_headers())
23
22
  Components::Schedule.create(JSON.parse(response.body))
24
23
  end
25
24
 
26
25
 
27
26
  # Get a list of schedules for a campaign
28
- # @param [String] access_token - Constant Contact OAuth2 access token
29
27
  # @param [Integer] campaign_id - Campaign id to be scheduled
30
28
  # @return [Array<Schedule>]
31
- def get_schedules(access_token, campaign_id)
29
+ def get_schedules(campaign_id)
32
30
  url = Util::Config.get('endpoints.base_url') +
33
31
  sprintf(Util::Config.get('endpoints.campaign_schedules'), campaign_id)
34
32
  url = build_url(url)
35
- response = RestClient.get(url, get_headers(access_token))
33
+ response = RestClient.get(url, get_headers())
36
34
  body = JSON.parse(response.body)
37
35
 
38
36
  schedules = []
@@ -45,59 +43,55 @@ module ConstantContact
45
43
 
46
44
 
47
45
  # Get a specific schedule for a campaign
48
- # @param [String] access_token - Constant Contact OAuth2 access token
49
46
  # @param [Integer] campaign_id - Campaign id to get a schedule for
50
47
  # @param [Integer] schedule_id - Schedule id to retrieve
51
48
  # @return [Schedule]
52
- def get_schedule(access_token, campaign_id, schedule_id)
49
+ def get_schedule(campaign_id, schedule_id)
53
50
  url = Util::Config.get('endpoints.base_url') +
54
51
  sprintf(Util::Config.get('endpoints.campaign_schedule'), campaign_id, schedule_id)
55
52
  url = build_url(url)
56
- response = RestClient.get(url, get_headers(access_token))
53
+ response = RestClient.get(url, get_headers())
57
54
  Components::Schedule.create(JSON.parse(response.body))
58
55
  end
59
56
 
60
57
 
61
58
  # Delete a specific schedule for a campaign
62
- # @param [String] access_token - Constant Contact OAuth2 access token
63
59
  # @param [Integer] campaign_id - Campaign id to delete a schedule for
64
60
  # @param [Integer] schedule_id - Schedule id to delete
65
61
  # @return [Boolean]
66
- def delete_schedule(access_token, campaign_id, schedule_id)
62
+ def delete_schedule(campaign_id, schedule_id)
67
63
  url = Util::Config.get('endpoints.base_url') +
68
64
  sprintf(Util::Config.get('endpoints.campaign_schedule'), campaign_id, schedule_id)
69
65
  url = build_url(url)
70
- response = RestClient.delete(url, get_headers(access_token))
66
+ response = RestClient.delete(url, get_headers())
71
67
  response.code == 204
72
68
  end
73
69
 
74
70
 
75
71
  # Update a specific schedule for a campaign
76
- # @param [String] access_token - Constant Contact OAuth2 access token
77
72
  # @param [Integer] campaign_id - Campaign id to be scheduled
78
73
  # @param [Schedule] schedule - Schedule to retrieve
79
74
  # @return [Schedule]
80
- def update_schedule(access_token, campaign_id, schedule)
75
+ def update_schedule(campaign_id, schedule)
81
76
  url = Util::Config.get('endpoints.base_url') +
82
77
  sprintf(Util::Config.get('endpoints.campaign_schedule'), campaign_id, schedule.id)
83
78
  url = build_url(url)
84
79
  payload = schedule.to_json
85
- response = RestClient.put(url, payload, get_headers(access_token))
80
+ response = RestClient.put(url, payload, get_headers())
86
81
  Components::Schedule.create(JSON.parse(response.body))
87
82
  end
88
83
 
89
84
 
90
85
  # Send a test send of a campaign
91
- # @param [String] access_token - Constant Contact OAuth2 access token
92
86
  # @param [Integer] campaign_id - Id of campaign to send test of
93
87
  # @param [TestSend] test_send - Test send details
94
88
  # @return [TestSend]
95
- def send_test(access_token, campaign_id, test_send)
89
+ def send_test(campaign_id, test_send)
96
90
  url = Util::Config.get('endpoints.base_url') +
97
91
  sprintf(Util::Config.get('endpoints.campaign_test_sends'), campaign_id)
98
92
  url = build_url(url)
99
93
  payload = test_send.to_json
100
- response = RestClient.post(url, payload, get_headers(access_token))
94
+ response = RestClient.post(url, payload, get_headers())
101
95
  Components::TestSend.create(JSON.parse(response.body))
102
96
  end
103
97
 
@@ -10,16 +10,15 @@ module ConstantContact
10
10
  class << self
11
11
 
12
12
  # Get bounces for a given campaign
13
- # @param [String] access_token - Constant Contact OAuth2 access token
14
13
  # @param [String] campaign_id - Campaign id
15
14
  # @param [Hash] params - query parameters to be appended to request
16
15
  # @return [ResultSet<BounceActivity>] - Containing a results array of BounceActivity
17
- def get_bounces(access_token, campaign_id, params = {})
16
+ def get_bounces(campaign_id, params = {})
18
17
  url = Util::Config.get('endpoints.base_url') +
19
18
  sprintf(Util::Config.get('endpoints.campaign_tracking_bounces'), campaign_id)
20
19
  url = build_url(url, params)
21
20
 
22
- response = RestClient.get(url, get_headers(access_token))
21
+ response = RestClient.get(url, get_headers())
23
22
  body = JSON.parse(response.body)
24
23
 
25
24
  bounces = []
@@ -32,16 +31,15 @@ module ConstantContact
32
31
 
33
32
 
34
33
  # Get clicks for a given campaign
35
- # @param [String] access_token - Constant Contact OAuth2 access token
36
34
  # @param [String] campaign_id - Campaign id
37
35
  # @param [Hash] params - query parameters to be appended to request
38
36
  # @return [ResultSet<ClickActivity>] - Containing a results array of ClickActivity
39
- def get_clicks(access_token, campaign_id, params = {})
37
+ def get_clicks(campaign_id, params = {})
40
38
  url = Util::Config.get('endpoints.base_url') +
41
39
  sprintf(Util::Config.get('endpoints.campaign_tracking_clicks'), campaign_id)
42
40
  url = build_url(url, params)
43
41
 
44
- response = RestClient.get(url, get_headers(access_token))
42
+ response = RestClient.get(url, get_headers())
45
43
  body = JSON.parse(response.body)
46
44
 
47
45
  clicks = []
@@ -54,16 +52,15 @@ module ConstantContact
54
52
 
55
53
 
56
54
  # Get forwards for a given campaign
57
- # @param [String] access_token - Constant Contact OAuth2 access token
58
55
  # @param [String] campaign_id - Campaign id
59
56
  # @param [Hash] params - query parameters to be appended to request
60
57
  # @return [ResultSet<ForwardActivity>] - Containing a results array of ForwardActivity
61
- def get_forwards(access_token, campaign_id, params = {})
58
+ def get_forwards(campaign_id, params = {})
62
59
  url = Util::Config.get('endpoints.base_url') +
63
60
  sprintf(Util::Config.get('endpoints.campaign_tracking_forwards'), campaign_id)
64
61
  url = build_url(url, params)
65
62
 
66
- response = RestClient.get(url, get_headers(access_token))
63
+ response = RestClient.get(url, get_headers())
67
64
  body = JSON.parse(response.body)
68
65
 
69
66
  forwards = []
@@ -76,16 +73,15 @@ module ConstantContact
76
73
 
77
74
 
78
75
  # Get opens for a given campaign
79
- # @param [String] access_token - Constant Contact OAuth2 access token
80
76
  # @param [String] campaign_id - Campaign id
81
77
  # @param [Hash] params - query parameters to be appended to request
82
78
  # @return [ResultSet<OpenActivity>] - Containing a results array of OpenActivity
83
- def get_opens(access_token, campaign_id, params = {})
79
+ def get_opens(campaign_id, params = {})
84
80
  url = Util::Config.get('endpoints.base_url') +
85
81
  sprintf(Util::Config.get('endpoints.campaign_tracking_opens'), campaign_id)
86
82
  url = build_url(url, params)
87
83
 
88
- response = RestClient.get(url, get_headers(access_token))
84
+ response = RestClient.get(url, get_headers())
89
85
  body = JSON.parse(response.body)
90
86
 
91
87
  opens = []
@@ -98,16 +94,15 @@ module ConstantContact
98
94
 
99
95
 
100
96
  # Get sends for a given campaign
101
- # @param [String] access_token - Constant Contact OAuth2 access token
102
97
  # @param [String] campaign_id - Campaign id
103
98
  # @param [Hash] params - query parameters to be appended to request
104
99
  # @return [ResultSet<SendActivity>] - Containing a results array of SendActivity
105
- def get_sends(access_token, campaign_id, params = {})
100
+ def get_sends(campaign_id, params = {})
106
101
  url = Util::Config.get('endpoints.base_url') +
107
102
  sprintf(Util::Config.get('endpoints.campaign_tracking_sends'), campaign_id)
108
103
  url = build_url(url, params)
109
104
 
110
- response = RestClient.get(url, get_headers(access_token))
105
+ response = RestClient.get(url, get_headers())
111
106
  body = JSON.parse(response.body)
112
107
 
113
108
  sends = []
@@ -120,16 +115,15 @@ module ConstantContact
120
115
 
121
116
 
122
117
  # Get unsubscribes for a given campaign
123
- # @param [String] access_token - Constant Contact OAuth2 access token
124
118
  # @param [String] campaign_id - Campaign id
125
119
  # @param [Hash] params - query params to be appended to request
126
120
  # @return [ResultSet<UnsubscribeActivity>] - Containing a results array of UnsubscribeActivity
127
- def get_unsubscribes(access_token, campaign_id, params = {})
121
+ def get_unsubscribes(campaign_id, params = {})
128
122
  url = Util::Config.get('endpoints.base_url') +
129
123
  sprintf(Util::Config.get('endpoints.campaign_tracking_unsubscribes'), campaign_id)
130
124
  url = build_url(url, params)
131
125
 
132
- response = RestClient.get(url, get_headers(access_token))
126
+ response = RestClient.get(url, get_headers())
133
127
  body = JSON.parse(response.body)
134
128
 
135
129
  unsubscribes = []
@@ -142,14 +136,13 @@ module ConstantContact
142
136
 
143
137
 
144
138
  # Get a summary of reporting data for a given campaign
145
- # @param [String] access_token - Constant Contact OAuth2 access token
146
139
  # @param [Integer] campaign_id - Campaign id
147
140
  # @return [TrackingSummary]
148
- def get_summary(access_token, campaign_id)
141
+ def get_summary(campaign_id)
149
142
  url = Util::Config.get('endpoints.base_url') +
150
143
  sprintf(Util::Config.get('endpoints.campaign_tracking_summary'), campaign_id)
151
144
  url = build_url(url)
152
- response = RestClient.get(url, get_headers(access_token))
145
+ response = RestClient.get(url, get_headers())
153
146
  Components::TrackingSummary.create(JSON.parse(response.body))
154
147
  end
155
148
 
@@ -10,14 +10,13 @@ module ConstantContact
10
10
  class << self
11
11
 
12
12
  # Get an array of contacts
13
- # @param [String] access_token - Constant Contact OAuth2 access token
14
13
  # @param [Hash] params - query parameters to be appended to the request
15
14
  # @return [ResultSet<Contact>]
16
- def get_contacts(access_token, params = {})
15
+ def get_contacts(params = {})
17
16
  url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.contacts')
18
17
  url = build_url(url, params)
19
18
 
20
- response = RestClient.get(url, get_headers(access_token))
19
+ response = RestClient.get(url, get_headers())
21
20
  body = JSON.parse(response.body)
22
21
 
23
22
  contacts = []
@@ -30,79 +29,73 @@ module ConstantContact
30
29
 
31
30
 
32
31
  # Get contact details for a specific contact
33
- # @param [String] access_token - Constant Contact OAuth2 access token
34
32
  # @param [Integer] contact_id - Unique contact id
35
33
  # @return [Contact]
36
- def get_contact(access_token, contact_id)
34
+ def get_contact(contact_id)
37
35
  url = Util::Config.get('endpoints.base_url') +
38
36
  sprintf(Util::Config.get('endpoints.contact'), contact_id)
39
37
  url = build_url(url)
40
- response = RestClient.get(url, get_headers(access_token))
38
+ response = RestClient.get(url, get_headers())
41
39
  Components::Contact.create(JSON.parse(response.body))
42
40
  end
43
41
 
44
42
 
45
43
  # Add a new contact to the Constant Contact account
46
- # @param [String] access_token - Constant Contact OAuth2 access token
47
44
  # @param [Contact] contact - Contact to add
48
45
  # @param [Boolean] params - query params to be appended to the request
49
46
  # @return [Contact]
50
- def add_contact(access_token, contact, params = {})
47
+ def add_contact(contact, params = {})
51
48
  url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.contacts')
52
49
  url = build_url(url, params)
53
50
  payload = contact.to_json
54
- response = RestClient.post(url, payload, get_headers(access_token))
51
+ response = RestClient.post(url, payload, get_headers())
55
52
  Components::Contact.create(JSON.parse(response.body))
56
53
  end
57
54
 
58
55
 
59
56
  # Delete contact details for a specific contact
60
- # @param [String] access_token - Constant Contact OAuth2 access token
61
57
  # @param [Integer] contact_id - Unique contact id
62
58
  # @return [Boolean]
63
- def delete_contact(access_token, contact_id)
59
+ def delete_contact(contact_id)
64
60
  url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.contact'), contact_id)
65
61
  url = build_url(url)
66
- response = RestClient.delete(url, get_headers(access_token))
62
+ response = RestClient.delete(url, get_headers())
67
63
  response.code == 204
68
64
  end
69
65
 
70
66
 
71
67
  # Delete a contact from all contact lists
72
- # @param [String] access_token - Constant Contact OAuth2 access token
73
68
  # @param [Integer] contact_id - Contact id to be removed from lists
74
69
  # @return [Boolean]
75
- def delete_contact_from_lists(access_token, contact_id)
70
+ def delete_contact_from_lists(contact_id)
76
71
  url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.contact_lists'), contact_id)
77
72
  url = build_url(url)
78
- response = RestClient.delete(url, get_headers(access_token))
73
+ response = RestClient.delete(url, get_headers())
79
74
  response.code == 204
80
75
  end
81
76
 
82
77
 
83
78
  # Delete a contact from a specific contact list
84
- # @param [String] access_token - Constant Contact OAuth2 access token
85
79
  # @param [Integer] contact_id - Contact id to be removed
86
80
  # @param [Integer] list_id - ContactList id to remove the contact from
87
81
  # @return [Boolean]
88
- def delete_contact_from_list(access_token, contact_id, list_id)
82
+ def delete_contact_from_list(contact_id, list_id)
89
83
  url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.contact_list'), contact_id, list_id)
90
84
  url = build_url(url)
91
- response = RestClient.delete(url, get_headers(access_token))
85
+ response = RestClient.delete(url, get_headers())
92
86
  response.code == 204
93
87
  end
94
88
 
95
89
 
96
90
  # Update contact details for a specific contact
97
- # @param [String] access_token - Constant Contact OAuth2 access token
98
91
  # @param [Contact] contact - Contact to be updated
99
92
  # @param [Hash] params - query params to be appended to the request
100
93
  # @return [Contact]
101
- def update_contact(access_token, contact, params = {})
94
+ def update_contact(contact, params = {})
102
95
  url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.contact'), contact.id)
103
96
  url = build_url(url, params)
104
97
  payload = contact.to_json
105
- response = RestClient.put(url, payload, get_headers(access_token))
98
+ response = RestClient.put(url, payload, get_headers())
106
99
  Components::Contact.create(JSON.parse(response.body))
107
100
  end
108
101