Sha256: 67c00750d18aeeef6fd9dcc042a6f6cdc9a1be68345b4fe70a705da4ff0c259f

Contents?: true

Size: 1.4 KB

Versions: 54

Compression:

Stored size: 1.4 KB

Contents

module Centaman
  class Service::BookingTime < Centaman::Service
    include Centaman::JsonWrapper
    attr_reader :booking_type_id, :start_date, :end_date, :timed_ticket_type_id

    def after_init(args)
      @booking_type_id = args[:booking_type_id]
      @start_date = args[:start_date]
      @end_date = args[:end_date]
      parse_dates
      @timed_ticket_type_id = args[:id] # when finding a particular time
    end

    def object_class
      Centaman::Object::BookingTime
    end

    def self.find(booking_type_id, booking_time_id, date)
      obj = new(
        booking_type_id: booking_type_id,
        booking_time_id: booking_time_id,
        start_date: date,
        end_date: date
      )
      obj.objects.detect {|obj| obj.id == booking_time_id }
    end

    def endpoint
      '/ticket_services/TimedTicketType'
    end

    def options
      super + [
        { key: 'BookingTypeId', value: booking_type_id },
        { key: 'StartDate', value: start_date },
        { key: 'EndDate', value: end_date },
        { key: 'id', value: timed_ticket_type_id },
      ]
    end

    def parse_dates
      @start_date = start_date.present? && start_date.is_a?(Date) ? format_date_to_string(start_date) : start_date
      @end_date = end_date.present? && end_date.is_a?(Date) ? format_date_to_string(end_date) : end_date
    end

    def format_date_to_string(date)
      date.strftime('%Y-%m-%d')
    end
  end
end

Version data entries

54 entries across 54 versions & 1 rubygems

Version Path
centaman-8.0.0 lib/centaman/service/booking_time.rb
centaman-7.0.5 lib/centaman/service/booking_time.rb
centaman-7.0.4 lib/centaman/service/booking_time.rb
centaman-7.0.3 lib/centaman/service/booking_time.rb
centaman-7.0.2 lib/centaman/service/booking_time.rb
centaman-7.0.1 lib/centaman/service/booking_time.rb
centaman-7.0.0 lib/centaman/service/booking_time.rb
centaman-6.0.8 lib/centaman/service/booking_time.rb
centaman-6.0.7 lib/centaman/service/booking_time.rb
centaman-6.0.5 lib/centaman/service/booking_time.rb
centaman-6.0.4 lib/centaman/service/booking_time.rb
centaman-6.0.3 lib/centaman/service/booking_time.rb
centaman-6.0.2 lib/centaman/service/booking_time.rb
centaman-6.0.1 lib/centaman/service/booking_time.rb
centaman-6.0.0 lib/centaman/service/booking_time.rb
centaman-5.0.8 lib/centaman/service/booking_time.rb
centaman-5.0.7 lib/centaman/service/booking_time.rb
centaman-5.0.6 lib/centaman/service/booking_time.rb
centaman-5.0.5 lib/centaman/service/booking_time.rb
centaman-5.0.4 lib/centaman/service/booking_time.rb