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.
Files changed (60) hide show
  1. checksums.yaml +7 -7
  2. data/README.md +7 -0
  3. data/constantcontact.gemspec +1 -1
  4. data/lib/constantcontact.rb +54 -54
  5. data/lib/constantcontact/api.rb +5 -3
  6. data/lib/constantcontact/auth/oauth2.rb +7 -4
  7. data/lib/constantcontact/auth/session_data_store.rb +52 -52
  8. data/lib/constantcontact/components/account/verified_email_address.rb +17 -17
  9. data/lib/constantcontact/components/activities/activity.rb +34 -34
  10. data/lib/constantcontact/components/activities/activity_error.rb +17 -17
  11. data/lib/constantcontact/components/activities/add_contacts.rb +109 -109
  12. data/lib/constantcontact/components/activities/add_contacts_import_data.rb +37 -37
  13. data/lib/constantcontact/components/activities/export_contacts.rb +19 -19
  14. data/lib/constantcontact/components/component.rb +13 -13
  15. data/lib/constantcontact/components/contacts/address.rb +18 -18
  16. data/lib/constantcontact/components/contacts/contact.rb +69 -69
  17. data/lib/constantcontact/components/contacts/contact_list.rb +17 -17
  18. data/lib/constantcontact/components/contacts/custom_field.rb +17 -17
  19. data/lib/constantcontact/components/contacts/email_address.rb +23 -23
  20. data/lib/constantcontact/components/contacts/note.rb +16 -16
  21. data/lib/constantcontact/components/email_marketing/campaign.rb +67 -67
  22. data/lib/constantcontact/components/email_marketing/click_through_details.rb +17 -17
  23. data/lib/constantcontact/components/email_marketing/message_footer.rb +20 -20
  24. data/lib/constantcontact/components/email_marketing/schedule.rb +18 -18
  25. data/lib/constantcontact/components/email_marketing/test_send.rb +32 -32
  26. data/lib/constantcontact/components/result_set.rb +15 -15
  27. data/lib/constantcontact/components/tracking/bounce_activity.rb +18 -18
  28. data/lib/constantcontact/components/tracking/click_activity.rb +17 -17
  29. data/lib/constantcontact/components/tracking/forward_activity.rb +17 -17
  30. data/lib/constantcontact/components/tracking/open_activity.rb +17 -17
  31. data/lib/constantcontact/components/tracking/send_activity.rb +17 -17
  32. data/lib/constantcontact/components/tracking/tracking_activity.rb +15 -15
  33. data/lib/constantcontact/components/tracking/tracking_summary.rb +17 -17
  34. data/lib/constantcontact/components/tracking/unsubscribe_activity.rb +18 -18
  35. data/lib/constantcontact/exceptions/ctct_exception.rb +15 -15
  36. data/lib/constantcontact/exceptions/illegal_argument_exception.rb +3 -3
  37. data/lib/constantcontact/exceptions/oauth2_exception.rb +3 -3
  38. data/lib/constantcontact/services/account_service.rb +19 -19
  39. data/lib/constantcontact/services/activity_service.rb +99 -99
  40. data/lib/constantcontact/services/base_service.rb +24 -24
  41. data/lib/constantcontact/services/campaign_schedule_service.rb +85 -85
  42. data/lib/constantcontact/services/campaign_tracking_service.rb +151 -151
  43. data/lib/constantcontact/services/contact_service.rb +106 -106
  44. data/lib/constantcontact/services/contact_tracking_service.rb +151 -151
  45. data/lib/constantcontact/services/email_marketing_service.rb +66 -66
  46. data/lib/constantcontact/services/list_service.rb +67 -67
  47. data/lib/constantcontact/util/config.rb +102 -96
  48. data/lib/constantcontact/util/helpers.rb +18 -18
  49. data/lib/constantcontact/version.rb +4 -4
  50. data/spec/constantcontact/api_spec.rb +223 -173
  51. data/spec/constantcontact/auth/oauth2_spec.rb +68 -4
  52. data/spec/constantcontact/components/contacts/address_spec.rb +7 -7
  53. data/spec/constantcontact/components/contacts/contact_list_spec.rb +7 -7
  54. data/spec/constantcontact/components/contacts/contact_spec.rb +7 -7
  55. data/spec/constantcontact/components/contacts/custom_field_spec.rb +7 -7
  56. data/spec/constantcontact/components/contacts/email_address_spec.rb +7 -7
  57. data/spec/constantcontact/services/contact_service_spec.rb +95 -95
  58. data/spec/constantcontact/services/list_service_spec.rb +48 -48
  59. data/spec/spec_helper.rb +1 -1
  60. metadata +55 -44
