Class: Suitcase::Hotel::Room

Inherits:
Object
  • Object
show all
Extended by:
Helpers
Includes:
Helpers
Defined in:
lib/suitcase/hotel/room.rb

Constant Summary

Constants included from Helpers

Helpers::URL_DEFAULTS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

base_url, build_session_params, generate_signature, handle_errors, main_url, parameterize, parameterize_rooms, parse_response, update_session, url

Constructor Details

#initialize(info) ⇒ Room

Internal: Create a new Room from within a Room search query.

info - A Hash of parsed information from the API, with any of the keys

from the attr_accessor's list.


23
24
25
26
27
# File 'lib/suitcase/hotel/room.rb', line 23

def initialize(info)
  info.each do |k, v|
    instance_variable_set("@" + k.to_s, v)
  end
end

Instance Attribute Details

#arrivalObject

Returns the value of attribute arrival.



4
5
6
# File 'lib/suitcase/hotel/room.rb', line 4

def arrival
  @arrival
end

#average_base_rateObject

Returns the value of attribute average_base_rate.



4
5
6
# File 'lib/suitcase/hotel/room.rb', line 4

def average_base_rate
  @average_base_rate
end

#average_nightly_rateObject

Returns the value of attribute average_nightly_rate.



4
5
6
# File 'lib/suitcase/hotel/room.rb', line 4

def average_nightly_rate
  @average_nightly_rate
end

#average_rateObject

Returns the value of attribute average_rate.



4
5
6
# File 'lib/suitcase/hotel/room.rb', line 4

def average_rate
  @average_rate
end

#bed_typesObject

Returns the value of attribute bed_types.



4
5
6
# File 'lib/suitcase/hotel/room.rb', line 4

def bed_types
  @bed_types
end

#cancellation_policyObject

Returns the value of attribute cancellation_policy.



4
5
6
# File 'lib/suitcase/hotel/room.rb', line 4

def cancellation_policy
  @cancellation_policy
end

#currency_codeObject

Returns the value of attribute currency_code.



4
5
6
# File 'lib/suitcase/hotel/room.rb', line 4

def currency_code
  @currency_code
end

#departureObject

Returns the value of attribute departure.



4
5
6
# File 'lib/suitcase/hotel/room.rb', line 4

def departure
  @departure
end

#deposit_requiredObject

Returns the value of attribute deposit_required.



4
5
6
# File 'lib/suitcase/hotel/room.rb', line 4

def deposit_required
  @deposit_required
end

#guarantee_onlyObject

Returns the value of attribute guarantee_only.



4
5
6
# File 'lib/suitcase/hotel/room.rb', line 4

def guarantee_only
  @guarantee_only
end

#guarantee_requiredObject

Returns the value of attribute guarantee_required.



4
5
6
# File 'lib/suitcase/hotel/room.rb', line 4

def guarantee_required
  @guarantee_required
end

#hotel_idObject

Returns the value of attribute hotel_id.



4
5
6
# File 'lib/suitcase/hotel/room.rb', line 4

def hotel_id
  @hotel_id
end

#max_nightly_rateObject

Returns the value of attribute max_nightly_rate.



4
5
6
# File 'lib/suitcase/hotel/room.rb', line 4

def max_nightly_rate
  @max_nightly_rate
end

#min_guest_ageObject

Returns the value of attribute min_guest_age.



4
5
6
# File 'lib/suitcase/hotel/room.rb', line 4

def min_guest_age
  @min_guest_age
end

#nightly_rate_totalObject

Returns the value of attribute nightly_rate_total.



4
5
6
# File 'lib/suitcase/hotel/room.rb', line 4

def nightly_rate_total
  @nightly_rate_total
end

#non_refundableObject

Returns the value of attribute non_refundable.



4
5
6
# File 'lib/suitcase/hotel/room.rb', line 4

def non_refundable
  @non_refundable
end

#occupancyObject

Returns the value of attribute occupancy.



4
5
6
# File 'lib/suitcase/hotel/room.rb', line 4

