Class: Centaman::Service::BookingTime

Inherits:
Centaman::Service show all
Includes:
JsonWrapper
Defined in:
lib/centaman/service/booking_time.rb

Constant Summary

Constants inherited from Centaman::Service

DEFAULT_TIMEOUT_TIME

Constants inherited from Wrapper

Wrapper::FIXIE

Instance Attribute Summary collapse

Attributes inherited from Wrapper

#api_password, #api_token, #api_username

Class Method Summary collapse

Instance Method Summary collapse

Methods included from JsonWrapper

#additional_hash_to_serialize_after_response, #build_object, #build_objects, #objects

Methods inherited from Centaman::Service

#after_post, #fetch_all, #payload, #payload_key, #post, #wrap_request_in_case_of_timeout

Methods inherited from Wrapper

#generate_token, #headers, #initialize, #options_hash

Constructor Details

This class inherits a constructor from Centaman::Wrapper

Instance Attribute Details

#booking_type_idObject (readonly)

Returns the value of attribute booking_type_id.



4
5
6
# File 'lib/centaman/service/booking_time.rb', line 4

def booking_type_id
  @booking_type_id
end

#end_dateObject (readonly)

Returns the value of attribute end_date.



4
5
6
# File 'lib/centaman/service/booking_time.rb', line 4

def end_date
  @end_date
end

#start_dateObject (readonly)

Returns the value of attribute start_date.



4
5
6
# File 'lib/centaman/service/booking_time.rb', line 4

def start_date
  @start_date
end

#timed_ticket_type_idObject (readonly)

Returns the value of attribute timed_ticket_type_id.



4
5
6
# File 'lib/centaman/service/booking_time.rb', line 4

def timed_ticket_type_id
  @timed_ticket_type_id
end

Class Method Details

.find(booking_type_id, booking_time_id, date) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/centaman/service/booking_time.rb', line 18

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

Instance Method Details

#after_init(args) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/centaman/service/booking_time.rb', line 6

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

#endpointObject



28
29
30
# File 'lib/centaman/service/booking_time.rb', line 28

def endpoint
  '/ticket_services/TimedTicketType'
end

#format_date_to_string(date) ⇒ Object



46
47
48
# File 'lib/centaman/service/booking_time.rb', line 46

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

#object_classObject



14
15
16
# File 'lib/centaman/service/booking_time.rb', line 14

def object_class
  Centaman::Object::BookingTime
end

#optionsObject



32
33
34
35
36
37
38
39
# File 'lib/centaman/service/booking_time.rb', line 32

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

#parse_datesObject



41
42
43
44
# File 'lib/centaman/service/booking_time.rb', line 41

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