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,81 +5,81 @@
5
5
  # Copyright (c) 2013 Constant Contact. All rights reserved.
6
6
 
7
7
  module ConstantContact
8
- module Services
9
- class ListService < BaseService
10
- class << self
8
+ module Services
9
+ class ListService < BaseService
10
+ class << self
11
11
 
12
- # Get lists within an account
13
- # @param [String] access_token - Constant Contact OAuth2 access token
14
- # @return [Array<ContactList>]
15
- def get_lists(access_token)
16
- url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.lists')
17
- url = build_url(url)
18
- response = RestClient.get(url, get_headers(access_token))
19
- lists = []
20
- JSON.parse(response.body).each do |contact|
21
- lists << Components::ContactList.create(contact)
22
- end
23
- lists
24
- end
12
+ # Get lists within an account
13
+ # @param [String] access_token - Constant Contact OAuth2 access token
14
+ # @return [Array<ContactList>]
15
+ def get_lists(access_token)
16
+ url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.lists')
17
+ url = build_url(url)
18
+ response = RestClient.get(url, get_headers(access_token))
19
+ lists = []
20
+ JSON.parse(response.body).each do |contact|
21
+ lists << Components::ContactList.create(contact)
22
+ end
23
+ lists
24
+ end
25
25
 
26
26
 
27
- # Add a new list to the Constant Contact account
28
- # @param [String] access_token - Constant Contact OAuth2 access token
29
- # @param [ContactList] list
30
- # @return [ContactList]
31
- def add_list(access_token, list)
32
- url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.lists')
33
- url = build_url(url)
34
- payload = list.to_json
35
- response = RestClient.post(url, payload, get_headers(access_token))
36
- Components::ContactList.create(JSON.parse(response.body))
37
- end
27
+ # Add a new list to the Constant Contact account
28
+ # @param [String] access_token - Constant Contact OAuth2 access token
29
+ # @param [ContactList] list
30
+ # @return [ContactList]
31
+ def add_list(access_token, list)
32
+ url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.lists')
33
+ url = build_url(url)
34
+ payload = list.to_json
35
+ response = RestClient.post(url, payload, get_headers(access_token))
36
+ Components::ContactList.create(JSON.parse(response.body))
37
+ end
38
38
 
39
39
 
40
- # Update a Contact List
41
- # @param [String] access_token - Constant Contact OAuth2 access token
42
- # @param [ContactList] list - ContactList to be updated
43
- # @return [ContactList]
44
- def update_list(access_token, list)
45
- url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.list'), list.id)
46
- url = build_url(url)
47
- payload = list.to_json
48
- response = RestClient.put(url, payload, get_headers(access_token))
49
- Components::ContactList.create(JSON.parse(response.body))
50
- end
40
+ # Update a Contact List
41
+ # @param [String] access_token - Constant Contact OAuth2 access token
42
+ # @param [ContactList] list - ContactList to be updated
43
+ # @return [ContactList]
44
+ def update_list(access_token, list)
45
+ url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.list'), list.id)
46
+ url = build_url(url)
47
+ payload = list.to_json
48
+ response = RestClient.put(url, payload, get_headers(access_token))
49
+ Components::ContactList.create(JSON.parse(response.body))
50
+ end
51
51
 
52
52
 
53
- # Get an individual contact list
54
- # @param [String] access_token - Constant Contact OAuth2 access token
55
- # @param [Integer] list_id - list id
56
- # @return [ContactList]
57
- def get_list(access_token, list_id)
58
- url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.list'), list_id)
59
- url = build_url(url)
60
- response = RestClient.get(url, get_headers(access_token))
61
- Components::ContactList.create(JSON.parse(response.body))
62
- end
53
+ # Get an individual contact list
54
+ # @param [String] access_token - Constant Contact OAuth2 access token
55
+ # @param [Integer] list_id - list id
56
+ # @return [ContactList]
57
+ def get_list(access_token, list_id)
58
+ url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.list'), list_id)
59
+ url = build_url(url)
60
+ response = RestClient.get(url, get_headers(access_token))
61
+ Components::ContactList.create(JSON.parse(response.body))
62
+ end
63
63
 
64
64
 
