constantcontact 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +127 -136
  3. data/constantcontact.gemspec +4 -3
  4. data/lib/constantcontact.rb +63 -44
  5. data/lib/constantcontact/api.rb +932 -535
  6. data/lib/constantcontact/auth/oauth2.rb +86 -66
  7. data/lib/constantcontact/components/account/verified_email_address.rb +14 -14
  8. data/lib/constantcontact/components/activities/activity.rb +30 -30
  9. data/lib/constantcontact/components/activities/activity_error.rb +14 -14
  10. data/lib/constantcontact/components/activities/add_contacts.rb +1 -1
  11. data/lib/constantcontact/components/activities/add_contacts_import_data.rb +37 -36
  12. data/lib/constantcontact/components/component.rb +25 -0
  13. data/lib/constantcontact/components/contacts/address.rb +12 -12
  14. data/lib/constantcontact/components/contacts/contact.rb +50 -44
  15. data/lib/constantcontact/components/contacts/contact_list.rb +12 -12
  16. data/lib/constantcontact/components/contacts/custom_field.rb +14 -14
  17. data/lib/constantcontact/components/contacts/email_address.rb +14 -14
  18. data/lib/constantcontact/components/contacts/note.rb +13 -13
  19. data/lib/constantcontact/components/email_marketing/campaign.rb +41 -41
  20. data/lib/constantcontact/components/email_marketing/click_through_details.rb +14 -14
  21. data/lib/constantcontact/components/email_marketing/message_footer.rb +14 -14
  22. data/lib/constantcontact/components/email_marketing/schedule.rb +14 -15
  23. data/lib/constantcontact/components/email_marketing/test_send.rb +21 -21
  24. data/lib/constantcontact/components/event_spot/contact.rb +27 -0
  25. data/lib/constantcontact/components/event_spot/event.rb +63 -0
  26. data/lib/constantcontact/components/event_spot/event_track.rb +28 -0
  27. data/lib/constantcontact/components/event_spot/fee.rb +27 -0
  28. data/lib/constantcontact/components/event_spot/guest.rb +31 -0
  29. data/lib/constantcontact/components/event_spot/notification_option.rb +27 -0
  30. data/lib/constantcontact/components/event_spot/promo_code.rb +26 -0
  31. data/lib/constantcontact/components/event_spot/registrant.rb +54 -0
  32. data/lib/constantcontact/components/event_spot/registrant_field.rb +27 -0
  33. data/lib/constantcontact/components/event_spot/registrant_section.rb +34 -0
  34. data/lib/constantcontact/components/event_spot/sale_item.rb +27 -0
  35. data/lib/constantcontact/components/library/file/library_file.rb +27 -0
  36. data/lib/constantcontact/components/library/folder/library_folder.rb +26 -0
  37. data/lib/constantcontact/components/library/info/library_summary.rb +26 -0
  38. data/lib/constantcontact/components/library/info/move_results.rb +26 -0
  39. data/lib/constantcontact/components/library/info/upload_status.rb +26 -0
  40. data/lib/constantcontact/components/tracking/bounce_activity.rb +14 -14
  41. data/lib/constantcontact/components/tracking/click_activity.rb +14 -14
  42. data/lib/constantcontact/components/tracking/forward_activity.rb +14 -14
  43. data/lib/constantcontact/components/tracking/open_activity.rb +14 -14
  44. data/lib/constantcontact/components/tracking/send_activity.rb +14 -14
  45. data/lib/constantcontact/components/tracking/tracking_summary.rb +17 -17
  46. data/lib/constantcontact/components/tracking/unsubscribe_activity.rb +14 -14
  47. data/lib/constantcontact/services/account_service.rb +4 -3
  48. data/lib/constantcontact/services/activity_service.rb +40 -3
  49. data/lib/constantcontact/services/base_service.rb +34 -6
  50. data/lib/constantcontact/services/campaign_tracking_service.rb +20 -20
  51. data/lib/constantcontact/services/contact_service.rb +10 -12
  52. data/lib/constantcontact/services/contact_tracking_service.rb +20 -20
  53. data/lib/constantcontact/services/email_marketing_service.rb +8 -10
  54. data/lib/constantcontact/services/event_spot_service.rb +254 -0
  55. data/lib/constantcontact/services/library_service.rb +297 -0
  56. data/lib/constantcontact/services/list_service.rb +6 -5
  57. data/lib/constantcontact/util/config.rb +135 -117
  58. data/lib/constantcontact/version.rb +1 -1
  59. data/spec/constantcontact/api_spec.rb +1223 -173
  60. data/spec/constantcontact/auth/oauth2_spec.rb +60 -47
  61. data/spec/constantcontact/components/contacts/address_spec.rb +1 -1
  62. data/spec/constantcontact/components/contacts/contact_list_spec.rb +1 -1
  63. data/spec/constantcontact/components/contacts/contact_spec.rb +1 -1
  64. data/spec/constantcontact/components/contacts/email_address_spec.rb +1 -1
  65. data/spec/constantcontact/services/activity_service_spec.rb +201 -0
  66. data/spec/constantcontact/services/base_service_spec.rb +27 -0
  67. data/spec/constantcontact/services/campaign_schedule_service_spec.rb +111 -0
  68. data/spec/constantcontact/services/campaign_tracking_service_spec.rb +127 -0
  69. data/spec/constantcontact/services/contact_service_spec.rb +24 -22
  70. data/spec/constantcontact/services/contact_tracking_service_spec.rb +127 -0
  71. data/spec/constantcontact/services/email_marketing_spec.rb +72 -66
  72. data/spec/constantcontact/services/event_spot_spec.rb +217 -0
  73. data/spec/constantcontact/services/library_service_spec.rb +248 -0
  74. data/spec/constantcontact/services/list_service_spec.rb +33 -17
  75. data/spec/spec_helper.rb +3 -1
  76. metadata +63 -7
