Module: BookingSync::API::Client::Rentals

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

Instance Method Summary collapse

Instance Method Details

#create_rental(options = {}) ⇒ BookingSync::API::Resource

Create a new rental

Parameters:

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

    rental attributes

Returns:



51
52
53
# File 'lib/bookingsync/api/client/rentals.rb', line 51

def create_rental(options = {})
  post(:rentals, rentals: [options]).pop
end

#delete_rental(rental) ⇒ NilClass

Delete a rental

Parameters:

Returns:

  • (NilClass)

    Returns nil on success.



73
74
75
# File 'lib/bookingsync/api/client/rentals.rb', line 73

def delete_rental(rental)
  delete "rentals/#{rental}"
end

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

Edit a rental

to be updated

Examples:

rental = @api.rentals.first
@api.edit_rental(rental, { sleeps: 3 })

Parameters:

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

    rental or ID of the rental

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

    rental attributes to be updated

Returns:



64
65
66
# File 'lib/bookingsync/api/client/rentals.rb', line 64

def edit_rental(rental, options = {})
  put("rentals/#{rental}", rentals: [options]).pop
end

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

Get a single rental

Parameters:

Returns:



43
44
45
# File 'lib/bookingsync/api/client/rentals.rb', line 43

def rental(rental, options = {})
  get("rentals/#{rental}", options).pop
end

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

List rentals

Returns rentals for the account user is authenticated with.

Examples:

Get the list of rentals for the current account

rentals = @api.rentals
rentals.first.name # => "Small apartment"

Get the list of rentals only with name and description for smaller response

@api.rentals(fields: [:name, :description])

Parameters:

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

    A customizable set of options.

Options Hash (options):

  • fields: (Array)

    List of fields to be fetched.

Returns:

See Also:



17
18
19
# File 'lib/bookingsync/api/client/rentals.rb', line 17

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

#rentals_meta(rentals = nil) ⇒ BookingSync::API::Resource

Get meta information about rentals.

Parameters:

  • rentals (Array) (defaults to: nil)

    IDs of Rentals, leave empty for all account’s rentals

Returns:



81
82
83
84
# File 'lib/bookingsync/api/client/rentals.rb', line 81

def rentals_meta(rentals = nil)
  path = reject_blank_values(["rentals", Array(rentals).join(","), "meta"]).join("/")
  get(path).pop
end

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

Search rentals

Returns list of light rentals. Composed of id, initial_price, final_price and updated_at.

villas = @api.rentals_search(rental_type: “villa”)

Examples:

Search rentals by rental type

Parameters:

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

    A customizable set of options.

Returns:



31
32
33
34
35
36
# File 'lib/bookingsync/api/client/rentals.rb', line 31

def rentals_search(options = {}, &block)
  ids = Array(options.delete(:ids))
  path = reject_blank_values(["rentals", ids.join(","), "search"]).join("/")
  defaults = { request_method: :post }
  paginate path, defaults.merge(options), &block
end