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,115 @@
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
+ before(:each) do
11
+ @request = double('http request', :user => nil, :password => nil, :url => 'http://example.com', :redirection_history => nil)
12
+ end
13
+
14
+ describe "#add_schedule" do
15
+ it "creates a new schedule for a campaign" do
16
+ campaign_id = 1
17
+ json = load_file('schedule_response.json')
18
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
19
+
20
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
21
+ RestClient.stub(:post).and_return(response)
22
+ new_schedule = ConstantContact::Components::Schedule.create(JSON.parse(json))
23
+
24
+ schedule = ConstantContact::Services::CampaignScheduleService.add_schedule(
25
+ campaign_id, new_schedule)
26
+ schedule.should be_kind_of(ConstantContact::Components::Schedule)
27
+ schedule.scheduled_date.should eq('2013-05-10T11:07:43.626Z')
28
+ end
29
+ end
30
+
31
+ describe "#get_schedules" do
32
+ it "gets a list of schedules for a campaign" do
33
+ campaign_id = 1
34
+ json = load_file('schedules_response.json')
35
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
36
+
37
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
38
+ RestClient.stub(:get).and_return(response)
39
+
40
+ schedules = ConstantContact::Services::CampaignScheduleService.get_schedules(
41
+ campaign_id)
42
+ schedules.first.should be_kind_of(ConstantContact::Components::Schedule)
43
+ schedules.first.scheduled_date.should eq('2012-12-16T11:07:43.626Z')
44
+ end
45
+ end
46
+
47
+ describe "#get_schedule" do
48
+ it "gets a specific schedule for a campaign" do
49
+ campaign_id = 1
50
+ schedule_id = 1
51
+
52
+ json = load_file('schedule_response.json')
53
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
54
+
55
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
56
+ RestClient.stub(:get).and_return(response)
57
+
58
+ schedule = ConstantContact::Services::CampaignScheduleService.get_schedule(
59
+ campaign_id, schedule_id)
60
+ schedule.should be_kind_of(ConstantContact::Components::Schedule)
61
+ schedule.scheduled_date.should eq('2013-05-10T11:07:43.626Z')
62
+ end
63
+ end
64
+
65
+ describe "#delete_schedule" do
66
+ it "deletes a specific schedule for a campaign" do
67
+ campaign_id = 1
68
+ schedule_id = 1
69
+ net_http_resp = Net::HTTPResponse.new(1.0, 204, 'No Content')
70
+
71
+ response = RestClient::Response.create('', net_http_resp, {}, @request)
72
+ RestClient.stub(:delete).and_return(response)
73
+
74
+ result = ConstantContact::Services::CampaignScheduleService.delete_schedule(
75
+ campaign_id, schedule_id)
76
+ result.should be_true
77
+ end
78
+ end
79
+
80
+ describe "#update_schedule" do
81
+ it "updates a specific schedule for a campaign" do
82
+ campaign_id = 1
83
+ json = load_file('schedule_response.json')
84
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
85
+
86
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
87
+ RestClient.stub(:put).and_return(response)
88
+ schedule = ConstantContact::Components::Schedule.create(JSON.parse(json))
89
+
90
+ result = ConstantContact::Services::CampaignScheduleService.update_schedule(
91
+ campaign_id, schedule)
92
+ result.should be_kind_of(ConstantContact::Components::Schedule)
93
+ result.scheduled_date.should eq('2013-05-10T11:07:43.626Z')
94
+ end
95
+ end
96
+
97
+ describe "#send_test" do
98
+ it "sends a test send of a campaign" do
99
+ campaign_id = 1
100
+ json_request = load_file('test_send_request.json')
101
+ json_response = load_file('test_send_response.json')
102
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
103
+
104
+ response = RestClient::Response.create(json_response, net_http_resp, {}, @request)
105
+ RestClient.stub(:post).and_return(response)
106
+ test_send = ConstantContact::Components::TestSend.create(JSON.parse(json_request))
107
+
108
+ result = ConstantContact::Services::CampaignScheduleService.send_test(
109
+ campaign_id, test_send)
110
+ result.should be_kind_of(ConstantContact::Components::TestSend)
111
+ result.personal_message.should eq('This is a test send of the email campaign message.')
112
+ end
113
+ end
114
+
115
+ end
@@ -0,0 +1,131 @@
1
+ #
2
+ # campaign_tracking_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::CampaignTrackingService do
10
+ before(:each) do
11
+ @request = double('http request', :user => nil, :password => nil, :url => 'http://example.com', :redirection_history => nil)
12
+ end
13
+
14
+ describe "#get_bounces" do
15
+ it "gets bounces for a given campaign" do
16
+ campaign_id = 1
17
+ params = {:limit => 5}
18
+ json = load_file('campaign_tracking_bounces_response.json')
19
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
20
+
21
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
22
+ RestClient.stub(:get).and_return(response)
23
+
24
+ set = ConstantContact::Services::CampaignTrackingService.get_bounces(campaign_id, params)
25
+ set.should be_kind_of(ConstantContact::Components::ResultSet)
26
+ set.results.first.should be_kind_of(ConstantContact::Components::BounceActivity)
27
+ set.results.first.activity_type.should eq('EMAIL_BOUNCE')
28
+ end
29
+ end
30
+
31
+ describe "#get_clicks" do
32
+ it "gets clicks for a given campaign" do
33
+ campaign_id = 1
34
+ params = {:limit => 5}
35
+ json = load_file('campaign_tracking_clicks_response.json')
36
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
37
+
38
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
39
+ RestClient.stub(:get).and_return(response)
40
+
41
+ set = ConstantContact::Services::CampaignTrackingService.get_clicks(campaign_id, params)
42
+ set.should be_kind_of(ConstantContact::Components::ResultSet)
43
+ set.results.first.should be_kind_of(ConstantContact::Components::ClickActivity)
44
+ set.results.first.activity_type.should eq('EMAIL_CLICK')
45
+ end
46
+ end
47
+
48
+ describe "#get_forwards" do
49
+ it "gets forwards for a given campaign" do
50
+ campaign_id = 1
51
+ params = {:limit => 5}
52
+ json = load_file('campaign_tracking_forwards_response.json')
53
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
54
+
55
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
56
+ RestClient.stub(:get).and_return(response)
57
+
58
+ set = ConstantContact::Services::CampaignTrackingService.get_forwards(campaign_id, params)
59
+ set.should be_kind_of(ConstantContact::Components::ResultSet)
60
+ set.results.first.should be_kind_of(ConstantContact::Components::ForwardActivity)
61
+ set.results.first.activity_type.should eq('EMAIL_FORWARD')
62
+ end
63
+ end
64
+
65
+ describe "#get_opens" do
66
+ it "gets opens for a given campaign" do
67
+ campaign_id = 1
68
+ params = {:limit => 5}
69
+ json = load_file('campaign_tracking_opens_response.json')
70
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
71
+
72
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
73
+ RestClient.stub(:get).and_return(response)
74
+
75
+ set = ConstantContact::Services::CampaignTrackingService.get_opens(campaign_id, params)
76
+ set.should be_kind_of(ConstantContact::Components::ResultSet)
77
+ set.results.first.should be_kind_of(ConstantContact::Components::OpenActivity)
78
+ set.results.first.activity_type.should eq('EMAIL_OPEN')
79
+ end
80
+ end
81
+
82
+ describe "#get_sends" do
83
+ it "gets sends for a given campaign" do
84
+ campaign_id = 1
85
+ params = {:limit => 5}
86
+ json = load_file('campaign_tracking_sends_response.json')
87
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
88
+
89
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
90
+ RestClient.stub(:get).and_return(response)
91
+
92
+ set = ConstantContact::Services::CampaignTrackingService.get_sends(campaign_id, params)
93
+ set.should be_kind_of(ConstantContact::Components::ResultSet)
94
+ set.results.first.should be_kind_of(ConstantContact::Components::SendActivity)
95
+ set.results.first.activity_type.should eq('EMAIL_SEND')
96
+ end
97
+ end
98
+
99
+ describe "#get_unsubscribes" do
100
+ it "gets unsubscribes for a given campaign" do
101
+ campaign_id = 1
102
+ params = {:limit => 5}
103
+ json = load_file('campaign_tracking_unsubscribes_response.json')
104
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
105
+
106
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
107
+ RestClient.stub(:get).and_return(response)
108
+
109
+ set = ConstantContact::Services::CampaignTrackingService.get_unsubscribes(campaign_id, params)
110
+ set.should be_kind_of(ConstantContact::Components::ResultSet)
111
+ set.results.first.should be_kind_of(ConstantContact::Components::UnsubscribeActivity)
112
+ set.results.first.activity_type.should eq('EMAIL_UNSUBSCRIBE')
113
+ end
114
+ end
115
+
116
+ describe "#get_summary" do
117
+ it "gets a summary of reporting data for a given campaign" do
118
+ campaign_id = 1
119
+ json = load_file('campaign_tracking_summary_response.json')
120
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
121
+
122
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
123
+ RestClient.stub(:get).and_return(response)
124
+
125
+ summary = ConstantContact::Services::CampaignTrackingService.get_summary(campaign_id)
126
+ summary.should be_kind_of(ConstantContact::Components::TrackingSummary)
127
+ summary.sends.should eq(15)
128
+ end
129
+ end
130
+
131
+ end
@@ -0,0 +1,111 @@
1
+ #
2
+ # contact_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::ContactService do
10
+ before(:each) do
11
+ @request = double('http request', :user => nil, :password => nil, :url => 'http://example.com', :redirection_history => nil)
12
+ end
13
+
14
+ describe "#get_contacts" do
15
+ it "returns an array of contacts" do
16
+ json = load_file('contacts_response.json')
17
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
18
+
19
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
20
+ RestClient.stub(:get).and_return(response)
21
+ contacts = ConstantContact::Services::ContactService.get_contacts()
22
+ contact = contacts.results[0]
23
+
24
+ contacts.should be_kind_of(ConstantContact::Components::ResultSet)
25
+ contact.should be_kind_of(ConstantContact::Components::Contact)
26
+ end
27
+ end
28
+
29
+ describe "#get_contact" do
30
+ it "returns a contact" do
31
+ json = load_file('contact_response.json')
32
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
33
+
34
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
35
+ RestClient.stub(:get).and_return(response)
36
+ contact = ConstantContact::Services::ContactService.get_contact(1)
37
+
38
+ contact.should be_kind_of(ConstantContact::Components::Contact)
39
+ end
40
+ end
41
+
42
+ describe "#add_contact" do
43
+ it "adds a contact" do
44
+ json = load_file('contact_response.json')
45
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
46
+
47
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
48
+ RestClient.stub(:post).and_return(response)
49
+ new_contact = ConstantContact::Components::Contact.create(JSON.parse(json))
50
+ contact = ConstantContact::Services::ContactService.add_contact(new_contact)
51
+
52
+ contact.should be_kind_of(ConstantContact::Components::Contact)
53
+ contact.status.should eq('ACTIVE')
54
+ end
55
+ end
56
+
57
+ describe "#delete_contact" do
58
+ it "deletes a contact" do
59
+ contact_id = 196
60
+ net_http_resp = Net::HTTPResponse.new(1.0, 204, 'No Content')
61
+
62
+ response = RestClient::Response.create('', net_http_resp, {}, @request)
63
+ RestClient.stub(:delete).and_return(response)
64
+
65
+ result = ConstantContact::Services::ContactService.delete_contact(contact_id)
66
+ result.should be_true
67
+ end
68
+ end
69
+
70
+ describe "#delete_contact_from_lists" do
71
+ it "deletes a contact" do
72
+ contact_id = 196
73
+ net_http_resp = Net::HTTPResponse.new(1.0, 204, 'No Content')
74
+
75
+ response = RestClient::Response.create('', net_http_resp, {}, @request)
76
+ RestClient.stub(:delete).and_return(response)
77
+
78
+ result = ConstantContact::Services::ContactService.delete_contact_from_lists(contact_id)
79
+ result.should be_true
80
+ end
81
+ end
82
+
83
+ describe "#delete_contact_from_list" do
84
+ it "deletes a contact" do
85
+ contact_id = 196
86
+ list_id = 1
87
+ net_http_resp = Net::HTTPResponse.new(1.0, 204, 'No Content')
88
+
89
+ response = RestClient::Response.create('', net_http_resp, {}, @request)
90
+ RestClient.stub(:delete).and_return(response)
91
+
92
+ result = ConstantContact::Services::ContactService.delete_contact_from_list(contact_id, list_id)
93
+ result.should be_true
94
+ end
95
+ end
96
+
97
+ describe "#update_contact" do
98
+ it "updates a contact" do
99
+ json = load_file('contact_response.json')
100
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
101
+
102
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
103
+ RestClient.stub(:put).and_return(response)
104
+ contact = ConstantContact::Components::Contact.create(JSON.parse(json))
105
+ result = ConstantContact::Services::ContactService.update_contact(contact)
106
+
107
+ result.should be_kind_of(ConstantContact::Components::Contact)
108
+ result.status.should eq('ACTIVE')
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,131 @@
1
+ #
2
+ # contact_tracking_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::ContactTrackingService do
10
+ before(:each) do
11
+ @request = double('http request', :user => nil, :password => nil, :url => 'http://example.com', :redirection_history => nil)
12
+ end
13
+
14
+ describe "#get_bounces" do
15
+ it "gets bounces for a given contact" do
16
+ contact_id = 1
17
+ params = {:limit => 5}
18
+ json = load_file('contact_tracking_bounces_response.json')
19
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
20
+
21
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
22
+ RestClient.stub(:get).and_return(response)
23
+
24
+ set = ConstantContact::Services::ContactTrackingService.get_bounces(contact_id, params)
25
+ set.should be_kind_of(ConstantContact::Components::ResultSet)
26
+ set.results.first.should be_kind_of(ConstantContact::Components::BounceActivity)
27
+ set.results.first.activity_type.should eq('EMAIL_BOUNCE')
28
+ end
29
+ end
30
+
31
+ describe "#get_clicks" do
32
+ it "gets clicks for a given contact" do
33
+ contact_id = 1
34
+ params = {:limit => 5}
35
+ json = load_file('contact_tracking_clicks_response.json')
36
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
37
+
38
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
39
+ RestClient.stub(:get).and_return(response)
40
+
41
+ set = ConstantContact::Services::ContactTrackingService.get_clicks(contact_id, params)
42
+ set.should be_kind_of(ConstantContact::Components::ResultSet)
43
+ set.results.first.should be_kind_of(ConstantContact::Components::ClickActivity)
44
+ set.results.first.activity_type.should eq('EMAIL_CLICK')
45
+ end
46
+ end
47
+
48
+ describe "#get_forwards" do
49
+ it "gets forwards for a given contact" do
50
+ contact_id = 1
51
+ params = {:limit => 5}
52
+ json = load_file('contact_tracking_forwards_response.json')
53
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
54
+
55
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
56
+ RestClient.stub(:get).and_return(response)
57
+
58
+ set = ConstantContact::Services::ContactTrackingService.get_forwards(contact_id, params)
59
+ set.should be_kind_of(ConstantContact::Components::ResultSet)
60
+ set.results.first.should be_kind_of(ConstantContact::Components::ForwardActivity)
61
+ set.results.first.activity_type.should eq('EMAIL_FORWARD')
62
+ end
63
+ end
64
+
65
+ describe "#get_opens" do
66
+ it "gets opens for a given contact" do
67
+ contact_id = 1
68
+ params = {:limit => 5}
69
+ json = load_file('contact_tracking_opens_response.json')
70
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
71
+
72
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
73
+ RestClient.stub(:get).and_return(response)
74
+
75
+ set = ConstantContact::Services::ContactTrackingService.get_opens(contact_id, params)
76
+ set.should be_kind_of(ConstantContact::Components::ResultSet)
77
+ set.results.first.should be_kind_of(ConstantContact::Components::OpenActivity)
78
+ set.results.first.activity_type.should eq('EMAIL_OPEN')
79
+ end
80
+ end
81
+
82
+ describe "#get_sends" do
83
+ it "gets sends for a given contact" do
84
+ contact_id = 1
85
+ params = {:limit => 5}
86
+ json = load_file('contact_tracking_sends_response.json')
87
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
88
+
89
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
90
+ RestClient.stub(:get).and_return(response)
91
+
92
+ set = ConstantContact::Services::ContactTrackingService.get_sends(contact_id, params)
93
+ set.should be_kind_of(ConstantContact::Components::ResultSet)
94
+ set.results.first.should be_kind_of(ConstantContact::Components::SendActivity)
95
+ set.results.first.activity_type.should eq('EMAIL_SEND')
96
+ end
97
+ end
98
+
99
+ describe "#get_unsubscribes" do
100
+ it "gets unsubscribes for a given contact" do
101
+ contact_id = 1
102
+ params = {:limit => 5}
103
+ json = load_file('contact_tracking_unsubscribes_response.json')
104
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
105
+
106
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
107
+ RestClient.stub(:get).and_return(response)
108
+
109
+ set = ConstantContact::Services::ContactTrackingService.get_unsubscribes(contact_id, params)
110
+ set.should be_kind_of(ConstantContact::Components::ResultSet)
111
+ set.results.first.should be_kind_of(ConstantContact::Components::UnsubscribeActivity)
112
+ set.results.first.activity_type.should eq('EMAIL_UNSUBSCRIBE')
113
+ end
114
+ end
115
+
116
+ describe "#get_summary" do
117
+ it "gets a summary of reporting data for a given contact" do
118
+ contact_id = 1
119
+ json = load_file('contact_tracking_summary_response.json')
120
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
121
+
122
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
123
+ RestClient.stub(:get).and_return(response)
124
+
125
+ summary = ConstantContact::Services::CampaignTrackingService.get_summary(contact_id)
126
+ summary.should be_kind_of(ConstantContact::Components::TrackingSummary)
127
+ summary.sends.should eq(15)
128
+ end
129
+ end
130
+
131
+ end
@@ -0,0 +1,100 @@
1
+ #
2
+ # email_marketing_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::EmailMarketingService do
10
+ before(:each) do
11
+ @request = double('http request', :user => nil, :password => nil, :url => 'http://example.com', :redirection_history => nil)
12
+ end
13
+
14
+ describe "#get_campaigns" do
15
+ it "returns an array of campaigns" do
16
+ json_response = load_file('email_campaigns_response.json')
17
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
18
+
19
+ response = RestClient::Response.create(json_response, net_http_resp, {}, @request)
20
+ RestClient.stub(:get).and_return(response)
21
+
22
+ campaigns = ConstantContact::Services::EmailMarketingService.get_campaigns()
23
+ campaigns.should be_kind_of(ConstantContact::Components::ResultSet)
24
+ campaigns.results.first.should be_kind_of(ConstantContact::Components::Campaign)
25
+ campaigns.results.first.name.should eq('1357157252225')
26
+ end
27
+ end
28
+
29
+ describe "#get_campaign" do
30
+ it "returns a campaign" do
31
+ json_response = load_file('email_campaign_response.json')
32
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
33
+
34
+ response = RestClient::Response.create(json_response, net_http_resp, {}, @request)
35
+ RestClient.stub(:get).and_return(response)
36
+
37
+ campaign = ConstantContact::Services::EmailMarketingService.get_campaign(1)
38
+ campaign.should be_kind_of(ConstantContact::Components::Campaign)
39
+ campaign.name.should eq('Campaign Name')
40
+ end
41
+ end
42
+
43
+ describe "#get_campaign_preview" do
44
+ it "gets the preview of the given campaign" do
45
+ json_response = load_file('email_campaign_preview_response.json')
46
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
47
+
48
+ response = RestClient::Response.create(json_response, net_http_resp, {}, @request)
49
+ RestClient.stub(:get).and_return(response)
50
+
51
+ campaign_preview = ConstantContact::Services::EmailMarketingService.get_campaign_preview(1)
52
+ campaign_preview.should be_kind_of(ConstantContact::Components::CampaignPreview)
53
+ campaign_preview.subject.should eq('Subject Test')
54
+ end
55
+ end
56
+
57
+ describe "#add_campaign" do
58
+ it "adds a campaign" do
59
+ json = load_file('email_campaign_response.json')
60
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
61
+
62
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
63
+ RestClient.stub(:post).and_return(response)
64
+ new_campaign = ConstantContact::Components::Campaign.create(JSON.parse(json))
65
+
66
+ campaign = ConstantContact::Services::EmailMarketingService.add_campaign(new_campaign)
67
+ campaign.should be_kind_of(ConstantContact::Components::Campaign)
68
+ campaign.name.should eq('Campaign Name')
69
+ end
70
+ end
71
+
72
+ describe "#delete_campaign" do
73
+ it "deletes a campaign" do
74
+ json = load_file('email_campaign_response.json')
75
+ net_http_resp = Net::HTTPResponse.new(1.0, 204, 'No Content')
76
+
77
+ response = RestClient::Response.create('', net_http_resp, {}, @request)
78
+ RestClient.stub(:delete).and_return(response)
79
+ campaign = ConstantContact::Components::Campaign.create(JSON.parse(json))
80
+
81
+ result = ConstantContact::Services::EmailMarketingService.delete_campaign(campaign)
82
+ result.should be_true
83
+ end
84
+ end
85
+
86
+ describe "#update_campaign" do
87
+ it "updates a campaign" do
88
+ json = load_file('email_campaign_response.json')
89
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
90
+
91
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
92
+ RestClient.stub(:put).and_return(response)
93
+ campaign = ConstantContact::Components::Campaign.create(JSON.parse(json))
94
+
95
+ result = ConstantContact::Services::EmailMarketingService.update_campaign(campaign)
96
+ result.should be_kind_of(ConstantContact::Components::Campaign)
97
+ result.name.should eq('Campaign Name')
98
+ end
99
+ end
100
+ end