lib/quick_travel/reservation.rb in quicktravel_client-2.3.1 vs lib/quick_travel/reservation.rb in quicktravel_client-2.4.0
- old
+ new
@@ -2,55 +2,33 @@
require 'quick_travel/adjustment'
require 'quick_travel/resource'
module QuickTravel
class Reservation < Adapter
+ has_many :adjustments
+ has_many :sub_reservations, class_name: 'Reservation'
+ belongs_to :to_route_stop, class_name: 'RouteStop'
+ belongs_to :from_route_stop, class_name: 'RouteStop'
+
def self.create(options)
json = post_and_validate('/api/reservations.json', options, expect: :json)
new(json)
end
def self.destroy(id)
delete_and_validate("/api/reservations/#{id}.json")
end
- def adjustments
- @adjustments_attributes.map { |adjustment| Adjustment.new(adjustment) }
- end
-
def resource
@resource ||= QuickTravel::Resource.find(resource_id) if resource_id
end
def start_date_time
start_time.to_time.on(first_travel_date) if start_time
end
def end_date_time
end_time.to_time.on(last_travel_date) if end_time
- end
-
- def to_route_stop
- QuickTravel::RouteStop.new(@to_route_stop_attributes) if @to_route_stop_attributes
- end
-
- def from_route_stop
- QuickTravel::RouteStop.new(@from_route_stop_attributes) if @from_route_stop_attributes
- end
-
- # it send API request for Resource show. and cache the data.
- # i think now this method is not required because now booking show api call have display_text for every reservation
- def details
- if @_resource.blank?
- @_resource = Resource.find(@resource_id) unless @resource_id.blank?
- end
- @_resource
- end
-
- def sub_reservations
- @sub_reservations ||= Array(@sub_reservations_attributes).map do |attributes|
- Reservation.new(attributes)
- end
end
def passengers_count_string(booking)
passengers_count(booking).join(', ')
end