module BookingSync::API::Client::Attachments
Public Instance Methods
Get a single attachment
@param attachment [BookingSync::API::Resource|Integer] Attachment or ID
of the attachment.
@return [BookingSync::API::Resource]
# File lib/bookingsync/api/client/attachments.rb, line 24 def attachment(attachment) get("inbox/attachments/#{attachment}").pop end
List attachments
Returns attachments for the account user is authenticated with. @param options [Hash] A customizable set of options. @option options [Array] fields: List of fields to be fetched. @return [Array<BookingSync::API::Resource>] Array of attachments.
@example Get the list of attachments for the current account
attachments = @api.attachments attachments.first.name # => "test.jpg"
@see developers.bookingsync.com/reference/endpoints/attachments/#list-attachments
# File lib/bookingsync/api/client/attachments.rb, line 15 def attachments(options = {}, &block) paginate "inbox/attachments", options, &block end
Create a new attachment
@param options [Hash] Attachmentâs attributes. @return [BookingSync::API::Resource] Newly created attachment.
# File lib/bookingsync/api/client/attachments.rb, line 32 def create_attachment(options = {}) if file_path = options.delete(:file_path) options[:file] ||= base_64_encode(file_path) end post("inbox/attachments", attachments: [options]).pop end
Edit a attachment
@param attachment [BookingSync::API::Resource|Integer] Attachment or ID of
the attachment to be updated.
@param options [Hash] Attachment attributes to be updated. @return [BookingSync::API::Resource] Updated attachment on success,
exception is raised otherwise.
@example
attachment = @api.attachments.first @api.edit_attachment(attachment, { name: "test.jpg" })
# File lib/bookingsync/api/client/attachments.rb, line 49 def edit_attachment(attachment, options = {}) if file_path = options.delete(:file_path) options[:file] ||= base_64_encode(file_path) end put("inbox/attachments/#{attachment}", attachments: [options]).pop end
Private Instance Methods
# File lib/bookingsync/api/client/attachments.rb, line 58 def base_64_encode(file_path) Base64.encode64(File.read(file_path)) end