constantcontact-ruby 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +2 -0
  3. data/README.md +136 -0
  4. data/constantcontact-ruby.gemspec +31 -0
  5. data/lib/constantcontact/api.rb +1012 -0
  6. data/lib/constantcontact/auth/oauth2.rb +105 -0
  7. data/lib/constantcontact/auth/session_data_store.rb +69 -0
  8. data/lib/constantcontact/components/account/account_address.rb +26 -0
  9. data/lib/constantcontact/components/account/account_info.rb +38 -0
  10. data/lib/constantcontact/components/account/verified_email_address.rb +26 -0
  11. data/lib/constantcontact/components/activities/activity.rb +43 -0
  12. data/lib/constantcontact/components/activities/activity_error.rb +26 -0
  13. data/lib/constantcontact/components/activities/add_contacts.rb +127 -0
  14. data/lib/constantcontact/components/activities/add_contacts_import_data.rb +46 -0
  15. data/lib/constantcontact/components/activities/export_contacts.rb +30 -0
  16. data/lib/constantcontact/components/component.rb +48 -0
  17. data/lib/constantcontact/components/contacts/address.rb +27 -0
  18. data/lib/constantcontact/components/contacts/contact.rb +92 -0
  19. data/lib/constantcontact/components/contacts/contact_list.rb +26 -0
  20. data/lib/constantcontact/components/contacts/custom_field.rb +26 -0
  21. data/lib/constantcontact/components/contacts/email_address.rb +33 -0
  22. data/lib/constantcontact/components/contacts/note.rb +26 -0
  23. data/lib/constantcontact/components/email_marketing/campaign.rb +83 -0
  24. data/lib/constantcontact/components/email_marketing/campaign_preview.rb +29 -0
  25. data/lib/constantcontact/components/email_marketing/click_through_details.rb +27 -0
  26. data/lib/constantcontact/components/email_marketing/message_footer.rb +29 -0
  27. data/lib/constantcontact/components/email_marketing/schedule.rb +27 -0
  28. data/lib/constantcontact/components/email_marketing/test_send.rb +45 -0
  29. data/lib/constantcontact/components/event_spot/contact.rb +27 -0
  30. data/lib/constantcontact/components/event_spot/event.rb +69 -0
  31. data/lib/constantcontact/components/event_spot/event_address.rb +29 -0
  32. data/lib/constantcontact/components/event_spot/event_fee.rb +27 -0
  33. data/lib/constantcontact/components/event_spot/event_item.rb +36 -0
  34. data/lib/constantcontact/components/event_spot/event_item_attribute.rb +26 -0
  35. data/lib/constantcontact/components/event_spot/event_track.rb +31 -0
  36. data/lib/constantcontact/components/event_spot/guest.rb +31 -0
  37. data/lib/constantcontact/components/event_spot/guest_section.rb +34 -0
  38. data/lib/constantcontact/components/event_spot/notification_option.rb +27 -0
  39. data/lib/constantcontact/components/event_spot/online_meeting.rb +28 -0
  40. data/lib/constantcontact/components/event_spot/payment_address.rb +29 -0
  41. data/lib/constantcontact/components/event_spot/payment_summary.rb +33 -0
  42. data/lib/constantcontact/components/event_spot/promocode.rb +25 -0
  43. data/lib/constantcontact/components/event_spot/registrant.rb +52 -0
  44. data/lib/constantcontact/components/event_spot/registrant_fee.rb +29 -0
  45. data/lib/constantcontact/components/event_spot/registrant_field.rb +27 -0
  46. data/lib/constantcontact/components/event_spot/registrant_order.rb +39 -0
  47. data/lib/constantcontact/components/event_spot/registrant_promo_code.rb +31 -0
  48. data/lib/constantcontact/components/event_spot/registrant_promo_code_info.rb +27 -0
  49. data/lib/constantcontact/components/event_spot/registrant_section.rb +34 -0
  50. data/lib/constantcontact/components/event_spot/sale_item.rb +29 -0
  51. data/lib/constantcontact/components/library/file/library_file.rb +27 -0
  52. data/lib/constantcontact/components/library/folder/library_folder.rb +26 -0
  53. data/lib/constantcontact/components/library/info/library_summary.rb +26 -0
  54. data/lib/constantcontact/components/library/info/move_results.rb +26 -0
  55. data/lib/constantcontact/components/library/info/upload_status.rb +26 -0
  56. data/lib/constantcontact/components/result_set.rb +50 -0
  57. data/lib/constantcontact/components/tracking/bounce_activity.rb +28 -0
  58. data/lib/constantcontact/components/tracking/click_activity.rb +26 -0
  59. data/lib/constantcontact/components/tracking/forward_activity.rb +26 -0
  60. data/lib/constantcontact/components/tracking/open_activity.rb +26 -0
  61. data/lib/constantcontact/components/tracking/send_activity.rb +27 -0
  62. data/lib/constantcontact/components/tracking/tracking_activity.rb +26 -0
  63. data/lib/constantcontact/components/tracking/tracking_summary.rb +27 -0
  64. data/lib/constantcontact/components/tracking/unsubscribe_activity.rb +27 -0
  65. data/lib/constantcontact/exceptions/ctct_exception.rb +25 -0
  66. data/lib/constantcontact/exceptions/illegal_argument_exception.rb +11 -0
  67. data/lib/constantcontact/exceptions/oauth2_exception.rb +11 -0
  68. data/lib/constantcontact/exceptions/webhooks_exception.rb +11 -0
  69. data/lib/constantcontact/services/account_service.rb +39 -0
  70. data/lib/constantcontact/services/activity_service.rb +136 -0
  71. data/lib/constantcontact/services/base_service.rb +68 -0
  72. data/lib/constantcontact/services/campaign_schedule_service.rb +101 -0
  73. data/lib/constantcontact/services/campaign_tracking_service.rb +152 -0
  74. data/lib/constantcontact/services/contact_service.rb +105 -0
  75. data/lib/constantcontact/services/contact_tracking_service.rb +152 -0
  76. data/lib/constantcontact/services/email_marketing_service.rb +94 -0
  77. data/lib/constantcontact/services/event_spot_service.rb +448 -0
  78. data/lib/constantcontact/services/library_service.rb +281 -0
  79. data/lib/constantcontact/services/list_service.rb +81 -0
  80. data/lib/constantcontact/util/config.rb +180 -0
  81. data/lib/constantcontact/util/helpers.rb +27 -0
  82. data/lib/constantcontact/version.rb +12 -0
  83. data/lib/constantcontact/webhooks/helpers/validator.rb +30 -0
  84. data/lib/constantcontact/webhooks/models/billing_change_notification.rb +27 -0
  85. data/lib/constantcontact/webhooks/webhooks_util.rb +45 -0
  86. data/lib/constantcontact.rb +124 -0
  87. data/spec/constantcontact/api_spec.rb +1560 -0
  88. data/spec/constantcontact/auth/oauth2_spec.rb +125 -0
  89. data/spec/constantcontact/components/contacts/address_spec.rb +18 -0
  90. data/spec/constantcontact/components/contacts/contact_list_spec.rb +18 -0
  91. data/spec/constantcontact/components/contacts/contact_spec.rb +18 -0
  92. data/spec/constantcontact/components/contacts/custom_field_spec.rb +18 -0
  93. data/spec/constantcontact/components/contacts/email_address_spec.rb +18 -0
  94. data/spec/constantcontact/sdk_spec.rb +24 -0
  95. data/spec/constantcontact/services/account_service_spec.rb +46 -0
  96. data/spec/constantcontact/services/activity_service_spec.rb +244 -0
  97. data/spec/constantcontact/services/base_service_spec.rb +50 -0
  98. data/spec/constantcontact/services/campaign_schedule_service_spec.rb +115 -0
  99. data/spec/constantcontact/services/campaign_tracking_service_spec.rb +131 -0
  100. data/spec/constantcontact/services/contact_service_spec.rb +111 -0
  101. data/spec/constantcontact/services/contact_tracking_service_spec.rb +131 -0
  102. data/spec/constantcontact/services/email_marketing_spec.rb +100 -0
  103. data/spec/constantcontact/services/event_spot_spec.rb +423 -0
  104. data/spec/constantcontact/services/library_service_spec.rb +252 -0
  105. data/spec/constantcontact/services/list_service_spec.rb +89 -0
  106. data/spec/constantcontact/webhooks/webhooks_spec.rb +26 -0
  107. metadata +243 -0
