Module: Suitcase::Helpers

Included in:
Hotel, Suitcase::Hotel::Location, PaymentOption, Room
Defined in:
lib/suitcase/helpers.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) base_url(info)



31
32
33
34
35
36
37
# File 'lib/suitcase/helpers.rb', line 31

def base_url(info)
  if info[:booking]
    URI.parse main_url(true)
  else
    URI.parse main_url(false)
  end
end

- (Object) main_url(secure)



23
24
25
# File 'lib/suitcase/helpers.rb', line 23

def main_url(secure)
  "http#{secure ? "s" : ""}://#{secure ? "book." : ""}api.ean.com/ean-services/rs/hotel/v3/"
end

- (Object) parse_response(uri)



27
28
29
# File 'lib/suitcase/helpers.rb', line 27

def parse_response(uri)
  JSON.parse(Net::HTTP.get_response(uri).body)
end

- (Object) update_session(parsed, session)



39
40
41
42
# File 'lib/suitcase/helpers.rb', line 39

def update_session(parsed, session)
  session ||= Suitcase::Session.new
  session.id = parsed[parsed.keys.first]["customerSessionId"] if parsed[parsed.keys.first]
end

- (Object) url(builder)



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/suitcase/helpers.rb', line 3

def url(builder)
  builder[:include_key] ||= true
  builder[:include_cid] ||= true
  builder[:secure] ||= false
  builder[:as_form] ||= false
  builder[:session] ||= Suitcase::Session.new
  method, params, include_key, include_cid = builder[:method], builder[:params], builder[:include_key], builder[:include_cid]
  params["apiKey"] = Configuration.hotel_api_key if include_key
  params["cid"] = (Configuration.hotel_cid ||= 55505) if include_cid
  url = main_url(builder[:secure]) + method.to_s + (builder[:as_form] ? "" : "?")
  session_info = {}
  session_info["customerSessionId"] = builder[:session].id if builder[:session].id
  session_info["customerIpAddress"] = builder[:session].ip_address if builder[:session].ip_address
  session_info["locale"] = builder[:session].locale if builder[:session].locale
  session_info["currencyCode"] = builder[:session].currency_code if builder[:session].currency_code
  session_info["customerUserAgent"] = builder[:session].user_agent if builder[:session].user_agent
  url += params.merge(session_info).map { |key, value| "#{key}=#{value}"}.join("&") unless builder[:as_form]
  URI.parse(URI.escape(url))
end