constantcontact 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +2 -0
  3. data/README.md +132 -0
  4. data/constantcontact.gemspec +32 -0
  5. data/lib/constantcontact.rb +75 -0
  6. data/lib/constantcontact/api.rb +541 -0
  7. data/lib/constantcontact/auth/oauth2.rb +82 -0
  8. data/lib/constantcontact/auth/session_data_store.rb +69 -0
  9. data/lib/constantcontact/components/account/verified_email_address.rb +27 -0
  10. data/lib/constantcontact/components/activities/activity.rb +44 -0
  11. data/lib/constantcontact/components/activities/activity_error.rb +27 -0
  12. data/lib/constantcontact/components/activities/add_contacts.rb +117 -0
  13. data/lib/constantcontact/components/activities/add_contacts_import_data.rb +45 -0
  14. data/lib/constantcontact/components/activities/export_contacts.rb +30 -0
  15. data/lib/constantcontact/components/component.rb +23 -0
  16. data/lib/constantcontact/components/contacts/address.rb +28 -0
  17. data/lib/constantcontact/components/contacts/contact.rb +86 -0
  18. data/lib/constantcontact/components/contacts/contact_list.rb +27 -0
  19. data/lib/constantcontact/components/contacts/custom_field.rb +27 -0
  20. data/lib/constantcontact/components/contacts/email_address.rb +34 -0
  21. data/lib/constantcontact/components/contacts/note.rb +25 -0
  22. data/lib/constantcontact/components/email_marketing/campaign.rb +83 -0
  23. data/lib/constantcontact/components/email_marketing/click_through_details.rb +28 -0
  24. data/lib/constantcontact/components/email_marketing/message_footer.rb +30 -0
  25. data/lib/constantcontact/components/email_marketing/schedule.rb +29 -0
  26. data/lib/constantcontact/components/email_marketing/test_send.rb +45 -0
  27. data/lib/constantcontact/components/result_set.rb +27 -0
  28. data/lib/constantcontact/components/tracking/bounce_activity.rb +29 -0
  29. data/lib/constantcontact/components/tracking/click_activity.rb +28 -0
  30. data/lib/constantcontact/components/tracking/forward_activity.rb +28 -0
  31. data/lib/constantcontact/components/tracking/open_activity.rb +28 -0
  32. data/lib/constantcontact/components/tracking/send_activity.rb +28 -0
  33. data/lib/constantcontact/components/tracking/tracking_activity.rb +27 -0
  34. data/lib/constantcontact/components/tracking/tracking_summary.rb +28 -0
  35. data/lib/constantcontact/components/tracking/unsubscribe_activity.rb +29 -0
  36. data/lib/constantcontact/exceptions/ctct_exception.rb +25 -0
  37. data/lib/constantcontact/exceptions/illegal_argument_exception.rb +11 -0
  38. data/lib/constantcontact/exceptions/oauth2_exception.rb +11 -0
  39. data/lib/constantcontact/services/account_service.rb +29 -0
  40. data/lib/constantcontact/services/activity_service.rb +107 -0
  41. data/lib/constantcontact/services/base_service.rb +37 -0
  42. data/lib/constantcontact/services/campaign_schedule_service.rb +107 -0
  43. data/lib/constantcontact/services/campaign_tracking_service.rb +159 -0
  44. data/lib/constantcontact/services/contact_service.rb +114 -0
  45. data/lib/constantcontact/services/contact_tracking_service.rb +159 -0
  46. data/lib/constantcontact/services/email_marketing_service.rb +87 -0
  47. data/lib/constantcontact/services/list_service.rb +85 -0
  48. data/lib/constantcontact/util/config.rb +140 -0
  49. data/lib/constantcontact/util/helpers.rb +27 -0
  50. data/lib/constantcontact/version.rb +12 -0
  51. data/spec/constantcontact/api_spec.rb +183 -0
  52. data/spec/constantcontact/auth/oauth2_spec.rb +48 -0
  53. data/spec/constantcontact/components/contacts/address_spec.rb +18 -0
  54. data/spec/constantcontact/components/contacts/contact_list_spec.rb +18 -0
  55. data/spec/constantcontact/components/contacts/contact_spec.rb +18 -0
  56. data/spec/constantcontact/components/contacts/custom_field_spec.rb +18 -0
  57. data/spec/constantcontact/components/contacts/email_address_spec.rb +18 -0
  58. data/spec/constantcontact/services/contact_service_spec.rb +105 -0
  59. data/spec/constantcontact/services/list_service_spec.rb +69 -0
  60. data/spec/spec_helper.rb +13 -0
  61. metadata +134 -0
