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 ways, 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:



48
49
50
51
52
53
# File 'lib/bookingsync/api/client/photos.rb', line 48

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:



75
76
77
# File 'lib/bookingsync/api/client/photos.rb', line 75

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:



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

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

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

Get a single photo

Parameters:

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

    Photo or ID of the photo.

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

    A customizable set of query options.

Options Hash (options):

  • fields: (Array)

    List of fields to be fetched.

Returns:



30
31
32
# File 'lib/bookingsync/api/client/photos.rb', line 30

def photo(photo, options = {})
  get("photos/#{photo}", 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