Class: VacationRentalsIcalAdapters::Adapters::JsonAvailabilityMapAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/vacation_rentals_ical_adapters/adapters/json_availability_map_adapter.rb

Overview

Availability map response format should be similar to

{

"availabilities": [
  {
    "map":"1111100000000011",
    "start_date":"2016-12-08"
  }
]

}

Instance Method Summary collapse

Instance Method Details

#applicable?(body:, source:) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
23
24
# File 'lib/vacation_rentals_ical_adapters/adapters/json_availability_map_adapter.rb', line 17

def applicable?(body:, source:)
  begin
    availability = JSON.parse(body)["availabilities"][0]
    !!(availability["map"].present? && availability["start_date"].to_date)
  rescue
    false
  end
end

#to_ical(body) ⇒ Object



26
27
28
29
# File 'lib/vacation_rentals_ical_adapters/adapters/json_availability_map_adapter.rb', line 26

def to_ical(body)
  events = parse_events(body)
  VacationRentalsIcalAdapters::IcalConverter.to_ical(events)
end