65
- # Get all contacts from an individual list
66
- # @param [String] access_token - Constant Contact OAuth2 access token
67
- # @param [Integer] list_id - list id to retrieve contacts for
68
- # @param [Hash] param - query parameters to attach to request
69
- # @return [Array<Contact>]
70
- def get_contacts_from_list(access_token, list_id, param = nil)
71
- url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.list_contacts'), list_id)
72
- url = build_url(url, param)
73
- response = RestClient.get(url, get_headers(access_token))
74
- contacts = []
75
- body = JSON.parse(response.body)
76
- body['results'].each do |contact|
77
- contacts << Components::Contact.create(contact)
78
- end
79
- Components::ResultSet.new(contacts, body['meta'])
80
- end
65
+ # Get all contacts from an individual list
66
+ # @param [String] access_token - Constant Contact OAuth2 access token
67
+ # @param [Integer] list_id - list id to retrieve contacts for
68
+ # @param [Hash] param - query parameters to attach to request
69
+ # @return [Array<Contact>]
70
+ def get_contacts_from_list(access_token, list_id, param = nil)
71
+ url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.list_contacts'), list_id)
72
+ url = build_url(url, param)
73
+ response = RestClient.get(url, get_headers(access_token))
74
+ contacts = []
75
+ body = JSON.parse(response.body)
76
+ body['results'].each do |contact|
77
+ contacts << Components::Contact.create(contact)
78
+ end
79
+ Components::ResultSet.new(contacts, body['meta'])
80
+ end
81
81
 
82
- end
83
- end
84
- end
82
+ end
83
+ end
84
+ end
85
85
  end
@@ -8,110 +8,116 @@ module ConstantContact
8
8
  module Util
9
9
  class Config
10
10
 