@@ -5,113 +5,113 @@
5
5
  # Copyright (c) 2013 Constant Contact. All rights reserved.
6
6
 
7
7
  module ConstantContact
8
- module Components
9
- class AddContacts < Component
10
- attr_accessor :import_data, :lists, :column_names
11
-
12
- # Constructor to create an AddContacts object from the given contacts and contact lists
13
- # @param [Array<Contact>] contacts - contacts array
14
- # @param [Array<ContactList>] lists - contact lists array]
15
- # @param [Array<String>] column_names - array of column names
16
- # @return [AddContacts]
17
- def initialize(contacts, lists, column_names = [])
18
- if !contacts.empty?
19
- if contacts[0].instance_of?(Components::AddContactsImportData)
20
- @import_data = contacts
21
- else
22
- raise Exceptions::IllegalArgumentException, sprintf(Util::Config.get('errors.id_or_object'), 'AddContactsImportData')
23
- end
24
- end
25
-
26
- @lists = lists
27
- @column_names = column_names
28
-
29
- # attempt to determine the column names being used if they are not provided
30
- if column_names.empty?
31
- used_columns = [Util::Config.get('activities_columns.email')]
32
-
33
- contact = contacts[0]
34
-
35
- if !contact.first_name.nil?
36
- used_columns << Util::Config.get('activities_columns.first_name')
37
- end
38
-
39
- if !contact.middle_name.nil?
40
- used_columns << Util::Config.get('activities_columns.middle_name')
41
- end
42
-
43
- if !contact.last_name.nil?
44
- used_columns << Util::Config.get('activities_columns.last_name')
45
- end
46
-
47
- if !contact.job_title.nil?
48
- used_columns << Util::Config.get('activities_columns.job_title')
49
- end
50
-
51
- if !contact.company_name.nil?
52
- used_columns << Util::Config.get('activities_columns.company_name')
53
- end
54
-
55
- if !contact.work_phone.nil?
56
- used_columns << Util::Config.get('activities_columns.work_phone')
57
- end
58
-
59
- if !contact.home_phone.nil?
60
- used_columns << Util::Config.get('activities_columns.home_phone')
61
- end
62
-
63
- address = contact.addresses[0]
64
-
65
- if !address.line1.nil?
66
- used_columns << Util::Config.get('activities_columns.address1')
67
- end
68
-
69
- if !address.line2.nil?
70
- used_columns << Util::Config.get('activities_columns.address2')
71
- end
72
-
73
- if !address.line3.nil?
74
- used_columns << Util::Config.get('activities_columns.address3')
75
- end
76
-
77
- if !address.city.nil?
78
- used_columns << Util::Config.get('activities_columns.city')
79
- end
80
-
81
- if !address.state_code.nil?
82
- used_columns << Util::Config.get('activities_columns.state')
83
- end
84
-
85
- if !address.state_code.nil?
86
- used_columns << Util::Config.get('activities_columns.state_province')
87
- end
88
-
89
- if !address.country_code.nil?
90
- used_columns << Util::Config.get('activities_columns.country')
91
- end
92
-
93
- if !address.postal_code.nil?
94
- used_columns << Util::Config.get('activities_columns.postal_code')
95
- end
96
-
97
- if !address.sub_postal_code.nil?
98
- used_columns << Util::Config.get('activities_columns.sub_postal_code')
99
- end
100
-
101
- # Custom Fields
102
- if !contact.custom_fields.nil?
103
- contact.custom_fields.each do |custom_field|
104
- if custom_field.name.match('custom_field_')
105
- custom_field_number = custom_field.name[13, custom_field.length]
106
- used_columns << Util::Config.get('activities_columns.custom_field_' + custom_field_number)
107
- end
108
- end
109
- end
110
-
111
- @column_names = used_columns
112
- end
113
- end
114
-
115
- end
116
- end
8
+ module Components
9
+ class AddContacts < Component
10
+ attr_accessor :import_data, :lists, :column_names
11
+
12
+ # Constructor to create an AddContacts object from the given contacts and contact lists
13
+ # @param [Array<Contact>] contacts - contacts array
14
+ # @param [Array<ContactList>] lists - contact lists array]
15
+ # @param [Array<String>] column_names - array of column names
16
+ # @return [AddContacts]
17
+ def initialize(contacts, lists, column_names = [])
18
+ if !contacts.empty?
19
+ if contacts[0].instance_of?(Components::AddContactsImportData)
20
+ @import_data = contacts
21
+ else
22
+ raise Exceptions::IllegalArgumentException, sprintf(Util::Config.get('errors.id_or_object'), 'AddContactsImportData')
23
+ end
24
+ end
25
+
26
+ @lists = lists
27
+ @column_names = column_names
28
+
29
+ # attempt to determine the column names being used if they are not provided
30
+ if column_names.empty?
31
+ used_columns = [Util::Config.get('activities_columns.email')]
32
+
33
+ contact = contacts[0]
34
+
35
+ if !contact.first_name.nil?
36
+ used_columns << Util::Config.get('activities_columns.first_name')
37
+ end
38
+
39
+ if !contact.middle_name.nil?
40
+ used_columns << Util::Config.get('activities_columns.middle_name')
41
+ end
42
+
43
+ if !contact.last_name.nil?
44
+ used_columns << Util::Config.get('activities_columns.last_name')
45
+ end
46
+
47
+ if !contact.job_title.nil?
48
+ used_columns << Util::Config.get('activities_columns.job_title')
49
+ end
50
+
51
+ if !contact.company_name.nil?
52
+ used_columns << Util::Config.get('activities_columns.company_name')
53
+ end
54
+
55
+ if !contact.work_phone.nil?
56
+ used_columns << Util::Config.get('activities_columns.work_phone')
57
+ end
58
+
59
+ if !contact.home_phone.nil?
60
+ used_columns << Util::Config.get('activities_columns.home_phone')
61
+ end
62
+
63
+ address = contact.addresses[0]
64
+
65
+ if !address.line1.nil?
66
+ used_columns << Util::Config.get('activities_columns.address1')
67
+ end
68
+
69
+ if !address.line2.nil?
70
+ used_columns << Util::Config.get('activities_columns.address2')
71
+ end
72
+
73
+ if !address.line3.nil?
74
+ used_columns << Util::Config.get('activities_columns.address3')
75
+ end
76
+
77
+ if !address.city.nil?
78
+ used_columns << Util::Config.get('activities_columns.city')
79
+ end
80
+
81
+ if !address.state_code.nil?
82
+ used_columns << Util::Config.get('activities_columns.state')
83
+ end
84
+
85
+ if !address.state_code.nil?
86
+ used_columns << Util::Config.get('activities_columns.state_province')
87
+ end
88
+
89
+ if !address.country_code.nil?
90
+ used_columns << Util::Config.get('activities_columns.country')
91
+ end
92
+
93
+ if !address.postal_code.nil?
94
+ used_columns << Util::Config.get('activities_columns.postal_code')
95
+ end
96
+
97
+ if !address.sub_postal_code.nil?
98
+ used_columns << Util::Config.get('activities_columns.sub_postal_code')
99
+ end
100
+
101
+ # Custom Fields
102
+ if !contact.custom_fields.nil?
103
+ contact.custom_fields.each do |custom_field|
104
+ if custom_field.name.match('custom_field_')
105
+ custom_field_number = custom_field.name[13, custom_field.length]
106
+ used_columns << Util::Config.get('activities_columns.custom_field_' + custom_field_number)
107
+ end
108
+ end
109
+ end
110
+
111
+ @column_names = used_columns
112
+ end
113
+ end
114
+
115
+ end
116
+ end
117
117
  end