@@ -7,7 +7,7 @@
7
7
  require 'spec_helper'
8
8
 
9
9
  describe ConstantContact::Auth::OAuth2 do
10
-
10
+
11
11
  before(:all) {
12
12
  ConstantContact::Util::Config.configure do |config|
13
13
  config[:auth].delete :api_key
@@ -15,21 +15,21 @@ describe ConstantContact::Auth::OAuth2 do
15
15
  config[:auth].delete :redirect_uri
16
16
  end
17
17
  }
18
-
19
- describe "#new" do
20
- it "fails without arguments and no configuration" do
21
- lambda {
22
- ConstantContact::Auth::OAuth2.new
23
- }.should raise_error(ArgumentError)
24
- end
25
-
26
- it "takes one argument" do
27
- opts = {:api_key => 'api key', :api_secret => 'secret', :redirect_url => 'redirect url'}
28
- lambda {
29
- ConstantContact::Auth::OAuth2.new(opts)
30
- }.should_not raise_error
31
- end
32
- end
18
+
19
+ describe "#new" do
20
+ it "fails without arguments and no configuration" do
21
+ lambda {
22
+ ConstantContact::Auth::OAuth2.new
23
+ }.should raise_error(ArgumentError)
24
+ end
25
+
26
+ it "takes one argument" do
27
+ opts = {:api_key => 'api key', :api_secret => 'secret', :redirect_url => 'redirect url'}
28
+ lambda {
29
+ ConstantContact::Auth::OAuth2.new(opts)
30
+ }.should_not raise_error
31
+ end
32
+ end
33
33
 
34
34
  context "with middle-ware configuration" do
35
35
  before(:all) do
@@ -39,9 +39,9 @@ describe ConstantContact::Auth::OAuth2 do
39
39
  config[:auth][:redirect_uri] = "config_redirect_uri"
40
40
  end
41
41
  end
42
- let(:proc) { lambda { ConstantContact::Auth::OAuth2.new } }
42
+ let(:proc) { lambda { ConstantContact::Auth::OAuth2.new } }
43
43
  it "without error" do
44
- proc.should_not raise_error
44
+ proc.should_not raise_error
45
45
  end
46
46
  let(:oauth) { proc.call }
47
47
  it "has correct api_key" do
@@ -53,7 +53,7 @@ describe ConstantContact::Auth::OAuth2 do
53
53
  it "has correct redirect_uri" do
