Class: Nylas::Attachments

Inherits:
Resource show all
Includes:
ApiOperations::Get
Defined in:
lib/nylas/resources/attachments.rb

Overview

Nylas Attachment API

Instance Method Summary collapse

Methods inherited from Resource

#initialize

Constructor Details

This class inherits a constructor from Nylas::Resource

Instance Method Details

#download(identifier:, attachment_id:, query_params:) {|chunk| ... } ⇒ nil, String

Download the attachment data.

This method supports streaming the download by passing a block, which will be called with each chunk of the response body as it is read. If no block is given, the entire response will be read into memory and returned (not recommended for large files).

Parameters:

  • identifier (String)

    Grant ID or email account to query.

  • attachment_id (String)

    The ID of the attachment to be downloaded.

  • query_params (Hash)

    The query parameters to include in the request.

Yield Parameters:

  • chunk (String)

    A chunk of the response body.

Returns:

  • (nil, String)

    Returns nil when a block is given (streaming mode). When no block is provided, the return is the entire raw response body.



37
38
39
40
41
42
43
44
45
# File 'lib/nylas/resources/attachments.rb', line 37

def download(identifier:, attachment_id:, query_params:, &block)
  download_request(
    path: "#{api_uri}/v3/grants/#{identifier}/attachments/#{attachment_id}/download",
    query: query_params,
    api_key: api_key,
    timeout: timeout,
    &block
  )
end

#download_bytes(identifier:, attachment_id:, query_params:) ⇒ nil, Array(Integer)

Download the attachment as a byte array.

Parameters:

  • identifier (String)

    Grant ID or email account to query.

  • attachment_id (String)

    The ID of the attachment to be downloaded.

  • query_params (Hash)

    The query parameters to include in the request.

Returns:

  • (nil, Array(Integer))

    Returns nil when a block is given (streaming mode). When no block is provided, the return is the entire raw response body.



54
55
56
57
58
59
60
61
62
63
# File 'lib/nylas/resources/attachments.rb', line 54

def download_bytes(identifier:, attachment_id:, query_params:)
  data = download_request(
    path: "#{api_uri}/v3/grants/#{identifier}/attachments/#{attachment_id}/download",
    query: query_params,
    api_key: api_key,
    timeout: timeout
  )

  data&.bytes
end

#find(identifier:, attachment_id:, query_params:) ⇒ Array(Hash, String)

Return metadata of an attachment.

Parameters:

  • identifier (String)

    Grant ID or email account to query.

  • attachment_id (String)

    The id of the attachment to retrieve.

  • query_params (Hash)

    The query parameters to include in the request.

Returns:

  • (Array(Hash, String))

    The attachment and API request ID.



17
18
19
20
21
22
# File 'lib/nylas/resources/attachments.rb', line 17

def find(identifier:, attachment_id:, query_params:)
  get(
    path: "#{api_uri}/v3/grants/#{identifier}/attachments/#{attachment_id}",
    query_params: query_params
  )
end