Skip to content

Instantly share code, notes, and snippets.

@hayduke19us
Created December 8, 2016 05:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hayduke19us/ee95bb45c737fc455c985be15b5ebe0e to your computer and use it in GitHub Desktop.
Save hayduke19us/ee95bb45c737fc455c985be15b5ebe0e to your computer and use it in GitHub Desktop.
module Serializers
class BookingRequest < Base
template(:new_relic) do |booking_request|
affiliate_code = booking_request.affiliate_code
property = @availability_config.try(:property)
@itinerary = booking_request.booked_itinerary
@availability_config = booking_request.availability_config
transaction = {
itinerary_number: @itinerary.try(:itinerary_number),
itinerary_audit_log_id: booking_request.audit_log.try(:id).to_s,
point_of_sale: booking_request.booking_interface,
session_token: booking_request.session_code,
check_in: booking_request.check_in.strftime('%s').to_i,
check_out: booking_request.check_out.strftime('%s').to_i,
formatted_check_in: booking_request.check_in.to_formatted_s(:iso8601),
formatted_check_out: booking_request.check_out.to_formatted_s(:iso8601),
nights: booking_request.nights.to_i,
room_count: booking_request.rooms.size,
rinfo: booking_request.rooms.map { |room| room[:ages] }.to_s,
supplier_code: @availability_config.try(:supplier_code),
supplier_name: "#{@availability_config.try(:supplier_code)}#{subsupplier_code}",
supplier_property_id: @availability_config.try(:supplier_property_id).to_s,
property_code: @availability_config.try(:property_code),
rate_plan_code: booking_request.rate_plan_code,
guarantee_code: booking_request.payment[:guarantee_code]
}
transaction.merge!(itinerary) if @itinerary && @itinerary.reservation.try(:room_rate)
transaction.merge!(Serializers::Property.new.sanitize(property, :new_relic)) if property
transaction.merge!(Serializers::Affiliate.new.sanitize(affiliate_code, :new_relic))
transaction
end
class << self
def subsupplier_code
":#{@availability_config.subsupplier_code}" if @availability_config && @availability_config.respond_to?(:subsupplier_code)
end
def reservation_sell_rate
{ :sell_rate_total => @itinerary.reservation.sell_rate_total.to_f,
:sell_rate_currency => @itinerary.reservation.room_rate.sell_rate.currency
}
end
def itinerary
attributes = { :room_type_name => @itinerary.reservation.room_rate.room_type.name,
:restriction_code => @itinerary.reservation.room_rate.rate_plan.restriction,
:classification_code => @itinerary.reservation.room_rate.rate_plan.classification }
custom_field_attributes = Hash[@itinerary.internal_custom_fields.map { |custom| ["custom_field_#{custom.name}".to_sym, custom.value] }]
attributes.merge(reservation_sell_rate).merge(custom_field_attributes)
end
end
template(:affiliate_failure_response) do |booking_request|
booking_request.booking_errors.for_affiliate.tap do |affiliate_response|
affiliate_response['itinerary_audit_log_id'] = booking_request.audit_log.id if booking_request.audit_log
affiliate_response['sc_server_name'] = booking_request.sc_server_name if booking_request.sc_server_name
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment