Module: TL::Parser
- Defined in:
- lib/TL/parser.rb,
lib/TL/parser/version.rb
Overview
parses page and loads offers from TL widget
Defined Under Namespace
Classes: Error
Constant Summary collapse
- LOGIN_KEY =
"TL-INT-"
- OFFERS_BASE_URL =
"https://ibe.tlintegration.com/ApiWebDistribution/BookingForm"
- VERSION =
"0.1.4"
Class Method Summary collapse
Class Method Details
.load_offers(url, opts = {}) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/TL/parser.rb', line 19 def load_offers(url, opts = {}) start_date = opts.fetch(:start_date, Date.today) finish_date = opts.fetch(:finish_date, Date.today.next_day) adults_count = opts.fetch(:adults_count, 2) children_ages = opts.fetch(:children_ages, []) format = opts.fetch(:format, :hash) doc = load_page(url) login = get_login(doc) hotel_id = get_hotel_id(login) offers_link = generate_offers_link(hotel_id, start_date, finish_date, adults_count, children_ages) offers = get_js(offers_link) return nil unless check_response(offers) #TODO сообщения об ошибке hotel_info = get_js(generate_hotel_link(hotel_id)) return nil unless check_response(hotel_info) if format == :hash JSON.parse(offers.body).merge(JSON.parse(hotel_info.body)) elsif format == :objects TL::Offer.from_hash_collection(JSON.parse(offers.body), JSON.parse(hotel_info.body)) end end |