Class: Suitcase::Hotel::Room

Inherits:
Object
  • Object
show all
Extended by:
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, main_url, parameterize, 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.


20
21
22
23
24
# File 'lib/suitcase/hotel/room.rb', line 20

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

#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

#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_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_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.



93
94
95
96
97
98
99
# File 'lib/suitcase/hotel/room.rb', line 93

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.



32
33
34
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
# File 'lib/suitcase/hotel/room.rb', line 32

def reserve!(info)
  params = {}
  params["hotelId"] = @hotel_id
  params["arrivalDate"] = @arrival
  params["departureDate"] = @departure
  params["supplierType"] = @supplier_type
  params["rateKey"] = @rate_key
  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]
  params["emailIntineraryList"] = info[:additional_emails].join(",") if info[:additional_emails]
  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"] = (expiration_date[:mon].to_s.length == 1 ? "0" + expiration_date[:mon].to_s : expiration_date[:mon].to_s)
  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]
  @rooms.each_with_index do |room, index|
    index += 1
    params["room#{index}"] = "#{room[:adults].to_s},#{room[:children_ages].join(",")}"
    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
    params["room#{index}SmokingPreference"] = room[:smoking_preference] or "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


  r = Reservation.new(itinerary_id: parsed["HotelRoomReservationResponse"]["itineraryId"],
                      confirmation_numbers: parsed["HotelRoomReservationResponse"]["confirmationNumbers"],
                      surcharges: [parsed["HotelRoomReservationResponse"]["RateInfo"]["ChargeableRateInfo"]["Surcharges"]["Surcharge"]].flatten.map { |s| Surcharge.parse(s) } 
                     )
  r.raw = parsed
  r
end