constantcontact-ruby 2.2.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.
Files changed (107) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +2 -0
  3. data/README.md +136 -0
  4. data/constantcontact-ruby.gemspec +31 -0
  5. data/lib/constantcontact/api.rb +1012 -0
  6. data/lib/constantcontact/auth/oauth2.rb +105 -0
  7. data/lib/constantcontact/auth/session_data_store.rb +69 -0
  8. data/lib/constantcontact/components/account/account_address.rb +26 -0
  9. data/lib/constantcontact/components/account/account_info.rb +38 -0
  10. data/lib/constantcontact/components/account/verified_email_address.rb +26 -0
  11. data/lib/constantcontact/components/activities/activity.rb +43 -0
  12. data/lib/constantcontact/components/activities/activity_error.rb +26 -0
  13. data/lib/constantcontact/components/activities/add_contacts.rb +127 -0
  14. data/lib/constantcontact/components/activities/add_contacts_import_data.rb +46 -0
  15. data/lib/constantcontact/components/activities/export_contacts.rb +30 -0
  16. data/lib/constantcontact/components/component.rb +48 -0
  17. data/lib/constantcontact/components/contacts/address.rb +27 -0
  18. data/lib/constantcontact/components/contacts/contact.rb +92 -0
  19. data/lib/constantcontact/components/contacts/contact_list.rb +26 -0
  20. data/lib/constantcontact/components/contacts/custom_field.rb +26 -0
  21. data/lib/constantcontact/components/contacts/email_address.rb +33 -0
  22. data/lib/constantcontact/components/contacts/note.rb +26 -0
  23. data/lib/constantcontact/components/email_marketing/campaign.rb +83 -0
  24. data/lib/constantcontact/components/email_marketing/campaign_preview.rb +29 -0
  25. data/lib/constantcontact/components/email_marketing/click_through_details.rb +27 -0
  26. data/lib/constantcontact/components/email_marketing/message_footer.rb +29 -0
  27. data/lib/constantcontact/components/email_marketing/schedule.rb +27 -0
  28. data/lib/constantcontact/components/email_marketing/test_send.rb +45 -0
  29. data/lib/constantcontact/components/event_spot/contact.rb +27 -0
  30. data/lib/constantcontact/components/event_spot/event.rb +69 -0
  31. data/lib/constantcontact/components/event_spot/event_address.rb +29 -0
  32. data/lib/constantcontact/components/event_spot/event_fee.rb +27 -0
  33. data/lib/constantcontact/components/event_spot/event_item.rb +36 -0
  34. data/lib/constantcontact/components/event_spot/event_item_attribute.rb +26 -0
  35. data/lib/constantcontact/components/event_spot/event_track.rb +31 -0
  36. data/lib/constantcontact/components/event_spot/guest.rb +31 -0
  37. data/lib/constantcontact/components/event_spot/guest_section.rb +34 -0
  38. data/lib/constantcontact/components/event_spot/notification_option.rb +27 -0
  39. data/lib/constantcontact/components/event_spot/online_meeting.rb +28 -0
  40. data/lib/constantcontact/components/event_spot/payment_address.rb +29 -0
  41. data/lib/constantcontact/components/event_spot/payment_summary.rb +33 -0
  42. data/lib/constantcontact/components/event_spot/promocode.rb +25 -0
  43. data/lib/constantcontact/components/event_spot/registrant.rb +52 -0
  44. data/lib/constantcontact/components/event_spot/registrant_fee.rb +29 -0
  45. data/lib/constantcontact/components/event_spot/registrant_field.rb +27 -0
  46. data/lib/constantcontact/components/event_spot/registrant_order.rb +39 -0
  47. data/lib/constantcontact/components/event_spot/registrant_promo_code.rb +31 -0
  48. data/lib/constantcontact/components/event_spot/registrant_promo_code_info.rb +27 -0
  49. data/lib/constantcontact/components/event_spot/registrant_section.rb +34 -0
  50. data/lib/constantcontact/components/event_spot/sale_item.rb +29 -0
  51. data/lib/constantcontact/components/library/file/library_file.rb +27 -0
  52. data/lib/constantcontact/components/library/folder/library_folder.rb +26 -0
  53. data/lib/constantcontact/components/library/info/library_summary.rb +26 -0
  54. data/lib/constantcontact/components/library/info/move_results.rb +26 -0
  55. data/lib/constantcontact/components/library/info/upload_status.rb +26 -0
  56. data/lib/constantcontact/components/result_set.rb +50 -0
  57. data/lib/constantcontact/components/tracking/bounce_activity.rb +28 -0
  58. data/lib/constantcontact/components/tracking/click_activity.rb +26 -0
  59. data/lib/constantcontact/components/tracking/forward_activity.rb +26 -0
  60. data/lib/constantcontact/components/tracking/open_activity.rb +26 -0
  61. data/lib/constantcontact/components/tracking/send_activity.rb +27 -0
  62. data/lib/constantcontact/components/tracking/tracking_activity.rb +26 -0
  63. data/lib/constantcontact/components/tracking/tracking_summary.rb +27 -0
  64. data/lib/constantcontact/components/tracking/unsubscribe_activity.rb +27 -0
  65. data/lib/constantcontact/exceptions/ctct_exception.rb +25 -0
  66. data/lib/constantcontact/exceptions/illegal_argument_exception.rb +11 -0
  67. data/lib/constantcontact/exceptions/oauth2_exception.rb +11 -0
  68. data/lib/constantcontact/exceptions/webhooks_exception.rb +11 -0
  69. data/lib/constantcontact/services/account_service.rb +39 -0
  70. data/lib/constantcontact/services/activity_service.rb +136 -0
  71. data/lib/constantcontact/services/base_service.rb +68 -0
  72. data/lib/constantcontact/services/campaign_schedule_service.rb +101 -0
  73. data/lib/constantcontact/services/campaign_tracking_service.rb +152 -0
  74. data/lib/constantcontact/services/contact_service.rb +105 -0
  75. data/lib/constantcontact/services/contact_tracking_service.rb +152 -0
  76. data/lib/constantcontact/services/email_marketing_service.rb +94 -0
  77. data/lib/constantcontact/services/event_spot_service.rb +448 -0
  78. data/lib/constantcontact/services/library_service.rb +281 -0
  79. data/lib/constantcontact/services/list_service.rb +81 -0
  80. data/lib/constantcontact/util/config.rb +180 -0
  81. data/lib/constantcontact/util/helpers.rb +27 -0
  82. data/lib/constantcontact/version.rb +12 -0
  83. data/lib/constantcontact/webhooks/helpers/validator.rb +30 -0
  84. data/lib/constantcontact/webhooks/models/billing_change_notification.rb +27 -0
  85. data/lib/constantcontact/webhooks/webhooks_util.rb +45 -0
  86. data/lib/constantcontact.rb +124 -0
  87. data/spec/constantcontact/api_spec.rb +1560 -0
  88. data/spec/constantcontact/auth/oauth2_spec.rb +125 -0
  89. data/spec/constantcontact/components/contacts/address_spec.rb +18 -0
  90. data/spec/constantcontact/components/contacts/contact_list_spec.rb +18 -0
  91. data/spec/constantcontact/components/contacts/contact_spec.rb +18 -0
  92. data/spec/constantcontact/components/contacts/custom_field_spec.rb +18 -0
  93. data/spec/constantcontact/components/contacts/email_address_spec.rb +18 -0
  94. data/spec/constantcontact/sdk_spec.rb +24 -0
  95. data/spec/constantcontact/services/account_service_spec.rb +46 -0
  96. data/spec/constantcontact/services/activity_service_spec.rb +244 -0
  97. data/spec/constantcontact/services/base_service_spec.rb +50 -0
  98. data/spec/constantcontact/services/campaign_schedule_service_spec.rb +115 -0
  99. data/spec/constantcontact/services/campaign_tracking_service_spec.rb +131 -0
  100. data/spec/constantcontact/services/contact_service_spec.rb +111 -0
  101. data/spec/constantcontact/services/contact_tracking_service_spec.rb +131 -0
  102. data/spec/constantcontact/services/email_marketing_spec.rb +100 -0
  103. data/spec/constantcontact/services/event_spot_spec.rb +423 -0
  104. data/spec/constantcontact/services/library_service_spec.rb +252 -0
  105. data/spec/constantcontact/services/list_service_spec.rb +89 -0
  106. data/spec/constantcontact/webhooks/webhooks_spec.rb +26 -0
  107. metadata +243 -0
