constantcontact 1.1.2 → 1.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 (33) hide show
  1. data/README.md +2 -2
  2. data/constantcontact.gemspec +1 -1
  3. data/lib/constantcontact.rb +15 -2
  4. data/lib/constantcontact/api.rb +164 -21
  5. data/lib/constantcontact/components/event_spot/contact.rb +5 -5
  6. data/lib/constantcontact/components/event_spot/event.rb +28 -22
  7. data/lib/constantcontact/components/event_spot/event_address.rb +29 -0
  8. data/lib/constantcontact/components/event_spot/{fee.rb → event_fee.rb} +7 -7
  9. data/lib/constantcontact/components/event_spot/event_item.rb +36 -0
  10. data/lib/constantcontact/components/event_spot/event_item_attribute.rb +26 -0
  11. data/lib/constantcontact/components/event_spot/event_track.rb +6 -3
  12. data/lib/constantcontact/components/event_spot/guest.rb +6 -6
  13. data/lib/constantcontact/components/event_spot/guest_section.rb +34 -0
  14. data/lib/constantcontact/components/event_spot/notification_option.rb +2 -2
  15. data/lib/constantcontact/components/event_spot/online_meeting.rb +28 -0
  16. data/lib/constantcontact/components/event_spot/payment_address.rb +29 -0
  17. data/lib/constantcontact/components/event_spot/payment_summary.rb +33 -0
  18. data/lib/constantcontact/components/event_spot/promocode.rb +25 -0
  19. data/lib/constantcontact/components/event_spot/registrant.rb +19 -21
  20. data/lib/constantcontact/components/event_spot/registrant_fee.rb +29 -0
  21. data/lib/constantcontact/components/event_spot/registrant_order.rb +39 -0
  22. data/lib/constantcontact/components/event_spot/registrant_promo_code.rb +31 -0
  23. data/lib/constantcontact/components/event_spot/registrant_promo_code_info.rb +27 -0
  24. data/lib/constantcontact/components/event_spot/registrant_section.rb +6 -6
  25. data/lib/constantcontact/components/event_spot/sale_item.rb +15 -13
  26. data/lib/constantcontact/services/event_spot_service.rb +252 -29
  27. data/lib/constantcontact/util/config.rb +12 -6
  28. data/lib/constantcontact/version.rb +1 -1
  29. data/spec/constantcontact/api_spec.rb +221 -21
  30. data/spec/constantcontact/services/event_spot_spec.rb +223 -21
  31. metadata +118 -76
  32. checksums.yaml +0 -7
  33. data/lib/constantcontact/components/event_spot/promo_code.rb +0 -26
@@ -0,0 +1,31 @@
1
+ #
2
+ # registrant_promo_code.rb
3
+ # ConstantContact
4
+ #
5
+ # Copyright (c) 2013 Constant Contact. All rights reserved.
6
+
7
+ module ConstantContact
8
+ module Components
9
+ module EventSpot
10
+ class RegistrantPromoCode < Component
11
+ attr_accessor :total_discount, :promo_code_info
12
+
13
+ # Factory method to create a RegistrantPromoCode object from a hash
14
+ # @param [Hash] props - hash of properties to create object from
15
+ # @return [RegistrantPromoCode]
16
+ def self.create(props)
17
+ obj = RegistrantPromoCode.new
18
+ props.each do |key, value|
19
+ key = key.to_s
20
+ if key == 'promo_code_info'
21
+ obj.send("#{key}=", Components::EventSpot::RegistrantPromoCodeInfo.create(value))
22
+ else
23
+ obj.send("#{key}=", value) if obj.respond_to? key
24
+ end
25
+ end if props
26
+ obj
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,27 @@
1
+ #
2
+ # registrant_promo_code_info.rb
3
+ # ConstantContact
4
+ #
5
+ # Copyright (c) 2013 Constant Contact. All rights reserved.
6
+
7
+ module ConstantContact
8
+ module Components
9
+ module EventSpot
10
+ class RegistrantPromoCodeInfo < Component
11
+ attr_accessor :code_name, :code_type, :discount_amount, :discount_scope, :discount_type, :redemption_count
12
+
13
+ # Factory method to create a RegistrantPromoCode object from a hash
14
+ # @param [Hash] props - hash of properties to create object from
15
+ # @return [RegistrantPromoCodeInfo]
16
+ def self.create(props)
17
+ obj = RegistrantPromoCodeInfo.new
18
+ props.each do |key, value|
19
+ key = key.to_s
20
+ obj.send("#{key}=", value) if obj.respond_to? key
21
+ end if props
22
+ obj
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -10,23 +10,23 @@ module ConstantContact
10
10
  class RegistrantSection < Component