@@ -5,41 +5,41 @@
5
5
  # Copyright (c) 2013 Constant Contact. All rights reserved.
6
6
 
7
7
  module ConstantContact
8
- module Components
9
- class AddContactsImportData < Component
10
- attr_accessor :first_name, :middle_name, :last_name, :job_title, :company_name,
11
- :work_phone, :home_phone, :email_addresses, :addresses, :custom_fields
12
-
13
-
14
- # Constructor to create an AddContactsImportData object from the given hash
15
- # @param [Hash] props - the hash with properties
16
- # @return [AddContactsImportData]
17
- def initialize(props = {})
18
- instance_variables.each do |property, value|
19
- send("#{property}=", get_value(props, property))
20
- end
21
- end
22
-
23
- # Setter
24
- def add_custom_field(custom_field)
25
- @custom_fields = [] if @custom_fields.nil?
26
- @custom_fields << custom_field
27
- end
28
-
29
-
30
- # Setter
31
- def add_address(address)
32
- @addresses = [] if @addresses.nil?
33
- @addresses << address
34
- end
35
-
36
-
37
- # Setter
38
- def add_email(email_address)
39
- @email_addresses = [] if @email_addresses.nil?
40
- @email_addresses << email_address
41
- end
42
-
43
- end
44
- end
8
+ module Components
9
+ class AddContactsImportData < Component
10
+ attr_accessor :first_name, :middle_name, :last_name, :job_title, :company_name,
11
+ :work_phone, :home_phone, :email_addresses, :addresses, :custom_fields
12
+
13
+
14
+ # Constructor to create an AddContactsImportData object from the given hash
15
+ # @param [Hash] props - the hash with properties
16
+ # @return [AddContactsImportData]
17
+ def initialize(props = {})
18
+ instance_variables.each do |property, value|
19
+ send("#{property}=", get_value(props, property))
20
+ end
21
+ end
22
+
23
+ # Setter
24
+ def add_custom_field(custom_field)
25
+ @custom_fields = [] if @custom_fields.nil?
26
+ @custom_fields << custom_field
27
+ end
28
+
29
+
30
+ # Setter
31
+ def add_address(address)
32
+ @addresses = [] if @addresses.nil?
33
+ @addresses << address
34
+ end
35
+
36
+
37
+ # Setter
38
+ def add_email(email_address)
39
+ @email_addresses = [] if @email_addresses.nil?
40
+ @email_addresses << email_address
41
+ end
42
+
43
+ end
44
+ end
45
45
  end
