Skip to content

Instantly share code, notes, and snippets.

@svs
Last active December 11, 2015 02:39
Show Gist options
  • Save svs/4532659 to your computer and use it in GitHub Desktop.
Save svs/4532659 to your computer and use it in GitHub Desktop.
class VendorBooker
# This class is responsible for calling the appropriate translation mechanism to convert a CRM Trip
# into the appropriate format to book
#
# It also translates the response into a CRM Booking object to persist to the database
def initialize(trip, vendor, credentials)
@trip = trip
@vendor = vendor
@credentials = credentials
end
def book!
booking_response_translator.new(customer.book!(vendor_booking, @credentials)).translate
end
private
def customer
Kernel.module_eval("#{vendor}Customer").new(@trip.customer)
end
def vendor_booking
Kernel.const_get("#{vendor}Booking").new(@trip).booking
end
def booking_response_translator
Kernel.const_get("#{vendor}BookingResponse")
end
def vendor
@vendor.to_s.camelize
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment