Class: PrioTicket::Availabilities

Inherits:
Object
  • Object
show all
Defined in:
lib/prioticket/availabilities.rb

Overview

This endpoint should be called in order to get up-to-date availability information for a product with managed capacity. The response will contain the availability for each time slot of the requested product that lies within the specified date range. Time slots will not be omitted in case of no availability. Neither will a NO_AVAILABILITY error be returned in that case. Instead, an explicit vacancy of zero should be expected.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = nil) ⇒ Availabilities

Returns a new instance of Availabilities.



16
17
18
19
20
21
# File 'lib/prioticket/availabilities.rb', line 16

def initialize(args=nil)
  return if args.nil?
  args.each do |k,v|
    PrioTicket.parse_json_value(self, k,v)
  end
end

Instance Attribute Details

#from_date_timeObject

Returns the value of attribute from_date_time.



11
12
13
# File 'lib/prioticket/availabilities.rb', line 11

def from_date_time
  @from_date_time
end

#to_date_timeObject

Returns the value of attribute to_date_time.



12
13
14
# File 'lib/prioticket/availabilities.rb', line 12

def to_date_time
  @to_date_time
end

#vacanciesObject

Returns the value of attribute vacancies.



13
14
15
# File 'lib/prioticket/availabilities.rb', line 13

def vacancies
  @vacancies
end

Class Method Details

.find(distributor_id: nil, ticket_id: nil, from_date: nil, until_date: nil, identifier: nil) ⇒ Object

Calls the request type ‘availabilities’ with given details and retruns an array of Availabilities objects

Parameters:

  • distributor_id (defaults to: nil)

    Integer

Returns:

  • Array



29
30
31
32
33
34
35
36
# File 'lib/prioticket/availabilities.rb', line 29

def self.find(distributor_id: nil, ticket_id: nil, from_date: nil, until_date: nil, identifier: nil)
  result = PrioTicket::API.call(request_body(ticket_id: ticket_id, distributor_id: distributor_id, from_date: from_date, until_date: until_date), identifier, false)
  list = []
  for a in result["data"]["availabilities"]
    list << Availabilities.new(a)
  end
  return list
end

.request_body(distributor_id: nil, ticket_id: nil, from_date: nil, until_date: nil) ⇒ Object

Computes the request body to send to the API endpoint

Parameters:

  • distributor_id (defaults to: nil)

    Integer

  • ticket_id (defaults to: nil)

    Integer

  • from_date (defaults to: nil)

    String

  • until_date (defaults to: nil)

    String

Returns:

  • Hash



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/prioticket/availabilities.rb', line 46

def self.request_body(distributor_id: nil, ticket_id: nil, from_date: nil, until_date: nil)
  {
    request_type: "availabilities",
    data: {
      distributor_id: distributor_id,
      ticket_id: ticket_id,
      from_date: PrioTicket.parsed_date(from_date),
      until_date: PrioTicket.parsed_date(until_date)
    }
  }
end

Instance Method Details

#reserveObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/prioticket/availabilities.rb', line 59

def reserve
  # {
  # "request_type": "reserve",
  # "data": {
  # "distributor_id": "501",
  # "ticket_id": "509",
  # "pickup_point_id": "Wyndham_Apollo_hotel",
  # "from_date_time": "2017-11-22T09:00:00+01:00",
  # "to_date_time": "2017-11-23T09:00:00+01:00",
  # "booking_details": [
  # {
  # "ticket_type": "ADULT",
  # "count": 1
  # }
  # ],
  # "distributor_reference": "ABC123456"
  # }
  # }

  # {
  # "response_type": "reserve",
  # "data": {
  # "reservation_reference": "123456789",
  # "distributor_reference": "ABC123456",
  # "booking_status": "Reserved"
  # }
  # }
end