@@ -5,26 +5,26 @@
5
5
  # Copyright (c) 2013 Constant Contact. All rights reserved.
6
6
 
7
7
  module ConstantContact
8
- module Components
9
- class ExportContacts < Component
10
- attr_accessor :file_type, :sort_by, :export_date_added,
11
- :export_added_by, :lists, :column_names
8
+ module Components
9
+ class ExportContacts < Component
10
+ attr_accessor :file_type, :sort_by, :export_date_added,
11
+ :export_added_by, :lists, :column_names
12
12
 
13
13
 
14
- # Constructor to create an ExportContacts object
15
- # @param [Array] lists - array of lists ids
16
- # @return [ExportContacts]
17
- def initialize(lists = nil)
18
- if !lists.nil?
19
- @lists = lists
20
- end
21
- @file_type = 'CSV'
22
- @sort_by = 'EMAIL_ADDRESS'
23
- @export_date_added = true
24
- @export_added_by = true
25
- @column_names = ['Email Address', 'First Name', 'Last Name']
26
- end
14
+ # Constructor to create an ExportContacts object
15
+ # @param [Array] lists - array of lists ids
16
+ # @return [ExportContacts]
17
+ def initialize(lists = nil)
18
+ if !lists.nil?
19
+ @lists = lists
20
+ end
21
+ @file_type = 'CSV'
22
+ @sort_by = 'EMAIL_ADDRESS'
23
+ @export_date_added = true
24
+ @export_added_by = true
25
+ @column_names = ['Email Address', 'First Name', 'Last Name']
26
+ end
27
27
 
