Last active
December 11, 2015 02:39
-
-
Save svs/4532659 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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