constantcontact 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
- ---
2
- SHA512:
3
- metadata.gz: ce4ab04068029132c0a484c8de77cdffa0a4eda24eeb8e42806266f0935151255a3d270b5c133aba9e337c87788597386cec2b5de64c1e81fe33c9a473d02076
4
- data.tar.gz: 19c32b1028d217e47bc65a3e145d666b5b57b67a9b58692e75ca6f25fb8f16daecb6e43f8392038a51eb2324f4907db5398884c9746270b3eeb422048904b214
5
- SHA1:
6
- metadata.gz: e6944720fbf8a0b247595feb9676859612b53376
7
- data.tar.gz: d2294f919b1f9d7292618c7a817ff29e0bc09987
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3f4035ebff0d2fa600a1671cf3aec57955f32e57
4
+ data.tar.gz: c395ffc1e0e64498f04f49f1850b63ee7c798ecf
5
+ SHA512:
6
+ metadata.gz: 2a6c7fb69db0876b55e1d26215d940520d0fd612dcd219bdebfb75bde753b9c32798127db1ac74012719c37068ca26fe03bdac9e8873ed8bfe44d232f0d2bd4c
7
+ data.tar.gz: 8edaaebe146ff2b94f22604a97704fdbcad79041e0460ba79cc6995aa6f34eda229b41a8233ba080c1824dcf9c4ac722f35e50b614e11d5935debb9bc12a5bc6
data/README.md CHANGED
@@ -70,6 +70,13 @@ Follow the link, go through all the Constant Contact steps required
70
70
  and then you will be redirected back to your action and you should see the list of contacts.
71
71
 
72
72
 
73
+ 6. Add config initializer (optional)
74
+ ````ruby
75
+ ConstantContact::Util::Config.configure do |config|
76
+ config[:auth][:api_key] = 'foobar'
77
+ config[:auth][:api_secret] = 'foobar'
78
+ end
79
+
73
80
  B. Sinatra example :
74
81
 
75
82
 
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
13
13
  s.summary = %q{Constant Contact SDK for Ruby}
14
14
  s.email = "apisupport@constantcontact.com"
15
15
  s.description = "Ruby library for interactions with Constant Contact v2 API"
16
- s.version = "1.0.0"
16
+ #s.version = "1.0.0"
17
17
  s.license = "MIT"
18
18
 
