Class: Nylas::Drafts

Inherits:
Resource show all
Includes:
ApiOperations::Delete, ApiOperations::Get, ApiOperations::Post, ApiOperations::Put
Defined in:
lib/nylas/resources/drafts.rb

Overview

Nylas Drafts API

Instance Method Summary collapse

Methods inherited from Resource

#initialize

Constructor Details

This class inherits a constructor from Nylas::Resource

Instance Method Details

#create(identifier:, request_body:) ⇒ Array(Hash, String)

Create an draft.

Parameters:

  • identifier (String)

    Grant ID or email account in which to create the draft.

  • request_body (Hash)

    The values to create the message with. If you're attaching files, you must pass an array of [File] objects, or you can use FileUtils::attach_file_request_builder to build each object attach.

Returns:

  • (Array(Hash, String))

    The created draft and API Request ID.



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/nylas/resources/drafts.rb', line 45

def create(identifier:, request_body:)
  form_body, opened_files = FileUtils.build_form_request(request_body)
  response = post(
    path: "#{api_uri}/v3/grants/#{identifier}/drafts",
    request_body: form_body
  )

  opened_files.each(&:close)

  response
end

#destroy(identifier:, draft_id:) ⇒ Array(TrueClass, String)

Delete an draft.

Parameters:

  • identifier (String)

    Grant ID or email account from which to delete an object.

  • draft_id (String)

    The id of the draft to delete.

Returns:

  • (Array(TrueClass, String))

    True and the API Request ID for the delete operation.



83
84
85
86
87
88
89
# File 'lib/nylas/resources/drafts.rb', line 83

def destroy(identifier:, draft_id:)
  _, request_id = delete(
    path: "#{api_uri}/v3/grants/#{identifier}/drafts/#{draft_id}"
  )

  [true, request_id]
end

#find(identifier:, draft_id:) ⇒ Array(Hash, String)

Return an draft.

Parameters:

  • identifier (String)

    Grant ID or email account to query.

  • draft_id (String)

    The id of the draft to return.

Returns:

  • (Array(Hash, String))

    The draft and API request ID.



32
33
34
35
36
# File 'lib/nylas/resources/drafts.rb', line 32

def find(identifier:, draft_id:)
  get(
    path: "#{api_uri}/v3/grants/#{identifier}/drafts/#{draft_id}"
  )
end

#list(identifier:, query_params: nil) ⇒ Array(Array(Hash), String)

Return all drafts.

Parameters:

  • identifier (String)

    Grant ID or email account to query.

  • query_params (Hash, nil) (defaults to: nil)

    Query params to pass to the request.

Returns:

  • (Array(Array(Hash), String))

    The list of drafts and API Request ID.



20
21
22
23
24
25
# File 'lib/nylas/resources/drafts.rb', line 20

def list(identifier:, query_params: nil)
  get(
    path: "#{api_uri}/v3/grants/#{identifier}/drafts",
    query_params: query_params
  )
end

#send(identifier:, draft_id:) ⇒ Array(Hash, String)

Send an draft.

Parameters:

  • identifier (String)

    Grant ID or email account from which to send the draft.

  • draft_id (String)

    The id of the draft to send.

Returns:

  • (Array(Hash, String))

    The sent message draft and the API Request ID.



96
97
98
99
100
# File 'lib/nylas/resources/drafts.rb', line 96

def send(identifier:, draft_id:)
  post(
    path: "#{api_uri}/v3/grants/#{identifier}/drafts/#{draft_id}"
  )
end

#update(identifier:, draft_id:, request_body:) ⇒ Array(Hash, String)

Update an draft.

Parameters:

  • identifier (String)

    Grant ID or email account in which to update the draft.

  • draft_id (String)

    The id of the draft to update.

  • request_body (Hash)

    The values to create the message with. If you're attaching files, you must pass an array of [File] objects, or you can use FileUtils::attach_file_request_builder to build each object attach.

Returns:

  • (Array(Hash, String))

    The updated draft and API Request ID.



65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/nylas/resources/drafts.rb', line 65

def update(identifier:, draft_id:, request_body:)
  form_body, opened_files = FileUtils.build_form_request(request_body)

  response = put(
    path: "#{api_uri}/v3/grants/#{identifier}/drafts/#{draft_id}",
    request_body: form_body
  )

  opened_files.each(&:close)

  response
end