Module: BookingSync::API::Client::Attachments

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

Instance Method Summary collapse

Instance Method Details

#attachment(attachment) ⇒ BookingSync::API::Resource

Get a single attachment

Parameters:

Returns:



24
25
26
# File 'lib/bookingsync/api/client/attachments.rb', line 24

def attachment(attachment)
  get("inbox/attachments/#{attachment}").pop
end

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

List attachments

Returns attachments for the account user is authenticated with.

Examples:

Get the list of attachments for the current account

attachments = @api.attachments
attachments.first.name # => "test.jpg"

Parameters:

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

    A customizable set of options.

Options Hash (options):

  • fields: (Array)

    List of fields to be fetched.

Returns:

See Also:



15
16
17
# File 'lib/bookingsync/api/client/attachments.rb', line 15

def attachments(options = {}, &block)
  paginate "inbox/attachments", options, &block
end

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

Create a new attachment

Parameters:

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

    Attachment’s attributes.

Returns:



32
33
34
35
36
37
# 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_attachment(attachment, options = {}) ⇒ BookingSync::API::Resource

Edit a attachment

Examples:

attachment = @api.attachments.first
@api.edit_attachment(attachment, { name: "test.jpg" })

Parameters:

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

    Attachment or ID of the attachment to be updated.

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

    Attachment attributes to be updated.

Returns:



49
50
51
52
53
54
# 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