constantcontact 1.0.0
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 -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,27 @@
|
|
1
|
+
#
|
2
|
+
# result_set.rb
|
3
|
+
# ConstantContact
|
4
|
+
#
|
5
|
+
# Copyright (c) 2013 Constant Contact. All rights reserved.
|
6
|
+
|
7
|
+
module ConstantContact
|
8
|
+
module Components
|
9
|
+
class ResultSet
|
10
|
+
attr_accessor :results, :next
|
11
|
+
|
12
|
+
|
13
|
+
# Constructor to create a ResultSet from the results/meta response when performing a get on a collection
|
14
|
+
# @param [Array<Hash>] results - results array from request
|
15
|
+
# @param [Hash] meta - meta hash from request
|
16
|
+
def initialize(results, meta)
|
17
|
+
@results = results
|
18
|
+
|
19
|
+
if meta.has_key?('pagination') and meta['pagination'].has_key?('next_link')
|
20
|
+
next_link = meta['pagination']['next_link']
|
21
|
+
@next = next_link[next_link.index('?'), next_link.length]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#
|
2
|
+
# bounce_activity.rb
|
3
|
+
# ConstantContact
|
4
|
+
#
|
5
|
+
# Copyright (c) 2013 Constant Contact. All rights reserved.
|
6
|
+
|
7
|
+
module ConstantContact
|
8
|
+
module Components
|
9
|
+
class BounceActivity < Component
|
10
|
+
attr_accessor :activity_type, :bounce_code, :bounce_description, :bounce_message, :bounce_date,
|
11
|
+
:contact_id, :email_address, :campaign_id
|
12
|
+
|
13
|
+
|
14
|
+
# Factory method to create a BounceActivity object from an array
|
15
|
+
# @param [Hash] props - hash of properties to create object from
|
16
|
+
# @return [BounceActivity]
|
17
|
+
def self.create(props)
|
18
|
+
bounce_activity = BounceActivity.new
|
19
|
+
if props
|
20
|
+
props.each do |key, value|
|
21
|
+
bounce_activity.send("#{key}=", value)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
bounce_activity
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#
|
2
|
+
# click_activity.rb
|
3
|
+
# ConstantContact
|
4
|
+
#
|
5
|
+
# Copyright (c) 2013 Constant Contact. All rights reserved.
|
6
|
+
|
7
|
+
module ConstantContact
|
8
|
+
module Components
|
9
|
+
class ClickActivity < Component
|
10
|
+
attr_accessor :activity_type, :campaign_id, :contact_id, :email_address, :link_id, :click_date
|
11
|
+
|
12
|
+
|
13
|
+
# Factory method to create a ClickActivity object from an array
|
14
|
+
# @param [Hash] props - hash of properties to create object from
|
15
|
+
# @return [ClickActivity]
|
16
|
+
def self.create(props)
|
17
|
+
click_activity = ClickActivity.new
|
18
|
+
if props
|
19
|
+
props.each do |key, value|
|
20
|
+
click_activity.send("#{key}=", value)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
click_activity
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#
|
2
|
+
# forward_activity.rb
|
3
|
+
# ConstantContact
|
4
|
+
#
|
5
|
+
# Copyright (c) 2013 Constant Contact. All rights reserved.
|
6
|
+
|
7
|
+
module ConstantContact
|
8
|
+
module Components
|
9
|
+
class ForwardActivity < Component
|
10
|
+
attr_accessor :activity_type, :campaign_id, :contact_id, :email_address, :forward_date
|
11
|
+
|
12
|
+
|
13
|
+
# Factory method to create a ForwardActivity object from an array
|
14
|
+
# @param [Hash] props - hash of properties to create object from
|
15
|
+
# @return [ForwardActivity]
|
16
|
+
def self.create(props)
|
17
|
+
forward_activity = ForwardActivity.new
|
18
|
+
if props
|
19
|
+
props.each do |key, value|
|
20
|
+
forward_activity.send("#{key}=", value)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
forward_activity
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#
|
2
|
+
# open_activity.rb
|
3
|
+
# ConstantContact
|
4
|
+
#
|
5
|
+
# Copyright (c) 2013 Constant Contact. All rights reserved.
|
6
|
+
|
7
|
+
module ConstantContact
|
8
|
+
module Components
|
9
|
+
class OpenActivity < Component
|
10
|
+
attr_accessor :activity_type, :campaign_id, :email_address, :open_date, :contact_id
|
11
|
+
|
12
|
+
|
13
|
+
# Factory method to create an OpenActivity object from an array
|
14
|
+
# @param [Hash] props - hash of properties to create object from
|
15
|
+
# @return [OpenActivity]
|
16
|
+
def self.create(props)
|
17
|
+
open_activity = OpenActivity.new
|
18
|
+
if props
|
19
|
+
props.each do |key, value|
|
20
|
+
open_activity.send("#{key}=", value)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
open_activity
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#
|
2
|
+
# send_activity.rb
|
3
|
+
# ConstantContact
|
4
|
+
#
|
5
|
+
# Copyright (c) 2013 Constant Contact. All rights reserved.
|
6
|
+
|
7
|
+
module ConstantContact
|
8
|
+
module Components
|
9
|
+
class SendActivity < Component
|
10
|
+
attr_accessor :activity_type, :campaign_id, :email_address, :contact_id, :send_date
|
11
|
+
|
12
|
+
|
13
|
+
# Factory method to create a SendActivity object from an array
|
14
|
+
# @param [Hash] props - hash of properties to create object from
|
15
|
+
# @return [SendActivity]
|
16
|
+
def self.create(props)
|
17
|
+
send_activity = SendActivity.new
|
18
|
+
if props
|
19
|
+
props.each do |key, value|
|
20
|
+
send_activity.send("#{key}=", value)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
send_activity
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#
|
2
|
+
# tracking_activity.rb
|
3
|
+
# ConstantContact
|
4
|
+
#
|
5
|
+
# Copyright (c) 2013 Constant Contact. All rights reserved.
|
6
|
+
|
7
|
+
module ConstantContact
|
8
|
+
module Components
|
9
|
+
class TrackingActivity < Component
|
10
|
+
attr_accessor :results, :next
|
11
|
+
|
12
|
+
|
13
|
+
# Constructor to create a TrackingActivity from the results/pagination response from getting a set of activities
|
14
|
+
# @param [Array] results - results array from a tracking endpoint
|
15
|
+
# @param [Hash] pagination - pagination hash returned from a tracking endpoint
|
16
|
+
# @return [TrackingActivity]
|
17
|
+
def initialize(results, pagination)
|
18
|
+
@results = results
|
19
|
+
|
20
|
+
if (pagination.has_key?('next'))
|
21
|
+
@next = pagination['next'][pagination['next'].index('&next=') + 6, pagination['next'].length]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#
|
2
|
+
# tracking_summary.rb
|
3
|
+
# ConstantContact
|
4
|
+
#
|
5
|
+
# Copyright (c) 2013 Constant Contact. All rights reserved.
|
6
|
+
|
7
|
+
module ConstantContact
|
8
|
+
module Components
|
9
|
+
class TrackingSummary < Component
|
10
|
+
attr_accessor :sends, :opens, :clicks, :forwards, :unsubscribes, :bounces, :contact_id
|
11
|
+
|
12
|
+
|
13
|
+
# Factory method to create a TrackingSummary object from an array
|
14
|
+
# @param [Hash] props - array of properties to create object from
|
15
|
+
# @return [TrackingSummary]
|
16
|
+
def self.create(props)
|
17
|
+
tracking_summary = TrackingSummary.new
|
18
|
+
if props
|
19
|
+
props.each do |key, value|
|
20
|
+
tracking_summary.send("#{key}=", value)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
tracking_summary
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#
|
2
|
+
# unsubscribe_activity.rb
|
3
|
+
# ConstantContact
|
4
|
+
#
|
5
|
+
# Copyright (c) 2013 Constant Contact. All rights reserved.
|
6
|
+
|
7
|
+
module ConstantContact
|
8
|
+
module Components
|
9
|
+
class UnsubscribeActivity < Component
|
10
|
+
attr_accessor :activity_type, :campaign_id, :contact_id, :email_address, :unsubscribe_date,
|
11
|
+
:unsubscribe_source, :unsubscribe_reason
|
12
|
+
|
13
|
+
|
14
|
+
# Factory method to create an UnsubscribeActivity object from an array
|
15
|
+
# @param [Hash] props - hash of properties to create object from
|
16
|
+
# @return [UnsubscribeActivity]
|
17
|
+
def self.create(props)
|
18
|
+
unsubscribe_activity = UnsubscribeActivity.new
|
19
|
+
if props
|
20
|
+
props.each do |key, value|
|
21
|
+
unsubscribe_activity.send("#{key}=", value)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
unsubscribe_activity
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
#
|
2
|
+
# ctct_exception.rb
|
3
|
+
# ConstantContact
|
4
|
+
#
|
5
|
+
# Copyright (c) 2013 Constant Contact. All rights reserved.
|
6
|
+
|
7
|
+
module ConstantContact
|
8
|
+
module Exceptions
|
9
|
+
class CtctException < Exception
|
10
|
+
attr_accessor :errors
|
11
|
+
|
12
|
+
# Setter
|
13
|
+
# @param [Array<String>] errors
|
14
|
+
def set_errors(errors)
|
15
|
+
@errors = errors
|
16
|
+
end
|
17
|
+
|
18
|
+
# Getter
|
19
|
+
# @return [Array<String>]
|
20
|
+
def get_errors
|
21
|
+
@errors
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#
|
2
|
+
# email_address_service.rb
|
3
|
+
# ConstantContact
|
4
|
+
#
|
5
|
+
# Copyright (c) 2013 Constant Contact. All rights reserved.
|
6
|
+
|
7
|
+
module ConstantContact
|
8
|
+
module Services
|
9
|
+
class AccountService < BaseService
|
10
|
+
class << self
|
11
|
+
|
12
|
+
# Get the verified emails from account
|
13
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
14
|
+
# @return [Array<VerifiedEmailAddress>]
|
15
|
+
def get_verified_email_addresses(access_token)
|
16
|
+
url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.account_verified_addresses')
|
17
|
+
url = build_url(url)
|
18
|
+
response = RestClient.get(url, get_headers(access_token))
|
19
|
+
email_addresses = []
|
20
|
+
JSON.parse(response.body).each do |email_address|
|
21
|
+
email_addresses << Components::VerifiedEmailAddress.create(email_address)
|
22
|
+
end
|
23
|
+
email_addresses
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
#
|
2
|
+
# activity_service.rb
|
3
|
+
# ConstantContact
|
4
|
+
#
|
5
|
+
# Copyright (c) 2013 Constant Contact. All rights reserved.
|
6
|
+
|
7
|
+
module ConstantContact
|
8
|
+
module Services
|
9
|
+
class ActivityService < BaseService
|
10
|
+
class << self
|
11
|
+
|
12
|
+
# Get a set of activities
|
13
|
+
# @param [String] access_token
|
14
|
+
# @return [Array<Activity>]
|
15
|
+
def get_activities(access_token)
|
16
|
+
url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.activities')
|
17
|
+
url = build_url(url)
|
18
|
+
response = RestClient.get(url, get_headers(access_token))
|
19
|
+
|
20
|
+
activities = []
|
21
|
+
JSON.parse(response.body).each do |activity|
|
22
|
+
activities << Components::Activity.create(activity)
|
23
|
+
end
|
24
|
+
|
25
|
+
activities
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
# Get an array of activities
|
30
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
31
|
+
# @param [String] activity_id - Activity id
|
32
|
+
# @return [Activity]
|
33
|
+
def get_activity(access_token, activity_id)
|
34
|
+
url = Util::Config.get('endpoints.base_url') +
|
35
|
+
sprintf(Util::Config.get('endpoints.activity'), activity_id)
|
36
|
+
url = build_url(url)
|
37
|
+
response = RestClient.get(url, get_headers(access_token))
|
38
|
+
Components::Activity.create(JSON.parse(response.body))
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
# Create an Add Contacts Activity
|
43
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
44
|
+
# @param [AddContacts] add_contacts
|
45
|
+
# @return [Activity]
|
46
|
+
def create_add_contacts_activity(access_token, add_contacts)
|
47
|
+
url = Util::Config.get('endpoints.base_url') +
|
48
|
+
Util::Config.get('endpoints.add_contacts_activity')
|
49
|
+
url = build_url(url)
|
50
|
+
payload = add_contacts.to_json
|
51
|
+
response = RestClient.post(url, payload, get_headers(access_token))
|
52
|
+
Components::Activity.create(JSON.parse(response.body))
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
# Create a Clear Lists Activity
|
57
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
58
|
+
# @param [Array<lists>] lists - array of list id's to be cleared
|
59
|
+
# @return [Activity]
|
60
|
+
def add_clear_lists_activity(access_token, lists)
|
61
|
+
url = Util::Config.get('endpoints.base_url') +
|
62
|
+
Util::Config.get('endpoints.clear_lists_activity')
|
63
|
+
url = build_url(url)
|
64
|
+
payload = {'lists' => lists}.to_json
|
65
|
+
response = RestClient.post(url, payload, get_headers(access_token))
|
66
|
+
Components::Activity.create(JSON.parse(response.body))
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
# Create an Export Contacts Activity
|
71
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
72
|
+
# @param [ExportContacts] export_contacts
|
73
|
+
# @return [Activity]
|
74
|
+
def add_export_contacts_activity(access_token, export_contacts)
|
75
|
+
url = Util::Config.get('endpoints.base_url') +
|
76
|
+
Util::Config.get('endpoints.export_contacts_activity')
|
77
|
+
url = build_url(url)
|
78
|
+
payload = export_contacts.to_json
|
79
|
+
response = RestClient.post(url, payload, get_headers(access_token))
|
80
|
+
Components::Activity.create(JSON.parse(response.body))
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
# Create a Remove Contacts From Lists Activity
|
85
|
+
# @param [String] access_token - Constant Contact OAuth2 access token
|
86
|
+
# @param [<Array>EmailAddress] email_addresses
|
87
|
+
# @param [<Array>RemoveFromLists] lists
|
88
|
+
# @return [Activity]
|
89
|
+
def add_remove_contacts_from_lists_activity(access_token, email_addresses, lists)
|
90
|
+
url = Util::Config.get('endpoints.base_url') +
|
91
|
+
Util::Config.get('endpoints.remove_from_lists_activity')
|
92
|
+
url = build_url(url)
|
93
|
+
|
94
|
+
payload = { 'import_data' => [], 'lists' => lists }
|
95
|
+
email_addresses.each do |email_address|
|
96
|
+
payload['import_data'] << { 'email_addresses' => [email_address] }
|
97
|
+
end
|
98
|
+
payload = payload.to_json
|
99
|
+
|
100
|
+
response = RestClient.post(url, payload, get_headers(access_token))
|
101
|
+
Components::Activity.create(JSON.parse(response.body))
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|