28
- end
29
- end
28
+ end
29
+ end
30
30
  end
@@ -5,19 +5,19 @@
5
5
  # Copyright (c) 2013 Constant Contact. All rights reserved.
6
6
 
7
7
  module ConstantContact
8
- module Components
9
- class Component
10
- protected
8
+ module Components
9
+ class Component
10
+ protected
11
11
 
12
- # Get the requested value from a hash, or return the default
13
- # @param [Hash] hsh - the hash to search for the provided hash key
14
- # @param [String] key - hash key to look for
15
- # @param [String] default - value to return if the key is not found, default is null
16
- # @return [String]
17
- def self.get_value(hsh, key, default = nil)
18
- hsh.has_key?(key) and hsh[key] ? hsh[key] : default
19
- end
12
+ # Get the requested value from a hash, or return the default
13
+ # @param [Hash] hsh - the hash to search for the provided hash key
14
+ # @param [String] key - hash key to look for
15
+ # @param [String] default - value to return if the key is not found, default is null
16
+ # @return [String]
17
+ def self.get_value(hsh, key, default = nil)
18
+ hsh.has_key?(key) and hsh[key] ? hsh[key] : default
19
+ end
20
20
 
21
- end
22
- end
21
+ end
22
+ end
23
23
  end
@@ -5,24 +5,24 @@
5
5
  # Copyright (c) 2013 Constant Contact. All rights reserved.
6
6
 
7
7
  module ConstantContact
8
- module Components
9
- class Address < Component
10
- attr_accessor :id, :line1, :line2, :line3, :city, :address_type, :state_code,
11
- :country_code, :postal_code, :sub_postal_code
8
+ module Components
9
+ class Address < Component
10
+ attr_accessor :id, :line1, :line2, :line3, :city, :address_type, :state_code,
11
+ :country_code, :postal_code, :sub_postal_code
12
12
 
13
- # Factory method to create an Address object from a json string
14
- # @param [Hash] props - array of properties to create object from
15
- # @return [Address]
16
- def self.create(props)
17
- address = Address.new
18
- if props
19
- props.each do |key, value|
20
- address.send("#{key}=", value)
21
- end
22
- end
23
- address
24
- end
13
+ # Factory method to create an Address object from a json string
14
+ # @param [Hash] props - array of properties to create object from
15
+ # @return [Address]
16
+ def self.create(props)
17
+ address = Address.new
18
+ if props
19
+ props.each do |key, value|
20
+ address.send("#{key}=", value)
21
+ end
22
+ end
23
+ address
24
+ end
25
25
 
26
- end
27
- end
26
+ end
27
+ end
28
28
  end
@@ -5,82 +5,82 @@
5
5
  # Copyright (c) 2013 Constant Contact. All rights reserved.
6
6
 
7
7
  module ConstantContact
8
- module Components
9
- class Contact < Component
8
+ module Components
9
+ class Contact < Component
10
10
 
11
- attr_accessor :id, :status, :first_name, :middle_name, :last_name, :confirmed, :email_addresses,
12
- :prefix_name, :job_title, :addresses, :company_name, :home_phone,
13
- :work_phone, :cell_phone, :fax, :custom_fields, :lists,
14
- :source_details, :source_is_url, :web_url, :modified_date,
15
- :created_date, :notes, :source
11
+ attr_accessor :id, :status, :first_name, :middle_name, :last_name, :confirmed, :email_addresses,
12
+ :prefix_name, :job_title, :addresses, :company_name, :home_phone,
13
+ :work_phone, :cell_phone, :fax, :custom_fields, :lists,
14
+ :source_details, :source_is_url, :web_url, :modified_date,
15
+ :created_date, :notes, :source
16
16
 