19
19
  s.files = [
@@ -13,63 +13,63 @@ require 'cgi/session/pstore'
13
13
 
14
14
 
15
15
  module ConstantContact
16
- autoload :Api, "constantcontact/api"
16
+ autoload :Api, "constantcontact/api"
17
17
 
18
- module Auth
19
- autoload :OAuth2, "constantcontact/auth/oauth2"
20
- autoload :Session, "constantcontact/auth/session_data_store"
21
- end
18
+ module Auth
19
+ autoload :OAuth2, "constantcontact/auth/oauth2"
20
+ autoload :Session, "constantcontact/auth/session_data_store"
21
+ end
22
22
 
23
- module Components
24
- autoload :Component, "constantcontact/components/component"
25
- autoload :ResultSet, "constantcontact/components/result_set"
26
- autoload :Activity, "constantcontact/components/activities/activity"
27
- autoload :ActivityError, "constantcontact/components/activities/activity_error"
28
- autoload :AddContacts, "constantcontact/components/activities/add_contacts"
29
- autoload :AddContactsImportData, "constantcontact/components/activities/add_contacts_import_data"
30
- autoload :ExportContacts, "constantcontact/components/activities/export_contacts"
31
- autoload :Address, "constantcontact/components/contacts/address"
32
- autoload :Contact, "constantcontact/components/contacts/contact"
33
- autoload :ContactList, "constantcontact/components/contacts/contact_list"
34
- autoload :CustomField, "constantcontact/components/contacts/custom_field"
35
- autoload :EmailAddress, "constantcontact/components/contacts/email_address"
36
- autoload :Note, "constantcontact/components/contacts/note"
37
- autoload :ClickThroughDetails, "constantcontact/components/email_marketing/click_through_details"
38
- autoload :Campaign, "constantcontact/components/email_marketing/campaign"
39
- autoload :MessageFooter, "constantcontact/components/email_marketing/message_footer"
40
- autoload :Schedule, "constantcontact/components/email_marketing/schedule"
41
- autoload :TestSend, "constantcontact/components/email_marketing/test_send"
42
- autoload :BounceActivity, "constantcontact/components/tracking/bounce_activity"
43
- autoload :ClickActivity, "constantcontact/components/tracking/click_activity"
44
- autoload :ForwardActivity, "constantcontact/components/tracking/forward_activity"
45
- autoload :OpenActivity, "constantcontact/components/tracking/open_activity"
46
- autoload :OptOutActivity, "constantcontact/components/tracking/opt_out_activity"
47
- autoload :SendActivity, "constantcontact/components/tracking/send_activity"
48
- autoload :TrackingActivity, "constantcontact/components/tracking/tracking_activity"
49
- autoload :TrackingSummary, "constantcontact/components/tracking/tracking_summary"
50
- autoload :VerifiedEmailAddress, "constantcontact/components/account/verified_email_address"
51
- end
23
+ module Components
24
+ autoload :Component, "constantcontact/components/component"
25
+ autoload :ResultSet, "constantcontact/components/result_set"
26
+ autoload :Activity, "constantcontact/components/activities/activity"
27
+ autoload :ActivityError, "constantcontact/components/activities/activity_error"
28
+ autoload :AddContacts, "constantcontact/components/activities/add_contacts"
29
+ autoload :AddContactsImportData, "constantcontact/components/activities/add_contacts_import_data"
30
+ autoload :ExportContacts, "constantcontact/components/activities/export_contacts"
31
+ autoload :Address, "constantcontact/components/contacts/address"
32
+ autoload :Contact, "constantcontact/components/contacts/contact"
33
+ autoload :ContactList, "constantcontact/components/contacts/contact_list"
34
+ autoload :CustomField, "constantcontact/components/contacts/custom_field"
35
+ autoload :EmailAddress, "constantcontact/components/contacts/email_address"
36
+ autoload :Note, "constantcontact/components/contacts/note"
37
+ autoload :ClickThroughDetails, "constantcontact/components/email_marketing/click_through_details"
38
+ autoload :Campaign, "constantcontact/components/email_marketing/campaign"
39
+ autoload :MessageFooter, "constantcontact/components/email_marketing/message_footer"
40
+ autoload :Schedule, "constantcontact/components/email_marketing/schedule"
41
+ autoload :TestSend, "constantcontact/components/email_marketing/test_send"
42
+ autoload :BounceActivity, "constantcontact/components/tracking/bounce_activity"
43
+ autoload :ClickActivity, "constantcontact/components/tracking/click_activity"
44
+ autoload :ForwardActivity, "constantcontact/components/tracking/forward_activity"
45
+ autoload :OpenActivity, "constantcontact/components/tracking/open_activity"
46
+ autoload :OptOutActivity, "constantcontact/components/tracking/opt_out_activity"
47
+ autoload :SendActivity, "constantcontact/components/tracking/send_activity"
48
+ autoload :TrackingActivity, "constantcontact/components/tracking/tracking_activity"
49
+ autoload :TrackingSummary, "constantcontact/components/tracking/tracking_summary"
50
+ autoload :VerifiedEmailAddress, "constantcontact/components/account/verified_email_address"
51
+ end
52
52
 
53
- module Exceptions
54
- autoload :CtctException, "constantcontact/exceptions/ctct_exception"
55
- autoload :IllegalArgumentException, "constantcontact/exceptions/illegal_argument_exception"
56
- autoload :OAuth2Exception, "constantcontact/exceptions/oauth2_exception"
57
- end
53
+ module Exceptions
54
+ autoload :CtctException, "constantcontact/exceptions/ctct_exception"
55
+ autoload :IllegalArgumentException, "constantcontact/exceptions/illegal_argument_exception"
56
+ autoload :OAuth2Exception, "constantcontact/exceptions/oauth2_exception"
57
+ end
58
58
 
59
- module Services
60
- autoload :BaseService, "constantcontact/services/base_service"
61
- autoload :ActivityService, "constantcontact/services/activity_service"
62
- autoload :CampaignScheduleService, "constantcontact/services/campaign_schedule_service"
63
- autoload :CampaignTrackingService, "constantcontact/services/campaign_tracking_service"
64
- autoload :ContactService, "constantcontact/services/contact_service"
65
- autoload :ContactTrackingService, "constantcontact/services/contact_tracking_service"
66
- autoload :EmailMarketingService, "constantcontact/services/email_marketing_service"
67
- autoload :ListService, "constantcontact/services/list_service"
68
- autoload :AccountService, "constantcontact/services/account_service"
69
- end
59
+ module Services
60
+ autoload :BaseService, "constantcontact/services/base_service"
61
+ autoload :ActivityService, "constantcontact/services/activity_service"
62
+ autoload :CampaignScheduleService, "constantcontact/services/campaign_schedule_service"
63
+ autoload :CampaignTrackingService, "constantcontact/services/campaign_tracking_service"
64
+ autoload :ContactService, "constantcontact/services/contact_service"
65
+ autoload :ContactTrackingService, "constantcontact/services/contact_tracking_service"
66
+ autoload :EmailMarketingService, "constantcontact/services/email_marketing_service"
67
+ autoload :ListService, "constantcontact/services/list_service"
68
+ autoload :AccountService, "constantcontact/services/account_service"
69
+ end
70
70
 
71
- module Util
72
- autoload :Config, "constantcontact/util/config"
73
- autoload :Helpers, "constantcontact/util/helpers"
74
- end
71
+ module Util
72
+ autoload :Config, "constantcontact/util/config"
73
+ autoload :Helpers, "constantcontact/util/helpers"
74
+ end
75
75
  end
@@ -6,12 +6,14 @@
6
6
 
7
7
  module ConstantContact
8
8
  class Api
9
-
10
9
  # Class constructor
11
10
  # @param [String] api_key - Constant Contact API Key
12
11
  # @return
13
- def initialize(api_key)
14
- Services::BaseService.api_key = api_key
12
+ def initialize(api_key = nil)
13
+ Services::BaseService.api_key = api_key || Util::Config.get('auth.api_key')
14
+ if Services::BaseService.api_key.nil? || Services::BaseService.api_key == ''
15
+ raise ArgumentError.new("api_key required either explicitly or in configuration.")
16
+ end
15
17
  end
16
18
 
17
19
 
@@ -16,10 +16,13 @@ module ConstantContact
16
16
  # @option opts [String] :api_secret - the Constant Contact secret key
17
17
  # @option opts [String] :redirect_url - the URL where Constact Contact is returning the authorization code
18
18
  # @return
19
- def initialize(opts)
20
- @client_id = opts[:api_key]
21
- @client_secret = opts[:api_secret]
22
- @redirect_uri = opts[:redirect_url]
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
23
26
  end
24
27
 
25
28
 
@@ -5,65 +5,65 @@
5
5
  # Copyright (c) 2013 Constant Contact. All rights reserved.
6
6
 
7
7
  module ConstantContact
8
- module Auth
9
- class Session
10
- attr_accessor :session
8
+ module Auth
9
+ class Session
10
+ attr_accessor :session
11
11
 
12
- # Create and initialize the session
13
- def initialize
14
- cgi = CGI.new('html4')
12
+ # Create and initialize the session
13
+ def initialize
14
+ cgi = CGI.new('html4')
15
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
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
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
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
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
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
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
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
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
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
59
 
60
- # Close current session
61
- # @return
62
- def close
63
- @session.close
64
- end
60
+ # Close current session
61
+ # @return
62
+ def close
63
+ @session.close
64
+ end
65
65
 
66
- end
67
- end
66
+ end
67
+ end
68
68
  end
69
69
 
@@ -5,23 +5,23 @@
5
5
  # Copyright (c) 2013 Constant Contact. All rights reserved.
6
6
 
7
7
  module ConstantContact
8
- module Components
9
- class VerifiedEmailAddress < Component
10
- attr_accessor :status, :email_address
8
+ module Components
9
+ class VerifiedEmailAddress < Component
10
+ attr_accessor :status, :email_address
11
11
 
12
- # Factory method to create a VerifiedEmailAddress object from a json string
13
- # @param [Hash] props - array of properties to create object from
14
- # @return [VerifiedEmailAddress]
15
- def self.create(props)
16
- email_address = VerifiedEmailAddress.new
17
- if props
18
- props.each do |key, value|
19
- email_address.send("#{key}=", value)
20
- end
21
- end
22
- email_address
23
- end
12
+ # Factory method to create a VerifiedEmailAddress object from a json string
13
+ # @param [Hash] props - array of properties to create object from
14
+ # @return [VerifiedEmailAddress]
15
+ def self.create(props)
16
+ email_address = VerifiedEmailAddress.new
17
+ if props
18
+ props.each do |key, value|
19
+ email_address.send("#{key}=", value)
20
+ end
21
+ end
22
+ email_address
23
+ end
24
24
 
25
- end
26
- end
25
+ end
26
+ end
27
27
  end
@@ -5,40 +5,40 @@
5
5
  # Copyright (c) 2013 Constant Contact. All rights reserved.
6
6
 
7
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
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
12
 
13
- # Factory method to create an Activity object from a json string
14
- # @param [Hash] props - hash of properties to create object from
15
- # @return [Activity]
16
- def self.create(props)
17
- activity = Activity.new
18
- if props
19
- props.each do |key, value|
20
- if key == 'errors'
21
- if value
22
- activity.errors = []
23
- value.each do |error|
24
- activity.errors << Components::ActivityError.create(error)
25
- end
26
- end
27
- elsif key == 'warnings'
28
- if value
29
- activity.warnings = []
30
- value.each do |error|
31
- activity.warnings << Components::ActivityError.create(error)
32
- end
33
- end
34
- else
35
- activity.send("#{key}=", value)
36
- end
37
- end
38
- end
39
- activity
40
- end
13
+ # Factory method to create an Activity object from a json string
14
+ # @param [Hash] props - hash of properties to create object from
15
+ # @return [Activity]
16
+ def self.create(props)
17
+ activity = Activity.new
18
+ if props
19
+ props.each do |key, value|
20
+ if key == 'errors'
21
+ if value
22
+ activity.errors = []
23
+ value.each do |error|
24
+ activity.errors << Components::ActivityError.create(error)
25
+ end
26
+ end
27
+ elsif key == 'warnings'
28
+ if value
29
+ activity.warnings = []
30
+ value.each do |error|
31
+ activity.warnings << Components::ActivityError.create(error)
32
+ end
33
+ end
34
+ else
35
+ activity.send("#{key}=", value)
36
+ end
37
+ end
38
+ end
39
+ activity
40
+ end
41
41
 
42
- end
43
- end
42
+ end
43
+ end
44
44
  end
@@ -5,23 +5,23 @@
5
5
  # Copyright (c) 2013 Constant Contact. All rights reserved.
6
6
 
7
7
  module ConstantContact
8
- module Components
9
- class ActivityError < Component
10
- attr_accessor :message, :line_number, :email_address
8
+ module Components
9
+ class ActivityError < Component
10
+ attr_accessor :message, :line_number, :email_address
11
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
- activity_error = ActivityError.new
17
- if props
18
- props.each do |key, value|
19
- activity_error.send("#{key}=", value)
20
- end
21
- end
22
- activity_error
23
- end
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
+ activity_error = ActivityError.new
17
+ if props
18
+ props.each do |key, value|
19
+ activity_error.send("#{key}=", value)
20
+ end
21
+ end
22
+ activity_error
23
+ end
24
24
 
25
- end
26
- end
25
+ end
26
+ end
27
27
  end