@@ -0,0 +1,1560 @@
1
+ #
2
+ # api_spec.rb
3
+ # ConstantContact
4
+ #
5
+ # Copyright (c) 2013 Constant Contact. All rights reserved.
6
+
7
+ require 'spec_helper'
8
+
9
+ describe ConstantContact::Api do
10
+
11
+ before(:all) do
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
+ end
18
+
19
+ it "without api_key defined" do
20
+ lambda {
21
+ ConstantContact::Api.new
22
+ }.should raise_error(ArgumentError, ConstantContact::Util::Config.get('errors.api_key_missing'))
23
+ end
24
+
25
+ it "without access_token defined" do
26
+ lambda {
27
+ ConstantContact::Api.new('api_key')
28
+ }.should raise_error(ArgumentError, ConstantContact::Util::Config.get('errors.access_token_missing'))
29
+ end
30
+
31
+ context "with middle-ware configuration" do
32
+ before(:all) do
33
+ ConstantContact::Services::BaseService.api_key = nil
34
+ ConstantContact::Util::Config.configure do |config|
35
+ config[:auth][:api_key] = "config_api_key"
36
+ config[:auth][:api_secret] = "config_api_secret"
37
+ config[:auth][:redirect_uri] = "config_redirect_uri"
38
+ end
39
+ end
40
+ let(:proc) { lambda { ConstantContact::Api.new } }
41
+ it "use implicit config" do
42
+ proc.should raise_error(ArgumentError, ConstantContact::Util::Config.get('errors.access_token_missing'))
43
+ end
44
+ it "has the correct implicit api key" do
45
+ ConstantContact::Services::BaseService.api_key.should == "config_api_key"
46
+ end
47
+ end
48
+
49
+ context "with middle-ware configuration" do
50
+ before(:all) do
51
+ ConstantContact::Services::BaseService.api_key = nil
52
+ ConstantContact::Util::Config.configure do |config|
53
+ config[:auth][:api_key] = "config_api_key"
54
+ config[:auth][:api_secret] = "config_api_secret"
55
+ config[:auth][:redirect_uri] = "config_redirect_uri"
56
+ end
57
+ ConstantContact::Api.new('explicit_api_key', 'access_token')
58
+ end
59
+ it "has the correct explicit api key" do
60
+ ConstantContact::Services::BaseService.api_key.should == "explicit_api_key"
61
+ end
62
+ end
63
+
64
+ describe "test methods" do
65
+ before(:each) do
66
+ @api = ConstantContact::Api.new('api key', 'access token')
67
+ @request = double('http request', :user => nil, :password => nil, :url => 'http://example.com', :redirection_history => nil)
68
+ end
69
+
70
+ describe "#get_account_info" do
71
+ it "gets a summary of account information" do
72
+ json_response = load_file('account_info_response.json')
73
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
74
+
75
+ response = RestClient::Response.create(json_response, net_http_resp, {}, @request)
76
+ RestClient.stub(:get).and_return(response)
77
+
78
+ result = @api.get_account_info()
79
+ result.should be_kind_of(ConstantContact::Components::AccountInfo)
80
+ result.website.should eq('http://www.example.com')
81
+ end
82
+ end
83
+
84
+ describe "#get_verified_email_addresses" do
85
+ it "gets verified addresses for the account" do
86
+ json_response = load_file('verified_email_addresses_response.json')
87
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
88
+
89
+ response = RestClient::Response.create(json_response, net_http_resp, {}, @request)
90
+ RestClient.stub(:get).and_return(response)
91
+
92
+ email_addresses = @api.get_verified_email_addresses()
93
+
94
+ email_addresses.should be_kind_of(Array)
95
+ email_addresses.first.should be_kind_of(ConstantContact::Components::VerifiedEmailAddress)
96
+ email_addresses.first.email_address.should eq('abc@def.com')
97
+ end
98
+ end
99
+
100
+ describe "#get_contacts" do
101
+ it "returns an array of contacts" do
102
+ json_response = load_file('contacts_response.json')
103
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
104
+
105
+ response = RestClient::Response.create(json_response, net_http_resp, {}, @request)
106
+ RestClient.stub(:get).and_return(response)
107
+ contacts = @api.get_contacts({:limit => 60})
108
+
109
+ contacts.should be_kind_of(ConstantContact::Components::ResultSet)
110
+ contacts.results.first.should be_kind_of(ConstantContact::Components::Contact)
111
+ contacts.results.first.fax.should eq('318-978-7575')
112
+ end
113
+ end
114
+
115
+ describe "#get_contact" do
116
+ it "returns a contact" do
117
+ json_response = load_file('contact_response.json')
118
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
119
+
120
+ response = RestClient::Response.create(json_response, net_http_resp, {}, @request)
121
+ RestClient.stub(:get).and_return(response)
122
+ contact = @api.get_contact(1)
123
+
124
+ contact.should be_kind_of(ConstantContact::Components::Contact)
125
+ end
126
+ end
127
+
128
+ describe "#get_contact_by_email" do
129
+ it "returns a contact" do
130
+ json_response = load_file('contacts_response.json')
131
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
132
+
133
+ response = RestClient::Response.create(json_response, net_http_resp, {}, @request)
134
+ RestClient.stub(:get).and_return(response)
135
+ contacts = @api.get_contact_by_email('rmartone@systems.com')
136
+
137
+ contacts.results.first.should be_kind_of(ConstantContact::Components::Contact)
138
+ end
139
+ end
140
+
141
+ describe "#add_contact" do
142
+ it "adds a contact" do
143
+ json_response = load_file('contact_response.json')
144
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
145
+
146
+ response = RestClient::Response.create(json_response, net_http_resp, {}, @request)
147
+ RestClient.stub(:post).and_return(response)
148
+ new_contact = ConstantContact::Components::Contact.create(JSON.parse(json_response))
149
+
150
+ contact = @api.add_contact(new_contact)
151
+ contact.should be_kind_of(ConstantContact::Components::Contact)
152
+ contact.status.should eq('ACTIVE')
153
+ end
154
+ end
155
+
156
+ describe "#delete_contact" do
157
+ it "deletes a contact" do
158
+ contact_id = 196
159
+ net_http_resp = Net::HTTPResponse.new(1.0, 204, 'No Content')
160
+
161
+ response = RestClient::Response.create('', net_http_resp, {}, @request)
162
+ RestClient.stub(:delete).and_return(response)
163
+
164
+ result = @api.delete_contact(contact_id)
165
+ result.should be_true
166
+ end
167
+ end
168
+
169
+ describe "#delete_contact_from_lists" do
170
+ it "deletes a contact" do
171
+ contact_id = 196
172
+ net_http_resp = Net::HTTPResponse.new(1.0, 204, 'No Content')
173
+
174
+ response = RestClient::Response.create('', net_http_resp, {}, @request)
175
+ RestClient.stub(:delete).and_return(response)
176
+
177
+ result = @api.delete_contact_from_lists(contact_id)
178
+ result.should be_true
179
+ end
180
+ end
181
+
182
+ describe "#delete_contact_from_list" do
183
+ it "deletes a contact" do
184
+ contact_id = 196
185
+ list_id = 1
186
+ net_http_resp = Net::HTTPResponse.new(1.0, 204, 'No Content')
187
+
188
+ response = RestClient::Response.create('', net_http_resp, {}, @request)
189
+ RestClient.stub(:delete).and_return(response)
190
+
191
+ result = @api.delete_contact_from_list(contact_id, list_id)
192
+ result.should be_true
193
+ end
194
+ end
195
+
196
+ describe "#update_contact" do
197
+ it "updates a contact" do
198
+ json = load_file('contact_response.json')
199
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
200
+
201
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
202
+ RestClient.stub(:put).and_return(response)
203
+ contact = ConstantContact::Components::Contact.create(JSON.parse(json))
204
+ result = @api.update_contact(contact)
205
+
206
+ result.should be_kind_of(ConstantContact::Components::Contact)
207
+ result.status.should eq('ACTIVE')
208
+ end
209
+ end
210
+
211
+ describe "#get_lists" do
212
+ it "returns an array of lists" do
213
+ json_response = load_file('lists_response.json')
214
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
215
+
216
+ response = RestClient::Response.create(json_response, net_http_resp, {}, @request)
217
+ RestClient.stub(:get).and_return(response)
218
+ lists = @api.get_lists()
219
+
220
+ lists.should be_kind_of(Array)
221
+ lists.first.should be_kind_of(ConstantContact::Components::ContactList)
222
+ lists.first.name.should eq('General Interest')
223
+ end
224
+ end
225
+
226
+ describe "#get_list" do
227
+ it "returns a list" do
228
+ json = load_file('list_response.json')
229
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
230
+
231
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
232
+ RestClient.stub(:get).and_return(response)
233
+
234
+ list = @api.get_list(1)
235
+ list.should be_kind_of(ConstantContact::Components::ContactList)
236
+ list.name.should eq('Monthly Specials')
237
+ end
238
+ end
239
+
240
+ describe "#add_list" do
241
+ it "adds a list" do
242
+ json = load_file('list_response.json')
243
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
244
+
245
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
246
+ RestClient.stub(:post).and_return(response)
247
+ new_list = ConstantContact::Components::ContactList.create(JSON.parse(json))
248
+
249
+ list = @api.add_list(new_list)
250
+ list.should be_kind_of(ConstantContact::Components::ContactList)
251
+ list.status.should eq('ACTIVE')
252
+ end
253
+ end
254
+
255
+ describe "#update_list" do
256
+ it "updates a list" do
257
+ json = load_file('list_response.json')
258
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
259
+
260
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
261
+ RestClient.stub(:put).and_return(response)
262
+ list = ConstantContact::Components::ContactList.create(JSON.parse(json))
263
+
264
+ result = @api.update_list(list)
265
+ result.should be_kind_of(ConstantContact::Components::ContactList)
266
+ result.status.should eq('ACTIVE')
267
+ end
268
+ end
269
+
270
+ describe "#get_contacts_from_list" do
271
+ it "returns an array of contacts" do
272
+ json_list = load_file('list_response.json')
273
+ json_contacts = load_file('contacts_response.json')
274
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
275
+
276
+ response = RestClient::Response.create(json_contacts, net_http_resp, {}, @request)
277
+ RestClient.stub(:get).and_return(response)
278
+ list = ConstantContact::Components::ContactList.create(JSON.parse(json_list))
279
+
280
+ contacts = @api.get_contacts_from_list(list, "?limit=4&next=true")
281
+ contacts.should be_kind_of(ConstantContact::Components::ResultSet)
282
+ contacts.results.first.should be_kind_of(ConstantContact::Components::Contact)
283
+ contacts.results.first.fax.should eq('318-978-7575')
284
+
285
+ contacts = @api.get_contacts_from_list(list, 4)
286
+ contacts.should be_kind_of(ConstantContact::Components::ResultSet)
287
+ contacts.results.first.should be_kind_of(ConstantContact::Components::Contact)
288
+ contacts.results.first.fax.should eq('318-978-7575')
289
+ end
290
+ end
291
+
292
+ describe "#get_events" do
293
+ it "returns an array of events" do
294
+ json = load_file('events.json')
295
+
296
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
297
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
298
+ RestClient.stub(:get).and_return(response)
299
+
300
+ events = @api.get_events()
301
+ events.should be_kind_of(ConstantContact::Components::ResultSet)
302
+ events.results.collect{|e| e.should be_kind_of(ConstantContact::Components::Event) }
303
+ end
304
+ end
305
+
306
+ describe "#get_event" do
307
+ it "returns an event" do
308
+ json = load_file('event.json')
309
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
310
+
311
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
312
+ RestClient.stub(:get).and_return(response)
313
+ event = @api.get_event(1)
314
+
315
+ event.should be_kind_of(ConstantContact::Components::Event)
316
+ end
317
+ end
318
+
319
+ describe "#add_event" do
320
+ it "adds an event" do
321
+ json = load_file('event.json')
322
+
323
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
324
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
325
+ RestClient.stub(:post).and_return(response)
326
+
327
+ event = ConstantContact::Components::Event.create(JSON.parse(json))
328
+ added = @api.add_event(event)
329
+
330
+ added.should respond_to(:id)
331
+ added.id.should_not be_empty
332
+ end
333
+ end
334
+
335
+ describe "#publish_event" do
336
+ it "updates an event with status of ACTIVE" do
337
+ json = load_file('event.json')
338
+ hash = JSON.parse json
339
+ hash["status"] = "ACTIVE"
340
+
341
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
342
+ response = RestClient::Response.create(hash.to_json, net_http_resp, {}, @request)
343
+ RestClient.stub(:patch).and_return(response)
344
+
345
+ event = ConstantContact::Components::Event.create(JSON.parse(json))
346
+ updated = @api.publish_event(event)
347
+ updated.should be_kind_of(ConstantContact::Components::Event)
348
+ updated.should respond_to(:status)
349
+ updated.status.should eq("ACTIVE")
350
+ end
351
+ end
352
+
353
+ describe "#cancel_event" do
354
+ it "updates an event's status to CANCELLED" do
355
+ json = load_file('event.json')
356
+ hash = JSON.parse json
357
+ hash["status"] = "CANCELLED"
358
+
359
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
360
+ response = RestClient::Response.create(hash.to_json, net_http_resp, {}, @request)
361
+ RestClient.stub(:patch).and_return(response)
362
+
363
+ event = ConstantContact::Components::Event.create(JSON.parse(json))
364
+ updated = @api.cancel_event(event)
365
+ updated.should be_kind_of(ConstantContact::Components::Event)
366
+ updated.should respond_to(:status)
367
+ updated.status.should eq("CANCELLED")
368
+ end
369
+ end
370
+
371
+ describe "#get_fees" do
372
+ it "returns an array of fees for an event" do
373
+ event_json = load_file('event.json')
374
+ fees_json = load_file('fees.json')
375
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
376
+
377
+ response = RestClient::Response.create(fees_json, net_http_resp, {}, @request)
378
+ RestClient.stub(:get).and_return(response)
379
+ event = ConstantContact::Components::Event.create(JSON.parse(event_json))
380
+ fees = @api.get_event_fees(event)
381
+ #fees.should be_kind_of(ConstantContact::Components::ResultSet)
382
+ #fees.results.collect{|f| f.should be_kind_of(ConstantContact::Components::Fee) }
383
+
384
+ fees.should be_kind_of(Array) # inconsistent with oether APIs.
385
+ fees.collect{|f| f.should be_kind_of(ConstantContact::Components::EventFee) }
386
+ end
387
+ end
388
+
389
+ describe "#get_fee" do
390
+ it "return an event fee" do
391
+ event_json = load_file('event.json')
392
+ fee_json = load_file('fees.json')
393
+
394
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
395
+ response = RestClient::Response.create(fee_json, net_http_resp, {}, @request)
396
+ RestClient.stub(:get).and_return(response)
397
+
398
+ event = ConstantContact::Components::Event.create(JSON.parse(event_json))
399
+ fee = ConstantContact::Components::EventFee.create(JSON.parse(fee_json))
400
+ retrieved = @api.get_event_fee(event, fee)
401
+ retrieved.should be_kind_of(ConstantContact::Components::EventFee)
402
+ end
403
+ end
404
+
405
+ describe "#add_fee" do
406
+ it "adds an event fee" do
407
+ event_json = load_file('event.json')
408
+ fee_json = load_file('fee.json')
409
+
410
+ net_http_resp = Net::HTTPResponse.new(1.0, 201, 'Created')
411
+ response = RestClient::Response.create(fee_json, net_http_resp, {}, @request)
412
+ RestClient.stub(:post).and_return(response)
413
+
414
+ event = ConstantContact::Components::Event.create(JSON.parse(event_json))
415
+ fee = ConstantContact::Components::EventFee.create(JSON.parse(fee_json))
416
+ added = @api.add_event_fee(event, fee)
417
+ added.should be_kind_of(ConstantContact::Components::EventFee)
418
+ added.id.should_not be_empty
419
+ end
420
+ end
421
+
422
+ describe "#update_fee" do
423
+ it "updates an event fee" do
424
+ event_json = load_file('event.json')
425
+ fee_json = load_file('fee.json')
426
+ hash = JSON.parse fee_json
427
+ hash['fee'] += 1
428
+
429
+ net_http_resp = Net::HTTPResponse.new(1.0, 201, 'Created')
430
+ response = RestClient::Response.create(hash.to_json, net_http_resp, {}, @request)
431
+ RestClient.stub(:put).and_return(response)
432
+
433
+ event = ConstantContact::Components::Event.create(JSON.parse(event_json))
434
+ fee = ConstantContact::Components::EventFee.create(JSON.parse(fee_json))
435
+ updated = @api.update_event_fee(event, fee)
436
+ updated.should be_kind_of(ConstantContact::Components::EventFee)
437
+ updated.fee.should_not eq(fee.fee)
438
+ updated.fee.should eq(fee.fee + 1)
439
+ end
440
+ end
441
+
442
+ describe "#delete_fee" do
443
+ it "deletes an event fee" do
444
+ event_json = load_file('event.json')
445
+ fee_json = load_file('fees.json')
446
+
447
+ net_http_resp = Net::HTTPResponse.new(1.0, 204, 'No Content')
448
+ response = RestClient::Response.create('', net_http_resp, {}, @request)
449
+ RestClient.stub(:delete).and_return(response)
450
+
451
+ event = ConstantContact::Components::Event.create(JSON.parse(event_json))
452
+ fee = ConstantContact::Components::EventFee.create(JSON.parse(fee_json))
453
+ @api.delete_event_fee(event, fee).should be_true
454
+ end
455
+ end
456
+
457
+ describe "#get_registrants" do
458
+ it "returns an array of event registrants" do
459
+ event_json = load_file('event.json')
460
+ registrants_json = load_file('registrants.json')
461
+
462
+ net_http_resp = Net::HTTPResponse.new(1.0, 201, 'Created')
463
+ response = RestClient::Response.create(registrants_json, net_http_resp, {}, @request)
464
+ RestClient.stub(:get).and_return(response)
465
+
466
+ event = ConstantContact::Components::Event.create(JSON.parse(event_json))
467
+ registrants = @api.get_event_registrants(event)
468
+ registrants.should be_kind_of(ConstantContact::Components::ResultSet)
469
+ registrants.results.collect{|r| r .should be_kind_of(ConstantContact::Components::Registrant) }
470
+ end
471
+ end
472
+
473
+ describe "#get_registrant" do
474
+ it "returns an event registrant" do
475
+ event_json = load_file('event.json')
476
+ registrant_json = load_file('registrant.json')
477
+
478
+ net_http_resp = Net::HTTPResponse.new(1.0, 201, 'Created')
479
+ response = RestClient::Response.create(registrant_json, net_http_resp, {}, @request)
480
+ RestClient.stub(:get).and_return(response)
481
+
482
+ event = ConstantContact::Components::Event.create(JSON.parse(event_json))
483
+ registrant = ConstantContact::Components::Registrant.create(JSON.parse(registrant_json))
484
+ retrieved = @api.get_event_registrant(event, registrant)
485
+ retrieved.should be_kind_of(ConstantContact::Components::Registrant)
486
+ retrieved.id.should_not be_empty
487
+ end
488
+ end
489
+
490
+ describe "#get_event_items" do
491
+ it "returns an array of event items" do
492
+ json_response = load_file('event_items_response.json')
493
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
494
+
495
+ response = RestClient::Response.create(json_response, net_http_resp, {}, @request)
496
+ RestClient.stub(:get).and_return(response)
497
+
498
+ results = @api.get_event_items(1)
499
+ results.should be_kind_of(Array)
500
+ results.first.should be_kind_of(ConstantContact::Components::EventItem)
501
+ results.first.name.should eq('Running Belt')
502
+ end
503
+ end
504
+
505
+ describe "#get_event_item" do
506
+ it "returns an event item" do
507
+ json = load_file('event_item_response.json')
508
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
509
+
510
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
511
+ RestClient.stub(:get).and_return(response)
512
+
513
+ result = @api.get_event_item(1, 1)
514
+ result.should be_kind_of(ConstantContact::Components::EventItem)
515
+ result.name.should eq('Running Belt')
516
+ end
517
+ end
518
+
519
+ describe "#add_event_item" do
520
+ it "adds an event item" do
521
+ json = load_file('event_item_response.json')
522
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
523
+
524
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
525
+ RestClient.stub(:post).and_return(response)
526
+ event_item = ConstantContact::Components::EventItem.create(JSON.parse(json))
527
+
528
+ result = @api.add_event_item(1, event_item)
529
+ result.should be_kind_of(ConstantContact::Components::EventItem)
530
+ result.name.should eq('Running Belt')
531
+ end
532
+ end
533
+
534
+ describe "#delete_event_item" do
535
+ it "deletes an event item" do
536
+ net_http_resp = Net::HTTPResponse.new(1.0, 204, 'No Content')
537
+
538
+ response = RestClient::Response.create('', net_http_resp, {}, @request)
539
+ RestClient.stub(:delete).and_return(response)
540
+
541
+ result = @api.delete_event_item(1, 1)
542
+ result.should be_true
543
+ end
544
+ end
545
+
546
+ describe "#update_event_item" do
547
+ it "updates an event item" do
548
+ json = load_file('event_item_response.json')
549
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
550
+
551
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
552
+ RestClient.stub(:put).and_return(response)
553
+ event_item = ConstantContact::Components::EventItem.create(JSON.parse(json))
554
+
555
+ result = @api.update_event_item(1, event_item)
556
+ result.should be_kind_of(ConstantContact::Components::EventItem)
557
+ result.name.should eq('Running Belt')
558
+ end
559
+ end
560
+
561
+ describe "#get_event_item_attributes" do
562
+ it "returns an array of event item attributes" do
563
+ json_response = load_file('event_item_attributes_response.json')
564
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
565
+
566
+ response = RestClient::Response.create(json_response, net_http_resp, {}, @request)
567
+ RestClient.stub(:get).and_return(response)
568
+
569
+ results = @api.get_event_item_attributes(1, 1)
570
+ results.should be_kind_of(Array)
571
+ results.first.should be_kind_of(ConstantContact::Components::EventItemAttribute)
572
+ results.first.name.should eq('Royal Blue')
573
+ end
574
+ end
575
+
576
+ describe "#get_event_item_attribute" do
577
+ it "returns an event item attribute" do
578
+ json = load_file('event_item_attribute_response.json')
579
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
580
+
581
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
582
+ RestClient.stub(:get).and_return(response)
583
+
584
+ result = @api.get_event_item_attribute(1, 1, 1)
585
+ result.should be_kind_of(ConstantContact::Components::EventItemAttribute)
586
+ result.name.should eq('Hi-Vis Green')
587
+ end
588
+ end
589
+
590
+ describe "#add_event_item_attribute" do
591
+ it "adds an event item attribute" do
592
+ json = load_file('event_item_attribute_response.json')
593
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
594
+
595
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
596
+ RestClient.stub(:post).and_return(response)
597
+ event_item_attribute = ConstantContact::Components::EventItemAttribute.create(JSON.parse(json))
598
+
599
+ result = @api.add_event_item_attribute(1, 1, event_item_attribute)
600
+ result.should be_kind_of(ConstantContact::Components::EventItemAttribute)
601
+ result.name.should eq('Hi-Vis Green')
602
+ end
603
+ end
604
+
605
+ describe "#delete_event_item_attribute" do
606
+ it "deletes an event item attribute" do
607
+ net_http_resp = Net::HTTPResponse.new(1.0, 204, 'No Content')
608
+
609
+ response = RestClient::Response.create('', net_http_resp, {}, @request)
610
+ RestClient.stub(:delete).and_return(response)
611
+
612
+ result = @api.delete_event_item_attribute(1, 1, 1)
613
+ result.should be_true
614
+ end
615
+ end
616
+
617
+ describe "#update_event_item_attribute" do
618
+ it "updates an event item attribute" do
619
+ json = load_file('event_item_attribute_response.json')
620
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
621
+
622
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
623
+ RestClient.stub(:put).and_return(response)
624
+ event_item_attribute = ConstantContact::Components::EventItemAttribute.create(JSON.parse(json))
625
+
626
+ result = @api.update_event_item_attribute(1, 1, event_item_attribute)
627
+ result.should be_kind_of(ConstantContact::Components::EventItemAttribute)
628
+ result.name.should eq('Hi-Vis Green')
629
+ end
630
+ end
631
+
632
+ describe "#get_promocodes" do
633
+ it "returns an array of promocodes" do
634
+ json_response = load_file('promocodes_response.json')
635
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
636
+
637
+ response = RestClient::Response.create(json_response, net_http_resp, {}, @request)
638
+ RestClient.stub(:get).and_return(response)
639
+
640
+ results = @api.get_promocodes(1)
641
+ results.should be_kind_of(Array)
642
+ results.first.should be_kind_of(ConstantContact::Components::Promocode)
643
+ results.first.code_name.should eq('REDUCED_FEE')
644
+ end
645
+ end
646
+
647
+ describe "#get_promocode" do
648
+ it "returns a promocode" do
649
+ json = load_file('promocode_response.json')
650
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
651
+
652
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
653
+ RestClient.stub(:get).and_return(response)
654
+
655
+ result = @api.get_promocode(1, 1)
656
+ result.should be_kind_of(ConstantContact::Components::Promocode)
657
+ result.code_name.should eq('TOTAL_FEE')
658
+ end
659
+ end
660
+
661
+ describe "#add_promocode" do
662
+ it "adds a promocode" do
663
+ json = load_file('promocode_response.json')
664
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
665
+
666
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
667
+ RestClient.stub(:post).and_return(response)
668
+ promocode = ConstantContact::Components::Promocode.create(JSON.parse(json))
669
+
670
+ result = @api.add_promocode(1, promocode)
671
+ result.should be_kind_of(ConstantContact::Components::Promocode)
672
+ result.code_name.should eq('TOTAL_FEE')
673
+ end
674
+ end
675
+
676
+ describe "#delete_promocode" do
677
+ it "deletes a promocode" do
678
+ net_http_resp = Net::HTTPResponse.new(1.0, 204, 'No Content')
679
+
680
+ response = RestClient::Response.create('', net_http_resp, {}, @request)
681
+ RestClient.stub(:delete).and_return(response)
682
+
683
+ result = @api.delete_promocode(1, 1)
684
+ result.should be_true
685
+ end
686
+ end
687
+
688
+ describe "#update_promocode" do
689
+ it "updates an event item" do
690
+ json = load_file('promocode_response.json')
691
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
692
+
693
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
694
+ RestClient.stub(:put).and_return(response)
695
+ promocode = ConstantContact::Components::Promocode.create(JSON.parse(json))
696
+
697
+ result = @api.update_promocode(1, promocode)
698
+ result.should be_kind_of(ConstantContact::Components::Promocode)
699
+ result.code_name.should eq('TOTAL_FEE')
700
+ end
701
+ end
702
+
703
+ describe "#get_email_campaigns" do
704
+ it "gets a set of campaigns" do
705
+ json_response = load_file('email_campaigns_response.json')
706
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
707
+
708
+ response = RestClient::Response.create(json_response, net_http_resp, {}, @request)
709
+ RestClient.stub(:get).and_return(response)
710
+
711
+ campaigns = @api.get_email_campaigns({:limit => 2})
712
+ campaigns.should be_kind_of(ConstantContact::Components::ResultSet)
713
+ campaigns.results.first.should be_kind_of(ConstantContact::Components::Campaign)
714
+ campaigns.results.first.name.should eq('1357157252225')
715
+ end
716
+ end
717
+
718
+ describe "#get_email_campaign" do
719
+ it "gets an individual campaign" do
720
+ json_response = load_file('email_campaign_response.json')
721
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
722
+
723
+ response = RestClient::Response.create(json_response, net_http_resp, {}, @request)
724
+ RestClient.stub(:get).and_return(response)
725
+
726
+ campaign = @api.get_email_campaign(1)
727
+ campaign.should be_kind_of(ConstantContact::Components::Campaign)
728
+ campaign.name.should eq('Campaign Name')
729
+ end
730
+ end
731
+
732
+ describe "#get_email_campaign_preview" do
733
+ it "gets the preview of an existing campaign" do
734
+ json_response = load_file('email_campaign_preview_response.json')
735
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
736
+
737
+ response = RestClient::Response.create(json_response, net_http_resp, {}, @request)
738
+ RestClient.stub(:get).and_return(response)
739
+
740
+ campaign_preview = @api.get_email_campaign_preview(1)
741
+ campaign_preview.should be_kind_of(ConstantContact::Components::CampaignPreview)
742
+ campaign_preview.subject.should eq('Subject Test')
743
+ end
744
+ end
745
+
746
+ describe "#add_email_campaign" do
747
+ it "creates a new campaign" do
748
+ json = load_file('email_campaign_response.json')
749
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
750
+
751
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
752
+ RestClient.stub(:post).and_return(response)
753
+ new_campaign = ConstantContact::Components::Campaign.create(JSON.parse(json))
754
+
755
+ campaign = @api.add_email_campaign(new_campaign)
756
+ campaign.should be_kind_of(ConstantContact::Components::Campaign)
757
+ campaign.name.should eq('Campaign Name')
758
+ end
759
+ end
760
+
761
+ describe "#delete_email_campaign" do
762
+ it "deletes an individual campaign" do
763
+ json = load_file('email_campaign_response.json')
764
+ net_http_resp = Net::HTTPResponse.new(1.0, 204, 'No Content')
765
+
766
+ response = RestClient::Response.create('', net_http_resp, {}, @request)
767
+ RestClient.stub(:delete).and_return(response)
768
+ campaign = ConstantContact::Components::Campaign.create(JSON.parse(json))
769
+
770
+ result = @api.delete_email_campaign(campaign)
771
+ result.should be_true
772
+ end
773
+ end
774
+
775
+ describe "#update_email_campaign" do
776
+ it "updates a specific campaign" do
777
+ json = load_file('email_campaign_response.json')
778
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
779
+
780
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
781
+ RestClient.stub(:put).and_return(response)
782
+ campaign = ConstantContact::Components::Campaign.create(JSON.parse(json))
783
+
784
+ result = @api.update_email_campaign(campaign)
785
+ result.should be_kind_of(ConstantContact::Components::Campaign)
786
+ result.name.should eq('Campaign Name')
787
+ end
788
+ end
789
+
790
+ describe "#add_email_campaign_schedule" do
791
+ it "schedules a campaign to be sent" do
792
+ campaign_id = 1
793
+ json = load_file('schedule_response.json')
794
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
795
+
796
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
797
+ RestClient.stub(:post).and_return(response)
798
+ new_schedule = ConstantContact::Components::Schedule.create(JSON.parse(json))
799
+
800
+ schedule = @api.add_email_campaign_schedule(campaign_id, new_schedule)
801
+ schedule.should be_kind_of(ConstantContact::Components::Schedule)
802
+ schedule.scheduled_date.should eq('2013-05-10T11:07:43.626Z')
803
+ end
804
+ end
805
+
806
+ describe "#get_email_campaign_schedules" do
807
+ it "gets an array of schedules associated with a given campaign" do
808
+ campaign_id = 1
809
+ json = load_file('schedules_response.json')
810
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
811
+
812
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
813
+ RestClient.stub(:get).and_return(response)
814
+
815
+ schedules = @api.get_email_campaign_schedules(campaign_id)
816
+ schedules.first.should be_kind_of(ConstantContact::Components::Schedule)
817
+ schedules.first.scheduled_date.should eq('2012-12-16T11:07:43.626Z')
818
+ end
819
+ end
820
+
821
+ describe "#get_email_campaign_schedule" do
822
+ it "gets a specific schedule associated with a given campaign" do
823
+ campaign_id = 1
824
+ schedule_id = 1
825
+
826
+ json = load_file('schedule_response.json')
827
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
828
+
829
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
830
+ RestClient.stub(:get).and_return(response)
831
+
832
+ schedule = @api.get_email_campaign_schedule(campaign_id, schedule_id)
833
+ schedule.should be_kind_of(ConstantContact::Components::Schedule)
834
+ schedule.scheduled_date.should eq('2013-05-10T11:07:43.626Z')
835
+ end
836
+ end
837
+
838
+ describe "#delete_email_campaign_schedule" do
839
+ it "deletes a specific schedule associated with a given campaign" do
840
+ campaign_id = 1
841
+ schedule_id = 1
842
+ net_http_resp = Net::HTTPResponse.new(1.0, 204, 'No Content')
843
+
844
+ response = RestClient::Response.create('', net_http_resp, {}, @request)
845
+ RestClient.stub(:delete).and_return(response)
846
+
847
+ result = @api.delete_email_campaign_schedule(campaign_id, schedule_id)
848
+ result.should be_true
849
+ end
850
+ end
851
+
852
+ describe "#update_email_campaign_schedule" do
853
+ it "updates a specific schedule associated with a given campaign" do
854
+ campaign_id = 1
855
+ json = load_file('schedule_response.json')
856
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
857
+
858
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
859
+ RestClient.stub(:put).and_return(response)
860
+ schedule = ConstantContact::Components::Schedule.create(JSON.parse(json))
861
+
862
+ result = @api.update_email_campaign_schedule(campaign_id, schedule)
863
+ result.should be_kind_of(ConstantContact::Components::Schedule)
864
+ result.scheduled_date.should eq('2013-05-10T11:07:43.626Z')
865
+ end
866
+ end
867
+
868
+ describe "#send_email_campaign_test" do
869
+ it "sends a test send of a campaign" do
870
+ campaign_id = 1
871
+ json_request = load_file('test_send_request.json')
872
+ json_response = load_file('test_send_response.json')
873
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
874
+
875
+ response = RestClient::Response.create(json_response, net_http_resp, {}, @request)
876
+ RestClient.stub(:post).and_return(response)
877
+ test_send = ConstantContact::Components::TestSend.create(JSON.parse(json_request))
878
+
879
+ result = @api.send_email_campaign_test(campaign_id, test_send)
880
+ result.should be_kind_of(ConstantContact::Components::TestSend)
881
+ result.personal_message.should eq('This is a test send of the email campaign message.')
882
+ end
883
+ end
884
+
885
+ describe "#get_email_campaign_bounces" do
886
+ it "gets bounces for a campaign" do
887
+ campaign_id = 1
888
+ params = {:limit => 5}
889
+ json = load_file('campaign_tracking_bounces_response.json')
890
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
891
+
892
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
893
+ RestClient.stub(:get).and_return(response)
894
+
895
+ set = @api.get_email_campaign_bounces(campaign_id, params)
896
+ set.should be_kind_of(ConstantContact::Components::ResultSet)
897
+ set.results.first.should be_kind_of(ConstantContact::Components::BounceActivity)
898
+ set.results.first.activity_type.should eq('EMAIL_BOUNCE')
899
+ end
900
+ end
901
+
902
+ describe "#get_email_campaign_clicks" do
903
+ it "gets clicks for a campaign" do
904
+ campaign_id = 1
905
+ params = {:limit => 5}
906
+ json = load_file('campaign_tracking_clicks_response.json')
907
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
908
+
909
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
910
+ RestClient.stub(:get).and_return(response)
911
+
912
+ set = @api.get_email_campaign_clicks(campaign_id, params)
913
+ set.should be_kind_of(ConstantContact::Components::ResultSet)
914
+ set.results.first.should be_kind_of(ConstantContact::Components::ClickActivity)
915
+ set.results.first.activity_type.should eq('EMAIL_CLICK')
916
+ end
917
+ end
918
+
919
+ describe "#get_email_campaign_forwards" do
920
+ it "gets forwards for a campaign" do
921
+ campaign_id = 1
922
+ params = {:limit => 5}
923
+ json = load_file('campaign_tracking_forwards_response.json')
924
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
925
+
926
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
927
+ RestClient.stub(:get).and_return(response)
928
+
929
+ set = @api.get_email_campaign_forwards(campaign_id, params)
930
+ set.should be_kind_of(ConstantContact::Components::ResultSet)
931
+ set.results.first.should be_kind_of(ConstantContact::Components::ForwardActivity)
932
+ set.results.first.activity_type.should eq('EMAIL_FORWARD')
933
+ end
934
+ end
935
+
936
+ describe "#get_email_campaign_opens" do
937
+ it "gets opens for a campaign" do
938
+ campaign_id = 1
939
+ params = {:limit => 5}
940
+ json = load_file('campaign_tracking_opens_response.json')
941
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
942
+
943
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
944
+ RestClient.stub(:get).and_return(response)
945
+
946
+ set = @api.get_email_campaign_opens(campaign_id, params)
947
+ set.should be_kind_of(ConstantContact::Components::ResultSet)
948
+ set.results.first.should be_kind_of(ConstantContact::Components::OpenActivity)
949
+ set.results.first.activity_type.should eq('EMAIL_OPEN')
950
+ end
951
+ end
952
+
953
+ describe "#get_email_campaign_sends" do
954
+ it "gets sends for a given campaign" do
955
+ campaign_id = 1
956
+ params = {:limit => 5}
957
+ json = load_file('campaign_tracking_sends_response.json')
958
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
959
+
960
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
961
+ RestClient.stub(:get).and_return(response)
962
+
963
+ set = @api.get_email_campaign_sends(campaign_id, params)
964
+ set.should be_kind_of(ConstantContact::Components::ResultSet)
965
+ set.results.first.should be_kind_of(ConstantContact::Components::SendActivity)
966
+ set.results.first.activity_type.should eq('EMAIL_SEND')
967
+ end
968
+ end
969
+
970
+ describe "#get_email_campaign_unsubscribes" do
971
+ it "gets unsubscribes for a campaign" do
972
+ campaign_id = 1
973
+ params = {:limit => 5}
974
+ json = load_file('campaign_tracking_unsubscribes_response.json')
975
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
976
+
977
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
978
+ RestClient.stub(:get).and_return(response)
979
+
980
+ set = @api.get_email_campaign_unsubscribes(campaign_id, params)
981
+ set.should be_kind_of(ConstantContact::Components::ResultSet)
982
+ set.results.first.should be_kind_of(ConstantContact::Components::UnsubscribeActivity)
983
+ set.results.first.activity_type.should eq('EMAIL_UNSUBSCRIBE')
984
+ end
985
+ end
986
+
987
+ describe "#get_email_campaign_summary_report" do
988
+ it "gets a reporting summary for a campaign" do
989
+ campaign_id = 1
990
+ json = load_file('campaign_tracking_summary_response.json')
991
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
992
+
993
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
994
+ RestClient.stub(:get).and_return(response)
995
+
996
+ summary = @api.get_email_campaign_summary_report(campaign_id)
997
+ summary.should be_kind_of(ConstantContact::Components::TrackingSummary)
998
+ summary.sends.should eq(15)
999
+ end
1000
+ end
1001
+
1002
+ describe "#get_contact_bounces" do
1003
+ it "gets bounces for a contact" do
1004
+ contact_id = 1
1005
+ params = {:limit => 5}
1006
+ json = load_file('contact_tracking_bounces_response.json')
1007
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
1008
+
1009
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
1010
+ RestClient.stub(:get).and_return(response)
1011
+
1012
+ set = @api.get_contact_bounces(contact_id, params)
1013
+ set.should be_kind_of(ConstantContact::Components::ResultSet)
1014
+ set.results.first.should be_kind_of(ConstantContact::Components::BounceActivity)
1015
+ set.results.first.activity_type.should eq('EMAIL_BOUNCE')
1016
+ end
1017
+ end
1018
+
1019
+ describe "#get_contact_clicks" do
1020
+ it "gets clicks for a contact" do
1021
+ contact_id = 1
1022
+ params = {:limit => 5}
1023
+ json = load_file('contact_tracking_clicks_response.json')
1024
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
1025
+
1026
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
1027
+ RestClient.stub(:get).and_return(response)
1028
+
1029
+ set = @api.get_contact_clicks(contact_id, params)
1030
+ set.should be_kind_of(ConstantContact::Components::ResultSet)
1031
+ set.results.first.should be_kind_of(ConstantContact::Components::ClickActivity)
1032
+ set.results.first.activity_type.should eq('EMAIL_CLICK')
1033
+ end
1034
+ end
1035
+
1036
+ describe "#get_contact_forwards" do
1037
+ it "gets forwards for a contact" do
1038
+ contact_id = 1
1039
+ params = {:limit => 5}
1040
+ json = load_file('contact_tracking_forwards_response.json')
1041
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
1042
+
1043
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
1044
+ RestClient.stub(:get).and_return(response)
1045
+
1046
+ set = @api.get_contact_forwards(contact_id, params)
1047
+ set.should be_kind_of(ConstantContact::Components::ResultSet)
1048
+ set.results.first.should be_kind_of(ConstantContact::Components::ForwardActivity)
1049
+ set.results.first.activity_type.should eq('EMAIL_FORWARD')
1050
+ end
1051
+ end
1052
+
1053
+ describe "#get_contact_opens" do
1054
+ it "gets opens for a given contact" do
1055
+ contact_id = 1
1056
+ params = {:limit => 5}
1057
+ json = load_file('contact_tracking_opens_response.json')
1058
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
1059
+
1060
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
1061
+ RestClient.stub(:get).and_return(response)
1062
+
1063
+ set = @api.get_contact_opens(contact_id, params)
1064
+ set.should be_kind_of(ConstantContact::Components::ResultSet)
1065
+ set.results.first.should be_kind_of(ConstantContact::Components::OpenActivity)
1066
+ set.results.first.activity_type.should eq('EMAIL_OPEN')
1067
+ end
1068
+ end
1069
+
1070
+ describe "#get_contact_sends" do
1071
+ it "gets sends for a contact" do
1072
+ contact_id = 1
1073
+ params = {:limit => 5}
1074
+ json = load_file('contact_tracking_sends_response.json')
1075
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
1076
+
1077
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
1078
+ RestClient.stub(:get).and_return(response)
1079
+
1080
+ set = @api.get_contact_sends(contact_id, params)
1081
+ set.should be_kind_of(ConstantContact::Components::ResultSet)
1082
+ set.results.first.should be_kind_of(ConstantContact::Components::SendActivity)
1083
+ set.results.first.activity_type.should eq('EMAIL_SEND')
1084
+ end
1085
+ end
1086
+
1087
+ describe "#get_contact_unsubscribes" do
1088
+ it "gets unsubscribes for a given contact" do
1089
+ contact_id = 1
1090
+ params = {:limit => 5}
1091
+ json = load_file('contact_tracking_unsubscribes_response.json')
1092
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
1093
+
1094
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
1095
+ RestClient.stub(:get).and_return(response)
1096
+
1097
+ set = @api.get_contact_unsubscribes(contact_id, params)
1098
+ set.should be_kind_of(ConstantContact::Components::ResultSet)
1099
+ set.results.first.should be_kind_of(ConstantContact::Components::UnsubscribeActivity)
1100
+ set.results.first.activity_type.should eq('EMAIL_UNSUBSCRIBE')
1101
+ end
1102
+ end
1103
+
1104
+ describe "#get_contact_summary_report" do
1105
+ it "gets a reporting summary for a Contact" do
1106
+ contact_id = 1
1107
+ json = load_file('contact_tracking_summary_response.json')
1108
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
1109
+
1110
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
1111
+ RestClient.stub(:get).and_return(response)
1112
+
1113
+ summary = @api.get_contact_summary_report(contact_id)
1114
+ summary.should be_kind_of(ConstantContact::Components::TrackingSummary)
1115
+ summary.sends.should eq(15)
1116
+ end
1117
+ end
1118
+
1119
+ describe "#get_activities" do
1120
+ it "gets an array of activities" do
1121
+ json_response = load_file('activities_response.json')
1122
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
1123
+
1124
+ response = RestClient::Response.create(json_response, net_http_resp, {}, @request)
1125
+ RestClient.stub(:get).and_return(response)
1126
+
1127
+ activities = @api.get_activities()
1128
+ activities.first.should be_kind_of(ConstantContact::Components::Activity)
1129
+ activities.first.type.should eq('REMOVE_CONTACTS_FROM_LISTS')
1130
+ end
1131
+ end
1132
+
1133
+ describe "#update_email_campaign" do
1134
+ it "updates a specific campaign" do
1135
+ json_response = load_file('activity_response.json')
1136
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
1137
+
1138
+ response = RestClient::Response.create(json_response, net_http_resp, {}, @request)
1139
+ RestClient.stub(:get).and_return(response)
1140
+
1141
+ activity = @api.get_activity('a07e1ilbm7shdg6ikeo')
1142
+ activity.should be_kind_of(ConstantContact::Components::Activity)
1143
+ activity.type.should eq('REMOVE_CONTACTS_FROM_LISTS')
1144
+ end
1145
+ end
1146
+
1147
+ describe "#add_create_contacts_activity" do
1148
+ it "adds an AddContacts activity to add contacts in bulk" do
1149
+ json_request = load_file('add_contacts_request.json')
1150
+ json_response = load_file('add_contacts_response.json')
1151
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
1152
+
1153
+ response = RestClient::Response.create(json_response, net_http_resp, {}, @request)
1154
+ RestClient.stub(:post).and_return(response)
1155
+
1156
+ contacts = []
1157
+
1158
+ # first contact
1159
+ import = ConstantContact::Components::AddContactsImportData.new({
1160
+ :first_name => "John",
1161
+ :last_name => "Smith",
1162
+ :birthday_month => "1",
1163
+ :birthday_day => "25",
1164
+ :anniversary => "03/12/2005",
1165
+ :job_title => "",
1166
+ :company_name => "My Company",
1167
+ :home_phone => "5555551212"
1168
+ })
1169
+
1170
+ # add emails
1171
+ import.add_email("user1@example.com")
1172
+
1173
+ # add addresses
1174
+ address = ConstantContact::Components::Address.create(
1175
+ :line1 => "123 Partridge Lane",
1176
+ :line2 => "Apt. 3",
1177
+ :city => "Anytown",
1178
+ :address_type => "PERSONAL",
1179
+ :state_code => "NH",
1180
+ :country_code => "US",
1181
+ :postal_code => "02145"
1182
+ )
1183
+ import.add_address(address)
1184
+
1185
+ contacts << import
1186
+
1187
+ # second contact
1188
+ import = ConstantContact::Components::AddContactsImportData.new({
1189
+ :first_name => "Jane",
1190
+ :last_name => "Doe",
1191
+ :job_title => "",
1192
+ :company_name => "Acme, Inc.",
1193
+ :home_phone => "5555551213"
1194
+ })
1195
+
1196
+ # add emails
1197
+ import.add_email("user2@example.com")
1198
+
1199
+ # add addresses
1200
+ address = ConstantContact::Components::Address.create(
1201
+ :line1 => "456 Jones Road",
1202
+ :city => "AnyTownShip",
1203
+ :address_type => "PERSONAL",
1204
+ :state_code => "DE",
1205
+ :country_code => "US",
1206
+ :postal_code => "01234"
1207
+ )
1208
+ import.add_address(address)
1209
+
1210
+ # add custom fields
1211
+ custom_field = ConstantContact::Components::CustomField.create(
1212
+ :name => "custom_field_6",
1213
+ :value => "Blue Jeans"
1214
+ )
1215
+ import.add_custom_field(custom_field)
1216
+
1217
+ custom_field = ConstantContact::Components::CustomField.create(
1218
+ :name => "custom_field_12",
1219
+ :value => "Special Order"
1220
+ )
1221
+ import.add_custom_field(custom_field)
1222
+
1223
+ contacts << import
1224
+
1225
+ lists = ['4', '5', '6']
1226
+
1227
+ add_contact = ConstantContact::Components::AddContacts.new(contacts, lists)
1228
+
1229
+ JSON.parse(json_request).should eq(JSON.parse(JSON.generate(add_contact)))
1230
+
1231
+ activity = @api.add_create_contacts_activity(add_contact)
1232
+ activity.should be_kind_of(ConstantContact::Components::Activity)
1233
+ activity.type.should eq('ADD_CONTACTS')
1234
+ end
1235
+ end
1236
+
1237
+ describe "#add_create_contacts_activity_from_file" do
1238
+ it "creates an Add Contacts Activity from a file. Valid file types are txt, csv, xls, xlsx" do
1239
+ content = load_file('add_contacts_request.csv')
1240
+ json = load_file('add_contacts_response.json')
1241
+ lists = 'list1, list2'
1242
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
1243
+
1244
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
1245
+ RestClient.stub(:post).and_return(response)
1246
+
1247
+ activity = @api.add_create_contacts_activity_from_file('contacts.txt', content, lists)
1248
+ activity.should be_kind_of(ConstantContact::Components::Activity)
1249
+ activity.type.should eq('ADD_CONTACTS')
1250
+ end
1251
+ end
1252
+
1253
+ describe "#add_clear_lists_activity" do
1254
+ it "adds a ClearLists Activity to remove all contacts from the provided lists" do
1255
+ json_clear_lists = load_file('clear_lists_response.json')
1256
+ json_list = load_file('list_response.json')
1257
+
1258
+ lists = []
1259
+ lists << ConstantContact::Components::ContactList.create(JSON.parse(json_list))
1260
+
1261
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
1262
+
1263
+ response = RestClient::Response.create(json_clear_lists, net_http_resp, {}, @request)
1264
+ RestClient.stub(:post).and_return(response)
1265
+
1266
+ activity = @api.add_clear_lists_activity(lists)
1267
+ activity.should be_kind_of(ConstantContact::Components::Activity)
1268
+ activity.type.should eq('CLEAR_CONTACTS_FROM_LISTS')
1269
+ end
1270
+ end
1271
+
1272
+ describe "#add_remove_contacts_from_lists_activity" do
1273
+ it "adds a Remove Contacts From Lists Activity" do
1274
+ json = load_file('remove_contacts_response.json')
1275
+ lists = 'list1, list2'
1276
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
1277
+
1278
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
1279
+ RestClient.stub(:post).and_return(response)
1280
+ email_addresses = ["djellesma@constantcontact.com"]
1281
+
1282
+ activity = @api.add_remove_contacts_from_lists_activity(
1283
+ email_addresses, lists)
1284
+ activity.should be_kind_of(ConstantContact::Components::Activity)
1285
+ activity.type.should eq('REMOVE_CONTACTS_FROM_LISTS')
1286
+ end
1287
+ end
1288
+
1289
+ describe "#add_remove_contacts_from_lists_activity_from_file" do
1290
+ it "adds a Remove Contacts From Lists Activity from a file. Valid file types are txt, csv, xls, xlsx" do
1291
+ content = load_file('remove_contacts_request.txt')
1292
+ json = load_file('remove_contacts_response.json')
1293
+ lists = 'list1, list2'
1294
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
1295
+
1296
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
1297
+ RestClient.stub(:post).and_return(response)
1298
+
1299
+ activity = @api.add_remove_contacts_from_lists_activity_from_file('contacts.txt', content, lists)
1300
+ activity.should be_kind_of(ConstantContact::Components::Activity)
1301
+ activity.type.should eq('REMOVE_CONTACTS_FROM_LISTS')
1302
+ end
1303
+ end
1304
+
1305
+ describe "#add_export_contacts_activity" do
1306
+ it "creates an Export Contacts Activity" do
1307
+ json_request = load_file('export_contacts_request.json')
1308
+ json_response = load_file('export_contacts_response.json')
1309
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
1310
+
1311
+ response = RestClient::Response.create(json_response, net_http_resp, {}, @request)
1312
+ RestClient.stub(:post).and_return(response)
1313
+ export_contacts = ConstantContact::Components::ExportContacts.new(JSON.parse(json_request))
1314
+
1315
+ activity = @api.add_export_contacts_activity(export_contacts)
1316
+ activity.should be_kind_of(ConstantContact::Components::Activity)
1317
+ activity.type.should eq('EXPORT_CONTACTS')
1318
+ end
1319
+ end
1320
+
1321
+ describe "#get_library_info" do
1322
+ it "retrieves a MyLibrary usage information" do
1323
+ json_response = load_file('library_info_response.json')
1324
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
1325
+
1326
+ response = RestClient::Response.create(json_response, net_http_resp, {}, @request)
1327
+ RestClient.stub(:get).and_return(response)
1328
+
1329
+ info = @api.get_library_info()
1330
+ info.should be_kind_of(ConstantContact::Components::LibrarySummary)
1331
+ info.usage_summary['folder_count'].should eq(6)
1332
+ end
1333
+ end
1334
+
1335
+ describe "#get_library_folders" do
1336
+ it "retrieves a list of MyLibrary folders" do
1337
+ json_response = load_file('library_folders_response.json')
1338
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
1339
+
1340
+ response = RestClient::Response.create(json_response, net_http_resp, {}, @request)
1341
+ RestClient.stub(:get).and_return(response)
1342
+
1343
+ folders = @api.get_library_folders({:limit => 2})
1344
+ folders.should be_kind_of(ConstantContact::Components::ResultSet)
1345
+ folders.results.first.should be_kind_of(ConstantContact::Components::LibraryFolder)
1346
+ folders.results.first.name.should eq('backgrounds')
1347
+ end
1348
+ end
1349
+
1350
+ describe "#add_library_folder" do
1351
+ it "creates a new MyLibrary folder" do
1352
+ json = load_file('library_folder_response.json')
1353
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
1354
+
1355
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
1356
+ RestClient.stub(:post).and_return(response)
1357
+ new_folder = ConstantContact::Components::LibraryFolder.create(JSON.parse(json))
1358
+
1359
+ folder = @api.add_library_folder(new_folder)
1360
+ folder.should be_kind_of(ConstantContact::Components::LibraryFolder)
1361
+ folder.name.should eq('wildflowers')
1362
+ end
1363
+ end
1364
+
1365
+ describe "#get_library_folder" do
1366
+ it "retrieves a specific MyLibrary folder using the folder_id path parameter" do
1367
+ json = load_file('library_folder_response.json')
1368
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
1369
+
1370
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
1371
+ RestClient.stub(:get).and_return(response)
1372
+
1373
+ folder = @api.get_library_folder(6)
1374
+ folder.should be_kind_of(ConstantContact::Components::LibraryFolder)
1375
+ folder.name.should eq('wildflowers')
1376
+ end
1377
+ end
1378
+
1379
+ describe "#update_library_folder" do
1380
+ it "retrieves a specific MyLibrary folder using the folder_id path parameter" do
1381
+ json = load_file('library_folder_response.json')
1382
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
1383
+
1384
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
1385
+ RestClient.stub(:put).and_return(response)
1386
+ folder = ConstantContact::Components::LibraryFolder.create(JSON.parse(json))
1387
+
1388
+ response = @api.update_library_folder(folder)
1389
+ response.should be_kind_of(ConstantContact::Components::LibraryFolder)
1390
+ response.name.should eq('wildflowers')
1391
+ end
1392
+ end
1393
+
1394
+ describe "#delete_library_folder" do
1395
+ it "deletes a MyLibrary folder" do
1396
+ folder_id = 6
1397
+ net_http_resp = Net::HTTPResponse.new(1.0, 204, 'No Content')
1398
+
1399
+ response = RestClient::Response.create('', net_http_resp, {}, @request)
1400
+ RestClient.stub(:delete).and_return(response)
1401
+
1402
+ result = @api.delete_library_folder(folder_id)
1403
+ result.should be_true
1404
+ end
1405
+ end
1406
+
1407
+ describe "#get_library_trash" do
1408
+ it "retrieve all files in the Trash folder" do
1409
+ json = load_file('library_trash_response.json')
1410
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
1411
+
1412
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
1413
+ RestClient.stub(:get).and_return(response)
1414
+
1415
+ files = @api.get_library_trash({:sort_by => 'SIZE_DESC'})
1416
+ files.should be_kind_of(ConstantContact::Components::ResultSet)
1417
+ files.results.first.should be_kind_of(ConstantContact::Components::LibraryFile)
1418
+ files.results.first.name.should eq('menu_form.pdf')
1419
+ end
1420
+ end
1421
+
1422
+ describe "#delete_library_trash" do
1423
+ it "permanently deletes all files in the Trash folder" do
1424
+ net_http_resp = Net::HTTPResponse.new(1.0, 204, 'No Content')
1425
+
1426
+ response = RestClient::Response.create('', net_http_resp, {}, @request)
1427
+ RestClient.stub(:delete).and_return(response)
1428
+
1429
+ result = @api.delete_library_trash()
1430
+ result.should be_true
1431
+ end
1432
+ end
1433
+
1434
+ describe "#get_library_files" do
1435
+ it "retrieves a collection of MyLibrary files in the Constant Contact account" do
1436
+ json_response = load_file('library_files_response.json')
1437
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
1438
+
1439
+ response = RestClient::Response.create(json_response, net_http_resp, {}, @request)
1440
+ RestClient.stub(:get).and_return(response)
1441
+
1442
+ files = @api.get_library_files({:type => 'ALL'})
1443
+ files.should be_kind_of(ConstantContact::Components::ResultSet)
1444
+ files.results.first.should be_kind_of(ConstantContact::Components::LibraryFile)
1445
+ files.results.first.name.should eq('IMG_0341.JPG')
1446
+ end
1447
+ end
1448
+
1449
+ describe "#get_library_files_by_folder" do
1450
+ it "retrieves a collection of MyLibrary files in the Constant Contact account" do
1451
+ folder_id = -1
1452
+ json_response = load_file('library_files_by_folder_response.json')
1453
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
1454
+
1455
+ response = RestClient::Response.create(json_response, net_http_resp, {}, @request)
1456
+ RestClient.stub(:get).and_return(response)
1457
+
1458
+ files = @api.get_library_files_by_folder(folder_id, {:limit => 10})
1459
+ files.should be_kind_of(ConstantContact::Components::ResultSet)
1460
+ files.results.first.should be_kind_of(ConstantContact::Components::LibraryFile)
1461
+ files.results.first.name.should eq('IMG_0341.JPG')
1462
+ end
1463
+ end
1464
+
1465
+ describe "#get_library_file" do
1466
+ it "retrieve a MyLibrary file using the file_id path parameter" do
1467
+ json = load_file('library_file_response.json')
1468
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
1469
+
1470
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
1471
+ RestClient.stub(:get).and_return(response)
1472
+
1473
+ file = @api.get_library_file(6)
1474
+ file.should be_kind_of(ConstantContact::Components::LibraryFile)
1475
+ file.name.should eq('IMG_0261.JPG')
1476
+ end
1477
+ end
1478
+
1479
+ describe "#add_library_file" do
1480
+ it "adds a new MyLibrary file using the multipart content-type" do
1481
+ file_name = 'logo.jpg'
1482
+ folder_id = 1
1483
+ description = 'Logo'
1484
+ source = 'MyComputer'
1485
+ file_type = 'JPG'
1486
+ contents = load_file('logo.jpg')
1487
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
1488
+ net_http_resp.add_field('Location', '"https://api.d1.constantcontact.com/v2/library/files/123456789')
1489
+
1490
+ response = RestClient::Response.create("", net_http_resp, {}, @request)
1491
+ RestClient.stub(:post).and_return(response)
1492
+
1493
+ response = @api.add_library_file(file_name, folder_id, description, source, file_type, contents)
1494
+ response.should be_kind_of(String)
1495
+ response.should eq('123456789')
1496
+ end
1497
+ end
1498
+
1499
+ describe "#update_library_file" do
1500
+ it "updates information for a specific MyLibrary file" do
1501
+ json = load_file('library_file_response.json')
1502
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
1503
+
1504
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
1505
+ RestClient.stub(:put).and_return(response)
1506
+ file = ConstantContact::Components::LibraryFile.create(JSON.parse(json))
1507
+
1508
+ response = @api.update_library_file(file)
1509
+ response.should be_kind_of(ConstantContact::Components::LibraryFile)
1510
+ response.name.should eq('IMG_0261.JPG')
1511
+ end
1512
+ end
1513
+
1514
+ describe "#delete_library_file" do
1515
+ it "deletes one or more MyLibrary files specified by the fileId path parameter" do
1516
+ file_id = '6, 7'
1517
+ net_http_resp = Net::HTTPResponse.new(1.0, 204, 'No Content')
1518
+
1519
+ response = RestClient::Response.create('', net_http_resp, {}, @request)
1520
+ RestClient.stub(:delete).and_return(response)
1521
+
1522
+ result = @api.delete_library_file(file_id)
1523
+ result.should be_true
1524
+ end
1525
+ end
1526
+
1527
+ describe "#get_library_files_upload_status" do
1528
+ it "retrieves the upload status for one or more MyLibrary files using the file_id path parameter" do
1529
+ file_id = '6, 7'
1530
+ json = load_file('library_files_upload_status_response.json')
1531
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
1532
+
1533
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
1534
+ RestClient.stub(:get).and_return(response)
1535
+
1536
+ statuses = @api.get_library_files_upload_status(file_id)
1537
+ statuses.should be_kind_of(Array)
1538
+ statuses.first.should be_kind_of(ConstantContact::Components::UploadStatus)
1539
+ statuses.first.status.should eq('Active')
1540
+ end
1541
+ end
1542
+
1543
+ describe "#move_library_files" do
1544
+ it "moves one or more MyLibrary files to a different folder in the user's account" do
1545
+ folder_id = 1
1546
+ file_id = '8, 9'
1547
+ json = load_file('library_files_move_results_response.json')
1548
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
1549
+
1550
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
1551
+ RestClient.stub(:put).and_return(response)
1552
+
1553
+ results = @api.move_library_files(folder_id, file_id)
1554
+ results.should be_kind_of(Array)
1555
+ results.first.should be_kind_of(ConstantContact::Components::MoveResults)
1556
+ results.first.uri.should eq('https://api.d1.constantcontact.com/v2/library/files/9')
1557
+ end
1558
+ end
1559
+ end
1560
+ end