54
54
  oauth.redirect_uri.should == "config_redirect_uri"
55
55
  end
56
- end
56
+ end
57
57
 
58
58
  context "with middle-ware configuration and explicit opts" do
59
59
  before(:all) do
@@ -63,9 +63,9 @@ describe ConstantContact::Auth::OAuth2 do
63
63
  config[:auth][:redirect_uri] = "config_redirect_uri"
64
64
  end
65
65
  end
66
- let(:proc) { lambda { ConstantContact::Auth::OAuth2.new :api_key => 'explicit_api_key', :api_secret => 'explicit_api_secret', :redirect_url => 'explicit_redirect_uri' } }
66
+ let(:proc) { lambda { ConstantContact::Auth::OAuth2.new :api_key => 'explicit_api_key', :api_secret => 'explicit_api_secret', :redirect_url => 'explicit_redirect_uri' } }
67
67
  it "without error" do
68
- proc.should_not raise_error
68
+ proc.should_not raise_error
69
69
  end
70
70
  let(:oauth) { proc.call }
71
71
  it "has correct api_key" do
@@ -77,36 +77,49 @@ describe ConstantContact::Auth::OAuth2 do
77
77
  it "has correct redirect_uri" do
78
78
  oauth.redirect_uri.should == "explicit_redirect_uri"
79
79
  end
80
- end
80
+ end
81
81
 
82
- it "with explicit arguments and no configuration" do
83
- lambda {
84
- ConstantContact::Auth::OAuth2.new :api_key => "api_key", :api_secret => "api_secret", :redirect_uri => "redirect_uri"
85
- }.should raise_error(ArgumentError)
86
- end
82
+ it "with explicit arguments and no configuration" do
83
+ lambda {
84
+ ConstantContact::Auth::OAuth2.new :api_key => "api_key", :api_secret => "api_secret", :redirect_url => "redirect_uri"
85
+ }.should_not raise_error
86
+ end
87
87
 
88
+ let(:proc) { lambda { ConstantContact::Auth::OAuth2.new(:api_key => "api_key", :api_secret => "api_secret", :redirect_url => "redirect_uri") } }
89
+ let(:oauth) { proc.call }
88
90
 
89
- describe "#get_authorization_url" do
90
- before(:each) do
91
- opts = {:api_key => 'api key', :api_secret => 'secret', :redirect_url => 'redirect url'}
92
- @auth = ConstantContact::Auth::OAuth2.new(opts)
93
- end
91
+ describe "#get_authorization_url" do
92
+ it "returns a string" do
93
+ oauth.get_authorization_url.should be_kind_of(String)
94
+ oauth.get_authorization_url(true, 'my_param').should match('state=my_param')
95
+ end
96
+ end
94
97
 
95
- it "returns a string" do
96
- @auth.get_authorization_url.should be_kind_of(String)
97
- end
98
- end
98
+ describe "#get_access_token" do
99
+ it "returns a Hash" do
100
+ json = load_file('access_token.json')
101
+ RestClient.stub(:post).and_return(json)
102
+ oauth.get_access_token('token').should be_kind_of(Hash)
103
+ end
99
104
 
100
- describe "#get_access_token" do
101
- before(:each) do
102
- opts = {:api_key => 'api key', :api_secret => 'secret', :redirect_url => 'redirect url'}
103
- @auth = ConstantContact::Auth::OAuth2.new(opts)
104
- end
105
+ it "throws an OAuth2Exception in case of error" do
106
+ json = load_file('access_token_error.json')
107
+ RestClient.stub(:post).and_return(json)
108
+ lambda {
109
+ oauth.get_access_token('token')
110
+ }.should raise_exception(ConstantContact::Exceptions::OAuth2Exception,
111
+ 'The resource owner or authorization server denied the request.')
112
+ end
113
+ end
114
+
115
+ describe "#get_token_info" do
116
+ it "returns a Hash" do
117
+ json = load_file('token_info.json')
118
+ RestClient.stub(:post).and_return(json)
119
+ info = oauth.get_token_info('token')
120
+ info.should be_kind_of(Hash)
121
+ info['user_name'].should eq('ctcttest')
122
+ end
123
+ end
105
124
 
