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.
- checksums.yaml +7 -0
- data/.rspec +2 -0
- data/README.md +136 -0
- data/constantcontact-ruby.gemspec +31 -0
- data/lib/constantcontact/api.rb +1012 -0
- data/lib/constantcontact/auth/oauth2.rb +105 -0
- data/lib/constantcontact/auth/session_data_store.rb +69 -0
- data/lib/constantcontact/components/account/account_address.rb +26 -0
- data/lib/constantcontact/components/account/account_info.rb +38 -0
- data/lib/constantcontact/components/account/verified_email_address.rb +26 -0
- data/lib/constantcontact/components/activities/activity.rb +43 -0
- data/lib/constantcontact/components/activities/activity_error.rb +26 -0
- data/lib/constantcontact/components/activities/add_contacts.rb +127 -0
- data/lib/constantcontact/components/activities/add_contacts_import_data.rb +46 -0
- data/lib/constantcontact/components/activities/export_contacts.rb +30 -0
- data/lib/constantcontact/components/component.rb +48 -0
- data/lib/constantcontact/components/contacts/address.rb +27 -0
- data/lib/constantcontact/components/contacts/contact.rb +92 -0
- data/lib/constantcontact/components/contacts/contact_list.rb +26 -0
- data/lib/constantcontact/components/contacts/custom_field.rb +26 -0
- data/lib/constantcontact/components/contacts/email_address.rb +33 -0
- data/lib/constantcontact/components/contacts/note.rb +26 -0
- data/lib/constantcontact/components/email_marketing/campaign.rb +83 -0
- data/lib/constantcontact/components/email_marketing/campaign_preview.rb +29 -0
- data/lib/constantcontact/components/email_marketing/click_through_details.rb +27 -0
- data/lib/constantcontact/components/email_marketing/message_footer.rb +29 -0
- data/lib/constantcontact/components/email_marketing/schedule.rb +27 -0
- data/lib/constantcontact/components/email_marketing/test_send.rb +45 -0
- data/lib/constantcontact/components/event_spot/contact.rb +27 -0
- data/lib/constantcontact/components/event_spot/event.rb +69 -0
- data/lib/constantcontact/components/event_spot/event_address.rb +29 -0
- data/lib/constantcontact/components/event_spot/event_fee.rb +27 -0
- data/lib/constantcontact/components/event_spot/event_item.rb +36 -0
- data/lib/constantcontact/components/event_spot/event_item_attribute.rb +26 -0
- data/lib/constantcontact/components/event_spot/event_track.rb +31 -0
- data/lib/constantcontact/components/event_spot/guest.rb +31 -0
- data/lib/constantcontact/components/event_spot/guest_section.rb +34 -0
- data/lib/constantcontact/components/event_spot/notification_option.rb +27 -0
- data/lib/constantcontact/components/event_spot/online_meeting.rb +28 -0
- data/lib/constantcontact/components/event_spot/payment_address.rb +29 -0
- data/lib/constantcontact/components/event_spot/payment_summary.rb +33 -0
- data/lib/constantcontact/components/event_spot/promocode.rb +25 -0
- data/lib/constantcontact/components/event_spot/registrant.rb +52 -0
- data/lib/constantcontact/components/event_spot/registrant_fee.rb +29 -0
- data/lib/constantcontact/components/event_spot/registrant_field.rb +27 -0
- data/lib/constantcontact/components/event_spot/registrant_order.rb +39 -0
- data/lib/constantcontact/components/event_spot/registrant_promo_code.rb +31 -0
- data/lib/constantcontact/components/event_spot/registrant_promo_code_info.rb +27 -0
- data/lib/constantcontact/components/event_spot/registrant_section.rb +34 -0
- data/lib/constantcontact/components/event_spot/sale_item.rb +29 -0
- data/lib/constantcontact/components/library/file/library_file.rb +27 -0
- data/lib/constantcontact/components/library/folder/library_folder.rb +26 -0
- data/lib/constantcontact/components/library/info/library_summary.rb +26 -0
- data/lib/constantcontact/components/library/info/move_results.rb +26 -0
- data/lib/constantcontact/components/library/info/upload_status.rb +26 -0
- data/lib/constantcontact/components/result_set.rb +50 -0
- data/lib/constantcontact/components/tracking/bounce_activity.rb +28 -0
- data/lib/constantcontact/components/tracking/click_activity.rb +26 -0
- data/lib/constantcontact/components/tracking/forward_activity.rb +26 -0
- data/lib/constantcontact/components/tracking/open_activity.rb +26 -0
- data/lib/constantcontact/components/tracking/send_activity.rb +27 -0
- data/lib/constantcontact/components/tracking/tracking_activity.rb +26 -0
- data/lib/constantcontact/components/tracking/tracking_summary.rb +27 -0
- data/lib/constantcontact/components/tracking/unsubscribe_activity.rb +27 -0
- data/lib/constantcontact/exceptions/ctct_exception.rb +25 -0
- data/lib/constantcontact/exceptions/illegal_argument_exception.rb +11 -0
- data/lib/constantcontact/exceptions/oauth2_exception.rb +11 -0
- data/lib/constantcontact/exceptions/webhooks_exception.rb +11 -0
- data/lib/constantcontact/services/account_service.rb +39 -0
- data/lib/constantcontact/services/activity_service.rb +136 -0
- data/lib/constantcontact/services/base_service.rb +68 -0
- data/lib/constantcontact/services/campaign_schedule_service.rb +101 -0
- data/lib/constantcontact/services/campaign_tracking_service.rb +152 -0
- data/lib/constantcontact/services/contact_service.rb +105 -0
- data/lib/constantcontact/services/contact_tracking_service.rb +152 -0
- data/lib/constantcontact/services/email_marketing_service.rb +94 -0
- data/lib/constantcontact/services/event_spot_service.rb +448 -0
- data/lib/constantcontact/services/library_service.rb +281 -0
- data/lib/constantcontact/services/list_service.rb +81 -0
- data/lib/constantcontact/util/config.rb +180 -0
- data/lib/constantcontact/util/helpers.rb +27 -0
- data/lib/constantcontact/version.rb +12 -0
- data/lib/constantcontact/webhooks/helpers/validator.rb +30 -0
- data/lib/constantcontact/webhooks/models/billing_change_notification.rb +27 -0
- data/lib/constantcontact/webhooks/webhooks_util.rb +45 -0
- data/lib/constantcontact.rb +124 -0
- data/spec/constantcontact/api_spec.rb +1560 -0
- data/spec/constantcontact/auth/oauth2_spec.rb +125 -0
- data/spec/constantcontact/components/contacts/address_spec.rb +18 -0
- data/spec/constantcontact/components/contacts/contact_list_spec.rb +18 -0
- data/spec/constantcontact/components/contacts/contact_spec.rb +18 -0
- data/spec/constantcontact/components/contacts/custom_field_spec.rb +18 -0
- data/spec/constantcontact/components/contacts/email_address_spec.rb +18 -0
- data/spec/constantcontact/sdk_spec.rb +24 -0
- data/spec/constantcontact/services/account_service_spec.rb +46 -0
- data/spec/constantcontact/services/activity_service_spec.rb +244 -0
- data/spec/constantcontact/services/base_service_spec.rb +50 -0
- data/spec/constantcontact/services/campaign_schedule_service_spec.rb +115 -0
- data/spec/constantcontact/services/campaign_tracking_service_spec.rb +131 -0
- data/spec/constantcontact/services/contact_service_spec.rb +111 -0
- data/spec/constantcontact/services/contact_tracking_service_spec.rb +131 -0
- data/spec/constantcontact/services/email_marketing_spec.rb +100 -0
- data/spec/constantcontact/services/event_spot_spec.rb +423 -0
- data/spec/constantcontact/services/library_service_spec.rb +252 -0
- data/spec/constantcontact/services/list_service_spec.rb +89 -0
- data/spec/constantcontact/webhooks/webhooks_spec.rb +26 -0
- metadata +243 -0
@@ -0,0 +1,423 @@
|
|
1
|
+
#
|
2
|
+
# event_spot_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::EventSpotService 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_events" do
|
15
|
+
it "returns a set of events" do
|
16
|
+
json = load_file('events.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
|
+
events = ConstantContact::Services::EventSpotService.get_events()
|
22
|
+
events.should be_kind_of(ConstantContact::Components::ResultSet)
|
23
|
+
events.results.collect{|e| e.should be_kind_of(ConstantContact::Components::Event) }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#get_event" do
|
28
|
+
it "returns an event" do
|
29
|
+
json = load_file('event.json')
|
30
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
31
|
+
|
32
|
+
response = RestClient::Response.create(json, net_http_resp, {}, @request)
|
33
|
+
RestClient.stub(:get).and_return(response)
|
34
|
+
event = ConstantContact::Services::EventSpotService.get_event(1)
|
35
|
+
|
36
|
+
event.should be_kind_of(ConstantContact::Components::Event)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#add_event" do
|
41
|
+
it "adds an event" do
|
42
|
+
json = load_file('event.json')
|
43
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
44
|
+
|
45
|
+
response = RestClient::Response.create(json, net_http_resp, {}, @request)
|
46
|
+
RestClient.stub(:post).and_return(response)
|
47
|
+
event = ConstantContact::Components::Event.create(JSON.parse(json))
|
48
|
+
added = ConstantContact::Services::EventSpotService.add_event(event)
|
49
|
+
|
50
|
+
added.should respond_to(:id)
|
51
|
+
added.id.should_not be_empty
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "#publish_event" do
|
56
|
+
it "updates an event with status of ACTIVE" do
|
57
|
+
json = load_file('event.json')
|
58
|
+
hash = JSON.parse json
|
59
|
+
hash["status"] = "ACTIVE"
|
60
|
+
|
61
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
62
|
+
response = RestClient::Response.create(hash.to_json, net_http_resp, {}, @request)
|
63
|
+
RestClient.stub(:patch).and_return(response)
|
64
|
+
|
65
|
+
event = ConstantContact::Components::Event.create(JSON.parse(json))
|
66
|
+
updated = ConstantContact::Services::EventSpotService.publish_event(event)
|
67
|
+
updated.should be_kind_of(ConstantContact::Components::Event)
|
68
|
+
updated.should respond_to(:status)
|
69
|
+
updated.status.should eq("ACTIVE")
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "#cancel_event" do
|
74
|
+
it "updates an event's status to CANCELLED" do
|
75
|
+
json = load_file('event.json')
|
76
|
+
hash = JSON.parse json
|
77
|
+
hash["status"] = "CANCELLED"
|
78
|
+
|
79
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
80
|
+
response = RestClient::Response.create(hash.to_json, net_http_resp, {}, @request)
|
81
|
+
RestClient.stub(:patch).and_return(response)
|
82
|
+
|
83
|
+
event = ConstantContact::Components::Event.create(JSON.parse(json))
|
84
|
+
updated = ConstantContact::Services::EventSpotService.cancel_event(event)
|
85
|
+
updated.should be_kind_of(ConstantContact::Components::Event)
|
86
|
+
updated.should respond_to(:status)
|
87
|
+
updated.status.should eq("CANCELLED")
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe "#get_fees" do
|
92
|
+
it "returns an array of fees for an event" do
|
93
|
+
event_json = load_file('event.json')
|
94
|
+
fees_json = load_file('fees.json')
|
95
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
96
|
+
|
97
|
+
response = RestClient::Response.create(fees_json, net_http_resp, {}, @request)
|
98
|
+
RestClient.stub(:get).and_return(response)
|
99
|
+
event = ConstantContact::Components::Event.create(JSON.parse(event_json))
|
100
|
+
fees = ConstantContact::Services::EventSpotService.get_fees(event)
|
101
|
+
#fees.should be_kind_of(ConstantContact::Components::ResultSet)
|
102
|
+
#fees.results.collect{|f| f.should be_kind_of(ConstantContact::Components::Fee) }
|
103
|
+
|
104
|
+
fees.should be_kind_of(Array) # inconsistent with oether APIs.
|
105
|
+
fees.collect{|f| f.should be_kind_of(ConstantContact::Components::EventFee) }
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe "#get_fee" do
|
110
|
+
it "return an event fee" do
|
111
|
+
event_json = load_file('event.json')
|
112
|
+
fee_json = load_file('fees.json')
|
113
|
+
|
114
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
115
|
+
response = RestClient::Response.create(fee_json, net_http_resp, {}, @request)
|
116
|
+
RestClient.stub(:get).and_return(response)
|
117
|
+
|
118
|
+
event = ConstantContact::Components::Event.create(JSON.parse(event_json))
|
119
|
+
fee = ConstantContact::Components::EventFee.create(JSON.parse(fee_json))
|
120
|
+
retrieved = ConstantContact::Services::EventSpotService.get_fee(event, fee)
|
121
|
+
retrieved.should be_kind_of(ConstantContact::Components::EventFee)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
describe "#add_fee" do
|
126
|
+
it "adds an event fee" do
|
127
|
+
event_json = load_file('event.json')
|
128
|
+
fee_json = load_file('fee.json')
|
129
|
+
|
130
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 201, 'Created')
|
131
|
+
response = RestClient::Response.create(fee_json, net_http_resp, {}, @request)
|
132
|
+
RestClient.stub(:post).and_return(response)
|
133
|
+
|
134
|
+
event = ConstantContact::Components::Event.create(JSON.parse(event_json))
|
135
|
+
fee = ConstantContact::Components::EventFee.create(JSON.parse(fee_json))
|
136
|
+
added = ConstantContact::Services::EventSpotService.add_fee(event, fee)
|
137
|
+
added.should be_kind_of(ConstantContact::Components::EventFee)
|
138
|
+
added.id.should_not be_empty
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
describe "#update_fee" do
|
143
|
+
it "updates an event fee" do
|
144
|
+
event_json = load_file('event.json')
|
145
|
+
fee_json = load_file('fee.json')
|
146
|
+
hash = JSON.parse fee_json
|
147
|
+
hash['fee'] += 1
|
148
|
+
|
149
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 201, 'Created')
|
150
|
+
response = RestClient::Response.create(hash.to_json, net_http_resp, {}, @request)
|
151
|
+
RestClient.stub(:put).and_return(response)
|
152
|
+
|
153
|
+
event = ConstantContact::Components::Event.create(JSON.parse(event_json))
|
154
|
+
fee = ConstantContact::Components::EventFee.create(JSON.parse(fee_json))
|
155
|
+
updated = ConstantContact::Services::EventSpotService.update_fee(event, fee)
|
156
|
+
updated.should be_kind_of(ConstantContact::Components::EventFee)
|
157
|
+
updated.fee.should_not eq(fee.fee)
|
158
|
+
updated.fee.should eq(fee.fee + 1)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
describe "#delete_fee" do
|
163
|
+
it "deletes an event fee" do
|
164
|
+
event_json = load_file('event.json')
|
165
|
+
fee_json = load_file('fees.json')
|
166
|
+
|
167
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 204, 'No Content')
|
168
|
+
response = RestClient::Response.create('', net_http_resp, {}, @request)
|
169
|
+
RestClient.stub(:delete).and_return(response)
|
170
|
+
|
171
|
+
event = ConstantContact::Components::Event.create(JSON.parse(event_json))
|
172
|
+
fee = ConstantContact::Components::EventFee.create(JSON.parse(fee_json))
|
173
|
+
ConstantContact::Services::EventSpotService.delete_fee(event, fee).should be_true
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
describe "#get_registrants" do
|
178
|
+
it "returns an array of event registrants" do
|
179
|
+
event_json = load_file('event.json')
|
180
|
+
registrants_json = load_file('registrants.json')
|
181
|
+
|
182
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 201, 'Created')
|
183
|
+
response = RestClient::Response.create(registrants_json, net_http_resp, {}, @request)
|
184
|
+
RestClient.stub(:get).and_return(response)
|
185
|
+
|
186
|
+
event = ConstantContact::Components::Event.create(JSON.parse(event_json))
|
187
|
+
registrants = ConstantContact::Services::EventSpotService.get_registrants(event)
|
188
|
+
registrants.should be_kind_of(ConstantContact::Components::ResultSet)
|
189
|
+
registrants.results.collect{|r| r .should be_kind_of(ConstantContact::Components::Registrant) }
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
describe "#get_registrant" do
|
194
|
+
it "returns an event registrant" do
|
195
|
+
event_json = load_file('event.json')
|
196
|
+
registrant_json = load_file('registrant.json')
|
197
|
+
|
198
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 201, 'Created')
|
199
|
+
response = RestClient::Response.create(registrant_json, net_http_resp, {}, @request)
|
200
|
+
RestClient.stub(:get).and_return(response)
|
201
|
+
|
202
|
+
event = ConstantContact::Components::Event.create(JSON.parse(event_json))
|
203
|
+
registrant = ConstantContact::Components::Registrant.create(JSON.parse(registrant_json))
|
204
|
+
retrieved = ConstantContact::Services::EventSpotService.get_registrant(event, registrant)
|
205
|
+
retrieved.should be_kind_of(ConstantContact::Components::Registrant)
|
206
|
+
retrieved.id.should_not be_empty
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
describe "#get_event_items" do
|
211
|
+
it "returns an array of event items" do
|
212
|
+
json_response = load_file('event_items_response.json')
|
213
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
214
|
+
|
215
|
+
response = RestClient::Response.create(json_response, net_http_resp, {}, @request)
|
216
|
+
RestClient.stub(:get).and_return(response)
|
217
|
+
|
218
|
+
results = ConstantContact::Services::EventSpotService.get_event_items(1)
|
219
|
+
results.should be_kind_of(Array)
|
220
|
+
results.first.should be_kind_of(ConstantContact::Components::EventItem)
|
221
|
+
results.first.name.should eq('Running Belt')
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
describe "#get_event_item" do
|
226
|
+
it "returns an event item" do
|
227
|
+
json = load_file('event_item_response.json')
|
228
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
229
|
+
|
230
|
+
response = RestClient::Response.create(json, net_http_resp, {}, @request)
|
231
|
+
RestClient.stub(:get).and_return(response)
|
232
|
+
|
233
|
+
result = ConstantContact::Services::EventSpotService.get_event_item(1, 1)
|
234
|
+
result.should be_kind_of(ConstantContact::Components::EventItem)
|
235
|
+
result.name.should eq('Running Belt')
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
describe "#add_event_item" do
|
240
|
+
it "adds an event item" do
|
241
|
+
json = load_file('event_item_response.json')
|
242
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
243
|
+
|
244
|
+
response = RestClient::Response.create(json, net_http_resp, {}, @request)
|
245
|
+
RestClient.stub(:post).and_return(response)
|
246
|
+
event_item = ConstantContact::Components::EventItem.create(JSON.parse(json))
|
247
|
+
|
248
|
+
result = ConstantContact::Services::EventSpotService.add_event_item(1, event_item)
|
249
|
+
result.should be_kind_of(ConstantContact::Components::EventItem)
|
250
|
+
result.name.should eq('Running Belt')
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
describe "#delete_event_item" do
|
255
|
+
it "deletes an event item" do
|
256
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 204, 'No Content')
|
257
|
+
|
258
|
+
response = RestClient::Response.create('', net_http_resp, {}, @request)
|
259
|
+
RestClient.stub(:delete).and_return(response)
|
260
|
+
|
261
|
+
result = ConstantContact::Services::EventSpotService.delete_event_item(1, 1)
|
262
|
+
result.should be_true
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
describe "#update_event_item" do
|
267
|
+
it "updates an event item" do
|
268
|
+
json = load_file('event_item_response.json')
|
269
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
270
|
+
|
271
|
+
response = RestClient::Response.create(json, net_http_resp, {}, @request)
|
272
|
+
RestClient.stub(:put).and_return(response)
|
273
|
+
event_item = ConstantContact::Components::EventItem.create(JSON.parse(json))
|
274
|
+
|
275
|
+
result = ConstantContact::Services::EventSpotService.update_event_item(1, event_item)
|
276
|
+
result.should be_kind_of(ConstantContact::Components::EventItem)
|
277
|
+
result.name.should eq('Running Belt')
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
describe "#get_event_item_attributes" do
|
282
|
+
it "returns an array of event item attributes" do
|
283
|
+
json_response = load_file('event_item_attributes_response.json')
|
284
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
285
|
+
|
286
|
+
response = RestClient::Response.create(json_response, net_http_resp, {}, @request)
|
287
|
+
RestClient.stub(:get).and_return(response)
|
288
|
+
|
289
|
+
results = ConstantContact::Services::EventSpotService.get_event_item_attributes(1, 1)
|
290
|
+
results.should be_kind_of(Array)
|
291
|
+
results.first.should be_kind_of(ConstantContact::Components::EventItemAttribute)
|
292
|
+
results.first.name.should eq('Royal Blue')
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
describe "#get_event_item_attribute" do
|
297
|
+
it "returns an event item attribute" do
|
298
|
+
json = load_file('event_item_attribute_response.json')
|
299
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
300
|
+
|
301
|
+
response = RestClient::Response.create(json, net_http_resp, {}, @request)
|
302
|
+
RestClient.stub(:get).and_return(response)
|
303
|
+
|
304
|
+
result = ConstantContact::Services::EventSpotService.get_event_item_attribute(1, 1, 1)
|
305
|
+
result.should be_kind_of(ConstantContact::Components::EventItemAttribute)
|
306
|
+
result.name.should eq('Hi-Vis Green')
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
310
|
+
describe "#add_event_item_attribute" do
|
311
|
+
it "adds an event item attribute" do
|
312
|
+
json = load_file('event_item_attribute_response.json')
|
313
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
314
|
+
|
315
|
+
response = RestClient::Response.create(json, net_http_resp, {}, @request)
|
316
|
+
RestClient.stub(:post).and_return(response)
|
317
|
+
event_item_attribute = ConstantContact::Components::EventItemAttribute.create(JSON.parse(json))
|
318
|
+
|
319
|
+
result = ConstantContact::Services::EventSpotService.add_event_item_attribute(1, 1, event_item_attribute)
|
320
|
+
result.should be_kind_of(ConstantContact::Components::EventItemAttribute)
|
321
|
+
result.name.should eq('Hi-Vis Green')
|
322
|
+
end
|
323
|
+
end
|
324
|
+
|
325
|
+
describe "#delete_event_item_attribute" do
|
326
|
+
it "deletes an event item attribute" do
|
327
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 204, 'No Content')
|
328
|
+
|
329
|
+
response = RestClient::Response.create('', net_http_resp, {}, @request)
|
330
|
+
RestClient.stub(:delete).and_return(response)
|
331
|
+
|
332
|
+
result = ConstantContact::Services::EventSpotService.delete_event_item_attribute(1, 1, 1)
|
333
|
+
result.should be_true
|
334
|
+
end
|
335
|
+
end
|
336
|
+
|
337
|
+
describe "#update_event_item_attribute" do
|
338
|
+
it "updates an event item attribute" do
|
339
|
+
json = load_file('event_item_attribute_response.json')
|
340
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
341
|
+
|
342
|
+
response = RestClient::Response.create(json, net_http_resp, {}, @request)
|
343
|
+
RestClient.stub(:put).and_return(response)
|
344
|
+
event_item_attribute = ConstantContact::Components::EventItemAttribute.create(JSON.parse(json))
|
345
|
+
|
346
|
+
result = ConstantContact::Services::EventSpotService.update_event_item_attribute(1, 1, event_item_attribute)
|
347
|
+
result.should be_kind_of(ConstantContact::Components::EventItemAttribute)
|
348
|
+
result.name.should eq('Hi-Vis Green')
|
349
|
+
end
|
350
|
+
end
|
351
|
+
|
352
|
+
describe "#get_promocodes" do
|
353
|
+
it "returns an array of promocodes" do
|
354
|
+
json_response = load_file('promocodes_response.json')
|
355
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
356
|
+
|
357
|
+
response = RestClient::Response.create(json_response, net_http_resp, {}, @request)
|
358
|
+
RestClient.stub(:get).and_return(response)
|
359
|
+
|
360
|
+
results = ConstantContact::Services::EventSpotService.get_promocodes(1)
|
361
|
+
results.should be_kind_of(Array)
|
362
|
+
results.first.should be_kind_of(ConstantContact::Components::Promocode)
|
363
|
+
results.first.code_name.should eq('REDUCED_FEE')
|
364
|
+
end
|
365
|
+
end
|
366
|
+
|
367
|
+
describe "#get_promocode" do
|
368
|
+
it "returns a promocode" do
|
369
|
+
json = load_file('promocode_response.json')
|
370
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
371
|
+
|
372
|
+
response = RestClient::Response.create(json, net_http_resp, {}, @request)
|
373
|
+
RestClient.stub(:get).and_return(response)
|
374
|
+
|
375
|
+
result = ConstantContact::Services::EventSpotService.get_promocode(1, 1)
|
376
|
+
result.should be_kind_of(ConstantContact::Components::Promocode)
|
377
|
+
result.code_name.should eq('TOTAL_FEE')
|
378
|
+
end
|
379
|
+
end
|
380
|
+
|
381
|
+
describe "#add_promocode" do
|
382
|
+
it "adds a promocode" do
|
383
|
+
json = load_file('promocode_response.json')
|
384
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
385
|
+
|
386
|
+
response = RestClient::Response.create(json, net_http_resp, {}, @request)
|
387
|
+
RestClient.stub(:post).and_return(response)
|
388
|
+
promocode = ConstantContact::Components::Promocode.create(JSON.parse(json))
|
389
|
+
|
390
|
+
result = ConstantContact::Services::EventSpotService.add_promocode(1, promocode)
|
391
|
+
result.should be_kind_of(ConstantContact::Components::Promocode)
|
392
|
+
result.code_name.should eq('TOTAL_FEE')
|
393
|
+
end
|
394
|
+
end
|
395
|
+
|
396
|
+
describe "#delete_promocode" do
|
397
|
+
it "deletes a promocode" do
|
398
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 204, 'No Content')
|
399
|
+
|
400
|
+
response = RestClient::Response.create('', net_http_resp, {}, @request)
|
401
|
+
RestClient.stub(:delete).and_return(response)
|
402
|
+
|
403
|
+
result = ConstantContact::Services::EventSpotService.delete_promocode(1, 1)
|
404
|
+
result.should be_true
|
405
|
+
end
|
406
|
+
end
|
407
|
+
|
408
|
+
describe "#update_promocode" do
|
409
|
+
it "updates an event item" do
|
410
|
+
json = load_file('promocode_response.json')
|
411
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
412
|
+
|
413
|
+
response = RestClient::Response.create(json, net_http_resp, {}, @request)
|
414
|
+
RestClient.stub(:put).and_return(response)
|
415
|
+
promocode = ConstantContact::Components::Promocode.create(JSON.parse(json))
|
416
|
+
|
417
|
+
result = ConstantContact::Services::EventSpotService.update_promocode(1, promocode)
|
418
|
+
result.should be_kind_of(ConstantContact::Components::Promocode)
|
419
|
+
result.code_name.should eq('TOTAL_FEE')
|
420
|
+
end
|
421
|
+
end
|
422
|
+
|
423
|
+
end
|
@@ -0,0 +1,252 @@
|
|
1
|
+
#
|
2
|
+
# library_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::LibraryService 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_library_info" do
|
15
|
+
it "retrieves a MyLibrary usage information" do
|
16
|
+
json_response = load_file('library_info_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
|
+
info = ConstantContact::Services::LibraryService.get_library_info()
|
23
|
+
info.should be_kind_of(ConstantContact::Components::LibrarySummary)
|
24
|
+
info.usage_summary['folder_count'].should eq(6)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "#get_library_folders" do
|
29
|
+
it "retrieves a list of MyLibrary folders" do
|
30
|
+
json_response = load_file('library_folders_response.json')
|
31
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
32
|
+
|
33
|
+
response = RestClient::Response.create(json_response, net_http_resp, {}, @request)
|
34
|
+
RestClient.stub(:get).and_return(response)
|
35
|
+
|
36
|
+
folders = ConstantContact::Services::LibraryService.get_library_folders({:limit => 2})
|
37
|
+
folders.should be_kind_of(ConstantContact::Components::ResultSet)
|
38
|
+
folders.results.first.should be_kind_of(ConstantContact::Components::LibraryFolder)
|
39
|
+
folders.results.first.name.should eq('backgrounds')
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "#add_library_folder" do
|
44
|
+
it "creates a new MyLibrary folder" do
|
45
|
+
json = load_file('library_folder_response.json')
|
46
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
47
|
+
|
48
|
+
response = RestClient::Response.create(json, net_http_resp, {}, @request)
|
49
|
+
RestClient.stub(:post).and_return(response)
|
50
|
+
new_folder = ConstantContact::Components::LibraryFolder.create(JSON.parse(json))
|
51
|
+
|
52
|
+
folder = ConstantContact::Services::LibraryService.add_library_folder(new_folder)
|
53
|
+
folder.should be_kind_of(ConstantContact::Components::LibraryFolder)
|
54
|
+
folder.name.should eq('wildflowers')
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "#get_library_folder" do
|
59
|
+
it "retrieves a specific MyLibrary folder using the folder_id path parameter" do
|
60
|
+
json = load_file('library_folder_response.json')
|
61
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
62
|
+
|
63
|
+
response = RestClient::Response.create(json, net_http_resp, {}, @request)
|
64
|
+
RestClient.stub(:get).and_return(response)
|
65
|
+
|
66
|
+
folder = ConstantContact::Services::LibraryService.get_library_folder(6)
|
67
|
+
folder.should be_kind_of(ConstantContact::Components::LibraryFolder)
|
68
|
+
folder.name.should eq('wildflowers')
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "#update_library_folder" do
|
73
|
+
it "retrieves a specific MyLibrary folder using the folder_id path parameter" do
|
74
|
+
json = load_file('library_folder_response.json')
|
75
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
76
|
+
|
77
|
+
response = RestClient::Response.create(json, net_http_resp, {}, @request)
|
78
|
+
RestClient.stub(:put).and_return(response)
|
79
|
+
folder = ConstantContact::Components::LibraryFolder.create(JSON.parse(json))
|
80
|
+
|
81
|
+
response = ConstantContact::Services::LibraryService.update_library_folder(folder)
|
82
|
+
response.should be_kind_of(ConstantContact::Components::LibraryFolder)
|
83
|
+
response.name.should eq('wildflowers')
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "#delete_library_folder" do
|
88
|
+
it "deletes a MyLibrary folder" do
|
89
|
+
folder_id = 6
|
90
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 204, 'No Content')
|
91
|
+
|
92
|
+
response = RestClient::Response.create('', net_http_resp, {}, @request)
|
93
|
+
RestClient.stub(:delete).and_return(response)
|
94
|
+
|
95
|
+
result = ConstantContact::Services::LibraryService.delete_library_folder(folder_id)
|
96
|
+
result.should be_true
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe "#get_library_trash" do
|
101
|
+
it "retrieve all files in the Trash folder" do
|
102
|
+
json = load_file('library_trash_response.json')
|
103
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
104
|
+
|
105
|
+
response = RestClient::Response.create(json, net_http_resp, {}, @request)
|
106
|
+
RestClient.stub(:get).and_return(response)
|
107
|
+
|
108
|
+
files = ConstantContact::Services::LibraryService.get_library_trash({:sort_by => 'SIZE_DESC'})
|
109
|
+
files.should be_kind_of(ConstantContact::Components::ResultSet)
|
110
|
+
files.results.first.should be_kind_of(ConstantContact::Components::LibraryFile)
|
111
|
+
files.results.first.name.should eq('menu_form.pdf')
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe "#delete_library_trash" do
|
116
|
+
it "permanently deletes all files in the Trash folder" do
|
117
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 204, 'No Content')
|
118
|
+
|
119
|
+
response = RestClient::Response.create('', net_http_resp, {}, @request)
|
120
|
+
RestClient.stub(:delete).and_return(response)
|
121
|
+
|
122
|
+
result = ConstantContact::Services::LibraryService.delete_library_trash()
|
123
|
+
result.should be_true
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
describe "#get_library_files" do
|
128
|
+
it "retrieves a collection of MyLibrary files in the Constant Contact account" do
|
129
|
+
json_response = load_file('library_files_response.json')
|
130
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
131
|
+
|
132
|
+
response = RestClient::Response.create(json_response, net_http_resp, {}, @request)
|
133
|
+
RestClient.stub(:get).and_return(response)
|
134
|
+
|
135
|
+
files = ConstantContact::Services::LibraryService.get_library_files({:type => 'ALL'})
|
136
|
+
files.should be_kind_of(ConstantContact::Components::ResultSet)
|
137
|
+
files.results.first.should be_kind_of(ConstantContact::Components::LibraryFile)
|
138
|
+
files.results.first.name.should eq('IMG_0341.JPG')
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
describe "#get_library_files_by_folder" do
|
143
|
+
it "retrieves a collection of MyLibrary files in the Constant Contact account" do
|
144
|
+
folder_id = -1
|
145
|
+
json_response = load_file('library_files_by_folder_response.json')
|
146
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
147
|
+
|
148
|
+
response = RestClient::Response.create(json_response, net_http_resp, {}, @request)
|
149
|
+
RestClient.stub(:get).and_return(response)
|
150
|
+
|
151
|
+
files = ConstantContact::Services::LibraryService.get_library_files_by_folder(folder_id, {:limit => 10})
|
152
|
+
files.should be_kind_of(ConstantContact::Components::ResultSet)
|
153
|
+
files.results.first.should be_kind_of(ConstantContact::Components::LibraryFile)
|
154
|
+
files.results.first.name.should eq('IMG_0341.JPG')
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
describe "#get_library_file" do
|
159
|
+
it "retrieve a MyLibrary file using the file_id path parameter" do
|
160
|
+
json = load_file('library_file_response.json')
|
161
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
162
|
+
|
163
|
+
response = RestClient::Response.create(json, net_http_resp, {}, @request)
|
164
|
+
RestClient.stub(:get).and_return(response)
|
165
|
+
|
166
|
+
file = ConstantContact::Services::LibraryService.get_library_file(6)
|
167
|
+
file.should be_kind_of(ConstantContact::Components::LibraryFile)
|
168
|
+
file.name.should eq('IMG_0261.JPG')
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
describe "#add_library_file" do
|
173
|
+
it "adds a new MyLibrary file using the multipart content-type" do
|
174
|
+
file_name = 'logo.jpg'
|
175
|
+
folder_id = 1
|
176
|
+
description = 'Logo'
|
177
|
+
source = 'MyComputer'
|
178
|
+
file_type = 'JPG'
|
179
|
+
contents = load_file('logo.jpg')
|
180
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
181
|
+
net_http_resp.add_field('Location', 'https://api.d1.constantcontact.com/v2/library/files/123456789')
|
182
|
+
|
183
|
+
response = RestClient::Response.create("", net_http_resp, {}, @request)
|
184
|
+
RestClient.stub(:post).and_return(response)
|
185
|
+
|
186
|
+
response = ConstantContact::Services::LibraryService.add_library_file(file_name, folder_id, description, source, file_type, contents)
|
187
|
+
response.should be_kind_of(String)
|
188
|
+
response.should eq('123456789')
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
describe "#update_library_file" do
|
193
|
+
it "updates information for a specific MyLibrary file" do
|
194
|
+
json = load_file('library_file_response.json')
|
195
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
196
|
+
|
197
|
+
response = RestClient::Response.create(json, net_http_resp, {}, @request)
|
198
|
+
RestClient.stub(:put).and_return(response)
|
199
|
+
file = ConstantContact::Components::LibraryFile.create(JSON.parse(json))
|
200
|
+
|
201
|
+
response = ConstantContact::Services::LibraryService.update_library_file(file)
|
202
|
+
response.should be_kind_of(ConstantContact::Components::LibraryFile)
|
203
|
+
response.name.should eq('IMG_0261.JPG')
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
describe "#delete_library_file" do
|
208
|
+
it "deletes one or more MyLibrary files specified by the fileId path parameter" do
|
209
|
+
file_id = '6, 7'
|
210
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 204, 'No Content')
|
211
|
+
|
212
|
+
response = RestClient::Response.create('', net_http_resp, {}, @request)
|
213
|
+
RestClient.stub(:delete).and_return(response)
|
214
|
+
|
215
|
+
result = ConstantContact::Services::LibraryService.delete_library_file(file_id)
|
216
|
+
result.should be_true
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
describe "#get_library_files_upload_status" do
|
221
|
+
it "retrieves the upload status for one or more MyLibrary files using the file_id path parameter" do
|
222
|
+
file_id = '6, 7'
|
223
|
+
json = load_file('library_files_upload_status_response.json')
|
224
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
225
|
+
|
226
|
+
response = RestClient::Response.create(json, net_http_resp, {}, @request)
|
227
|
+
RestClient.stub(:get).and_return(response)
|
228
|
+
|
229
|
+
statuses = ConstantContact::Services::LibraryService.get_library_files_upload_status(file_id)
|
230
|
+
statuses.should be_kind_of(Array)
|
231
|
+
statuses.first.should be_kind_of(ConstantContact::Components::UploadStatus)
|
232
|
+
statuses.first.status.should eq('Active')
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
describe "#move_library_files" do
|
237
|
+
it "moves one or more MyLibrary files to a different folder in the user's account" do
|
238
|
+
folder_id = 1
|
239
|
+
file_id = '8, 9'
|
240
|
+
json = load_file('library_files_move_results_response.json')
|
241
|
+
net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
|
242
|
+
|
243
|
+
response = RestClient::Response.create(json, net_http_resp, {}, @request)
|
244
|
+
RestClient.stub(:put).and_return(response)
|
245
|
+
|
246
|
+
results = ConstantContact::Services::LibraryService.move_library_files(folder_id, file_id)
|
247
|
+
results.should be_kind_of(Array)
|
248
|
+
results.first.should be_kind_of(ConstantContact::Components::MoveResults)
|
249
|
+
results.first.uri.should eq('https://api.d1.constantcontact.com/v2/library/files/9')
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|