class PrioTicket::Booking
Describes a Booking
This API
is called to get a ticket booked and get a barcode/QR-code in response. The booking API
provides a booking reference in response. There are 5 different booking options:
Attributes
completed booking attrs
attr_accessor :booking_type
contact details
Public Class Methods
Cancels a Booking
@return Booking
# File lib/prioticket/booking.rb, line 86 def self.cancel(distributor_id: nil, booking_reference: nil, distributor_reference: nil, identifier: nil) body = { request_type: "cancel_booking", data: { distributor_id: distributor_id, booking_reference: booking_reference, distributor_reference: booking_reference } } result = PrioTicket::API.call(body, identifier) booking = PrioTicket::Booking.new(result["data"]) return booking end
Gets the status from a Booking
@return Booking
# File lib/prioticket/booking.rb, line 104 def self.get_status(distributor_id: nil, booking_reference: nil, distributor_reference: nil, identifier: nil) body = { request_type: "booking_status", data: { distributor_id: distributor_id, booking_reference: booking_reference, distributor_reference: booking_reference } } result = PrioTicket::API.call(body, identifier) booking = PrioTicket::Booking.new(result["data"]) return booking end
# File lib/prioticket/booking.rb, line 39 def initialize(args) return if args.nil? args.each do |k,v| PrioTicket.parse_json_value(self, k,v) end end
Public Instance Methods
# File lib/prioticket/booking.rb, line 54 def canceled booking_status == "Cancelled" end
Sends the reservation request tot the API
# File lib/prioticket/booking.rb, line 49 def save request_booking end
# File lib/prioticket/booking.rb, line 60 def success booking_status == "Confirmed" end
Fetches information from ticket_details, to validate the input for this booking. e.g. if ticket_type == 2, from/to date are required.
@return [type] [description]
# File lib/prioticket/booking.rb, line 73 def ticket begin @ticket ||= PrioTicket::TicketDetails.find(distributor_id: distributor_id, ticket_id: booking_type['ticket_id'], identifier: identifier) rescue false end end
Private Instance Methods
Parses the return value from the API
# File lib/prioticket/booking.rb, line 192 def parse_result(result) self.booking_status = result["data"]["booking_status"] self.booking_reference = result["data"]["booking_reference"] PrioTicket.parse_json_value(self, :booking_details, result["data"]["booking_details"]) end
Computes the details to send to the API
@return Hash
# File lib/prioticket/booking.rb, line 134 def request_body for att in [:distributor_id, :booking_type, :booking_name, :booking_email, :contact, :notes, :product_language, :distributor_reference] raise PrioTicketError.new("Booking is missing attribute `#{att}` (Hash)") unless send(att) end body = { request_type: "booking", data: { distributor_id: distributor_id, booking_type: validated_booking_type_hash, booking_name: booking_name, booking_email: booking_email, contact: PrioTicket.openstruct_to_hash(contact).to_h, notes: notes.to_a, product_language: product_language, distributor_reference: distributor_reference } } # add pickuppoint to body, if present # body[:data][:pickup_point_id] = pickup_point_id if pickup_point_id return body end
Sends the reservation request to the API
endpoint and enriches current object with status and reference.
# File lib/prioticket/booking.rb, line 124 def request_booking result = PrioTicket::API.call(request_body, identifier) parse_result(result) end
Calculates and validates the information for 'booking_type'
@return Hash
# File lib/prioticket/booking.rb, line 161 def validated_booking_type_hash # loops through all the booking details and raises error # if from/to date_time are not present. if ticket if [2,3].include?(ticket.ticket_class) unless booking_type.from_date_time && booking_type.to_date_time unless booking_type.reservation_reference && booking_type.reservation_reference != '' puts booking_type.inspect err_msg = "The `booking_type` attribute requires a from_date_time and to_date_time for a ticket of ticket_class #{ticket.ticket_class}." raise PrioTicketError.new(err_msg) end end end end data = {} data[:ticket_id] = booking_type.ticket_id unless booking_type.reservation_reference data[:booking_details] = booking_type.booking_details.map{|bd| PrioTicket.openstruct_to_hash(bd)} unless booking_type.reservation_reference data[:reservation_reference] = booking_type.reservation_reference if booking_type.reservation_reference if booking_type.from_date_time && booking_type.to_date_time data[:from_date_time] = booking_type.from_date_time data[:to_date_time] = booking_type.to_date_time end return data end