106
- it "returns a Hash" do
107
- json = load_json('access_token.json')
108
- RestClient.stub(:post).and_return(json)
109
- @auth.get_access_token('token').should be_kind_of(Hash)
110
- end
111
- end
112
125
  end
@@ -9,7 +9,7 @@ require 'spec_helper'
9
9
  describe ConstantContact::Components::Address do
10
10
  describe "#from_list" do
11
11
  it "should return an address" do
12
- json = load_json('address.json')
12
+ json = load_file('address.json')
13
13
  address = ConstantContact::Components::Address.create(JSON.parse(json))
14
14
 
15
15
  address.line1.should eq('6 Main Street')
@@ -9,7 +9,7 @@ require 'spec_helper'
9
9
  describe ConstantContact::Components::ContactList do
10
10
  describe "#from_list" do
11
11
  it "should return a list" do
12
- json = load_json('list.json')
12
+ json = load_file('list.json')
13
13
  list = ConstantContact::Components::ContactList.create(JSON.parse(json))
14
14
 
15
15
  list.name.should eq('Fake List')
@@ -9,7 +9,7 @@ require 'spec_helper'
9
9
  describe ConstantContact::Components::Contact do
10
10
  describe "#from_list" do
11
11
  it "should return a contact" do
12
- json = load_json('contact.json')
12
+ json = load_file('contact.json')
13
13
  contact = ConstantContact::Components::Contact.create(JSON.parse(json))
14
14
 
15
15
  contact.last_name.should eq('Smith')
@@ -9,7 +9,7 @@ require 'spec_helper'
9
9
  describe ConstantContact::Components::EmailAddress do
10
10
  describe "#from_list" do
11
11
  it "should return an email address" do
12
- json = load_json('email_address.json')
12
+ json = load_file('email_address.json')
13
13
  email = ConstantContact::Components::EmailAddress.create(JSON.parse(json))
14
14
 
15
15
  email.email_address.should eq('wm2q7rwtp77m@roving.com')