11
11
  attr_accessor :label, :fields
12
12
 
13
- # Factory method to create an event RegistrantSection object from a hash
13
+ # Factory method to create a RegistrantSection object from a hash
14
14
  # @param [Hash] props - hash of properties to create object from
15
- # @return [Campaign]
15
+ # @return [RegistrantSection]
16
16
  def self.create(props)
17
- section = RegistrantSection.new
17
+ obj = RegistrantSection.new
18
18
  props.each do |key, value|
19
19
  key = key.to_s
20
20
  if key == 'fields'
21
21
  value ||= []
22
- section.fields = value.collect do |field|
22
+ obj.fields = value.collect do |field|
23
23
  Components::EventSpot::RegistrantField.create(field)
24
24
  end
25
25
  else
26
- section.send("#{key}=", value) if section.respond_to? key
26
+ obj.send("#{key}=", value) if obj.respond_to? key
27
27
  end
28
28
  end if props
29
- section
29
+ obj
30
30
  end
31
31
  end
32
32
  end
@@ -1,26 +1,28 @@
1
1
  #
2
- # fee.rb
2
+ # sale_item.rb
3
3
  # ConstantContact
4
4
  #
5
5
  # Copyright (c) 2013 Constant Contact. All rights reserved.
6
6
 
7
7
  module ConstantContact
8
8
  module Components
9
- class SaleItem < Component
10
- attr_accessor :id, :amount, :promo_type, :fee_period_type, :type, :name, :quantity
9
+ module EventSpot
10
+ class SaleItem < Component
11
+ attr_accessor :id, :amount, :promo_type, :fee_period_type, :type, :name, :quantity
11
12
 
12
- # Factory method to create an event Fee object from a hash
13
- # @param [Hash] props - hash of properties to create object from
14
- # @return [Campaign]
15
- def self.create(props)
16
- item = SaleItem.new
17
- if props
18
- props.each do |key, value|
19
- key = key.to_s
20
- item.send("#{key}=", value) if item.respond_to? key
13
+ # Factory method to create a SaleItem object from a hash
14
+ # @param [Hash] props - hash of properties to create object from
15
+ # @return [SaleItem]
16
+ def self.create(props)
17
+ obj = SaleItem.new
18
+ if props
19
+ props.each do |key, value|
20
+ key = key.to_s
21
+ obj.send("#{key}=", value) if obj.respond_to? key
22
+ end
21
23
  end
24
+ obj
22
25
  end
23
- item
24
26
  end
25
27
  end
26
28
  end
@@ -58,20 +58,6 @@ module ConstantContact
58
58
  end
59
59
 
60
60
 
61
- # Delete an EventSpot event
62
- # @param [String] access_token - Constant Contact OAuth2 access token
63
- # @param [Integer] event - Valid event id
64
- # @return [Boolean]
65
- def delete_event(access_token, event)
66
- event_id = get_id_for(event)
67
- url = Util::Config.get('endpoints.base_url') +
68
- sprintf(Util::Config.get('endpoints.event'), event_id)
69
- url = build_url(url)
70
- response = RestClient.delete(url, get_headers(access_token))
71
- response.code == 204
72
- end
73
-
74
-
75
61
  # Update a specific EventSpot event
76
62
  # @param [String] access_token - Constant Contact OAuth2 access token
77
63
  # @param [Event] event - Event to be updated
@@ -120,8 +106,8 @@ module ConstantContact
120
106
  # Create a new event fee
121
107
  # @param [String] access_token - Constant Contact OAuth2 access token
122
108
  # @param [Integer] event - Valid event id
