Class: Suitcase::Hotel::Cancellation

Inherits:
Object
  • Object
show all
Extended by:
Helpers
Includes:
Helpers
Defined in:
lib/suitcase/hotel/cancellation.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) ⇒ Cancellation

Accepts a hash with the itinerary_id, confirmation_number, email and optional reason code (COP ILL DEA OTH)



13
14
15
16
17
# File 'lib/suitcase/hotel/cancellation.rb', line 13

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

Instance Attribute Details

#cancellation_numberObject

Returns the value of attribute cancellation_number.



7
8
9
# File 'lib/suitcase/hotel/cancellation.rb', line 7

def cancellation_number
  @cancellation_number
end

#confirmation_numberObject

Returns the value of attribute confirmation_number.



7
8
9
# File 'lib/suitcase/hotel/cancellation.rb', line 7

def confirmation_number
  @confirmation_number
end

#emailObject

Returns the value of attribute email.



7
8
9
# File 'lib/suitcase/hotel/cancellation.rb', line 7

def email
  @email
end

#itinerary_idObject

Returns the value of attribute itinerary_id.



7
8
9
# File 'lib/suitcase/hotel/cancellation.rb', line 7

def itinerary_id
  @itinerary_id
end

#reasonObject

Returns the value of attribute reason.



7
8
9
# File 'lib/suitcase/hotel/cancellation.rb', line 7

def reason
  @reason
end

Instance Method Details

#cancel_reservation!Object

Makes the call to EAN and if successful sets the cancellation_number attribute



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/suitcase/hotel/cancellation.rb', line 21

def cancel_reservation!
  params = {}
  params["itineraryId"]        = itinerary_id
  params["email"]              = email
  params["confirmationNumber"] = confirmation_number
  params["reason"]             = reason if valid_reason?

  uri = Cancellation.url(
    method: 'cancel',
    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
  handle_errors(parsed)
  @cancellation_number = parsed["HotelRoomCancellationResponse"]["cancellationNumber"]
end

#reservation_canceled?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/suitcase/hotel/cancellation.rb', line 45

def reservation_canceled?
  !cancellation_number.nil?
end

#valid_reason?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/suitcase/hotel/cancellation.rb', line 49

def valid_reason?
  %w(COP ILL DEA OTH).include?(reason)
end