Class: Suitcase::Room

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

base_url, main_url, parse_response, update_session, url

Constructor Details

#initialize(info) ⇒ Room

Returns a new instance of Room



6
7
8
9
10
# File 'lib/suitcase/hotel/room.rb', line 6

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



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

def arrival
  @arrival
end

#average_base_rateObject

Returns the value of attribute average_base_rate



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

def average_base_rate
  @average_base_rate
end

#average_nightly_rateObject

Returns the value of attribute average_nightly_rate



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

def average_nightly_rate
  @average_nightly_rate
end

#average_rateObject

Returns the value of attribute average_rate



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

def average_rate
  @average_rate
end

#bed_typesObject

Returns the value of attribute bed_types



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

def bed_types
  @bed_types
end

#currency_codeObject

Returns the value of attribute currency_code



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

def currency_code
  @currency_code
end

#departureObject

Returns the value of attribute departure



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

def departure
  @departure
end

#hotel_idObject

Returns the value of attribute hotel_id



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

def hotel_id
  @hotel_id
end

#max_nightly_rateObject

Returns the value of attribute max_nightly_rate



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

def max_nightly_rate
  @max_nightly_rate
end

#min_guest_ageObject

Returns the value of attribute min_guest_age



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

def min_guest_age
  @min_guest_age
end

#nightly_rate_totalObject

Returns the value of attribute nightly_rate_total



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

def nightly_rate_total
  @nightly_rate_total
end

#non_refundableObject

Returns the value of attribute non_refundable



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

def non_refundable
  @non_refundable
end

#occupancyObject

Returns the value of attribute occupancy



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

def occupancy
  @occupancy
end

#price_breakdownObject

Returns the value of attribute price_breakdown



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

def price_breakdown
  @price_breakdown
end

#promoObject

Returns the value of attribute promo



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

def promo
  @promo
end

#quoted_occupancyObject

Returns the value of attribute quoted_occupancy



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

def quoted_occupancy
  @quoted_occupancy
end

#rate_codeObject

Returns the value of attribute rate_code



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

def rate_code
  @rate_code
end

#rate_keyObject

Returns the value of attribute rate_key



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

def rate_key
  @rate_key
end

#room_type_codeObject

Returns the value of attribute room_type_code



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

def room_type_code
  @room_type_code
end

#room_type_descriptionObject

Returns the value of attribute room_type_description



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

def room_type_description
  @room_type_description
end

#roomsObject

Returns the value of attribute rooms



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

def rooms
  @rooms
end

#supplier_typeObject

Returns the value of attribute supplier_type



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

def supplier_type
  @supplier_type
end

#surcharge_totalObject

Returns the value of attribute surcharge_total



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

def surcharge_total
  @surcharge_total
end

#tax_rateObject

Returns the value of attribute tax_rate



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

def tax_rate
  @tax_rate
end

#totalObject

Returns the value of attribute total



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

def total
  @total
end

#total_priceObject

Returns the value of attribute total_price



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

def total_price
  @total_price
end

#value_addsObject

Returns the value of attribute value_adds



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

def value_adds
  @value_adds
end

Instance Method Details

#chargeable_rateObject



61
62
63
64
65
66
67
# File 'lib/suitcase/hotel/room.rb', line 61

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

#reserve!(info) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
# File 'lib/suitcase/hotel/room.rb', line 12

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.base_url = "https://" + uri.host
  res = session.post uri.request_uri, {}
  parsed = JSON.parse res.body
  Reservation.new(itinerary_id: parsed["HotelRoomReservationResponse"]["itineraryId"], confirmation_numbers: parsed["HotelRoomReservationResponse"]["confirmationNumbers"])
end