123
- # @param [Fee] fee - Event fee to be created
124
- # @return [Fee]
109
+ # @param [EventFee] fee - Event fee to be created
110
+ # @return [EventFee]
125
111
  def add_fee(access_token, event, fee)
126
112
  event_id = get_id_for(event)
127
113
  url = Util::Config.get('endpoints.base_url') +
@@ -129,14 +115,14 @@ module ConstantContact
129
115
  url = build_url(url)
130
116
  payload = fee.to_json
131
117
  response = RestClient.post(url, payload, get_headers(access_token))
132
- Components::Fee.create(JSON.parse(response.body))
118
+ Components::EventFee.create(JSON.parse(response.body))
133
119
  end
134
120
 
135
121
 
136
- # Get a set of event fees
122
+ # Get an array of event fees
137
123
  # @param [String] access_token - Constant Contact OAuth2 access token
138
124
  # @param [Integer] event - Valid event id
139
- # @return [ResultSet<Fee>]
125
+ # @return [Array<EventFee>]
140
126
  def get_fees(access_token, event)
141
127
  event_id = get_id_for(event)
142
128
  url = Util::Config.get('endpoints.base_url') +
@@ -147,7 +133,7 @@ module ConstantContact
147
133
  body = JSON.parse(response.body)
148
134
 
149
135
  fees = body.collect do |fee|
150
- Components::Fee.create(fee)
136
+ Components::EventFee.create(fee)
151
137
  end
152
138
  end
153
139
 
@@ -156,7 +142,7 @@ module ConstantContact
156
142
  # @param [String] access_token - Constant Contact OAuth2 access token
157
143
  # @param [Integer] event - Valid event id
158
144
  # @param [Integer] fee - Valid fee id
159
- # @return [Fee]
145
+ # @return [EventFee]
160
146
  def get_fee(access_token, event, fee)
161
147
  event_id = get_id_for(event)
162
148
  fee_id = get_id_for(fee)
@@ -165,7 +151,7 @@ module ConstantContact
165
151
  url = build_url(url)
166
152
 
167
153
  response = RestClient.get(url, get_headers(access_token))
168
- fee = Components::Fee.create(JSON.parse(response.body))
154
+ fee = Components::EventFee.create(JSON.parse(response.body))
169
155
  end
170
156
 
171
157
 
@@ -173,10 +159,10 @@ module ConstantContact
173
159
  # @param [String] access_token - Constant Contact OAuth2 access token
174
160
  # @param [Integer] event - Valid event id
175
161
  # @param [Integer] fee - Valid fee id
176
- # @return [Fee]
162
+ # @return [EventFee]
177
163
  def update_fee(access_token, event, fee)
178
164
  event_id = get_id_for(event)
179
- if fee.kind_of?(ConstantContact::Components::Fee)
165
+ if fee.kind_of?(ConstantContact::Components::EventFee)
180
166
  fee_id = fee.id
181
167
  elsif fee.kind_of?(Hash)
182
168
  fee_id = fee['id']
@@ -190,7 +176,7 @@ module ConstantContact
190
176
  payload = fee.to_json
191
177
 
192
178
  response = RestClient.put(url, payload, get_headers(access_token))
193
- fee = Components::Fee.create(JSON.parse(response.body))
179
+ fee = Components::EventFee.create(JSON.parse(response.body))
194
180
  end
195
181
 
196
182
 
@@ -198,7 +184,7 @@ module ConstantContact
198
184
  # @param [String] access_token - Constant Contact OAuth2 access token
199
185
  # @param [Integer] event - Valid event id
200
186
  # @param [Integer] fee - Valid fee id
201
- # @return [Fee]
187
+ # @return [Boolean]
202
188
  def delete_fee(access_token, event, fee)
203
189
  event_id = get_id_for(event)
204
190
  fee_id = get_id_for(fee)
@@ -236,18 +222,255 @@ module ConstantContact
236
222
  # @param [String] access_token - Constant Contact OAuth2 access token
237
223
  # @param [Integer] event - Valid event id
238
224
  # @param [Integer] registrant - Valid fee id
239
- # @return [Fee]
225
+ # @return [Registrant]
240
226
  def get_registrant(access_token, event, registrant)