11
- class << self
11
+ # Return a hash of configuration strings
12
+ # @return [Hash] - hash of configuration properties
13
+ @props = {
14
+ # REST endpoints
15
+ :endpoints => {
16
+ :base_url => 'https://api.constantcontact.com/v2/',
12
17
 
13
- # Return a hash of configuration strings
14
- # @return [Hash] - hash of configuration properties
15
- def props
16
- {
17
- # REST endpoints
18
- :endpoints => {
19
- :base_url => 'https://api.constantcontact.com/v2/',
18
+ :activity => 'activities/%s',
19
+ :activities => 'activities',
20
+ :export_contacts_activity => 'activities/exportcontacts',
21
+ :clear_lists_activity => 'activities/clearlists',
22
+ :remove_from_lists_activity => 'activities/removefromlists',
23
+ :add_contacts_activity => 'activities/addcontacts',
20
24
 
21
- :activity => 'activities/%s',
22
- :activities => 'activities',
23
- :export_contacts_activity => 'activities/exportcontacts',
24
- :clear_lists_activity => 'activities/clearlists',
25
- :remove_from_lists_activity => 'activities/removefromlists',
26
- :add_contacts_activity => 'activities/addcontacts',
25
+ :account_verified_addresses => 'account/verifiedemailaddresses',
27
26
 
28
- :account_verified_addresses => 'account/verifiedemailaddresses',
27
+ :contact => 'contacts/%s',
28
+ :contacts => 'contacts',
29
+ :lists => 'lists',
30
+ :list => 'lists/%s',
31
+ :list_contacts => 'lists/%s/contacts',
32
+ :contact_lists => 'contacts/%s/lists',
33
+ :contact_list => 'contacts/%s/lists/%s',
29
34
 
30
- :contact => 'contacts/%s',
31
- :contacts => 'contacts',
32
- :lists => 'lists',
33
- :list => 'lists/%s',
34
- :list_contacts => 'lists/%s/contacts',
35
- :contact_lists => 'contacts/%s/lists',
36
- :contact_list => 'contacts/%s/lists/%s',
35
+ :campaigns => 'emailmarketing/campaigns',
36
+ :campaign => 'emailmarketing/campaigns/%s',
37
+ :campaign_schedules => 'emailmarketing/campaigns/%s/schedules',
38
+ :campaign_schedule => 'emailmarketing/campaigns/%s/schedules/%s',
39
+ :campaign_test_sends => 'emailmarketing/campaigns/%s/tests',
40
+ :campaign_tracking_summary => 'emailmarketing/campaigns/%s/tracking/reports/summary',
41
+ :campaign_tracking_bounces => 'emailmarketing/campaigns/%s/tracking/bounces',
42
+ :campaign_tracking_clicks => 'emailmarketing/campaigns/%s/tracking/clicks',
43
+ :campaign_tracking_forwards => 'emailmarketing/campaigns/%s/tracking/forwards',
44
+ :campaign_tracking_opens => 'emailmarketing/campaigns/%s/tracking/opens',
45
+ :campaign_tracking_sends => 'emailmarketing/campaigns/%s/tracking/sends',
46
+ :campaign_tracking_unsubscribes => 'emailmarketing/campaigns/%s/tracking/unsubscribes',
47
+ :campaign_tracking_link => 'emailmarketing/campaigns/%s/tracking/clicks/%s',
37
48
 
38
- :campaigns => 'emailmarketing/campaigns',
39
- :campaign => 'emailmarketing/campaigns/%s',
40
- :campaign_schedules => 'emailmarketing/campaigns/%s/schedules',
41
- :campaign_schedule => 'emailmarketing/campaigns/%s/schedules/%s',
42
- :campaign_test_sends => 'emailmarketing/campaigns/%s/tests',
43
- :campaign_tracking_summary => 'emailmarketing/campaigns/%s/tracking/reports/summary',
44
- :campaign_tracking_bounces => 'emailmarketing/campaigns/%s/tracking/bounces',
45
- :campaign_tracking_clicks => 'emailmarketing/campaigns/%s/tracking/clicks',
46
- :campaign_tracking_forwards => 'emailmarketing/campaigns/%s/tracking/forwards',
47
- :campaign_tracking_opens => 'emailmarketing/campaigns/%s/tracking/opens',
48
- :campaign_tracking_sends => 'emailmarketing/campaigns/%s/tracking/sends',
49
- :campaign_tracking_unsubscribes => 'emailmarketing/campaigns/%s/tracking/unsubscribes',
50
- :campaign_tracking_link => 'emailmarketing/campaigns/%s/tracking/clicks/%s',
49
+ :contact_tracking_summary => 'contacts/%s/tracking/reports/summary',
50
+ :contact_tracking_bounces => 'contacts/%s/tracking/bounces',
51
+ :contact_tracking_clicks => 'contacts/%s/tracking/clicks',
52
+ :contact_tracking_forwards => 'contacts/%s/tracking/forwards',
53
+ :contact_tracking_opens => 'contacts/%s/tracking/opens',
54
+ :contact_tracking_sends => 'contacts/%s/tracking/sends',
55
+ :contact_tracking_unsubscribes => 'contacts/%s/tracking/unsubscribes',
56
+ :contact_tracking_link => 'contacts/%s/tracking/clicks/%s'
57
+ },
51
58
 
52
- :contact_tracking_summary => 'contacts/%s/tracking/reports/summary',
53
- :contact_tracking_bounces => 'contacts/%s/tracking/bounces',
54
- :contact_tracking_clicks => 'contacts/%s/tracking/clicks',
55
- :contact_tracking_forwards => 'contacts/%s/tracking/forwards',
56
- :contact_tracking_opens => 'contacts/%s/tracking/opens',
57
- :contact_tracking_sends => 'contacts/%s/tracking/sends',
58
- :contact_tracking_unsubscribes => 'contacts/%s/tracking/unsubscribes',
59
- :contact_tracking_link => 'contacts/%s/tracking/clicks/%s'
60
- },
59
+ # OAuth2 Authorization related configuration options
60
+ :auth => {
61
+ :base_url => 'https://oauth2.constantcontact.com/oauth2/',
62
+ :response_type_code => 'code',
63
+ :response_type_token => 'token',
64
+ :authorization_code_grant_type => 'authorization_code',
65
+ :authorization_endpoint => 'oauth/siteowner/authorize',
66
+ :token_endpoint => 'oauth/token',
67
+ :api_key => '',
68
+ :api_secret => '',
69
+ :redirect_uri => ''
70
+ },
61
71
 
62
- # OAuth2 Authorization related configuration options
63
- :auth => {
64
- :base_url => 'https://oauth2.constantcontact.com/oauth2/',
65
- :response_type_code => 'code',
66
- :response_type_token => 'token',
67
- :authorization_code_grant_type => 'authorization_code',
68
- :authorization_endpoint => 'oauth/siteowner/authorize',
69
- :token_endpoint => 'oauth/token'
70
- },
71
-
72
- # Column names used with bulk activities
73
- :activities_columns => {
74
- :email => 'EMAIL',
75
- :first_name => 'FIRST NAME',
76
- :middle_name => 'MIDDLE NAME',
77
- :last_name => 'LAST NAME',
78
- :job_title => 'JOB TITLE',
79
- :company_name => 'COMPANY NAME',
80
- :work_phone => 'WORK PHONE',
81
- :home_phone => 'HOME PHONE',
82
- :address1 => 'ADDRESS LINE 1',
83
- :address2 => 'ADDRESS LINE 2',
84
- :address3 => 'ADDRESS LINE 3',
85
- :city => 'CITY',
86
- :state => 'STATE',
87
- :state_province => 'US STATE/CA PROVINCE',
88
- :country => 'COUNTRY',
89
- :postal_code => 'ZIP/POSTAL CODE',
90
- :sub_postal_code => 'SUB ZIP/POSTAL CODE',
91
- :custom_field_1 => 'CUSTOM FIELD 1',
92
- :custom_field_2 => 'CUSTOM FIELD 2',
93
- :custom_field_3 => 'CUSTOM FIELD 3',
94
- :custom_field_4 => 'CUSTOM FIELD 4',
95
- :custom_field_5 => 'CUSTOM FIELD 5',
96
- :custom_field_6 => 'CUSTOM FIELD 6',
97
- :custom_field_7 => 'CUSTOM FIELD 7',
98
- :custom_field_8 => 'CUSTOM FIELD 8',
99
- :custom_field_9 => 'CUSTOM FIELD 9',
100
- :custom_field_10 => 'CUSTOM FIELD 10',
101
- :custom_field_11 => 'CUSTOM FIELD 11',
102
- :custom_field_12 => 'CUSTOM FIELD 12',
103
- :custom_field_13 => 'CUSTOM FIELD 13',
104
- :custom_field_14 => 'CUSTOM FIELD 14',
105
- :custom_field_15 => 'CUSTOM FIELD 15'
106
- },
107
-
108
- # Errors to be returned for various exceptions
109
- :errors => {
110
- :id_or_object => 'Only an id or %s object are allowed for this method.'
111
- }
112
- }
113
- end
72
+ # Column names used with bulk activities
73
+ :activities_columns => {
74
+ :email => 'EMAIL',
75
+ :first_name => 'FIRST NAME',
76
+ :middle_name => 'MIDDLE NAME',
77
+ :last_name => 'LAST NAME',
78
+ :job_title => 'JOB TITLE',
79
+ :company_name => 'COMPANY NAME',
80
+ :work_phone => 'WORK PHONE',
81
+ :home_phone => 'HOME PHONE',
82
+ :address1 => 'ADDRESS LINE 1',
83
+ :address2 => 'ADDRESS LINE 2',
84
+ :address3 => 'ADDRESS LINE 3',
85
+ :city => 'CITY',
86
+ :state => 'STATE',
87
+ :state_province => 'US STATE/CA PROVINCE',
88
+ :country => 'COUNTRY',
89
+ :postal_code => 'ZIP/POSTAL CODE',
90
+ :sub_postal_code => 'SUB ZIP/POSTAL CODE',
91
+ :custom_field_1 => 'CUSTOM FIELD 1',
92
+ :custom_field_2 => 'CUSTOM FIELD 2',
93
+ :custom_field_3 => 'CUSTOM FIELD 3',
94
+ :custom_field_4 => 'CUSTOM FIELD 4',
95
+ :custom_field_5 => 'CUSTOM FIELD 5',
96
+ :custom_field_6 => 'CUSTOM FIELD 6',
97
+ :custom_field_7 => 'CUSTOM FIELD 7',
98
+ :custom_field_8 => 'CUSTOM FIELD 8',
99
+ :custom_field_9 => 'CUSTOM FIELD 9',
100
+ :custom_field_10 => 'CUSTOM FIELD 10',
101
+ :custom_field_11 => 'CUSTOM FIELD 11',
102
+ :custom_field_12 => 'CUSTOM FIELD 12',
103
+ :custom_field_13 => 'CUSTOM FIELD 13',
104
+ :custom_field_14 => 'CUSTOM FIELD 14',
105
+ :custom_field_15 => 'CUSTOM FIELD 15'
106
+ },
114
107
 
108
+ # Errors to be returned for various exceptions
109
+ :errors => {
110
+ :id_or_object => 'Only an id or %s object are allowed for this method.'
111
+ }
112
+ }
113
+
114
+ class << self
115
+ attr_accessor :props
116
+
117
+ def configure
118
+ yield props if block_given?
119
+ end
120
+
115
121
  # Get a configuration property given a specified location, example usage: Config::get('auth.token_endpoint')
