VacationRentalsIcalAdapters Build Status Gem Version Coverage Status

Gem for converting different formats from various vacation rental distribution channels to iCal format. So far it handles the following adapters:

  • iCal Adapter: returns not changed iCal body if it is indeed iCal format
  • XML Arkiane Adapter - transforms XML response from xml.arkiane.com for given property into iCal format
  • CSV BookedDays Adapter - check the code for example payload
  • JSON Availability Map Adapter - check the code for example payload

Installation

Add this line to your application's Gemfile:

gem 'vacation_rentals_ical_adapters'

And then execute:

$ bundle

Or install it yourself as:

$ gem install vacation_rentals_ical_adapters

Usage

The public API is limited to VacationRentalsIcalAdapters::Parser#to_ical method, here's example how to use it:

source = "http://xml.arkiane.com/xml_v2.asp?app=X&clt=X&top=-1&qry=to_get_planning@top_id=X,@lot_ref=X"
arkiane_xml_body = %q{<?xml version='1.0' encoding='ISO-8859-1'?>
<QRY-CLT1XXX-TOP-1>
  <LINE>
    <Planning>
      <l_plng_no>1</l_plng_no>
      <l_imme_no>1</l_imme_no>
      <l_lot_no>12</l_lot_no>
      <l_ref>XXX</l_ref>
      <o_debut>27/08/2016</o_debut>
      <o_fin>10/12/2016</o_fin>
      <o_type>YYY</o_type>
    </Planning>
  </LINE>
  <LINE>
    <Planning>
      <l_plng_no>1</l_plng_no>
      <l_imme_no>1</l_imme_no>
      <l_lot_no>12</l_lot_no>
      <l_ref>XXX</l_ref>
      <o_debut>01/11/2016</o_debut>
      <o_fin>01/12/2016</o_fin>
      <o_type>YYY</o_type>
    </Planning>
  </LINE>
</QRY-CLT1XXX-TOP-1>}

VacationRentalsIcalAdapters::Parser.to_ical(arkiane_xml_body, source: source)
  => """
BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VEVENT
DTEND;VALUE=DATE:20161210
DTSTART;VALUE=DATE:20160827
END:VEVENT
BEGIN:VEVENT
DTEND;VALUE=DATE:20161201
DTSTART;VALUE=DATE:20161101
END:VEVENT
END:VCALENDAR
"""

Adding new adapters

Every new adapter needs to implement applicable?(body:, source:) and to_ical(body) methods. Once you've create a new adapter, you need to register it inside VacationRentalsIcalAdapters::Adapters class, for example:

require "vacation_rentals_ical_adapters/adapters/new_awesome_adapter"

register(NewAwesomeAdapter.new)

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/Azdaroth/vacation_rentals_ical_adapters.

License

The gem is available as open source under the terms of the MIT License.