constantcontact 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +2 -0
- data/README.md +132 -0
- data/constantcontact.gemspec +32 -0
- data/lib/constantcontact.rb +75 -0
- data/lib/constantcontact/api.rb +541 -0
- data/lib/constantcontact/auth/oauth2.rb +82 -0
- data/lib/constantcontact/auth/session_data_store.rb +69 -0
- data/lib/constantcontact/components/account/verified_email_address.rb +27 -0
- data/lib/constantcontact/components/activities/activity.rb +44 -0
- data/lib/constantcontact/components/activities/activity_error.rb +27 -0
- data/lib/constantcontact/components/activities/add_contacts.rb +117 -0
- data/lib/constantcontact/components/activities/add_contacts_import_data.rb +45 -0
- data/lib/constantcontact/components/activities/export_contacts.rb +30 -0
- data/lib/constantcontact/components/component.rb +23 -0
- data/lib/constantcontact/components/contacts/address.rb +28 -0
- data/lib/constantcontact/components/contacts/contact.rb +86 -0
- data/lib/constantcontact/components/contacts/contact_list.rb +27 -0
- data/lib/constantcontact/components/contacts/custom_field.rb +27 -0
- data/lib/constantcontact/components/contacts/email_address.rb +34 -0
- data/lib/constantcontact/components/contacts/note.rb +25 -0
- data/lib/constantcontact/components/email_marketing/campaign.rb +83 -0
- data/lib/constantcontact/components/email_marketing/click_through_details.rb +28 -0
- data/lib/constantcontact/components/email_marketing/message_footer.rb +30 -0
- data/lib/constantcontact/components/email_marketing/schedule.rb +29 -0
- data/lib/constantcontact/components/email_marketing/test_send.rb +45 -0
- data/lib/constantcontact/components/result_set.rb +27 -0
- data/lib/constantcontact/components/tracking/bounce_activity.rb +29 -0
- data/lib/constantcontact/components/tracking/click_activity.rb +28 -0
- data/lib/constantcontact/components/tracking/forward_activity.rb +28 -0
- data/lib/constantcontact/components/tracking/open_activity.rb +28 -0
- data/lib/constantcontact/components/tracking/send_activity.rb +28 -0
- data/lib/constantcontact/components/tracking/tracking_activity.rb +27 -0
- data/lib/constantcontact/components/tracking/tracking_summary.rb +28 -0
- data/lib/constantcontact/components/tracking/unsubscribe_activity.rb +29 -0
- data/lib/constantcontact/exceptions/ctct_exception.rb +25 -0
- data/lib/constantcontact/exceptions/illegal_argument_exception.rb +11 -0
- data/lib/constantcontact/exceptions/oauth2_exception.rb +11 -0
- data/lib/constantcontact/services/account_service.rb +29 -0
- data/lib/constantcontact/services/activity_service.rb +107 -0
- data/lib/constantcontact/services/base_service.rb +37 -0
- data/lib/constantcontact/services/campaign_schedule_service.rb +107 -0
- data/lib/constantcontact/services/campaign_tracking_service.rb +159 -0
- data/lib/constantcontact/services/contact_service.rb +114 -0
- data/lib/constantcontact/services/contact_tracking_service.rb +159 -0
- data/lib/constantcontact/services/email_marketing_service.rb +87 -0
- data/lib/constantcontact/services/list_service.rb +85 -0
- data/lib/constantcontact/util/config.rb +140 -0
- data/lib/constantcontact/util/helpers.rb +27 -0
- data/lib/constantcontact/version.rb +12 -0
- data/spec/constantcontact/api_spec.rb +183 -0
- data/spec/constantcontact/auth/oauth2_spec.rb +48 -0
- data/spec/constantcontact/components/contacts/address_spec.rb +18 -0
- data/spec/constantcontact/components/contacts/contact_list_spec.rb +18 -0
- data/spec/constantcontact/components/contacts/contact_spec.rb +18 -0
- data/spec/constantcontact/components/contacts/custom_field_spec.rb +18 -0
- data/spec/constantcontact/components/contacts/email_address_spec.rb +18 -0
- data/spec/constantcontact/services/contact_service_spec.rb +105 -0
- data/spec/constantcontact/services/list_service_spec.rb +69 -0
- data/spec/spec_helper.rb +13 -0
- metadata +134 -0
@@ -0,0 +1,87 @@
|
|
1
|
+
#
|
2
|
+
# email_marketing_service.rb
|
3
|
+
# ConstantContact
|
4
|
+
#
|
5
|
+
# Copyright (c) 2013 Constant Contact. All rights reserved.
|
6
|
+
|
7
|
+
module ConstantContact
|
8
|
+
module Services
|
9
|
+
class EmailMarketingService < BaseService
|
10
|
+
class << self
|
11
|
+
|
12
|
+
# Create a new campaign
|
13
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
14
|
+
# @param [Campaign] campaign - Campaign to be created
|
15
|
+
# @return [Campaign]
|
16
|
+
def add_campaign(access_token, campaign)
|
17
|
+
url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.campaigns')
|
18
|
+
url = build_url(url)
|
19
|
+
payload = campaign.to_json
|
20
|
+
response = RestClient.post(url, payload, get_headers(access_token))
|
21
|
+
Components::Campaign.create(JSON.parse(response.body))
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
# Get a set of campaigns
|
26
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
27
|
+
# @param [Hash] param - query parameters to be appended to the request
|
28
|
+
# @return [ResultSet<Campaign>]
|
29
|
+
def get_campaigns(access_token, param = nil)
|
30
|
+
url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.campaigns')
|
31
|
+
url = build_url(url, param)
|
32
|
+
|
33
|
+
response = RestClient.get(url, get_headers(access_token))
|
34
|
+
body = JSON.parse(response.body)
|
35
|
+
|
36
|
+
campaigns = []
|
37
|
+
body['results'].each do |campaign|
|
38
|
+
campaigns << Components::Campaign.create_summary(campaign)
|
39
|
+
end
|
40
|
+
|
41
|
+
Components::ResultSet.new(campaigns, body['meta'])
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
# Get campaign details for a specific campaign
|
46
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
47
|
+
# @param [Integer] campaign_id - Valid campaign id
|
48
|
+
# @return [Campaign]
|
49
|
+
def get_campaign(access_token, campaign_id)
|
50
|
+
url = Util::Config.get('endpoints.base_url') +
|
51
|
+
sprintf(Util::Config.get('endpoints.campaign'), campaign_id)
|
52
|
+
url = build_url(url)
|
53
|
+
response = RestClient.get(url, get_headers(access_token))
|
54
|
+
Components::Campaign.create(JSON.parse(response.body))
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
# Delete an email campaign
|
59
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
60
|
+
# @param [Integer] campaign_id - Valid campaign id
|
61
|
+
# @return [Boolean]
|
62
|
+
def delete_campaign(access_token, campaign_id)
|
63
|
+
url = Util::Config.get('endpoints.base_url') +
|
64
|
+
sprintf(Util::Config.get('endpoints.campaign'), campaign_id)
|
65
|
+
url = build_url(url)
|
66
|
+
response = RestClient.delete(url, get_headers(access_token))
|
67
|
+
response.code == 204
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
# Update a specific email campaign
|
72
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
73
|
+
# @param [Campaign] campaign - Campaign to be updated
|
74
|
+
# @return [Campaign]
|
75
|
+
def update_campaign(access_token, campaign)
|
76
|
+
url = Util::Config.get('endpoints.base_url') +
|
77
|
+
sprintf(Util::Config.get('endpoints.campaign'), campaign.id)
|
78
|
+
url = build_url(url)
|
79
|
+
payload = campaign.to_json
|
80
|
+
response = RestClient.put(url, payload, get_headers(access_token))
|
81
|
+
Components::Campaign.create(JSON.parse(response.body))
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
#
|
2
|
+
# list_service.rb
|
3
|
+
# ConstantContact
|
4
|
+
#
|
5
|
+
# Copyright (c) 2013 Constant Contact. All rights reserved.
|
6
|
+
|
7
|
+
module ConstantContact
|
8
|
+
module Services
|
9
|
+
class ListService < BaseService
|
10
|
+
class << self
|
11
|
+
|
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
|
+
|
26
|
+
|
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
|
+
|
39
|
+
|
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
|
+
|
52
|
+
|
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
|
+
|
64
|
+
|
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
|
+
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
#
|
2
|
+
# config.rb
|
3
|
+
# ConstantContact
|
4
|
+
#
|
5
|
+
# Copyright (c) 2013 Constant Contact. All rights reserved.
|
6
|
+
|
7
|
+
module ConstantContact
|
8
|
+
module Util
|
9
|
+
class Config
|
10
|
+
|
11
|
+
class << self
|
12
|
+
|
13
|
+
# Return a hash of configuration strings
|
14
|
+
# @return [Hash] - hash of configuration properties
|
15
|
+
def props
|
16
|
+
{
|
17
|
+
# REST endpoints
|
18
|
+
:endpoints => {
|
19
|
+
:base_url => 'https://api.constantcontact.com/v2/',
|
20
|
+
|
21
|
+
:activity => 'activities/%s',
|
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',
|
27
|
+
|
28
|
+
:account_verified_addresses => 'account/verifiedemailaddresses',
|
29
|
+
|
30
|
+
:contact => 'contacts/%s',
|
31
|
+
:contacts => 'contacts',
|
32
|
+
:lists => 'lists',
|
33
|
+
:list => 'lists/%s',
|
34
|
+
:list_contacts => 'lists/%s/contacts',
|
35
|
+
:contact_lists => 'contacts/%s/lists',
|
36
|
+
:contact_list => 'contacts/%s/lists/%s',
|
37
|
+
|
38
|
+
:campaigns => 'emailmarketing/campaigns',
|
39
|
+
:campaign => 'emailmarketing/campaigns/%s',
|
40
|
+
:campaign_schedules => 'emailmarketing/campaigns/%s/schedules',
|
41
|
+
:campaign_schedule => 'emailmarketing/campaigns/%s/schedules/%s',
|
42
|
+
:campaign_test_sends => 'emailmarketing/campaigns/%s/tests',
|
43
|
+
:campaign_tracking_summary => 'emailmarketing/campaigns/%s/tracking/reports/summary',
|
44
|
+
:campaign_tracking_bounces => 'emailmarketing/campaigns/%s/tracking/bounces',
|
45
|
+
:campaign_tracking_clicks => 'emailmarketing/campaigns/%s/tracking/clicks',
|
46
|
+
:campaign_tracking_forwards => 'emailmarketing/campaigns/%s/tracking/forwards',
|
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',
|
51
|
+
|
52
|
+
:contact_tracking_summary => 'contacts/%s/tracking/reports/summary',
|
53
|
+
:contact_tracking_bounces => 'contacts/%s/tracking/bounces',
|
54
|
+
:contact_tracking_clicks => 'contacts/%s/tracking/clicks',
|
55
|
+
:contact_tracking_forwards => 'contacts/%s/tracking/forwards',
|
56
|
+
:contact_tracking_opens => 'contacts/%s/tracking/opens',
|
57
|
+
:contact_tracking_sends => 'contacts/%s/tracking/sends',
|
58
|
+
:contact_tracking_unsubscribes => 'contacts/%s/tracking/unsubscribes',
|
59
|
+
:contact_tracking_link => 'contacts/%s/tracking/clicks/%s'
|
60
|
+
},
|
61
|
+
|
62
|
+
# OAuth2 Authorization related configuration options
|
63
|
+
:auth => {
|
64
|
+
:base_url => 'https://oauth2.constantcontact.com/oauth2/',
|
65
|
+
:response_type_code => 'code',
|
66
|
+
:response_type_token => 'token',
|
67
|
+
:authorization_code_grant_type => 'authorization_code',
|
68
|
+
:authorization_endpoint => 'oauth/siteowner/authorize',
|
69
|
+
:token_endpoint => 'oauth/token'
|
70
|
+
},
|
71
|
+
|
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
|
+
},
|
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
|
114
|
+
|
115
|
+
# Get a configuration property given a specified location, example usage: Config::get('auth.token_endpoint')
|
116
|
+
# @param [String] index - location of the property to obtain
|
117
|
+
# @return [String]
|
118
|
+
def get(index)
|
119
|
+
properties = index.split('.')
|
120
|
+
get_value(properties, props)
|
121
|
+
end
|
122
|
+
|
123
|
+
private
|
124
|
+
|
125
|
+
# Navigate through a config array looking for a particular index
|
126
|
+
# @param [Array] index The index sequence we are navigating down
|
127
|
+
# @param [Hash, String] value The portion of the config array to process
|
128
|
+
# @return [String]
|
129
|
+
def get_value(index, value)
|
130
|
+
index = index.is_a?(Array) ? index : [index]
|
131
|
+
key = index.shift.to_sym
|
132
|
+
value.is_a?(Hash) and value[key] and value[key].is_a?(Hash) ?
|
133
|
+
get_value(index, value[key]) :
|
134
|
+
value[key]
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#
|
2
|
+
# helpers.rb
|
3
|
+
# ConstantContact
|
4
|
+
#
|
5
|
+
# Copyright (c) 2013 Constant Contact. All rights reserved.
|
6
|
+
|
7
|
+
module ConstantContact
|
8
|
+
module Util
|
9
|
+
class Helpers
|
10
|
+
class << self
|
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
|
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
|
+
end
|
@@ -0,0 +1,183 @@
|
|
1
|
+
#
|
2
|
+
# api_spec.rb
|
3
|
+
# ConstantContact
|
4
|
+
#
|
5
|
+
# Copyright (c) 2013 Constant Contact. All rights reserved.
|
6
|
+
|
7
|
+
require 'spec_helper'
|
8
|
+
|
9
|
+
describe ConstantContact::Api do
|
10
|
+
before(:each) do
|
11
|
+
@api = ConstantContact::Api.new('api key')
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#get_contacts" do
|
15
|
+
it "returns an array of contacts" do
|
16
|
+
json = load_json('contacts.json')
|
17
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
18
|
+
|
19
|
+
response = RestClient::Response.create(json, net_http_resp, {})
|
20
|
+
RestClient.stub(:get).and_return(response)
|
21
|
+
contacts = @api.get_contacts('token')
|
22
|
+
contact = contacts.results[0]
|
23
|
+
|
24
|
+
contacts.should be_kind_of(ConstantContact::Components::ResultSet)
|
25
|
+
contact.should be_kind_of(ConstantContact::Components::Contact)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#get_contact" do
|
30
|
+
it "returns a contact" do
|
31
|
+
json = load_json('contact.json')
|
32
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
33
|
+
|
34
|
+
response = RestClient::Response.create(json, net_http_resp, {})
|
35
|
+
RestClient.stub(:get).and_return(response)
|
36
|
+
contact = @api.get_contact('token', 1)
|
37
|
+
|
38
|
+
contact.should be_kind_of(ConstantContact::Components::Contact)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#get_contact_by_email" do
|
43
|
+
it "returns a contact" do
|
44
|
+
json = load_json('contacts.json')
|
45
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
46
|
+
|
47
|
+
response = RestClient::Response.create(json, net_http_resp, {})
|
48
|
+
RestClient.stub(:get).and_return(response)
|
49
|
+
contacts = @api.get_contact_by_email('token', 'john.smith@gmail.com')
|
50
|
+
contact = contacts.results[0]
|
51
|
+
|
52
|
+
contact.should be_kind_of(ConstantContact::Components::Contact)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "#add_contact" do
|
57
|
+
it "adds a contact" do
|
58
|
+
json = load_json('contact.json')
|
59
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
60
|
+
|
61
|
+
response = RestClient::Response.create(json, net_http_resp, {})
|
62
|
+
RestClient.stub(:post).and_return(response)
|
63
|
+
contact = ConstantContact::Components::Contact.create(JSON.parse(json))
|
64
|
+
added = @api.add_contact('token', contact)
|
65
|
+
|
66
|
+
added.should respond_to(:status)
|
67
|
+
added.status.should eq('REMOVED')
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "#delete_contact" do
|
72
|
+
it "deletes a contact" do
|
73
|
+
json = load_json('contact.json')
|
74
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 204, 'No Content')
|
75
|
+
|
76
|
+
response = RestClient::Response.create('', net_http_resp, {})
|
77
|
+
RestClient.stub(:delete).and_return(response)
|
78
|
+
contact = ConstantContact::Components::Contact.create(JSON.parse(json))
|
79
|
+
@api.delete_contact('token', contact).should be_true
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "#delete_contact_from_lists" do
|
84
|
+
it "deletes a contact" do
|
85
|
+
json = load_json('contact.json')
|
86
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 204, 'No Content')
|
87
|
+
|
88
|
+
response = RestClient::Response.create('', net_http_resp, {})
|
89
|
+
RestClient.stub(:delete).and_return(response)
|
90
|
+
contact = ConstantContact::Components::Contact.create(JSON.parse(json))
|
91
|
+
@api.delete_contact_from_lists('token', contact).should be_true
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe "#delete_contact_from_list" do
|
96
|
+
it "deletes a contact" do
|
97
|
+
contact_json = load_json('contact.json')
|
98
|
+
list_json = load_json('list.json')
|
99
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 204, 'No Content')
|
100
|
+
|
101
|
+
response = RestClient::Response.create('', net_http_resp, {})
|
102
|
+
RestClient.stub(:delete).and_return(response)
|
103
|
+
contact = ConstantContact::Components::Contact.create(JSON.parse(contact_json))
|
104
|
+
list = ConstantContact::Components::ContactList.create(JSON.parse(list_json))
|
105
|
+
@api.delete_contact_from_list('token', contact, list).should be_true
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe "#update_contact" do
|
110
|
+
it "updates a contact" do
|
111
|
+
json = load_json('contact.json')
|
112
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
113
|
+
|
114
|
+
response = RestClient::Response.create(json, net_http_resp, {})
|
115
|
+
RestClient.stub(:put).and_return(response)
|
116
|
+
contact = ConstantContact::Components::Contact.create(JSON.parse(json))
|
117
|
+
added = @api.update_contact('token', contact)
|
118
|
+
|
119
|
+
added.should respond_to(:status)
|
120
|
+
added.status.should eq('REMOVED')
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe "#get_lists" do
|
125
|
+
it "returns an array of lists" do
|
126
|
+
json = load_json('lists.json')
|
127
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
128
|
+
|
129
|
+
response = RestClient::Response.create(json, net_http_resp, {})
|
130
|
+
RestClient.stub(:get).and_return(response)
|
131
|
+
lists = @api.get_lists('token')
|
132
|
+
list = lists[0]
|
133
|
+
|
134
|
+
lists.should be_kind_of(Array)
|
135
|
+
list.should be_kind_of(ConstantContact::Components::ContactList)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
describe "#get_list" do
|
140
|
+
it "returns a list" do
|
141
|
+
json = load_json('list.json')
|
142
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
143
|
+
|
144
|
+
response = RestClient::Response.create(json, net_http_resp, {})
|
145
|
+
RestClient.stub(:get).and_return(response)
|
146
|
+
contact = @api.get_list('token', 1)
|
147
|
+
|
148
|
+
contact.should be_kind_of(ConstantContact::Components::ContactList)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
describe "#add_list" do
|
153
|
+
it "adds a list" do
|
154
|
+
json = load_json('list.json')
|
155
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
156
|
+
|
157
|
+
response = RestClient::Response.create(json, net_http_resp, {})
|
158
|
+
RestClient.stub(:post).and_return(response)
|
159
|
+
list = ConstantContact::Components::ContactList.create(JSON.parse(json))
|
160
|
+
added = @api.add_list('token', list)
|
161
|
+
|
162
|
+
added.should respond_to(:status)
|
163
|
+
added.status.should eq('ACTIVE')
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
describe "#get_contacts_from_list" do
|
168
|
+
it "returns an array of contacts" do
|
169
|
+
json_list = load_json('list.json')
|
170
|
+
json_contacts = load_json('contacts.json')
|
171
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
172
|
+
|
173
|
+
response = RestClient::Response.create(json_contacts, net_http_resp, {})
|
174
|
+
RestClient.stub(:get).and_return(response)
|
175
|
+
list = ConstantContact::Components::ContactList.create(JSON.parse(json_list))
|
176
|
+
contacts = @api.get_contacts_from_list('token', list)
|
177
|
+
contact = contacts.results[0]
|
178
|
+
|
179
|
+
contacts.should be_kind_of(ConstantContact::Components::ResultSet)
|
180
|
+
contact.should be_kind_of(ConstantContact::Components::Contact)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|