116
122
  # @param [String] index - location of the property to obtain
117
123
  # @return [String]
@@ -5,23 +5,23 @@
5
5
  # Copyright (c) 2013 Constant Contact. All rights reserved.
6
6
 
7
7
  module ConstantContact
8
- module Util
9
- class Helpers
10
- class << self
11
-
12
- # Build the HTTP query from the given parameters
13
- # @param [Hash] params
14
- # @return [String] query string
15
- def http_build_query(params)
16
- params.collect{ |k,v| "#{k.to_s}=#{encode(v.to_s)}" }.reverse.join('&')
17
- end
8
+ module Util
9
+ class Helpers
10
+ class << self
18
11
 
19
- # Escape special characters
20
- # @param [String] str
21
- def encode(str)
22
- CGI.escape(str).gsub('.', '%2E').gsub('-', '%2D')
23
- end
24
- end
25
- end
26
- end
12
+ # Build the HTTP query from the given parameters
13
+ # @param [Hash] params
14
+ # @return [String] query string
15
+ def http_build_query(params)
16
+ params.collect{ |k,v| "#{k.to_s}=#{encode(v.to_s)}" }.reverse.join('&')
17
+ end
18
+
19
+ # Escape special characters
20
+ # @param [String] str
21
+ def encode(str)
22
+ CGI.escape(str).gsub('.', '%2E').gsub('-', '%2D')
23
+ end
24
+ end
25
+ end
26
+ end
27
27
  end