@@ -0,0 +1,201 @@
1
+ #
2
+ # activity_service_spec.rb
3
+ # ConstantContact
4
+ #
5
+ # Copyright (c) 2013 Constant Contact. All rights reserved.
6
+
7
+ require 'spec_helper'
8
+
9
+ describe ConstantContact::Services::ActivityService do
10
+ describe "#get_activities" do
11
+ it "gets a set of activities" do
12
+ json_response = load_file('activities_response.json')
13
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
14
+
15
+ response = RestClient::Response.create(json_response, net_http_resp, {})
16
+ RestClient.stub(:get).and_return(response)
17
+
18
+ activities = ConstantContact::Services::ActivityService.get_activities('token')
19
+ activities.first.should be_kind_of(ConstantContact::Components::Activity)
20
+ activities.first.type.should eq('REMOVE_CONTACTS_FROM_LISTS')
21
+ end
22
+ end
23
+
24
+ describe "#get_activity" do
25
+ it "gets an activity" do
26
+ json_response = load_file('activity_response.json')
27
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
28
+
29
+ response = RestClient::Response.create(json_response, net_http_resp, {})
30
+ RestClient.stub(:get).and_return(response)
31
+
32
+ activity = ConstantContact::Services::ActivityService.get_activity('token', 'a07e1ilbm7shdg6ikeo')
33
+ activity.should be_kind_of(ConstantContact::Components::Activity)
34
+ activity.type.should eq('REMOVE_CONTACTS_FROM_LISTS')
35
+ end
36
+ end
37
+
38
+ describe "#create_add_contacts_activity" do
39
+ it "creates an Add Contacts Activity" do
40
+ json_add_contacts = load_file('add_contacts_response.json')
41
+ json_lists = load_file('lists_response.json')
42
+ json_contacts = load_file('contacts_response.json')
43
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
44
+
45
+ response = RestClient::Response.create(json_add_contacts, net_http_resp, {})
46
+ RestClient.stub(:post).and_return(response)
47
+
48
+ import = ConstantContact::Components::AddContactsImportData.new
49
+ address = ConstantContact::Components::Address.create(
50
+ :line1 => "1601 Trapelo Rd",
51
+ :city => "Waltham",
52
+ :state => "MA"
53
+ )
54
+ import.add_address(address)
55
+
56
+ custom_field = ConstantContact::Components::CustomField.create(
57
+ :name => "custom_field_1",
58
+ :value => "my custom value"
59
+ )
60
+ import.add_custom_field(custom_field)
61
+ import.add_email("abc@def.com")
62
+
63
+ contacts = []
64
+ contacts << import
65
+ contacts_objects = JSON.parse(json_contacts)
66
+ contacts_objects['results'].each do |contact|
67
+ contacts << ConstantContact::Components::Contact.create(contact)
68
+ end
69
+
70
+ lists = []
71
+ lists_objects = JSON.parse(json_lists)
72
+ lists_objects.each do |list|
73
+ lists << ConstantContact::Components::ContactList.create(list)
74
+ end
75
+
76
+ add_contact = ConstantContact::Components::AddContacts.new(contacts, lists)
77
+
78
+ activity = ConstantContact::Services::ActivityService.create_add_contacts_activity(
79
+ 'token', add_contact)
80
+ activity.should be_kind_of(ConstantContact::Components::Activity)
81
+ activity.type.should eq('ADD_CONTACTS')
82
+ end
83
+ end
84
+
85
+ describe "#create_add_contacts_activity_from_file" do
86
+ it "creates an Add Contacts Activity from a file" do
87
+ content = load_file('add_contacts_request.csv')
88
+ json = load_file('add_contacts_response.json')
89
+ lists = 'list1, list2'
90
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
91
+
92
+ response = RestClient::Response.create(json, net_http_resp, {})
93
+ RestClient.stub(:post).and_return(response)
94
+
95
+ activity = ConstantContact::Services::ActivityService.create_add_contacts_activity_from_file(
96
+ 'token', 'contacts.txt', content, lists)
97
+ activity.should be_kind_of(ConstantContact::Components::Activity)
98
+ activity.type.should eq('ADD_CONTACTS')
99
+ end
100
+ end
101
+
102
+ describe "#add_clear_lists_activity" do
103
+ it "creates a Clear Lists Activity" do
104
+ json_clear_lists = load_file('clear_lists_response.json')
105
+ json_list = load_file('list_response.json')
106
+
107
+ lists = []
108
+ lists << ConstantContact::Components::ContactList.create(JSON.parse(json_list))
109
+
110
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
111
+
112
+ response = RestClient::Response.create(json_clear_lists, net_http_resp, {})
113
+ RestClient.stub(:post).and_return(response)
114
+
115
+ activity = ConstantContact::Services::ActivityService.add_clear_lists_activity(
116
+ 'token', lists)
117
+ activity.should be_kind_of(ConstantContact::Components::Activity)
118
+ activity.type.should eq('CLEAR_CONTACTS_FROM_LISTS')
119
+ end
120
+ end
121
+
122
+ describe "#add_remove_contacts_from_lists_activity" do
123
+ it "creates a Remove Contacts From Lists Activity" do
124
+ json = load_file('remove_contacts_response.json')
125
+ lists = 'list1, list2'
126
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
127
+
128
+ response = RestClient::Response.create(json, net_http_resp, {})
129
+ RestClient.stub(:post).and_return(response)
130
+ email_addresses = ["djellesma@constantcontact.com"]
131
+
132
+ activity = ConstantContact::Services::ActivityService.add_remove_contacts_from_lists_activity(
133
+ 'token', email_addresses, lists)
134
+ activity.should be_kind_of(ConstantContact::Components::Activity)
135
+ activity.type.should eq('REMOVE_CONTACTS_FROM_LISTS')
136
+ end
137
+ end
138
+
139
+ describe "#add_remove_contacts_from_lists_activity_from_file" do
140
+ it "creates a Remove Contacts Activity from a file" do
141
+ content = load_file('remove_contacts_request.txt')
142
+ json = load_file('remove_contacts_response.json')
143
+ lists = 'list1, list2'
144
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
145
+
146
+ response = RestClient::Response.create(json, net_http_resp, {})
147
+ RestClient.stub(:post).and_return(response)
148
+
149
+ activity = ConstantContact::Services::ActivityService.add_remove_contacts_from_lists_activity_from_file(
150
+ 'token', 'contacts.txt', content, lists)
151
+ activity.should be_kind_of(ConstantContact::Components::Activity)
152
+ activity.type.should eq('REMOVE_CONTACTS_FROM_LISTS')
153
+ end
154
+ end
155
+
156
+ describe "#add_export_contacts_activity" do
157
+ it "creates an Export Contacts Activity" do
158
+ json_request = load_file('export_contacts_request.json')
159
+ json_response = load_file('export_contacts_response.json')
160
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
161
+
162
+ response = RestClient::Response.create(json_response, net_http_resp, {})
163
+ RestClient.stub(:post).and_return(response)
164
+
165
+ export_contacts = ConstantContact::Components::ExportContacts.new(JSON.parse(json_request))
166
+
167
+ activity = ConstantContact::Services::ActivityService.add_export_contacts_activity(
168
+ 'token', export_contacts)
169
+ activity.should be_kind_of(ConstantContact::Components::Activity)
170
+ activity.type.should eq('EXPORT_CONTACTS')
171
+ end
172
+ end
173
+
174
+ describe "#add_remove_contacts_from_lists_activity" do
175
+ it "creates a Remove Contacts From Lists Activity" do
176
+ json_request = load_file('remove_contacts_from_lists_request.json')
177
+ json_response = load_file('remove_contacts_from_lists_response.json')
178
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
179
+
180
+ response = RestClient::Response.create(json_response, net_http_resp, {})
181
+ RestClient.stub(:post).and_return(response)
182
+
183
+ request_object = JSON.parse(json_request)
184
+
185
+ lists = [], email_addresses = []
186
+ request_object['lists'].each do |list|
187
+ lists << ConstantContact::Components::ContactList.create(:id => list)
188
+ end
189
+ request_object['import_data'].each do |data|
190
+ data['email_addresses'].each do |email_address|
191
+ email_addresses << email_address
192
+ end
193
+ end
194
+
195
+ activity = ConstantContact::Services::ActivityService.add_remove_contacts_from_lists_activity(
196
+ 'token', email_addresses, lists)
197
+
198
+ activity.type.should eq('REMOVE_CONTACTS_FROM_LISTS')
199
+ end
200
+ end
201
+ end
@@ -0,0 +1,27 @@
1
+ #
2
+ # base_service_spec.rb
3
+ # ConstantContact
4
+ #
5
+ # Copyright (c) 2013 Constant Contact. All rights reserved.
6
+
7
+ require 'spec_helper'
8
+
9
+ describe ConstantContact::Services::BaseService do
10
+ describe "#get_headers" do
11
+ it "gets a hash of headers" do
12
+ token = 'foo'
13
+ headers = ConstantContact::Services::BaseService.send(:get_headers, token)
14
+
15
+ expect(headers).to be_a Hash
16
+ expect(headers[:content_type]).to be_a String
17
+ expect(headers[:content_type]).to eq('application/json')
18
+ expect(headers[:accept]).to be_a String
19
+ expect(headers[:accept]).to eq('application/json')
20
+ expect(headers[:authorization]).to be_a String
21
+ expect(headers[:authorization]).to eq("Bearer #{token}")
22
+ expect(headers[:user_agent]).to be_a String
23
+ expect(headers[:user_agent].include?("Ruby SDK v#{ConstantContact::SDK::VERSION}")).to be_true
24
+ expect(headers[:user_agent].include?(RUBY_DESCRIPTION)).to be_true
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,111 @@
1
+ #
2
+ # campaign_schedule_service_service_spec.rb
3
+ # ConstantContact
4
+ #
5
+ # Copyright (c) 2013 Constant Contact. All rights reserved.
6
+
7
+ require 'spec_helper'
8
+
9
+ describe ConstantContact::Services::CampaignScheduleService do
10
+ describe "#add_schedule" do
11
+ it "creates a new schedule for a campaign" do
12
+ campaign_id = 1
13
+ json = load_file('schedule_response.json')
14
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
15
+
16
+ response = RestClient::Response.create(json, net_http_resp, {})
17
+ RestClient.stub(:post).and_return(response)
18
+ new_schedule = ConstantContact::Components::Schedule.create(JSON.parse(json))
19
+
20
+ schedule = ConstantContact::Services::CampaignScheduleService.add_schedule(
21
+ 'token', campaign_id, new_schedule)
22
+ schedule.should be_kind_of(ConstantContact::Components::Schedule)
23
+ schedule.scheduled_date.should eq('2013-05-10T11:07:43.626Z')
24
+ end
25
+ end
26
+
27
+ describe "#get_schedules" do
28
+ it "gets a list of schedules for a campaign" do
29
+ campaign_id = 1
30
+ json = load_file('schedules_response.json')
31
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
32
+
33
+ response = RestClient::Response.create(json, net_http_resp, {})
34
+ RestClient.stub(:get).and_return(response)
35
+
36
+ schedules = ConstantContact::Services::CampaignScheduleService.get_schedules(
37
+ 'token', campaign_id)
38
+ schedules.first.should be_kind_of(ConstantContact::Components::Schedule)
39
+ schedules.first.scheduled_date.should eq('2012-12-16T11:07:43.626Z')
40
+ end
41
+ end
42
+
43
+ describe "#get_schedule" do
44
+ it "gets a specific schedule for a campaign" do
45
+ campaign_id = 1
46
+ schedule_id = 1
47
+
48
+ json = load_file('schedule_response.json')
49
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
50
+
51
+ response = RestClient::Response.create(json, net_http_resp, {})
52
+ RestClient.stub(:get).and_return(response)
53
+
54
+ schedule = ConstantContact::Services::CampaignScheduleService.get_schedule(
55
+ 'token', campaign_id, schedule_id)
56
+ schedule.should be_kind_of(ConstantContact::Components::Schedule)
57
+ schedule.scheduled_date.should eq('2013-05-10T11:07:43.626Z')
58
+ end
59
+ end
60
+
61
+ describe "#delete_schedule" do
62
+ it "deletes a specific schedule for a campaign" do
63
+ campaign_id = 1
64
+ schedule_id = 1
65
+ net_http_resp = Net::HTTPResponse.new(1.0, 204, 'No Content')
66
+
67
+ response = RestClient::Response.create('', net_http_resp, {})
68
+ RestClient.stub(:delete).and_return(response)
69
+
70
+ result = ConstantContact::Services::CampaignScheduleService.delete_schedule(
71
+ 'token', campaign_id, schedule_id)
72
+ result.should be_true
73
+ end
74
+ end
75
+
76
+ describe "#update_schedule" do
77
+ it "updates a specific schedule for a campaign" do
78
+ campaign_id = 1
79
+ json = load_file('schedule_response.json')
80
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
81
+
82
+ response = RestClient::Response.create(json, net_http_resp, {})
83
+ RestClient.stub(:put).and_return(response)
84
+ schedule = ConstantContact::Components::Schedule.create(JSON.parse(json))
85
+
86
+ result = ConstantContact::Services::CampaignScheduleService.update_schedule(
87
+ 'token', campaign_id, schedule)
88
+ result.should be_kind_of(ConstantContact::Components::Schedule)
89
+ result.scheduled_date.should eq('2013-05-10T11:07:43.626Z')
90
+ end
91
+ end
92
+
93
+ describe "#send_test" do
94
+ it "sends a test send of a campaign" do
95
+ campaign_id = 1
96
+ json_request = load_file('test_send_request.json')
97
+ json_response = load_file('test_send_response.json')
98
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
99
+
100
+ response = RestClient::Response.create(json_response, net_http_resp, {})
101
+ RestClient.stub(:post).and_return(response)
102
+ test_send = ConstantContact::Components::TestSend.create(JSON.parse(json_request))
103
+
104
+ result = ConstantContact::Services::CampaignScheduleService.send_test(
105
+ 'token', campaign_id, test_send)
106
+ result.should be_kind_of(ConstantContact::Components::TestSend)
107
+ result.personal_message.should eq('This is a test send of the email campaign message.')
108
+ end
109
+ end
110
+
111
+ end