@@ -0,0 +1,23 @@
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
+ protected
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
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,28 @@
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_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 - 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
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,86 @@
1
+ #
2
+ # contact.rb
3
+ # ConstantContact
4
+ #
5
+ # Copyright (c) 2013 Constant Contact. All rights reserved.
6
+
7
+ module ConstantContact
8
+ module Components
9
+ class Contact < Component
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
16
+
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
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
67
+
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
75
+
76
+
77
+ # Setter
78
+ # @param [Address] address
79
+ def add_address(address)
80
+ @addresses = [] if @addresses.nil?
81
+ @addresses << address
82
+ end
83
+
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,27 @@
1
+ #
2
+ # contact_list.rb
3
+ # ConstantContact
4
+ #
5
+ # Copyright (c) 2013 Constant Contact. All rights reserved.
6
+
7
+ module ConstantContact
8
+ module Components
9
+ class ContactList < Component
10
+ attr_accessor :id, :name, :status, :contact_count, :opt_in_default
11
+
12
+ # Factory method to create a ContactList object from a json string
13
+ # @param [Hash] props - array of properties to create object from
14
+ # @return [ContactList]
15
+ def self.create(props)
16
+ contact_list = ContactList.new
17
+ if props
18
+ props.each do |key, value|
19
+ contact_list.send("#{key}=", value)
20
+ end
21
+ end
22
+ contact_list
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ #
2
+ # custom_field.rb
3
+ # ConstantContact
4
+ #
5
+ # Copyright (c) 2013 Constant Contact. All rights reserved.
6
+
7
+ module ConstantContact
8
+ module Components
9
+ class CustomField < Component
10
+ attr_accessor :name, :value
11
+
12
+ # Factory method to create a CustomField object from a json string
13
+ # @param [Hash] props - array of properties to create object from
14
+ # @return [CustomField]
15
+ def self.create(props)
16
+ custom_field = CustomField.new
17
+ if props
18
+ props.each do |key, value|
19
+ custom_field.send("#{key}=", value)
20
+ end
21
+ end
22
+ custom_field
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,34 @@
1
+ #
2
+ # email_address.rb
3
+ # ConstantContact
4
+ #
5
+ # Copyright (c) 2013 Constant Contact. All rights reserved.
6
+
7
+ module ConstantContact
8
+ module Components
9
+ class EmailAddress < Component
10
+ attr_accessor :id, :status, :confirm_status, :opt_in_source, :opt_in_date, :opt_out_date, :email_address
11
+
12
+ # Class constructor
13
+ # @param [String] email_address
14
+ # @return [EmailAddress]
15
+ def initialize(email_address = nil)
16
+ @email_address = email_address if email_address
17
+ end
18
+
19
+ # Factory method to create an EmailAddress object from a json string
20
+ # @param [Hash] props - array of properties to create object from
21
+ # @return [EmailAddress]
22
+ def self.create(props)
23
+ email_address = EmailAddress.new
24
+ if props
25
+ props.each do |key, value|
26
+ email_address.send("#{key}=", value)
27
+ end
28
+ end
29
+ email_address
30
+ end
31
+
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,25 @@
1
+ #
2
+ # note.rb
3
+ # ConstantContact
4
+ #
5
+ # Copyright (c) 2013 Constant Contact. All rights reserved.
6
+
7
+ module ConstantContact
8
+ module Components
9
+ class Note < Component
10
+ attr_accessor :id, :note, :created_date
11
+
12
+ # Factory method to create a Note object from a json string
13
+ # @param props - JSON string representing a contact
14
+ # @return Note
15
+ def self.create(props)
16
+ note = Note.new
17
+ if props
18
+ props.each do |key, value|
19
+ note.send("#{key}=", value)
20
+ end
21
+ end
22
+ note
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,83 @@
1
+ #
2
+ # email_campaign.rb
3
+ # ConstantContact
4
+ #
5
+ # Copyright (c) 2013 Constant Contact. All rights reserved.
6
+
7
+ module ConstantContact
8
+ module Components
9
+ class Campaign < Component
10
+ attr_accessor :id, :name, :subject, :status, :from_name, :from_email, :reply_to_email, :template_type,
11
+ :created_date, :modified_date, :last_run_date, :next_run_date,
12
+ :is_permission_reminder_enabled, :permission_reminder_text,
13
+ :is_view_as_webpage_enabled, :view_as_web_page_text, :view_as_web_page_link_text,
14
+ :greeting_salutations, :greeting_name, :greeting_string, :email_content, :text_content,
15
+ :message_footer, :tracking_summary, :email_content_format, :style_sheet, :sent_to_contact_lists,
16
+ :click_through_details, :include_forward_email, :is_visible_in_ui
17
+
18
+
19
+ # Factory method to create an EmailCampaign object from an array
20
+ # @param [Hash] props - hash of properties to create object from
21
+ # @return [Campaign]
22
+ def self.create(props)
23
+ campaign = Campaign.new
24
+ if props
25
+ props.each do |key, value|
26
+ if key == 'message_footer'
27
+ campaign.message_footer = Components::MessageFooter.create(value)
28
+ elsif key == 'tracking_summary'
29
+ campaign.tracking_summary = Components::TrackingSummary.create(value)
30
+ elsif key == 'sent_to_contact_lists'
31
+ if value
32
+ campaign.sent_to_contact_lists = []
33
+ value.each do |sent_to_contact_list|
34
+ campaign.sent_to_contact_lists << Components::ContactList.create(sent_to_contact_list)
35
+ end
36
+ end
37
+ elsif key == 'click_through_details'
38
+ if value
39
+ campaign.click_through_details = []
40
+ value.each do |click_through_details|
41
+ campaign.click_through_details << Components::ClickThroughDetails.create(click_through_details)
42
+ end
43
+ end
44
+ else
45
+ campaign.send("#{key}=", value)
46
+ end
47
+ end
48
+ end
49
+ campaign
50
+ end
51
+
52
+
53
+ # Factory method to create a Campaign object from an array
54
+ # @param [Hash] props - hash of initial properties to set
55
+ # @return [Campaign]
56
+ def self.create_summary(props)
57
+ campaign = Campaign.new
58
+ if props
59
+ props.each do |key, value|
60
+ campaign.send("#{key}=", value)
61
+ end
62
+ end
63
+ campaign
64
+ end
65
+
66
+
67
+ # Add a contact list to set of lists associated with this email
68
+ # @param [Mixed] contact_list - Contact list id, or ContactList object
69
+ def add_list(contact_list)
70
+ if contact_list.instance_of?(ContactList)
71
+ list = contact_list
72
+ elsif contact_list.to_i.to_s == contact_list
73
+ list = ContactList.new(contact_list)
74
+ else
75
+ raise Exceptions::IllegalArgumentException, sprintf(Util::Config.get('errors.id_or_object'), 'ContactList')
76
+ end
77
+
78
+ @sent_to_contact_lists << list
79
+ end
80
+
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,28 @@
1
+ #
2
+ # click_through_details.rb
3
+ # ConstantContact
4
+ #
5
+ # Copyright (c) 2013 Constant Contact. All rights reserved.
6
+
7
+ module ConstantContact
8
+ module Components
9
+ class ClickThroughDetails < Component
10
+ attr_accessor :url, :url_uid, :click_count
11
+
12
+
13
+ # Factory method to create an ClickThroughDetails object from an array
14
+ # @param [Hash] props - hash of properties to create object from
15
+ # @return [ClickThroughDetails]
16
+ def self.create(props)
17
+ click_through_details = ClickThroughDetails.new
18
+ if props
19
+ props.each do |key, value|
20
+ click_through_details.send("#{key}=", value)
21
+ end
22
+ end
23
+ click_through_details
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,30 @@
1
+ #
2
+ # message_footer.rb
3
+ # ConstantContact
4
+ #
5
+ # Copyright (c) 2013 Constant Contact. All rights reserved.
6
+
7
+ module ConstantContact
8
+ module Components
9
+ class MessageFooter < Component
10
+ attr_accessor :city, :state, :country, :organization_name, :address_line_1,
11
+ :address_line_2, :address_line_3, :international_state,
12
+ :postal_code, :include_forward_email, :forward_email_link_text,
13
+ :include_subscribe_link, :subscribe_link_text
14
+
15
+ # Factory method to create a MessageFooter object from an array
16
+ # @param [Hash] props - hash of properties to create object from
17
+ # @return [MessageFooter]
18
+ def self.create(props)
19
+ message_footer = MessageFooter.new
20
+ if props
21
+ props.each do |key, value|
22
+ message_footer.send("#{key}=", value)
23
+ end
24
+ end
25
+ message_footer
26
+ end
27
+
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,29 @@
1
+ #
2
+ # schedule.rb
3
+ # ConstantContact
4
+ #
5
+ # Copyright (c) 2013 Constant Contact. All rights reserved.
6
+
7
+ module ConstantContact
8
+ module Components
9
+ class Schedule < Component
10
+ attr_accessor :id, :scheduled_date
11
+
12
+
13
+ # Factory method to create a Schedule object from an array
14
+ # @param [Hash] props - hash of properties to create object from
15
+ # @return [Schedule]
16
+ def self.create(props)
17
+ schedule = Schedule.new
18
+ if props
19
+ props = props.first if props.is_a?(Array)
20
+ props.each do |key, value|
21
+ schedule.send("#{key}=", value)
22
+ end
23
+ end
24
+ schedule
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,45 @@
1
+ #
2
+ # test_send.rb
3
+ # ConstantContact
4
+ #
5
+ # Copyright (c) 2013 Constant Contact. All rights reserved.
6
+
7
+ module ConstantContact
8
+ module Components
9
+ class TestSend < Component
10
+ attr_accessor :format, :personal_message, :email_addresses
11
+
12
+
13
+ # Factory method to create a TestSend object from an array
14
+ # @param [Hash] props - hash of properties to create object from
15
+ # @return [TestSend]
16
+ def self.create(props)
17
+ test_send = TestSend.new
18
+ if props
19
+ props.each do |key, value|
20
+ if key == 'email_addresses'
21
+ if value
22
+ test_send.email_addresses = []
23
+ value.each do |email_address|
24
+ test_send.email_addresses << email_address
25
+ end
26
+ end
27
+ else
28
+ test_send.send("#{key}=", value)
29
+ end
30
+ end
31
+ end
32
+ test_send
33
+ end
34
+
35
+
36
+ # Add an email address to the set of addresses to send the test send too
37
+ # @param [String] email_address
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
+ end