17
17
 
18
- # Factory method to create a Contact object from a json string
19
- # @param [Hash] props - JSON string representing a contact
20
- # @return [Contact]
21
- def self.create(props)
22
- contact = Contact.new
23
- if props
24
- props.each do |key, value|
25
- if key == 'email_addresses'
26
- if value
27
- contact.email_addresses = []
28
- value.each do |email_address|
29
- contact.email_addresses << Components::EmailAddress.create(email_address)
30
- end
31
- end
32
- elsif key == 'addresses'
33
- if value
34
- contact.addresses = []
35
- value.each do |address|
36
- contact.addresses << Components::Address.create(address)
37
- end
38
- end
39
- elsif key == 'custom_fields'
40
- if value
41
- contact.custom_fields = []
42
- value.each do |custom_field|
43
- contact.custom_fields << Components::CustomField.create(custom_field)
44
- end
45
- end
46
- elsif key == 'lists'
47
- if value
48
- contact.lists = []
49
- value.each do |contact_list|
50
- contact.lists << Components::ContactList.create(contact_list)
51
- end
52
- end
53
- else
54
- contact.send("#{key}=", value)
55
- end
56
- end
57
- end
58
- contact
59
- end
18
+ # Factory method to create a Contact object from a json string
19
+ # @param [Hash] props - JSON string representing a contact
20
+ # @return [Contact]
21
+ def self.create(props)
22
+ contact = Contact.new
23
+ if props
24
+ props.each do |key, value|
25
+ if key == 'email_addresses'
26
+ if value
27
+ contact.email_addresses = []
28
+ value.each do |email_address|
29
+ contact.email_addresses << Components::EmailAddress.create(email_address)
30
+ end
31
+ end
32
+ elsif key == 'addresses'
33
+ if value
34
+ contact.addresses = []
35
+ value.each do |address|
36
+ contact.addresses << Components::Address.create(address)
37
+ end
38
+ end
39
+ elsif key == 'custom_fields'
40
+ if value
41
+ contact.custom_fields = []
42
+ value.each do |custom_field|
43
+ contact.custom_fields << Components::CustomField.create(custom_field)
44
+ end
45
+ end
46
+ elsif key == 'lists'
47
+ if value
48
+ contact.lists = []
49
+ value.each do |contact_list|
50
+ contact.lists << Components::ContactList.create(contact_list)
51
+ end
52
+ end
53
+ else
54
+ contact.send("#{key}=", value)
55
+ end
56
+ end
57
+ end
58
+ contact
59
+ end
60
60
 
61
- # Setter
62
- # @param [ContactList] contact_list
63
- def add_list(contact_list)
64
- @lists = [] if @lists.nil?
65
- @lists << contact_list
66
- end
61
+ # Setter
62
+ # @param [ContactList] contact_list
63
+ def add_list(contact_list)
64
+ @lists = [] if @lists.nil?
65
+ @lists << contact_list
66
+ end
67
67
 
68
68
 
69
- # Setter
70
- # @param [EmailAddress] email_address
71
- def add_email(email_address)
72
- @email_addresses = [] if @email_addresses.nil?
73
- @email_addresses << email_address
74
- end
69
+ # Setter
70
+ # @param [EmailAddress] email_address
71
+ def add_email(email_address)
72
+ @email_addresses = [] if @email_addresses.nil?
73
+ @email_addresses << email_address
74
+ end
75
75
 
76
76
 
77
- # Setter
78
- # @param [Address] address
79
- def add_address(address)
80
- @addresses = [] if @addresses.nil?
81
- @addresses << address
82
- end
77
+ # Setter
78
+ # @param [Address] address
79
+ def add_address(address)
80
+ @addresses = [] if @addresses.nil?
81
+ @addresses << address
82
+ end
83
83
 
84
- end
85
- end
84
+ end
85
+ end
86
86
  end