module BookingSync::API::Client::Bookings

Public Instance Methods

add_bookings_fee(booking, options = {}) click to toggle source

Add a bookings_fee

@param booking [BookingSync::API::Resource|Integer] Booking or ID of the booking for which the bookings fee should be added @param options [Hash] Bookings_fee attributes. @return [BookingSync::API::Resource] Booking attributes, bookings fees included @example

booking = @api.bookings.first
@api.add_bookings_fee(booking, { price: 100, times_booked: 1, name_en: "Cleaning Fee" })
# File lib/bookingsync/api/client/bookings.rb, line 95
def add_bookings_fee(booking, options = {})
  patch("bookings/#{booking}/add_bookings_fee", bookings_fees: [options]).pop
end
booking(booking, options = {}) click to toggle source

Get a single booking

@param booking [BookingSync::API::Resource|Integer] Booking or ID

of the booking.

@param options [Hash] A customizable set of query options. @option options [Array] fields: List of fields to be fetched. @option options [Boolean] include_canceled: If true canceled bookings

are shown, otherwise they are hidden.

@return [BookingSync::API::Resource]

# File lib/bookingsync/api/client/bookings.rb, line 42
def booking(booking, options = {})
  get("bookings/#{booking}", options).pop
end
bookings(options = {}, &block) click to toggle source

List bookings

Return public future bookings for the account user is authenticated with. @param options [Hash] A customizable set of query options. @option options [Array] fields: List of fields to be fetched. @option options [Time] from: Select bookings ending after given date. @option options [Time] until: Select bookings starting before given date. @option options [Integer] months: Select bookings starting before

:from + months, if :from is blank, current time is taken.

@option options [Boolean] include_canceled: If true canceled bookings

are shown, otherwise they are hidden.

@option options [Array] status: Array of booking states.

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

@return [Array<BookingSync::API::Resource>] Array of bookings. @example

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

@example Pagination

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

@see developers.bookingsync.com/reference/endpoints/bookings/#list-bookings @see developers.bookingsync.com/reference/endpoints/bookings/#search-bookings

# File lib/bookingsync/api/client/bookings.rb, line 29
def bookings(options = {}, &block)
  paginate :bookings, options, &block
end
cancel_booking(booking, options = nil) click to toggle source

Cancel a booking

@param booking [BookingSync::API::Resource|Integer] Booking or ID of

the booking to be canceled.

@param options [Hash] Booking attributes to be updated.

(For now, only `cancelation_reason` is allowed)

@return [NilClass] Returns nil on success. @example

@api.cancel_booking(booking_id)

@example Providing cancelation_reason

@api.cancel_booking(booking_id, { cancelation_reason: "payment_failed" })
# File lib/bookingsync/api/client/bookings.rb, line 81
def cancel_booking(booking, options = nil)
  options = { bookings: [options] } if options
  delete "bookings/#{booking}", options
end
create_booking(rental, options = {}) click to toggle source

Create a booking

@param rental [BookingSync::API::Resource|Integer] Rental or ID of

the rental for which booking will be created.

@param options [Hash] Booking attributes. @return [BookingSync::API::Resource] Newly create booking.

# File lib/bookingsync/api/client/bookings.rb, line 52
def create_booking(rental, options = {})
  post("rentals/#{rental}/bookings", bookings: [options]).pop
end
edit_booking(booking, options = {}) click to toggle source

Edit a booking

@param booking [BookingSync::API::Resource|Integer] Booking or ID of the booking

to be updated

@param options [Hash] Booking attributes to be updated @return [BookingSync::API::Resource] Updated booking on success, exception is raised otherwise @example

booking = @api.bookings.first
@api.edit_booking(booking, { adults: 1 })
# File lib/bookingsync/api/client/bookings.rb, line 65
def edit_booking(booking, options = {})
  put("bookings/#{booking}", bookings: [options]).pop
end
remove_bookings_fee(booking, bookings_fee_id) click to toggle source

Remove a bookings_fee

@param booking [BookingSync::API::Resource|Integer] Booking or ID of the booking for which the bookings fee should be removed @param options [Integer] ID of the bookings_fee to be removed. @return [BookingSync::API::Resource] Booking attributes, remaining bookings fees included @example

booking = @api.bookings.first
@api.remove_bookings_fee(booking, 1)
# File lib/bookingsync/api/client/bookings.rb, line 108
def remove_bookings_fee(booking, bookings_fee_id)
  patch("bookings/#{booking}/remove_bookings_fee/#{bookings_fee_id}").pop
end