@@ -0,0 +1,105 @@
1
+ #
2
+ # oauth2.rb
3
+ # ConstantContact
4
+ #
5
+ # Copyright (c) 2013 Constant Contact. All rights reserved.
6
+
7
+ module ConstantContact
8
+ module Auth
9
+ class OAuth2
10
+ attr_accessor :client_id, :client_secret, :redirect_uri, :props
11
+
12
+
13
+ # Class constructor
14
+ # @param [Hash] opts - the options to create an OAuth2 object with
15
+ # @option opts [String] :api_key - the Constant Contact API Key
16
+ # @option opts [String] :api_secret - the Constant Contact secret key
17
+ # @option opts [String] :redirect_url - the URL where Constact Contact is returning the authorization code
18
+ # @return
19
+ def initialize(opts = {})
20
+ @client_id = opts[:api_key] || Util::Config.get('auth.api_key')
21
+ @client_secret = opts[:api_secret] || Util::Config.get('auth.api_secret')
22
+ @redirect_uri = opts[:redirect_url] || Util::Config.get('auth.redirect_uri')
23
+ if @client_id.nil? || @client_id == '' || @client_secret.nil? || @client_secret.nil? || @redirect_uri.nil? || @redirect_uri == ''
24
+ raise ArgumentError.new "Either api_key, api_secret or redirect_uri is missing in explicit call or configuration."
25
+ end
26
+ end
27
+
28
+
29
+ # Get the URL at which the user can authenticate and authorize the requesting application
30
+ # @param [Boolean] server - whether or not to use OAuth2 server flow, alternative is client flow
31
+ # @param [String] state - an optional value used by the client to maintain state between the request and callback
32
+ # @return [String] the authorization URL
33
+ def get_authorization_url(server = true, state = nil)
34
+ response_type = server ? Util::Config.get('auth.response_type_code') : Util::Config.get('auth.response_type_token')
35
+ params = {
36
+ :response_type => response_type,
37
+ :client_id => @client_id,
38
+ :redirect_uri => @redirect_uri
39
+ }
40
+ if state
41
+ params[:state] = state
42
+ end
43
+ [
44
+ Util::Config.get('auth.base_url'),
45
+ Util::Config.get('auth.authorization_endpoint'),
46
+ '?',
47
+ Util::Helpers.http_build_query(params)
48
+ ].join
49
+ end
50
+
51
+
52
+ # Obtain an access token
53
+ # @param [String] code - the code returned from Constant Contact after a user has granted access to his account
54
+ # @return [String] the access token
55
+ def get_access_token(code)
56
+ params = {
57
+ :grant_type => Util::Config.get('auth.authorization_code_grant_type'),
58
+ :client_id => @client_id,
59
+ :client_secret => @client_secret,
60
+ :code => code,
61
+ :redirect_uri => @redirect_uri
62
+ }
63
+
64
+ url = [
65
+ Util::Config.get('auth.base_url'),
66
+ Util::Config.get('auth.token_endpoint')
67
+ ].join
68
+
69
+ response_body = ''
70
+ begin
71
+ response = RestClient.post(url, params)
72
+ response_body = JSON.parse(response)
73
+ rescue => e
74
+ response_body = e.respond_to?(:response) && e.response ?
75
+ JSON.parse(e.response) :
76
+ {'error' => '', 'error_description' => e.message}
77
+ end
78
+
79
+ if response_body['error_description']
80
+ error = response_body['error_description']
81
+ raise Exceptions::OAuth2Exception, error
82
+ end
83
+
84
+ response_body
85
+ end
86
+
87
+
88
+ # Get an information about an access token
89
+ # @param [String] access_token - Constant Contact OAuth2 access token
90
+ # @return array
91
+ def get_token_info(access_token)
92
+ params = {
93
+ :access_token => access_token
94
+ }
95
+ url = [
96
+ Util::Config.get('auth.base_url'),
97
+ Util::Config.get('auth.token_info')
98
+ ].join
99
+ response = RestClient.post(url, params)
100
+ response_body = JSON.parse(response)
101
+ end
102
+
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,69 @@
1
+ #
2
+ # session_data_store.rb
3
+ # ConstantContact
4
+ #
5
+ # Copyright (c) 2013 Constant Contact. All rights reserved.
6
+
7
+ module ConstantContact
8
+ module Auth
9
+ class Session
10
+ attr_accessor :session
11
+
12
+ # Create and initialize the session
13
+ def initialize
14
+ cgi = CGI.new('html4')
15
+
16
+ # We make sure to delete an old session if one exists,
17
+ # not just to free resources, but to prevent the session
18
+ # from being maliciously hijacked later on.
19
+ begin
20
+ @session = CGI::Session.new(cgi, 'database_manager' => CGI::Session::PStore, 'new_session' => false)
21
+ @session.delete
22
+ rescue ArgumentError # if no old session
23
+ end
24
+ @session = CGI::Session.new(cgi, 'database_manager' => CGI::Session::PStore, 'new_session' => true)
25
+ @session['datastore'] = {}
26
+ end
27
+
28
+ # Add a new user to the data store
29
+ # @param [String] username - Constant Contact username
30
+ # @param [Hash] params - additional parameters
31
+ # @return
32
+ def add_user(username, params)
33
+ @session['datastore'][username] = params
34
+ end
35
+
36
+ # Get an existing user from the data store
37
+ # @param [String] username - Constant Contact username key
38
+ # @return [String] The username value
39
+ def get_user(username)
40
+ @session['datastore'].has_key?(username) ? @session['datastore'][username] : false
41
+ end
42
+
43
+ # Update an existing user in the data store
44
+ # @param [String] username - Constant Contact username
45
+ # @param [Hash] params - additional parameters
46
+ # @return
47
+ def update_user(username, params)
48
+ if @session['datastore'].has_key?(username)
49
+ @session['datastore'][username] = params
50
+ end
51
+ end
52
+
53
+ # Delete an existing user from the data store
54
+ # @param [String] username - Constant Contact username
55
+ # @return
56
+ def delete_user(username)
57
+ @session['datastore'][username] = nil
58
+ end
59
+
60
+ # Close current session
61
+ # @return
62
+ def close
63
+ @session.close
64
+ end
65
+
66
+ end
67
+ end
68
+ end
69
+
@@ -0,0 +1,26 @@
1
+ #
2
+ # account_address.rb
3
+ # ConstantContact
4
+ #
5
+ # Copyright (c) 2013 Constant Contact. All rights reserved.
6
+
7
+ module ConstantContact
8
+ module Components
9
+ class AccountAddress < Component
10
+ attr_accessor :city, :country_code, :line1, :postal_code, :state_code
11
+
12
+ # Factory method to create an AccountAddress object from a json string
13
+ # @param [Hash] props - properties to create object from
14
+ # @return [AccountAddress]
15
+ def self.create(props)
16
+ obj = AccountAddress.new
17
+ if props
18
+ props.each do |key, value|
19
+ obj.send("#{key}=", value) if obj.respond_to? key
20
+ end
21
+ end
22
+ obj
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,38 @@
1
+ #
2
+ # account_info.rb
3
+ # ConstantContact
4
+ #
5
+ # Copyright (c) 2013 Constant Contact. All rights reserved.
6
+
7
+ module ConstantContact
8
+ module Components
9
+ class AccountInfo < Component
10
+ attr_accessor :website, :organization_name, :first_name, :last_name, :email, :phone, :country_code, :state_code,
11
+ :company_logo, :time_zone, :organization_addresses
12
+
13
+ # Class constructor
14
+ # @return [AccountInfo]
15
+ def initialize
16
+ end
17
+
18
+ # Factory method to create an AccountInfo object from a json string
19
+ # @param [Hash] props - properties to create object from
20
+ # @return [AccountInfo]
21
+ def self.create(props)
22
+ obj = AccountInfo.new
23
+ if props
24
+ props.each do |key, value|
25
+ key = key.to_s
26
+ if key == 'organization_addresses'
27
+ value = value || []
28
+ obj.organization_addresses = value.collect{|address| Components::AccountAddress.create(address) }
29
+ else
30
+ obj.send("#{key}=", value) if obj.respond_to? key
31
+ end
32
+ end
33
+ end
34
+ obj
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,26 @@
1
+ #
2
+ # verified_email_address.rb
3
+ # ConstantContact
4
+ #
5
+ # Copyright (c) 2013 Constant Contact. All rights reserved.
6
+
7
+ module ConstantContact
8
+ module Components
9
+ class VerifiedEmailAddress < Component
10
+ attr_accessor :status, :email_address
11
+
12
+ # Factory method to create a VerifiedEmailAddress object from a json string
13
+ # @param [Hash] props - properties to create object from
14
+ # @return [VerifiedEmailAddress]
15
+ def self.create(props)
16
+ obj = VerifiedEmailAddress.new
17
+ if props
18
+ props.each do |key, value|
19
+ obj.send("#{key}=", value) if obj.respond_to? key
20
+ end
21
+ end
22
+ obj
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,43 @@
1
+ #
2
+ # activity.rb
3
+ # ConstantContact
4
+ #
5
+ # Copyright (c) 2013 Constant Contact. All rights reserved.
6
+
7
+ module ConstantContact
8
+ module Components
9
+ class Activity < Component
10
+ attr_accessor :id, :type, :status, :start_date, :finish_date, :file_name, :created_date,
11
+ :error_count, :errors, :warnings, :contact_count
12
+
13
+ # Factory method to create an Activity object from a json string
14
+ # @param [Hash] props - properties to create object from
15
+ # @return [Activity]
16
+ def self.create(props)
17
+ obj = Activity.new
18
+ if props
19
+ props.each do |key, value|
20
+ if key == 'errors'
21
+ if value
22
+ obj.errors = []
23
+ value.each do |error|
24
+ obj.errors << Components::ActivityError.create(error)
25
+ end
26
+ end
27
+ elsif key == 'warnings'
28
+ if value
29
+ obj.warnings = []
30
+ value.each do |error|
31
+ obj.warnings << Components::ActivityError.create(error)
32
+ end
33
+ end
34
+ else
35
+ obj.send("#{key}=", value) if obj.respond_to? key
36
+ end
37
+ end
38
+ end
39
+ obj
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,26 @@
1
+ #
2
+ # activity_error.rb
3
+ # ConstantContact
4
+ #
5
+ # Copyright (c) 2013 Constant Contact. All rights reserved.
6
+
7
+ module ConstantContact
8
+ module Components
9
+ class ActivityError < Component
10
+ attr_accessor :message, :line_number, :email_address
11
+
12
+ # Factory method to create an ActivityError object from an array
13
+ # @param [Hash] props - hash of properties to create object from
14
+ # @return [ActivityError]
15
+ def self.create(props)
16
+ obj = ActivityError.new
17
+ if props
18
+ props.each do |key, value|
19
+ obj.send("#{key}=", value) if obj.respond_to? key
20
+ end
21
+ end
22
+ obj
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,127 @@
1
+ #
2
+ # add_contacts.rb
3
+ # ConstantContact
4
+ #
5
+ # Copyright (c) 2013 Constant Contact. All rights reserved.
6
+
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
+ contacts.each do |contact|
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.birthday_day.nil?
48
+ used_columns << Util::Config.get('activities_columns.birthday_day')
49
+ end
50
+
51
+ if !contact.birthday_month.nil?
52
+ used_columns << Util::Config.get('activities_columns.birthday_month')
53
+ end
54
+
55
+ if !contact.anniversary.nil?
56
+ used_columns << Util::Config.get('activities_columns.anniversary')
57
+ end
58
+
59
+ if !contact.job_title.nil?
60
+ used_columns << Util::Config.get('activities_columns.job_title')
61
+ end
62
+
63
+ if !contact.company_name.nil?
64
+ used_columns << Util::Config.get('activities_columns.company_name')
65
+ end
66
+
67
+ if !contact.work_phone.nil?
68
+ used_columns << Util::Config.get('activities_columns.work_phone')
69
+ end
70
+
71
+ if !contact.home_phone.nil?
72
+ used_columns << Util::Config.get('activities_columns.home_phone')
73
+ end
74
+
75
+ contact.addresses.each do |address|
76
+
77
+ if !address.line1.nil?
78
+ used_columns << Util::Config.get('activities_columns.address1')
79
+ end
80
+
81
+ if !address.line2.nil?
82
+ used_columns << Util::Config.get('activities_columns.address2')
83
+ end
84
+
85
+ if !address.line3.nil?
86
+ used_columns << Util::Config.get('activities_columns.address3')
87
+ end
88
+
89
+ if !address.city.nil?
90
+ used_columns << Util::Config.get('activities_columns.city')
91
+ end
92
+
93
+ if !address.state_code.nil? || !address.state.nil?
94
+ used_columns << Util::Config.get('activities_columns.state')
95
+ end
96
+
97
+ if !address.country_code.nil?
98
+ used_columns << Util::Config.get('activities_columns.country')
99
+ end
100
+
101
+ if !address.postal_code.nil?
102
+ used_columns << Util::Config.get('activities_columns.postal_code')
103
+ end
104
+
105
+ if !address.sub_postal_code.nil?
106
+ used_columns << Util::Config.get('activities_columns.sub_postal_code')
107
+ end
108
+ end
109
+
110
+ # Custom Fields
111
+ if !contact.custom_fields.nil?
112
+ contact.custom_fields.each do |custom_field|
113
+ if custom_field.name.match('custom_field_')
114
+ custom_field_number = custom_field.name[13, custom_field.name.length]
115
+ used_columns << Util::Config.get('activities_columns.custom_field_' + custom_field_number)
116
+ end
117
+ end
118
+ end
119
+ end
120
+
121
+ @column_names = used_columns.uniq
122
+ end
123
+ end
124
+
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,46 @@
1
+ #
2
+ # add_contacts_import_data.rb
3
+ # ConstantContact
4
+ #
5
+ # Copyright (c) 2013 Constant Contact. All rights reserved.
6
+
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, :birthday_month, :birthday_day, :anniversary,
12
+ :email_addresses, :addresses, :custom_fields
13
+
14
+
15
+ # Constructor to create an AddContactsImportData object from the given hash
16
+ # @param [Hash] props - properties to create object from
17
+ # @return [AddContactsImportData]
18
+ def initialize(props = {})
19
+ props.each do |key, value|
20
+ send("#{key}=", value) if respond_to? key
21
+ end
22
+ end
23
+
24
+ # Setter
25
+ def add_custom_field(custom_field)
26
+ @custom_fields = [] if @custom_fields.nil?
27
+ @custom_fields << custom_field
28
+ end
29
+
30
+
31
+ # Setter
32
+ def add_address(address)
33
+ @addresses = [] if @addresses.nil?
34
+ @addresses << address
35
+ end
36
+
37
+
38
+ # Setter
39
+ def add_email(email_address)
40
+ @email_addresses = [] if @email_addresses.nil?
41
+ @email_addresses << email_address
42
+ end
43
+
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,30 @@
1
+ #
2
+ # export_contacts.rb
3
+ # ConstantContact
4
+ #
5
+ # Copyright (c) 2013 Constant Contact. All rights reserved.
6
+
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
12
+
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
27
+
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,48 @@
1
+ #
2
+ # component.rb
3
+ # ConstantContact
4
+ #
5
+ # Copyright (c) 2013 Constant Contact. All rights reserved.
6
+
7
+ module ConstantContact
8
+ module Components
9
+ class Component
10
+
11
+ def to_hash
12
+ hash = Hash.new
13
+ self.instance_variables.collect do |var|
14
+ hash[var.to_s[1..-1]] = self.class.to_hash_value(self.instance_variable_get(var))
15
+ end
16
+ hash
17
+ end
18
+
19
+ def self.to_hash_value(val)
20
+ if val.is_a? ConstantContact::Components::Component
21
+ return val.to_hash
22
+ elsif val.is_a? Array
23
+ return val.collect{|subval| Component.to_hash_value(subval) }
24
+ elsif val.is_a? DateTime
25
+ return val.to_s
26
+ else
27
+ return val
28
+ end
29
+ end
30
+
31
+ def to_json(val = nil)
32
+ self.to_hash.to_json
33
+ end
34
+
35
+ protected
36
+
37
+ # Get the requested value from a hash, or return the default
38
+ # @param [Hash] hsh - the hash to search for the provided hash key
39
+ # @param [String] key - hash key to look for
40
+ # @param [String] default - value to return if the key is not found, default is null
41
+ # @return [String]
42
+ def self.get_value(hsh, key, default = nil)
43
+ hsh.has_key?(key) and hsh[key] ? hsh[key] : default
44
+ end
45
+
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,27 @@
1
+ #
2
+ # address.rb
3
+ # ConstantContact
4
+ #
5
+ # Copyright (c) 2013 Constant Contact. All rights reserved.
6
+
7
+ module ConstantContact
8
+ module Components
9
+ class Address < Component
10
+ attr_accessor :id, :line1, :line2, :line3, :city, :address_type, :state, :state_code,
11
+ :country_code, :postal_code, :sub_postal_code
12
+
13
+ # Factory method to create an Address object from a json string
14
+ # @param [Hash] props - properties to create object from
15
+ # @return [Address]
16
+ def self.create(props)
17
+ obj = Address.new
18
+ if props
19
+ props.each do |key, value|
20
+ obj.send("#{key}=", value) if obj.respond_to? key
21
+ end
22
+ end
23
+ obj
24
+ end
25
+ end
26
+ end
27
+ end