def occupancy
  @occupancy
end

#price_breakdownObject

Returns the value of attribute price_breakdown.



4
5
6
# File 'lib/suitcase/hotel/room.rb', line 4

def price_breakdown
  @price_breakdown
end

#promoObject

Returns the value of attribute promo.



4
5
6
# File 'lib/suitcase/hotel/room.rb', line 4

def promo
  @promo
end

#promo_descriptionObject

Returns the value of attribute promo_description.



4
5
6
# File 'lib/suitcase/hotel/room.rb', line 4

def promo_description
  @promo_description
end

#quoted_occupancyObject

Returns the value of attribute quoted_occupancy.



4
5
6
# File 'lib/suitcase/hotel/room.rb', line 4

def quoted_occupancy
  @quoted_occupancy
end

#rate_changeObject

Returns the value of attribute rate_change.



4
5
6
# File 'lib/suitcase/hotel/room.rb', line 4

def rate_change
  @rate_change
end

#rate_codeObject

Returns the value of attribute rate_code.



4
5
6
# File 'lib/suitcase/hotel/room.rb', line 4

def rate_code
  @rate_code
end

#rate_descriptionObject

Returns the value of attribute rate_description.



4
5
6
# File 'lib/suitcase/hotel/room.rb', line 4

def rate_description
  @rate_description
end

#rate_keyObject

Returns the value of attribute rate_key.



4
5
6
# File 'lib/suitcase/hotel/room.rb', line 4

def rate_key
  @rate_key
end

#rawObject

Returns the value of attribute raw.



4
5
6
# File 'lib/suitcase/hotel/room.rb', line 4

def raw
  @raw
end

#room_type_codeObject

Returns the value of attribute room_type_code.



4
5
6
# File 'lib/suitcase/hotel/room.rb', line 4

def room_type_code
  @room_type_code
end

#room_type_descriptionObject

Returns the value of attribute room_type_description.



4
5
6
# File 'lib/suitcase/hotel/room.rb', line 4

def room_type_description
  @room_type_description
end

#roomsObject

Returns the value of attribute rooms.



4
5
6
# File 'lib/suitcase/hotel/room.rb', line 4

def rooms
  @rooms
end

#supplier_typeObject

Returns the value of attribute supplier_type.



4
5
6
# File 'lib/suitcase/hotel/room.rb', line 4

def supplier_type
  @supplier_type
end

#surcharge_totalObject

Returns the value of attribute surcharge_total.



4
5
6
# File 'lib/suitcase/hotel/room.rb', line 4

def surcharge_total
  @surcharge_total
end

#surchargesObject

Returns the value of attribute surcharges.



4
5
6
# File 'lib/suitcase/hotel/room.rb', line 4

def surcharges
  @surcharges
end

#tax_rateObject

Returns the value of attribute tax_rate.



4
5
6
# File 'lib/suitcase/hotel/room.rb', line 4

def tax_rate
  @tax_rate
end

#totalObject

Returns the value of attribute total.



4
5
6
# File 'lib/suitcase/hotel/room.rb', line 4

def total
  @total
end

#total_priceObject

Returns the value of attribute total_price.



4
5
6
# File 'lib/suitcase/hotel/room.rb', line 4

def total_price
  @total_price
end

#value_addsObject

Returns the value of attribute value_adds.



4
5
6
# File 'lib/suitcase/hotel/room.rb', line 4

def value_adds
  @value_adds
end

Instance Method Details

#chargeable_rateObject

Public: The chargeable rate for the Hotel room.

Returns the chargeable rate for the Room.



118
119
120
121
122
123
124
# File 'lib/suitcase/hotel/room.rb', line 118

def chargeable_rate
  if @supplier_type == "E"
    @total_price
  else
    @max_nightly_rate
  end
end

#reserve!(info) ⇒ Object

Public: Reserve a room.

info - A Hash of the information described on the Suitcase

