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

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

Add a bookings_fee

for which the bookings fee should be added

Examples:

booking = @api.bookings.first
@api.add_bookings_fee(booking, { price: 100, times_booked: 1, name_en: "Cleaning Fee" })

Parameters:

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

    Booking or ID of the booking

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

    Bookings_fee attributes.

Returns:



95
96
97
# 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 = {}) ⇒ BookingSync::API::Resource

Get a single booking

Parameters:

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

    Booking or ID of the booking.

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

    A customizable set of query options.

Options Hash (options):

  • fields: (Array)

    List of fields to be fetched.

  • include_canceled: (Boolean)

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

Returns:



42
43
44
# File 'lib/bookingsync/api/client/bookings.rb', line 42

def booking(booking, options = {})
  get("bookings/#{booking}", options).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 = nil) ⇒ NilClass

Cancel a booking

Examples:

@api.cancel_booking(booking_id)

Providing cancelation_reason

@api.cancel_booking(booking_id, { cancelation_reason: "payment_failed" })

Parameters:

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

    Booking or ID of the booking to be canceled.

  • options (Hash) (defaults to: nil)

    Booking attributes to be updated. (For now, only ‘cancelation_reason` is allowed)

Returns:

  • (NilClass)

    Returns nil on success.



81
82
83
84
# 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 = {}) ⇒ 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:



52
53
54
# 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 = {}) ⇒ 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:



65
66
67
# 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) ⇒ BookingSync::API::Resource

Remove a bookings_fee

for which the bookings fee should be removed

Examples:

booking = @api.bookings.first
@api.remove_bookings_fee(booking, 1)

Parameters:

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

    Booking or ID of the booking

  • options (Integer)

    ID of the bookings_fee to be removed.

Returns:



108
109
110
# 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