module QboApi::Attachment

Public Instance Methods

attachment_connection() click to toggle source
# File lib/qbo_api/attachment.rb, line 35
def attachment_connection
  @attachment_connection ||= authorized_multipart_connection(endpoint_url)
end
delete_attachment(attachable:) click to toggle source

The ‘attachable` must be the full payload returned in the read response

# File lib/qbo_api/attachment.rb, line 26
def delete_attachment(attachable:)
  raw_response = connection.post do |request|
    request.url "#{realm_id}/attachable?operation=delete"
    request.body = attachable.to_json
  end

  response(raw_response, entity: :attachable)
end
read_attachment(id:) click to toggle source
# File lib/qbo_api/attachment.rb, line 3
def read_attachment(id:)
  raw_response = connection.get do |request|
    request.url "#{realm_id}/attachable/#{id}"
  end
  response(raw_response, entity: :attachable)
end
upload_attachment(payload:, attachment:) click to toggle source
# File lib/qbo_api/attachment.rb, line 10
def upload_attachment(payload:, attachment:)
  content_type = payload['ContentType'] || payload[:ContentType]
  file_name = payload['FileName'] || payload[:FileName]
  raw_response = attachment_connection.post do |request|
    request.url "#{realm_id}/upload"
    request.body = {
      'file_metadata_01':
          Faraday::UploadIO.new(StringIO.new(payload.to_json), 'application/json', 'attachment.json'),
      'file_content_01':
          Faraday::UploadIO.new(attachment, content_type, file_name)
    }
  end
  response(raw_response, entity: :attachable)
end