Class: ShakeTheCounter::Section

Inherits:
Object
  • Object
show all
Defined in:
lib/shake_the_counter/section.rb

Overview

Sets up a section object

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}, performance: nil) ⇒ Section

Sets up a new section



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/shake_the_counter/section.rb', line 17

def initialize(args={}, performance: nil)
  self.key = args["SectionKey"]
  self.name = args["SectionName"]
  self.performance_section_key = args["PerformanceSectionKey"]
  self.available_seats = args["AvailableSeats"]
  self.performance = performance
  self.price_types = []
  for price_type in args["PriceTypes"]
    self.price_types << ShakeTheCounter::PriceType.new(price_type, section: self)
  end
  self.raw_data = args
end

Instance Attribute Details

#available_seatsObject

Returns the value of attribute available_seats.



9
10
11
# File 'lib/shake_the_counter/section.rb', line 9

def available_seats
  @available_seats
end

#keyObject

Returns the value of attribute key.



6
7
8
# File 'lib/shake_the_counter/section.rb', line 6

def key
  @key
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/shake_the_counter/section.rb', line 8

def name
  @name
end

#performanceObject

Returns the value of attribute performance.



11
12
13
# File 'lib/shake_the_counter/section.rb', line 11

def performance
  @performance
end

#performance_section_keyObject

Returns the value of attribute performance_section_key.



7
8
9
# File 'lib/shake_the_counter/section.rb', line 7

def performance_section_key
  @performance_section_key
end

#price_typesObject

Returns the value of attribute price_types.



10
11
12
# File 'lib/shake_the_counter/section.rb', line 10

def price_types
  @price_types
end

#raw_dataObject

Returns the value of attribute raw_data.



12
13
14
# File 'lib/shake_the_counter/section.rb', line 12

def raw_data
  @raw_data
end

Instance Method Details

#make_reservation(price_type_list: {}, affiliate: '', first_name: '', last_name: '', email: '') ⇒ Object

Makes a reservation for this section POST /api/v1/event/eventKey/performance/performanceKey/section/performanceSectionKey/reservation/languageCode

Parameters:

  • email: (defaults to: '')

    ” [type] [description]

Returns:

  • Reservation



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/shake_the_counter/section.rb', line 36

def make_reservation(price_type_list: {}, affiliate: '', first_name: '', last_name: '', email: '')
  # step 1: make the reservation
  path = "event/#{performance.event.key}/performance/#{performance.key}/section/#{performance_section_key}/reservation/#{performance.event.client.language_code}"
  body = { 
    PriceTypeList: price_type_list
  }
  result = performance.event.client.call(path, http_method: :post, body: body.to_json)
  reservation = ShakeTheCounter::Reservation.new(result)

  # step 2: create a contact
  path = "contact/#{performance.event.client.language_code}"
  body = { 
    FirstName: first_name,
    LastName: last_name,
    MailAddress: email,
    LanguageCode: performance.event.client.language_code
  }
  result = performance.event.client.call(path, http_method: :post, body: body.to_json)
  contact = ShakeTheCounter::Contact.new(result)      

  # step 3: link contact to the reservation
  path = "reservation/#{reservation.key}/contact"
  body = {
    ContactKey: contact.key
  }
  result = performance.event.client.call(path, http_method: :post, body: body.to_json)

  return reservation
end