[wiki](http://github.com/thoughtfusion/suitcase/wiki/User-flow).

Returns a Suitcase::Reservation.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/suitcase/hotel/room.rb', line 35

def reserve!(info)
  params = {}
  params["hotelId"] = @hotel_id
  params["arrivalDate"] = @arrival
  params["departureDate"] = @departure
  params["supplierType"] = @supplier_type
  # Only submit the rateKey if it is a merchant hotel
  params["rateKey"] = @rate_key if @supplier_type == "E"
  params["rateTypeCode"] = @room_type_code
  params["rateCode"] = @rate_code
  params["roomTypeCode"] = @room_type_code
  params["chargeableRate"] = chargeable_rate      
  params["email"] = info[:email]
  params["firstName"] = info[:first_name]
  params["lastName"] = info[:last_name]
  params["homePhone"] = info[:home_phone]
  params["workPhone"] = info[:work_phone] if info[:work_phone]
  params["extension"] = info[:work_phone_extension] if info[:work_phone_extension]
  params["faxPhone"] = info[:fax_phone] if info[:fax_phone]
  params["companyName"] = info[:company_name] if info[:company_name]
  if info[:additional_emails]
    params["emailIntineraryList"] = info[:additional_emails].join(",")
  end
  params["creditCardType"] = info[:payment_option].code
  params["creditCardNumber"] = info[:credit_card_number]
  params["creditCardIdentifier"] = info[:credit_card_verification_code]
  expiration_date = Date._parse(info[:credit_card_expiration_date])
  params["creditCardExpirationMonth"] = if expiration_date[:mon] < 10
                                          "0" + expiration_date[:mon].to_s
                                        else
                                          expiration_date[:mon].to_s
                                        end
  params["creditCardExpirationYear"] = expiration_date[:year].to_s
  params["address1"] = info[:address1]
  params["address2"] = info[:address2] if info[:address2]
  params["address3"] = info[:address3] if info[:address3]
  params["city"] = info[:city]
  params.merge!(parameterize_rooms(@rooms))
  @rooms.each_with_index do |room, index|
    index += 1
    params["room#{index}FirstName"] = room[:first_name] || params["firstName"] # defaults to the billing
    params["room#{index}LastName"] = room[:last_name] || params["lastName"] # person's name
    params["room#{index}BedTypeId"] = room[:bed_type].id if @supplier_type == "E"
    params["room#{index}SmokingPreference"] = room[:smoking_preference] || "E"
  end
  params["stateProvinceCode"] = info[:province]
  params["countryCode"] = info[:country]
  params["postalCode"] = info[:postal_code]

  uri = Room.url(
    method: "res",
    params: params,
    include_key: true,
    include_cid: true,
    secure: true
  )
  session = Patron::Session.new
  session.timeout = 30000
  session.base_url = "https://" + uri.host
  res = session.post uri.request_uri, {}
  parsed = JSON.parse res.body

  reservation_res = parsed["HotelRoomReservationResponse"]
  handle_errors(parsed)
  rate_info = reservation_res["RateInfos"]["RateInfo"]
  surcharges = if @supplier_type == "E" && rate_info["ChargeableRateInfo"]["Surcharges"]
    [rate_info["ChargeableRateInfo"]["Surcharges"]["Surcharge"]].
      flatten.map { |s| Surcharge.parse(s) }
  else
    []
  end
  r = Reservation.new(
    itinerary_id: reservation_res["itineraryId"],
    confirmation_numbers: reservation_res["confirmationNumbers"],
    surcharges: surcharges 
  )
  r.raw = parsed
  r
end

#room_rate_descriptionObject

Public: The description of the displayed rate.

Returns the rate description based on the ‘rate_change` attribute.



129
130
131
132
133
134
135
# File 'lib/suitcase/hotel/room.rb', line 129

def room_rate_description
  if @rate_change
    "rate changes during the dates requested and the single nightly rate displayed is the highest nightly rate of the dates requested without taxes and fees."
  else
    "highest single night rate during the dates selected without taxes or fees"
  end
end