Module: BookingSync::API::Client::Bookings

Included in:
BookingSync::API::Client
Defined in:
lib/bookingsync/api/client/bookings.rb

Instance Method Summary collapse

Instance Method Details

#booking(booking) ⇒ BookingSync::API::Resource

Get a single booking

Parameters:

Returns:



38
39
40
# File 'lib/bookingsync/api/client/bookings.rb', line 38

def booking(booking)
  get("bookings/#{booking}").pop
end

#bookings(options = {}, &block) ⇒ Array<BookingSync::API::Resource>

List bookings

Return public future bookings for the account user is authenticated with.

Examples:

@api.bookings(months: 12, states: [:booked, :unavailable], include_canceled: true)

Pagination

@api.bookings(per_page: 10) do |batch|
  # do something with ten bookings
end

Parameters:

  • options (Hash) (defaults to: {})

    A customizable set of query options.

Options Hash (options):

  • fields: (Array)

    List of fields to be fetched.

  • from: (Time)

    Select bookings ending after given date.

  • until: (Time)

    Select bookings starting before given date.

  • months: (Integer)

    Select bookings starting before :from + months, if :from is blank, current time is taken.

  • include_canceled: (Boolean)

    If true canceled bookings are shown, otherwise they are hidden.

  • status: (Array)

    Array of booking states. If specyfied bookings with given states are shown. Possible statuses: ‘:booked`, `:unavailable` and `:tentative`

Returns:

See Also:



29
30
31
# File 'lib/bookingsync/api/client/bookings.rb', line 29

def bookings(options = {}, &block)
  paginate :bookings, options, &block
end

#cancel_booking(booking, options = {}) ⇒ NilClass

Cancel a booking

Parameters:

Returns:

  • (NilClass)

    Returns nil on success.



70
71
72
# File 'lib/bookingsync/api/client/bookings.rb', line 70

def cancel_booking(booking, options = {})
  delete "bookings/#{booking}"
end

#create_booking(rental, options = {}) ⇒ BookingSync::API::Resource

Create a booking

Parameters:

  • rental (BookingSync::API::Resource|Integer)

    Rental or ID of the rental for which booking will be created.

  • options (Hash) (defaults to: {})

    Booking attributes.

Returns:



48
49
50
# File 'lib/bookingsync/api/client/bookings.rb', line 48

def create_booking(rental, options = {})
  post("rentals/#{rental}/bookings", bookings: [options]).pop
end

#edit_booking(booking, options = {}) ⇒ BookingSync::API::Resource

Edit a booking

Examples:

booking = @api.bookings.first
@api.edit_booking(booking, { adults: 1 })

Parameters:

  • booking (BookingSync::API::Resource|Integer)

    Booking or ID of the booking to be updated

  • options (Hash) (defaults to: {})

    Booking attributes to be updated

Returns:



61
62
63
# File 'lib/bookingsync/api/client/bookings.rb', line 61

def edit_booking(booking, options = {})
  put("bookings/#{booking}", bookings: [options]).pop
end