@@ -5,8 +5,8 @@
5
5
  # Copyright (c) 2013 Constant Contact. All rights reserved.
6
6
 
7
7
  module ConstantContact
8
- module SDK
9
- # Gem version
10
- VERSION = "1.0.0"
11
- end
8
+ module SDK
9
+ # Gem version
10
+ VERSION = "1.0.1"
11
+ end
12
12
  end
@@ -7,177 +7,227 @@
7
7
  require 'spec_helper'
8
8
 
9
9
  describe ConstantContact::Api do
10
- before(:each) do
11
- @api = ConstantContact::Api.new('api key')
12
- end
13
-
14
- describe "#get_contacts" do
15
- it "returns an array of contacts" do
16
- json = load_json('contacts.json')
17
- net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
18
-
19
- response = RestClient::Response.create(json, net_http_resp, {})
20
- RestClient.stub(:get).and_return(response)
21
- contacts = @api.get_contacts('token')
22
- contact = contacts.results[0]
23
-
24
- contacts.should be_kind_of(ConstantContact::Components::ResultSet)
25
- contact.should be_kind_of(ConstantContact::Components::Contact)
26
- end
27
- end
28
-
29
- describe "#get_contact" do
30
- it "returns a contact" do
31
- json = load_json('contact.json')
32
- net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
33
-
34
- response = RestClient::Response.create(json, net_http_resp, {})
35
- RestClient.stub(:get).and_return(response)
36
- contact = @api.get_contact('token', 1)
37
-
38
- contact.should be_kind_of(ConstantContact::Components::Contact)
39
- end
40
- end
41
-
42
- describe "#get_contact_by_email" do
43
- it "returns a contact" do
44
- json = load_json('contacts.json')
45
- net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
46
-
47
- response = RestClient::Response.create(json, net_http_resp, {})
48
- RestClient.stub(:get).and_return(response)
49
- contacts = @api.get_contact_by_email('token', 'john.smith@gmail.com')
50
- contact = contacts.results[0]
51
-
52
- contact.should be_kind_of(ConstantContact::Components::Contact)
53
- end
54
- end
55
-
56
- describe "#add_contact" do
57
- it "adds a contact" do
58
- json = load_json('contact.json')
59
- net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
60
-
61
- response = RestClient::Response.create(json, net_http_resp, {})
62
- RestClient.stub(:post).and_return(response)
63
- contact = ConstantContact::Components::Contact.create(JSON.parse(json))
64
- added = @api.add_contact('token', contact)
65
-
66
- added.should respond_to(:status)
67
- added.status.should eq('REMOVED')
68
- end
69
- end
70
-
71
- describe "#delete_contact" do
72
- it "deletes a contact" do
73
- json = load_json('contact.json')
74
- net_http_resp = Net::HTTPResponse.new(1.0, 204, 'No Content')
75
-
76
- response = RestClient::Response.create('', net_http_resp, {})
77
- RestClient.stub(:delete).and_return(response)
78
- contact = ConstantContact::Components::Contact.create(JSON.parse(json))
79
- @api.delete_contact('token', contact).should be_true
80
- end
81
- end
82
-
83
- describe "#delete_contact_from_lists" do
84
- it "deletes a contact" do
85
- json = load_json('contact.json')
86
- net_http_resp = Net::HTTPResponse.new(1.0, 204, 'No Content')
87
-
88
- response = RestClient::Response.create('', net_http_resp, {})
89
- RestClient.stub(:delete).and_return(response)
90
- contact = ConstantContact::Components::Contact.create(JSON.parse(json))
91
- @api.delete_contact_from_lists('token', contact).should be_true
92
- end
93
- end
94
-
95
- describe "#delete_contact_from_list" do
96
- it "deletes a contact" do
97
- contact_json = load_json('contact.json')
98
- list_json = load_json('list.json')
99
- net_http_resp = Net::HTTPResponse.new(1.0, 204, 'No Content')
100
-
101
- response = RestClient::Response.create('', net_http_resp, {})
102
- RestClient.stub(:delete).and_return(response)
103
- contact = ConstantContact::Components::Contact.create(JSON.parse(contact_json))
104
- list = ConstantContact::Components::ContactList.create(JSON.parse(list_json))
105
- @api.delete_contact_from_list('token', contact, list).should be_true
106
- end
107
- end
108
-
109
- describe "#update_contact" do
110
- it "updates a contact" do
111
- json = load_json('contact.json')
112
- net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
113
-
114
- response = RestClient::Response.create(json, net_http_resp, {})
115
- RestClient.stub(:put).and_return(response)
116
- contact = ConstantContact::Components::Contact.create(JSON.parse(json))
117
- added = @api.update_contact('token', contact)
118
-
119
- added.should respond_to(:status)
120
- added.status.should eq('REMOVED')
121
- end
122
- end
123
-
124
- describe "#get_lists" do
125
- it "returns an array of lists" do
126
- json = load_json('lists.json')
127
- net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
128
-
129
- response = RestClient::Response.create(json, net_http_resp, {})
130
- RestClient.stub(:get).and_return(response)
131
- lists = @api.get_lists('token')
132
- list = lists[0]
133
-
134
- lists.should be_kind_of(Array)
135
- list.should be_kind_of(ConstantContact::Components::ContactList)
136
- end
137
- end
138
-
139
- describe "#get_list" do
140
- it "returns a list" do
141
- json = load_json('list.json')
142
- net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
143
-
144
- response = RestClient::Response.create(json, net_http_resp, {})
145
- RestClient.stub(:get).and_return(response)
146
- contact = @api.get_list('token', 1)
147
-
148
- contact.should be_kind_of(ConstantContact::Components::ContactList)
149
- end
150
- end
151
-
152
- describe "#add_list" do
153
- it "adds a list" do
154
- json = load_json('list.json')
155
- net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
156
-
157
- response = RestClient::Response.create(json, net_http_resp, {})
158
- RestClient.stub(:post).and_return(response)
159
- list = ConstantContact::Components::ContactList.create(JSON.parse(json))
160
- added = @api.add_list('token', list)
161
-
162
- added.should respond_to(:status)
163
- added.status.should eq('ACTIVE')
164
- end
165
- end
166
-
167
- describe "#get_contacts_from_list" do
168
- it "returns an array of contacts" do
169
- json_list = load_json('list.json')
170
- json_contacts = load_json('contacts.json')
171
- net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
172
-
173
- response = RestClient::Response.create(json_contacts, net_http_resp, {})
174
- RestClient.stub(:get).and_return(response)
175
- list = ConstantContact::Components::ContactList.create(JSON.parse(json_list))
176
- contacts = @api.get_contacts_from_list('token', list)
177
- contact = contacts.results[0]
178
-
179
- contacts.should be_kind_of(ConstantContact::Components::ResultSet)
180
- contact.should be_kind_of(ConstantContact::Components::Contact)
181
- end
182
- end
10
+
11
+ before(:all) {
12
+ ConstantContact::Util::Config.configure do |config|
13
+ config[:auth].delete :api_key
14
+ config[:auth].delete :api_secret
15
+ config[:auth].delete :redirect_uri
16
+ end
17
+ }
18
+
19
+ it "without api_key defined" do
20
+ lambda {
21
+ ConstantContact::Api.new
22
+ }.should raise_error(ArgumentError)
23
+ end
24
+
25
+ context "with middle-ware configuration" do
26
+ before(:all) do
27
+ ConstantContact::Services::BaseService.api_key = nil
28
+ ConstantContact::Util::Config.configure do |config|
29
+ config[:auth][:api_key] = "config_api_key"
30
+ config[:auth][:api_secret] = "config_api_secret"
31
+ config[:auth][:redirect_uri] = "config_redirect_uri"
32
+ end
33
+ end
34
+ let(:proc) { lambda { ConstantContact::Api.new } }
35
+ it "use implicit config" do
36
+ proc.should_not raise_error
37
+ end
38
+ it "has the correct client_id" do
39
+ ConstantContact::Services::BaseService.api_key.should == "config_api_key"
40
+ end
41
+ end
42
+
43
+ context "with middle-ware configuration" do
44
+ before(:all) do
45
+ ConstantContact::Services::BaseService.api_key = nil
46
+ ConstantContact::Util::Config.configure do |config|
47
+ config[:auth][:api_key] = "config_api_key"
48
+ config[:auth][:api_secret] = "config_api_secret"
49
+ config[:auth][:redirect_uri] = "config_redirect_uri"
50
+ end
51
+ ConstantContact::Api.new 'explicit_api_key'
52
+ end
53
+ it "has the correct explicit api key" do
54
+ ConstantContact::Services::BaseService.api_key.should == "explicit_api_key"
55
+ end
56
+ end
57
+
58
+ describe "test methods" do
59
+ before(:each) do
60
+ @api = ConstantContact::Api.new('api key')
61
+ end
62
+
63
+ describe "#get_contacts" do
64
+ it "returns an array of contacts" do
65
+ json = load_json('contacts.json')
66
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
67
+
68
+ response = RestClient::Response.create(json, net_http_resp, {})
69
+ RestClient.stub(:get).and_return(response)
70
+ contacts = @api.get_contacts('token')
71
+ contact = contacts.results[0]
72
+
73
+ contacts.should be_kind_of(ConstantContact::Components::ResultSet)
74
+ contact.should be_kind_of(ConstantContact::Components::Contact)
75
+ end
76
+ end
77
+
78
+ describe "#get_contact" do
79
+ it "returns a contact" do
80
+ json = load_json('contact.json')
81
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
82
+
83
+ response = RestClient::Response.create(json, net_http_resp, {})
84
+ RestClient.stub(:get).and_return(response)
85
+ contact = @api.get_contact('token', 1)
86
+
87
+ contact.should be_kind_of(ConstantContact::Components::Contact)
88
+ end
89
+ end
90
+
91
+ describe "#get_contact_by_email" do
92
+ it "returns a contact" do
93
+ json = load_json('contacts.json')
94
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
95
+
96
+ response = RestClient::Response.create(json, net_http_resp, {})
97
+ RestClient.stub(:get).and_return(response)
98
+ contacts = @api.get_contact_by_email('token', 'john.smith@gmail.com')
99
+ contact = contacts.results[0]
100
+
101
+ contact.should be_kind_of(ConstantContact::Components::Contact)
102
+ end
103
+ end
104
+
105
+ describe "#add_contact" do
106
+ it "adds a contact" do
107
+ json = load_json('contact.json')
108
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
109
+
110
+ response = RestClient::Response.create(json, net_http_resp, {})
111
+ RestClient.stub(:post).and_return(response)
112
+ contact = ConstantContact::Components::Contact.create(JSON.parse(json))
113
+ added = @api.add_contact('token', contact)
114
+
115
+ added.should respond_to(:status)
116
+ added.status.should eq('REMOVED')
117
+ end
118
+ end
119
+
120
+ describe "#delete_contact" do
121
+ it "deletes a contact" do
122
+ json = load_json('contact.json')
123
+ net_http_resp = Net::HTTPResponse.new(1.0, 204, 'No Content')
124
+
125
+ response = RestClient::Response.create('', net_http_resp, {})
126
+ RestClient.stub(:delete).and_return(response)
127
+ contact = ConstantContact::Components::Contact.create(JSON.parse(json))
128
+ @api.delete_contact('token', contact).should be_true
129
+ end
130
+ end
131
+
132
+ describe "#delete_contact_from_lists" do
133
+ it "deletes a contact" do
134
+ json = load_json('contact.json')
135
+ net_http_resp = Net::HTTPResponse.new(1.0, 204, 'No Content')
136
+
137
+ response = RestClient::Response.create('', net_http_resp, {})
138
+ RestClient.stub(:delete).and_return(response)
139
+ contact = ConstantContact::Components::Contact.create(JSON.parse(json))
140
+ @api.delete_contact_from_lists('token', contact).should be_true
141
+ end
142
+ end
143
+
144
+ describe "#delete_contact_from_list" do
145
+ it "deletes a contact" do
146
+ contact_json = load_json('contact.json')
147
+ list_json = load_json('list.json')
148
+ net_http_resp = Net::HTTPResponse.new(1.0, 204, 'No Content')
149
+
150
+ response = RestClient::Response.create('', net_http_resp, {})
151
+ RestClient.stub(:delete).and_return(response)
152
+ contact = ConstantContact::Components::Contact.create(JSON.parse(contact_json))
153
+ list = ConstantContact::Components::ContactList.create(JSON.parse(list_json))
154
+ @api.delete_contact_from_list('token', contact, list).should be_true
155
+ end
156
+ end
157
+
158
+ describe "#update_contact" do
159
+ it "updates a contact" do
160
+ json = load_json('contact.json')
161
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
162
+
163
+ response = RestClient::Response.create(json, net_http_resp, {})
164
+ RestClient.stub(:put).and_return(response)
165
+ contact = ConstantContact::Components::Contact.create(JSON.parse(json))
166
+ added = @api.update_contact('token', contact)
167
+
168
+ added.should respond_to(:status)
169
+ added.status.should eq('REMOVED')
170
+ end
171
+ end
172
+
173
+ describe "#get_lists" do
174
+ it "returns an array of lists" do
175
+ json = load_json('lists.json')
176
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
177
+
178
+ response = RestClient::Response.create(json, net_http_resp, {})
179
+ RestClient.stub(:get).and_return(response)
180
+ lists = @api.get_lists('token')
181
+ list = lists[0]
182
+
183
+ lists.should be_kind_of(Array)
184
+ list.should be_kind_of(ConstantContact::Components::ContactList)
185
+ end
186
+ end
187
+
188
+ describe "#get_list" do
189
+ it "returns a list" do
190
+ json = load_json('list.json')
191
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
192
+
193
+ response = RestClient::Response.create(json, net_http_resp, {})
194
+ RestClient.stub(:get).and_return(response)
195
+ contact = @api.get_list('token', 1)
196
+
197
+ contact.should be_kind_of(ConstantContact::Components::ContactList)
198
+ end
199
+ end
200
+
201
+ describe "#add_list" do
202
+ it "adds a list" do
203
+ json = load_json('list.json')
204
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
205
+
206
+ response = RestClient::Response.create(json, net_http_resp, {})
207
+ RestClient.stub(:post).and_return(response)
208
+ list = ConstantContact::Components::ContactList.create(JSON.parse(json))
209
+ added = @api.add_list('token', list)
210
+
211
+ added.should respond_to(:status)
212
+ added.status.should eq('ACTIVE')
213
+ end
214
+ end
215
+
216
+ describe "#get_contacts_from_list" do
217
+ it "returns an array of contacts" do
218
+ json_list = load_json('list.json')
219
+ json_contacts = load_json('contacts.json')
220
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
221
+
222
+ response = RestClient::Response.create(json_contacts, net_http_resp, {})
223
+ RestClient.stub(:get).and_return(response)
224
+ list = ConstantContact::Components::ContactList.create(JSON.parse(json_list))
225
+ contacts = @api.get_contacts_from_list('token', list)
226
+ contact = contacts.results[0]
227
+
228
+ contacts.should be_kind_of(ConstantContact::Components::ResultSet)
229
+ contact.should be_kind_of(ConstantContact::Components::Contact)
230
+ end
231
+ end
232
+ end
183
233
  end