241
227
  event_id = get_id_for(event)
242
228
  registrant_id = get_id_for(registrant)
243
229
  url = Util::Config.get('endpoints.base_url') +
244
- sprintf(Util::Config.get('endpoints.event_fee'), event_id, registrant_id)
230
+ sprintf(Util::Config.get('endpoints.event_registrant'), event_id, registrant_id)
231
+ url = build_url(url)
232
+
233
+ response = RestClient.get(url, get_headers(access_token))
234
+ Components::Registrant.create(JSON.parse(response.body))
235
+ end
236
+
237
+
238
+ # Get an array of event items for an individual event
239
+ # @param [String] access_token - Constant Contact OAuth2 access token
240
+ # @param [Integer] event_id - event id to retrieve items for
241
+ # @return [Array<EventItem>]
242
+ def get_event_items(access_token, event_id)
243
+ url = Util::Config.get('endpoints.base_url') +
244
+ sprintf(Util::Config.get('endpoints.event_items'), event_id)
245
+ url = build_url(url)
246
+ response = RestClient.get(url, get_headers(access_token))
247
+
248
+ event_items = []
249
+ JSON.parse(response.body).each do |event_item|
250
+ event_items << Components::EventItem.create(event_item)
251
+ end
252
+
253
+ event_items
254
+ end
255
+
256
+
257
+ # Get an individual event item
258
+ # @param [String] access_token - Constant Contact OAuth2 access token
259
+ # @param [Integer] event_id - id of event to retrieve item for
260
+ # @param [Integer] item_id - id of item to be retrieved
261
+ # @return [EventItem]
262
+ def get_event_item(access_token, event_id, item_id)
263
+ url = Util::Config.get('endpoints.base_url') +
264
+ sprintf(Util::Config.get('endpoints.event_item'), event_id, item_id)
265
+ url = build_url(url)
266
+ response = RestClient.get(url, get_headers(access_token))
267
+ Components::EventItem.create(JSON.parse(response.body))
268
+ end
269
+
270
+
271
+ # Create a new event item for an event
272
+ # @param [String] access_token - Constant Contact OAuth2 access token
273
+ # @param [Integer] event_id - id of event to be associated with the event item
274
+ # @param [EventItem] event_item - event item to be created
275
+ # @return [EventItem]
276
+ def add_event_item(access_token, event_id, event_item)
277
+ url = Util::Config.get('endpoints.base_url') +
278
+ sprintf(Util::Config.get('endpoints.event_items'), event_id)
279
+ url = build_url(url)
280
+ payload = event_item.to_json
281
+ response = RestClient.post(url, payload, get_headers(access_token))
282
+ Components::EventItem.create(JSON.parse(response.body))
283
+ end
284
+
285
+
286
+ # Delete a specific event item for an event
287
+ # @param [String] access_token - Constant Contact OAuth2 access token
288
+ # @param [Integer] event_id - id of event to delete an event item for
289
+ # @param [Integer] item_id - id of event item to be deleted
290
+ # @return [Boolean]
291
+ def delete_event_item(access_token, event_id, item_id)
292
+ url = Util::Config.get('endpoints.base_url') +
293
+ sprintf(Util::Config.get('endpoints.event_item'), event_id, item_id)
294
+ url = build_url(url)
295
+ response = RestClient.delete(url, get_headers(access_token))
296
+ response.code == 204
297
+ end
298
+
299
+
300
+ # Update a specific event item for an event
301
+ # @param [String] access_token - Constant Contact OAuth2 access token
302
+ # @param [Integer] event_id - id of event associated with the event item
303
+ # @param [EventItem] event_item - event item to be updated
304
+ # @return [EventItem]
305
+ def update_event_item(access_token, event_id, event_item)
306
+ url = Util::Config.get('endpoints.base_url') +
307
+ sprintf(Util::Config.get('endpoints.event_item'), event_id, event_item.id)
308
+ url = build_url(url)
309
+ payload = event_item.to_json
310
+ response = RestClient.put(url, payload, get_headers(access_token))
311
+ Components::EventItem.create(JSON.parse(response.body))
312
+ end
313
+
314
+
315
+ # Get an array of attributes for an individual event item
316
+ # @param [String] access_token - Constant Contact OAuth2 access token
317
+ # @param [Integer] event_id - event id to retrieve item for
318
+ # @param [Integer] item_id - event item id to retrieve attributes for
319
+ # @return [Array<EventItemAttribute>]
320
+ def get_event_item_attributes(access_token, event_id, item_id)
321
+ url = Util::Config.get('endpoints.base_url') +
322
+ sprintf(Util::Config.get('endpoints.event_item_attributes'), event_id, item_id)
323
+ url = build_url(url)
324
+ response = RestClient.get(url, get_headers(access_token))
325
+
326
+ event_item_attributes = []
327
+ JSON.parse(response.body).each do |event_item_attribute|
328
+ event_item_attributes << Components::EventItemAttribute.create(event_item_attribute)
329
+ end
330
+
331
+ event_item_attributes
332
+ end
333
+
334
+
335
+ # Get an individual event item attribute
336
+ # @param [String] access_token - Constant Contact OAuth2 access token
337
+ # @param [Integer] event_id - id of event to retrieve item for
338
+ # @param [Integer] item_id - id of item to retrieve attribute for
339
+ # @param [Integer] attribute_id - id of attribute to be retrieved
340
+ # @return [EventItemAttribute]
341
+ def get_event_item_attribute(access_token, event_id, item_id, attribute_id)
342
+ url = Util::Config.get('endpoints.base_url') +
343
+ sprintf(Util::Config.get('endpoints.event_item_attribute'), event_id, item_id, attribute_id)
344
+ url = build_url(url)
345
+ response = RestClient.get(url, get_headers(access_token))
346
+ Components::EventItemAttribute.create(JSON.parse(response.body))
347
+ end
348
+
349
+
350
+ # Create a new event item attribute for an event item
351
+ # @param [String] access_token - Constant Contact OAuth2 access token
352
+ # @param [Integer] event_id - id of event to be associated with the event item attribute
353
+ # @param [Integer] item_id - id of event item to be associated with the event item attribute
354
+ # @param [EventItemAttribute] event_item_attribute - event item attribute to be created
355
+ # @return [EventItemAttribute]
356
+ def add_event_item_attribute(access_token, event_id, item_id, event_item_attribute)
357
+ url = Util::Config.get('endpoints.base_url') +
358
+ sprintf(Util::Config.get('endpoints.event_item_attributes'), event_id, item_id)
359
+ url = build_url(url)
360
+ payload = event_item_attribute.to_json
361
+ response = RestClient.post(url, payload, get_headers(access_token))
362
+ Components::EventItemAttribute.create(JSON.parse(response.body))
363
+ end
364
+
365
+
366
+ # Delete a specific event item for an event
367
+ # @param [String] access_token - Constant Contact OAuth2 access token
368
+ # @param [Integer] event_id - id of event to delete an event item attribute for
369
+ # @param [Integer] item_id - id of event item to delete an event item attribute for
370
+ # @param [Integer] attribute_id - id of attribute to be deleted
371
+ # @return [Boolean]
372
+ def delete_event_item_attribute(access_token, event_id, item_id, attribute_id)
373
+ url = Util::Config.get('endpoints.base_url') +
374
+ sprintf(Util::Config.get('endpoints.event_item_attribute'), event_id, item_id, attribute_id)
375
+ url = build_url(url)
376
+ response = RestClient.delete(url, get_headers(access_token))
377
+ response.code == 204
378
+ end
379
+
380
+
381
+ # Update a specific event item attribute for an event item
382
+ # @param [String] access_token - Constant Contact OAuth2 access token
383
+ # @param [Integer] event_id - id of event associated with the event item
384
+ # @param [Integer] item_id - id of event item associated with the event item attribute
385
+ # @param [EventItemAttribute] event_item_attribute - event item to be updated
386
+ # @return [EventItemAttribute]
387
+ def update_event_item_attribute(access_token, event_id, item_id, event_item_attribute)
388
+ url = Util::Config.get('endpoints.base_url') +
389
+ sprintf(Util::Config.get('endpoints.event_item'), event_id, item_id, event_item_attribute.id)
390
+ url = build_url(url)
391
+ payload = event_item_attribute.to_json
392
+ response = RestClient.put(url, payload, get_headers(access_token))
393
+ Components::EventItemAttribute.create(JSON.parse(response.body))
394
+ end
395
+
396
+
397
+ # Get an array of promocodes for an individual event
398
+ # @param [String] access_token - Constant Contact OAuth2 access token
399
+ # @param [Integer] event_id - event id to retrieve promocodes for
400
+ # @return [Array<Promocode>]
401
+ def get_promocodes(access_token, event_id)
402
+ url = Util::Config.get('endpoints.base_url') +
403
+ sprintf(Util::Config.get('endpoints.event_promocodes'), event_id)
245
404
  url = build_url(url)
