constantcontact 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -7
- data/README.md +7 -0
- data/constantcontact.gemspec +1 -1
- data/lib/constantcontact.rb +54 -54
- data/lib/constantcontact/api.rb +5 -3
- data/lib/constantcontact/auth/oauth2.rb +7 -4
- data/lib/constantcontact/auth/session_data_store.rb +52 -52
- data/lib/constantcontact/components/account/verified_email_address.rb +17 -17
- data/lib/constantcontact/components/activities/activity.rb +34 -34
- data/lib/constantcontact/components/activities/activity_error.rb +17 -17
- data/lib/constantcontact/components/activities/add_contacts.rb +109 -109
- data/lib/constantcontact/components/activities/add_contacts_import_data.rb +37 -37
- data/lib/constantcontact/components/activities/export_contacts.rb +19 -19
- data/lib/constantcontact/components/component.rb +13 -13
- data/lib/constantcontact/components/contacts/address.rb +18 -18
- data/lib/constantcontact/components/contacts/contact.rb +69 -69
- data/lib/constantcontact/components/contacts/contact_list.rb +17 -17
- data/lib/constantcontact/components/contacts/custom_field.rb +17 -17
- data/lib/constantcontact/components/contacts/email_address.rb +23 -23
- data/lib/constantcontact/components/contacts/note.rb +16 -16
- data/lib/constantcontact/components/email_marketing/campaign.rb +67 -67
- data/lib/constantcontact/components/email_marketing/click_through_details.rb +17 -17
- data/lib/constantcontact/components/email_marketing/message_footer.rb +20 -20
- data/lib/constantcontact/components/email_marketing/schedule.rb +18 -18
- data/lib/constantcontact/components/email_marketing/test_send.rb +32 -32
- data/lib/constantcontact/components/result_set.rb +15 -15
- data/lib/constantcontact/components/tracking/bounce_activity.rb +18 -18
- data/lib/constantcontact/components/tracking/click_activity.rb +17 -17
- data/lib/constantcontact/components/tracking/forward_activity.rb +17 -17
- data/lib/constantcontact/components/tracking/open_activity.rb +17 -17
- data/lib/constantcontact/components/tracking/send_activity.rb +17 -17
- data/lib/constantcontact/components/tracking/tracking_activity.rb +15 -15
- data/lib/constantcontact/components/tracking/tracking_summary.rb +17 -17
- data/lib/constantcontact/components/tracking/unsubscribe_activity.rb +18 -18
- data/lib/constantcontact/exceptions/ctct_exception.rb +15 -15
- data/lib/constantcontact/exceptions/illegal_argument_exception.rb +3 -3
- data/lib/constantcontact/exceptions/oauth2_exception.rb +3 -3
- data/lib/constantcontact/services/account_service.rb +19 -19
- data/lib/constantcontact/services/activity_service.rb +99 -99
- data/lib/constantcontact/services/base_service.rb +24 -24
- data/lib/constantcontact/services/campaign_schedule_service.rb +85 -85
- data/lib/constantcontact/services/campaign_tracking_service.rb +151 -151
- data/lib/constantcontact/services/contact_service.rb +106 -106
- data/lib/constantcontact/services/contact_tracking_service.rb +151 -151
- data/lib/constantcontact/services/email_marketing_service.rb +66 -66
- data/lib/constantcontact/services/list_service.rb +67 -67
- data/lib/constantcontact/util/config.rb +102 -96
- data/lib/constantcontact/util/helpers.rb +18 -18
- data/lib/constantcontact/version.rb +4 -4
- data/spec/constantcontact/api_spec.rb +223 -173
- data/spec/constantcontact/auth/oauth2_spec.rb +68 -4
- data/spec/constantcontact/components/contacts/address_spec.rb +7 -7
- data/spec/constantcontact/components/contacts/contact_list_spec.rb +7 -7
- data/spec/constantcontact/components/contacts/contact_spec.rb +7 -7
- data/spec/constantcontact/components/contacts/custom_field_spec.rb +7 -7
- data/spec/constantcontact/components/contacts/email_address_spec.rb +7 -7
- data/spec/constantcontact/services/contact_service_spec.rb +95 -95
- data/spec/constantcontact/services/list_service_spec.rb +48 -48
- data/spec/spec_helper.rb +1 -1
- metadata +55 -44
@@ -5,81 +5,81 @@
|
|
5
5
|
# Copyright (c) 2013 Constant Contact. All rights reserved.
|
6
6
|
|
7
7
|
module ConstantContact
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
module Services
|
9
|
+
class ListService < BaseService
|
10
|
+
class << self
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
12
|
+
# Get lists within an account
|
13
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
14
|
+
# @return [Array<ContactList>]
|
15
|
+
def get_lists(access_token)
|
16
|
+
url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.lists')
|
17
|
+
url = build_url(url)
|
18
|
+
response = RestClient.get(url, get_headers(access_token))
|
19
|
+
lists = []
|
20
|
+
JSON.parse(response.body).each do |contact|
|
21
|
+
lists << Components::ContactList.create(contact)
|
22
|
+
end
|
23
|
+
lists
|
24
|
+
end
|
25
25
|
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
27
|
+
# Add a new list to the Constant Contact account
|
28
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
29
|
+
# @param [ContactList] list
|
30
|
+
# @return [ContactList]
|
31
|
+
def add_list(access_token, list)
|
32
|
+
url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.lists')
|
33
|
+
url = build_url(url)
|
34
|
+
payload = list.to_json
|
35
|
+
response = RestClient.post(url, payload, get_headers(access_token))
|
36
|
+
Components::ContactList.create(JSON.parse(response.body))
|
37
|
+
end
|
38
38
|
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
40
|
+
# Update a Contact List
|
41
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
42
|
+
# @param [ContactList] list - ContactList to be updated
|
43
|
+
# @return [ContactList]
|
44
|
+
def update_list(access_token, list)
|
45
|
+
url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.list'), list.id)
|
46
|
+
url = build_url(url)
|
47
|
+
payload = list.to_json
|
48
|
+
response = RestClient.put(url, payload, get_headers(access_token))
|
49
|
+
Components::ContactList.create(JSON.parse(response.body))
|
50
|
+
end
|
51
51
|
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
53
|
+
# Get an individual contact list
|
54
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
55
|
+
# @param [Integer] list_id - list id
|
56
|
+
# @return [ContactList]
|
57
|
+
def get_list(access_token, list_id)
|
58
|
+
url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.list'), list_id)
|
59
|
+
url = build_url(url)
|
60
|
+
response = RestClient.get(url, get_headers(access_token))
|
61
|
+
Components::ContactList.create(JSON.parse(response.body))
|
62
|
+
end
|
63
63
|
|
64
64
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
65
|
+
# Get all contacts from an individual list
|
66
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
67
|
+
# @param [Integer] list_id - list id to retrieve contacts for
|
68
|
+
# @param [Hash] param - query parameters to attach to request
|
69
|
+
# @return [Array<Contact>]
|
70
|
+
def get_contacts_from_list(access_token, list_id, param = nil)
|
71
|
+
url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.list_contacts'), list_id)
|
72
|
+
url = build_url(url, param)
|
73
|
+
response = RestClient.get(url, get_headers(access_token))
|
74
|
+
contacts = []
|
75
|
+
body = JSON.parse(response.body)
|
76
|
+
body['results'].each do |contact|
|
77
|
+
contacts << Components::Contact.create(contact)
|
78
|
+
end
|
79
|
+
Components::ResultSet.new(contacts, body['meta'])
|
80
|
+
end
|
81
81
|
|
82
|
-
|
83
|
-
|
84
|
-
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
85
|
end
|
@@ -8,110 +8,116 @@ module ConstantContact
|
|
8
8
|
module Util
|
9
9
|
class Config
|
10
10
|
|
11
|
-
|
11
|
+
# Return a hash of configuration strings
|
12
|
+
# @return [Hash] - hash of configuration properties
|
13
|
+
@props = {
|
14
|
+
# REST endpoints
|
15
|
+
:endpoints => {
|
16
|
+
:base_url => 'https://api.constantcontact.com/v2/',
|
12
17
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
:base_url => 'https://api.constantcontact.com/v2/',
|
18
|
+
:activity => 'activities/%s',
|
19
|
+
:activities => 'activities',
|
20
|
+
:export_contacts_activity => 'activities/exportcontacts',
|
21
|
+
:clear_lists_activity => 'activities/clearlists',
|
22
|
+
:remove_from_lists_activity => 'activities/removefromlists',
|
23
|
+
:add_contacts_activity => 'activities/addcontacts',
|
20
24
|
|
21
|
-
|
22
|
-
:activities => 'activities',
|
23
|
-
:export_contacts_activity => 'activities/exportcontacts',
|
24
|
-
:clear_lists_activity => 'activities/clearlists',
|
25
|
-
:remove_from_lists_activity => 'activities/removefromlists',
|
26
|
-
:add_contacts_activity => 'activities/addcontacts',
|
25
|
+
:account_verified_addresses => 'account/verifiedemailaddresses',
|
27
26
|
|
28
|
-
|
27
|
+
:contact => 'contacts/%s',
|
28
|
+
:contacts => 'contacts',
|
29
|
+
:lists => 'lists',
|
30
|
+
:list => 'lists/%s',
|
31
|
+
:list_contacts => 'lists/%s/contacts',
|
32
|
+
:contact_lists => 'contacts/%s/lists',
|
33
|
+
:contact_list => 'contacts/%s/lists/%s',
|
29
34
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
35
|
+
:campaigns => 'emailmarketing/campaigns',
|
36
|
+
:campaign => 'emailmarketing/campaigns/%s',
|
37
|
+
:campaign_schedules => 'emailmarketing/campaigns/%s/schedules',
|
38
|
+
:campaign_schedule => 'emailmarketing/campaigns/%s/schedules/%s',
|
39
|
+
:campaign_test_sends => 'emailmarketing/campaigns/%s/tests',
|
40
|
+
:campaign_tracking_summary => 'emailmarketing/campaigns/%s/tracking/reports/summary',
|
41
|
+
:campaign_tracking_bounces => 'emailmarketing/campaigns/%s/tracking/bounces',
|
42
|
+
:campaign_tracking_clicks => 'emailmarketing/campaigns/%s/tracking/clicks',
|
43
|
+
:campaign_tracking_forwards => 'emailmarketing/campaigns/%s/tracking/forwards',
|
44
|
+
:campaign_tracking_opens => 'emailmarketing/campaigns/%s/tracking/opens',
|
45
|
+
:campaign_tracking_sends => 'emailmarketing/campaigns/%s/tracking/sends',
|
46
|
+
:campaign_tracking_unsubscribes => 'emailmarketing/campaigns/%s/tracking/unsubscribes',
|
47
|
+
:campaign_tracking_link => 'emailmarketing/campaigns/%s/tracking/clicks/%s',
|
37
48
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
:campaign_tracking_opens => 'emailmarketing/campaigns/%s/tracking/opens',
|
48
|
-
:campaign_tracking_sends => 'emailmarketing/campaigns/%s/tracking/sends',
|
49
|
-
:campaign_tracking_unsubscribes => 'emailmarketing/campaigns/%s/tracking/unsubscribes',
|
50
|
-
:campaign_tracking_link => 'emailmarketing/campaigns/%s/tracking/clicks/%s',
|
49
|
+
:contact_tracking_summary => 'contacts/%s/tracking/reports/summary',
|
50
|
+
:contact_tracking_bounces => 'contacts/%s/tracking/bounces',
|
51
|
+
:contact_tracking_clicks => 'contacts/%s/tracking/clicks',
|
52
|
+
:contact_tracking_forwards => 'contacts/%s/tracking/forwards',
|
53
|
+
:contact_tracking_opens => 'contacts/%s/tracking/opens',
|
54
|
+
:contact_tracking_sends => 'contacts/%s/tracking/sends',
|
55
|
+
:contact_tracking_unsubscribes => 'contacts/%s/tracking/unsubscribes',
|
56
|
+
:contact_tracking_link => 'contacts/%s/tracking/clicks/%s'
|
57
|
+
},
|
51
58
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
59
|
+
# OAuth2 Authorization related configuration options
|
60
|
+
:auth => {
|
61
|
+
:base_url => 'https://oauth2.constantcontact.com/oauth2/',
|
62
|
+
:response_type_code => 'code',
|
63
|
+
:response_type_token => 'token',
|
64
|
+
:authorization_code_grant_type => 'authorization_code',
|
65
|
+
:authorization_endpoint => 'oauth/siteowner/authorize',
|
66
|
+
:token_endpoint => 'oauth/token',
|
67
|
+
:api_key => '',
|
68
|
+
:api_secret => '',
|
69
|
+
:redirect_uri => ''
|
70
|
+
},
|
61
71
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
:custom_field_7 => 'CUSTOM FIELD 7',
|
98
|
-
:custom_field_8 => 'CUSTOM FIELD 8',
|
99
|
-
:custom_field_9 => 'CUSTOM FIELD 9',
|
100
|
-
:custom_field_10 => 'CUSTOM FIELD 10',
|
101
|
-
:custom_field_11 => 'CUSTOM FIELD 11',
|
102
|
-
:custom_field_12 => 'CUSTOM FIELD 12',
|
103
|
-
:custom_field_13 => 'CUSTOM FIELD 13',
|
104
|
-
:custom_field_14 => 'CUSTOM FIELD 14',
|
105
|
-
:custom_field_15 => 'CUSTOM FIELD 15'
|
106
|
-
},
|
107
|
-
|
108
|
-
# Errors to be returned for various exceptions
|
109
|
-
:errors => {
|
110
|
-
:id_or_object => 'Only an id or %s object are allowed for this method.'
|
111
|
-
}
|
112
|
-
}
|
113
|
-
end
|
72
|
+
# Column names used with bulk activities
|
73
|
+
:activities_columns => {
|
74
|
+
:email => 'EMAIL',
|
75
|
+
:first_name => 'FIRST NAME',
|
76
|
+
:middle_name => 'MIDDLE NAME',
|
77
|
+
:last_name => 'LAST NAME',
|
78
|
+
:job_title => 'JOB TITLE',
|
79
|
+
:company_name => 'COMPANY NAME',
|
80
|
+
:work_phone => 'WORK PHONE',
|
81
|
+
:home_phone => 'HOME PHONE',
|
82
|
+
:address1 => 'ADDRESS LINE 1',
|
83
|
+
:address2 => 'ADDRESS LINE 2',
|
84
|
+
:address3 => 'ADDRESS LINE 3',
|
85
|
+
:city => 'CITY',
|
86
|
+
:state => 'STATE',
|
87
|
+
:state_province => 'US STATE/CA PROVINCE',
|
88
|
+
:country => 'COUNTRY',
|
89
|
+
:postal_code => 'ZIP/POSTAL CODE',
|
90
|
+
:sub_postal_code => 'SUB ZIP/POSTAL CODE',
|
91
|
+
:custom_field_1 => 'CUSTOM FIELD 1',
|
92
|
+
:custom_field_2 => 'CUSTOM FIELD 2',
|
93
|
+
:custom_field_3 => 'CUSTOM FIELD 3',
|
94
|
+
:custom_field_4 => 'CUSTOM FIELD 4',
|
95
|
+
:custom_field_5 => 'CUSTOM FIELD 5',
|
96
|
+
:custom_field_6 => 'CUSTOM FIELD 6',
|
97
|
+
:custom_field_7 => 'CUSTOM FIELD 7',
|
98
|
+
:custom_field_8 => 'CUSTOM FIELD 8',
|
99
|
+
:custom_field_9 => 'CUSTOM FIELD 9',
|
100
|
+
:custom_field_10 => 'CUSTOM FIELD 10',
|
101
|
+
:custom_field_11 => 'CUSTOM FIELD 11',
|
102
|
+
:custom_field_12 => 'CUSTOM FIELD 12',
|
103
|
+
:custom_field_13 => 'CUSTOM FIELD 13',
|
104
|
+
:custom_field_14 => 'CUSTOM FIELD 14',
|
105
|
+
:custom_field_15 => 'CUSTOM FIELD 15'
|
106
|
+
},
|
114
107
|
|
108
|
+
# Errors to be returned for various exceptions
|
109
|
+
:errors => {
|
110
|
+
:id_or_object => 'Only an id or %s object are allowed for this method.'
|
111
|
+
}
|
112
|
+
}
|
113
|
+
|
114
|
+
class << self
|
115
|
+
attr_accessor :props
|
116
|
+
|
117
|
+
def configure
|
118
|
+
yield props if block_given?
|
119
|
+
end
|
120
|
+
|
115
121
|
# Get a configuration property given a specified location, example usage: Config::get('auth.token_endpoint')
|
116
122
|
# @param [String] index - location of the property to obtain
|
117
123
|
# @return [String]
|
@@ -5,23 +5,23 @@
|
|
5
5
|
# Copyright (c) 2013 Constant Contact. All rights reserved.
|
6
6
|
|
7
7
|
module ConstantContact
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
# Build the HTTP query from the given parameters
|
13
|
-
# @param [Hash] params
|
14
|
-
# @return [String] query string
|
15
|
-
def http_build_query(params)
|
16
|
-
params.collect{ |k,v| "#{k.to_s}=#{encode(v.to_s)}" }.reverse.join('&')
|
17
|
-
end
|
8
|
+
module Util
|
9
|
+
class Helpers
|
10
|
+
class << self
|
18
11
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
12
|
+
# Build the HTTP query from the given parameters
|
13
|
+
# @param [Hash] params
|
14
|
+
# @return [String] query string
|
15
|
+
def http_build_query(params)
|
16
|
+
params.collect{ |k,v| "#{k.to_s}=#{encode(v.to_s)}" }.reverse.join('&')
|
17
|
+
end
|
18
|
+
|
19
|
+
# Escape special characters
|
20
|
+
# @param [String] str
|
21
|
+
def encode(str)
|
22
|
+
CGI.escape(str).gsub('.', '%2E').gsub('-', '%2D')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
27
|
end
|
@@ -7,177 +7,227 @@
|
|
7
7
|
require 'spec_helper'
|
8
8
|
|
9
9
|
describe ConstantContact::Api do
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
10
|
+
|
11
|
+
before(:all) {
|
12
|
+
ConstantContact::Util::Config.configure do |config|
|
13
|
+
config[:auth].delete :api_key
|
14
|
+
config[:auth].delete :api_secret
|
15
|
+
config[:auth].delete :redirect_uri
|
16
|
+
end
|
17
|
+
}
|
18
|
+
|
19
|
+
it "without api_key defined" do
|
20
|
+
lambda {
|
21
|
+
ConstantContact::Api.new
|
22
|
+
}.should raise_error(ArgumentError)
|
23
|
+
end
|
24
|
+
|
25
|
+
context "with middle-ware configuration" do
|
26
|
+
before(:all) do
|
27
|
+
ConstantContact::Services::BaseService.api_key = nil
|
28
|
+
ConstantContact::Util::Config.configure do |config|
|
29
|
+
config[:auth][:api_key] = "config_api_key"
|
30
|
+
config[:auth][:api_secret] = "config_api_secret"
|
31
|
+
config[:auth][:redirect_uri] = "config_redirect_uri"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
let(:proc) { lambda { ConstantContact::Api.new } }
|
35
|
+
it "use implicit config" do
|
36
|
+
proc.should_not raise_error
|
37
|
+
end
|
38
|
+
it "has the correct client_id" do
|
39
|
+
ConstantContact::Services::BaseService.api_key.should == "config_api_key"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "with middle-ware configuration" do
|
44
|
+
before(:all) do
|
45
|
+
ConstantContact::Services::BaseService.api_key = nil
|
46
|
+
ConstantContact::Util::Config.configure do |config|
|
47
|
+
config[:auth][:api_key] = "config_api_key"
|
48
|
+
config[:auth][:api_secret] = "config_api_secret"
|
49
|
+
config[:auth][:redirect_uri] = "config_redirect_uri"
|
50
|
+
end
|
51
|
+
ConstantContact::Api.new 'explicit_api_key'
|
52
|
+
end
|
53
|
+
it "has the correct explicit api key" do
|
54
|
+
ConstantContact::Services::BaseService.api_key.should == "explicit_api_key"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "test methods" do
|
59
|
+
before(:each) do
|
60
|
+
@api = ConstantContact::Api.new('api key')
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "#get_contacts" do
|
64
|
+
it "returns an array of contacts" do
|
65
|
+
json = load_json('contacts.json')
|
66
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
67
|
+
|
68
|
+
response = RestClient::Response.create(json, net_http_resp, {})
|
69
|
+
RestClient.stub(:get).and_return(response)
|
70
|
+
contacts = @api.get_contacts('token')
|
71
|
+
contact = contacts.results[0]
|
72
|
+
|
73
|
+
contacts.should be_kind_of(ConstantContact::Components::ResultSet)
|
74
|
+
contact.should be_kind_of(ConstantContact::Components::Contact)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "#get_contact" do
|
79
|
+
it "returns a contact" do
|
80
|
+
json = load_json('contact.json')
|
81
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
82
|
+
|
83
|
+
response = RestClient::Response.create(json, net_http_resp, {})
|
84
|
+
RestClient.stub(:get).and_return(response)
|
85
|
+
contact = @api.get_contact('token', 1)
|
86
|
+
|
87
|
+
contact.should be_kind_of(ConstantContact::Components::Contact)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe "#get_contact_by_email" do
|
92
|
+
it "returns a contact" do
|
93
|
+
json = load_json('contacts.json')
|
94
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
95
|
+
|
96
|
+
response = RestClient::Response.create(json, net_http_resp, {})
|
97
|
+
RestClient.stub(:get).and_return(response)
|
98
|
+
contacts = @api.get_contact_by_email('token', 'john.smith@gmail.com')
|
99
|
+
contact = contacts.results[0]
|
100
|
+
|
101
|
+
contact.should be_kind_of(ConstantContact::Components::Contact)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe "#add_contact" do
|
106
|
+
it "adds a contact" do
|
107
|
+
json = load_json('contact.json')
|
108
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
109
|
+
|
110
|
+
response = RestClient::Response.create(json, net_http_resp, {})
|
111
|
+
RestClient.stub(:post).and_return(response)
|
112
|
+
contact = ConstantContact::Components::Contact.create(JSON.parse(json))
|
113
|
+
added = @api.add_contact('token', contact)
|
114
|
+
|
115
|
+
added.should respond_to(:status)
|
116
|
+
added.status.should eq('REMOVED')
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe "#delete_contact" do
|
121
|
+
it "deletes a contact" do
|
122
|
+
json = load_json('contact.json')
|
123
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 204, 'No Content')
|
124
|
+
|
125
|
+
response = RestClient::Response.create('', net_http_resp, {})
|
126
|
+
RestClient.stub(:delete).and_return(response)
|
127
|
+
contact = ConstantContact::Components::Contact.create(JSON.parse(json))
|
128
|
+
@api.delete_contact('token', contact).should be_true
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
describe "#delete_contact_from_lists" do
|
133
|
+
it "deletes a contact" do
|
134
|
+
json = load_json('contact.json')
|
135
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 204, 'No Content')
|
136
|
+
|
137
|
+
response = RestClient::Response.create('', net_http_resp, {})
|
138
|
+
RestClient.stub(:delete).and_return(response)
|
139
|
+
contact = ConstantContact::Components::Contact.create(JSON.parse(json))
|
140
|
+
@api.delete_contact_from_lists('token', contact).should be_true
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
describe "#delete_contact_from_list" do
|
145
|
+
it "deletes a contact" do
|
146
|
+
contact_json = load_json('contact.json')
|
147
|
+
list_json = load_json('list.json')
|
148
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 204, 'No Content')
|
149
|
+
|
150
|
+
response = RestClient::Response.create('', net_http_resp, {})
|
151
|
+
RestClient.stub(:delete).and_return(response)
|
152
|
+
contact = ConstantContact::Components::Contact.create(JSON.parse(contact_json))
|
153
|
+
list = ConstantContact::Components::ContactList.create(JSON.parse(list_json))
|
154
|
+
@api.delete_contact_from_list('token', contact, list).should be_true
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
describe "#update_contact" do
|
159
|
+
it "updates a contact" do
|
160
|
+
json = load_json('contact.json')
|
161
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
162
|
+
|
163
|
+
response = RestClient::Response.create(json, net_http_resp, {})
|
164
|
+
RestClient.stub(:put).and_return(response)
|
165
|
+
contact = ConstantContact::Components::Contact.create(JSON.parse(json))
|
166
|
+
added = @api.update_contact('token', contact)
|
167
|
+
|
168
|
+
added.should respond_to(:status)
|
169
|
+
added.status.should eq('REMOVED')
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
describe "#get_lists" do
|
174
|
+
it "returns an array of lists" do
|
175
|
+
json = load_json('lists.json')
|
176
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
177
|
+
|
178
|
+
response = RestClient::Response.create(json, net_http_resp, {})
|
179
|
+
RestClient.stub(:get).and_return(response)
|
180
|
+
lists = @api.get_lists('token')
|
181
|
+
list = lists[0]
|
182
|
+
|
183
|
+
lists.should be_kind_of(Array)
|
184
|
+
list.should be_kind_of(ConstantContact::Components::ContactList)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
describe "#get_list" do
|
189
|
+
it "returns a list" do
|
190
|
+
json = load_json('list.json')
|
191
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
192
|
+
|
193
|
+
response = RestClient::Response.create(json, net_http_resp, {})
|
194
|
+
RestClient.stub(:get).and_return(response)
|
195
|
+
contact = @api.get_list('token', 1)
|
196
|
+
|
197
|
+
contact.should be_kind_of(ConstantContact::Components::ContactList)
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
describe "#add_list" do
|
202
|
+
it "adds a list" do
|
203
|
+
json = load_json('list.json')
|
204
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
205
|
+
|
206
|
+
response = RestClient::Response.create(json, net_http_resp, {})
|
207
|
+
RestClient.stub(:post).and_return(response)
|
208
|
+
list = ConstantContact::Components::ContactList.create(JSON.parse(json))
|
209
|
+
added = @api.add_list('token', list)
|
210
|
+
|
211
|
+
added.should respond_to(:status)
|
212
|
+
added.status.should eq('ACTIVE')
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
describe "#get_contacts_from_list" do
|
217
|
+
it "returns an array of contacts" do
|
218
|
+
json_list = load_json('list.json')
|
219
|
+
json_contacts = load_json('contacts.json')
|
220
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
221
|
+
|
222
|
+
response = RestClient::Response.create(json_contacts, net_http_resp, {})
|
223
|
+
RestClient.stub(:get).and_return(response)
|
224
|
+
list = ConstantContact::Components::ContactList.create(JSON.parse(json_list))
|
225
|
+
contacts = @api.get_contacts_from_list('token', list)
|
226
|
+
contact = contacts.results[0]
|
227
|
+
|
228
|
+
contacts.should be_kind_of(ConstantContact::Components::ResultSet)
|
229
|
+
contact.should be_kind_of(ConstantContact::Components::Contact)
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
183
233
|
end
|