Module: BookingSync::API::Client::Photos

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

Instance Method Summary collapse

Instance Method Details

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

Create a photo

Examples:

Create a photo.

@api.create_photo(10, photo_path: 'rentals/big_one.jpg')

Parameters:

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

    Rental object or ID for which the photo will be created. Image can be provided in three was, as a file path, encode string or as an URL.

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

    Photo’s attributes.

Options Hash (options):

  • photo_path: (String)

    Path to the image to be uploaded.

  • photo: (String)

    Photo encoded with Base64

  • remote_photo_url: (String)

    URL to a remote image which will be fetched and then saved

Returns:

See Also:



37
38
39
40
41
42
# File 'lib/bookingsync/api/client/photos.rb', line 37

def create_photo(rental, options = {})
  if photo_path = options.delete(:photo_path)
    options[:photo] ||= encode(photo_path)
  end
  post("rentals/#{rental}/photos", photos: [options]).pop
end

#delete_photo(photo) ⇒ NilClass

Delete a photo

Parameters:

Returns:

  • (NilClass)

    Returns nil on success.

See Also:



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

def delete_photo(photo)
  delete "photos/#{photo}"
end

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

Edit a photo

Parameters:

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

    Photo or ID of the photo to be updated.

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

    Photo’s attributes.

Returns:

See Also:



51
52
53
54
55
56
# File 'lib/bookingsync/api/client/photos.rb', line 51

def edit_photo(photo, options = {})
  if photo_path = options.delete(:photo_path)
    options[:photo] ||= encode(photo_path)
  end
  put("photos/#{photo}", photos: [options]).pop
end

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

List photos

Returns photos for the account user is authenticated with.

Examples:

Get the list of photos for the current account

photos = @api.photos
photos.first.position # => 1

Get the list of photos only with medium_url and position for smaller response

@api.photos(fields: [:medium_url, :position])

Parameters:

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

    A customizable set of options.

Options Hash (options):

  • fields: (Array)

    List of fields to be fetched.

Returns:

See Also:



19
20
21
# File 'lib/bookingsync/api/client/photos.rb', line 19

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