405
+ response = RestClient.get(url, get_headers(access_token))
406
+
407
+ promocodes = []
408
+ JSON.parse(response.body).each do |promocode|
409
+ promocodes << Components::Promocode.create(promocode)
410
+ end
411
+
412
+ promocodes
413
+ end
414
+
246
415
 
416
+ # Get an individual promocode
417
+ # @param [String] access_token - Constant Contact OAuth2 access token
418
+ # @param [Integer] event_id - id of event to retrieve item for
419
+ # @param [Integer] promocode_id - id of item to be retrieved
420
+ # @return [Promocode]
421
+ def get_promocode(access_token, event_id, promocode_id)
422
+ url = Util::Config.get('endpoints.base_url') +
423
+ sprintf(Util::Config.get('endpoints.event_promocode'), event_id, promocode_id)
424
+ url = build_url(url)
247
425
  response = RestClient.get(url, get_headers(access_token))
248
- registrant = Components::Registrant.create(JSON.parse(response.body))
426
+ Components::Promocode.create(JSON.parse(response.body))
427
+ end
428
+
429
+
430
+ # Create a new promocode for an event
431
+ # @param [String] access_token - Constant Contact OAuth2 access token
432
+ # @param [Integer] event_id - id of event to be associated with the promocode
433
+ # @param [Promocode] promocode - promocode to be created
434
+ # @return [Promocode]
435
+ def add_promocode(access_token, event_id, promocode)
436
+ url = Util::Config.get('endpoints.base_url') +
437
+ sprintf(Util::Config.get('endpoints.event_promocodes'), event_id)
438
+ url = build_url(url)
439
+ payload = promocode.to_json
440
+ response = RestClient.post(url, payload, get_headers(access_token))
441
+ Components::Promocode.create(JSON.parse(response.body))
442
+ end
443
+
444
+
445
+ # Delete a specific promocode for an event
446
+ # @param [String] access_token - Constant Contact OAuth2 access token
447
+ # @param [Integer] event_id - id of event to delete a promocode for
448
+ # @param [Integer] promocode_id - id of promocode to be deleted
449
+ # @return [Boolean]
450
+ def delete_promocode(access_token, event_id, promocode_id)
451
+ url = Util::Config.get('endpoints.base_url') +
452
+ sprintf(Util::Config.get('endpoints.event_promocode'), event_id, promocode_id)
453
+ url = build_url(url)
454
+ response = RestClient.delete(url, get_headers(access_token))
455
+ response.code == 204
249
456
  end
250
457
 
458
+
459
+ # Update a specific promocode for an event
460
+ # @param [String] access_token - Constant Contact OAuth2 access token
461
+ # @param [Integer] event_id - id of event associated with the promocode
462
+ # @param [Promocode] promocode - promocode to be updated
463
+ # @return [Promocode]
464
+ def update_promocode(access_token, event_id, promocode)
465
+ url = Util::Config.get('endpoints.base_url') +
466
+ sprintf(Util::Config.get('endpoints.event_promocode'), event_id, promocode.id)
467
+ url = build_url(url)
468
+ payload = promocode.to_json
469
+ response = RestClient.put(url, payload, get_headers(access_token))
470
+ Components::Promocode.create(JSON.parse(response.body))
471
+ end
472
+
473
+
251
474
  end
252
475
  end
253
476
  end