Class: Nylas::Messages

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

Overview

Nylas Messages API

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sdk_instance) ⇒ Messages

Initializes the messages resource.

Parameters:

  • sdk_instance (Nylas::API)

    The API instance to which the resource is bound.



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

def initialize(sdk_instance)
  super(sdk_instance)
  @smart_compose = SmartCompose.new(sdk_instance)
end

Instance Attribute Details

#smart_composeObject (readonly)

Returns the value of attribute smart_compose.



29
30
31
# File 'lib/nylas/resources/messages.rb', line 29

def smart_compose
  @smart_compose
end

Instance Method Details

#clean_messages(identifier:, request_body:) ⇒ Array(Hash)

Clean a message.

Parameters:

  • identifier (String)

    Grant ID or email account from which to clean a message.

  • request_body (Hash)

    The options to clean a message with

Returns:

  • (Array(Hash))

    The list of clean messages.



106
107
108
109
110
111
# File 'lib/nylas/resources/messages.rb', line 106

def clean_messages(identifier:, request_body:)
  put(
    path: "#{api_uri}/v3/grants/#{identifier}/messages/clean",
    request_body: request_body
  )
end

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

Delete a message.

Parameters:

  • identifier (String)

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

  • message_id (String)

    The id of the message to delete.

Returns:

  • (Array(TrueClass, String))

    True and the API Request ID for the delete operation.



93
94
95
96
97
98
99
# File 'lib/nylas/resources/messages.rb', line 93

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

  [true, request_id]
end

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

Return a message.

Parameters:

  • identifier (String)

    Grant ID or email account to query.

  • message_id (String)

    The id of the message to return.

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

    Query params to pass to the request. You can use the fields parameter to specify which data to return:

    • MessageFields::STANDARD (default): Returns the standard message payload

    • MessageFields::INCLUDE_HEADERS: Returns messages and their custom headers

    • MessageFields::INCLUDE_TRACKING_OPTIONS: Returns messages and their tracking settings

    • MessageFields::RAW_MIME: Returns the grant_id, object, id, and raw_mime fields only

Returns:

  • (Array(Hash, String))

    The message and API request ID.



66
67
68
69
70
71
# File 'lib/nylas/resources/messages.rb', line 66

def find(identifier:, message_id:, query_params: nil)
  get(
    path: "#{api_uri}/v3/grants/#{identifier}/messages/#{message_id}",
    query_params: query_params
  )
end

#find_scheduled_messages(identifier:, schedule_id:) ⇒ Array(Hash, String)

Retrieve your scheduled messages.

Parameters:

  • identifier (String)

    Grant ID or email account from which to list the scheduled messages from.

  • schedule_id (String)

    The id of the scheduled message to stop.

Returns:

  • (Array(Hash, String))

    The scheduled message and the API Request ID.



149
150
151
152
153
# File 'lib/nylas/resources/messages.rb', line 149

def find_scheduled_messages(identifier:, schedule_id:)
  get(
    path: "#{api_uri}/v3/grants/#{identifier}/messages/schedules/#{schedule_id}"
  )
end

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

Return all messages.

Parameters:

  • identifier (String)

    Grant ID or email account to query.

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

    Query params to pass to the request. You can use the fields parameter to specify which data to return:

    • MessageFields::STANDARD (default): Returns the standard message payload

    • MessageFields::INCLUDE_HEADERS: Returns messages and their custom headers

    • MessageFields::INCLUDE_TRACKING_OPTIONS: Returns messages and their tracking settings

    • MessageFields::RAW_MIME: Returns the grant_id, object, id, and raw_mime fields only

Returns:

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

    The list of messages, API Request ID, and next cursor.



48
49
50
51
52
53
# File 'lib/nylas/resources/messages.rb', line 48

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

#list_scheduled_messages(identifier:) ⇒ Array(Array(Hash), String)

Retrieve your scheduled messages.

Parameters:

  • identifier (String)

    Grant ID or email account from which to find the scheduled message from.

Returns:

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

    The list of scheduled messages and the API Request ID.



138
139
140
141
142
# File 'lib/nylas/resources/messages.rb', line 138

def list_scheduled_messages(identifier:)
  get(
    path: "#{api_uri}/v3/grants/#{identifier}/messages/schedules"
  )
end

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

Send a message.

Parameters:

  • identifier (String)

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

  • 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 pass in base64 encoded strings if the total attachment size is less than 3mb. You can also use FileUtils::attach_file_request_builder to build each object attach.

Returns:

  • (Array(Hash, String))

    The sent message and the API Request ID.



121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/nylas/resources/messages.rb', line 121

def send(identifier:, request_body:)
  payload, opened_files = FileUtils.handle_message_payload(request_body)

  response = post(
    path: "#{api_uri}/v3/grants/#{identifier}/messages/send",
    request_body: payload
  )

  opened_files.each(&:close)

  response
end

#stop_scheduled_messages(identifier:, schedule_id:) ⇒ Array(Hash, String)

Stop a scheduled message.

Parameters:

  • identifier (String)

    Grant ID or email account from which to list the scheduled messages from.

  • schedule_id (String)

    The id of the scheduled message to stop..

Returns:

  • (Array(Hash, String))

    The scheduled message and the API Request ID.



160
161
162
163
164
# File 'lib/nylas/resources/messages.rb', line 160

def stop_scheduled_messages(identifier:, schedule_id:)
  delete(
    path: "#{api_uri}/v3/grants/#{identifier}/messages/schedules/#{schedule_id}"
  )
end

#update(identifier:, message_id:, request_body:, query_params: nil) ⇒ Array(Hash, String)

Update a message.

Parameters:

  • identifier (String)

    Grant ID or email account in which to update an object.

  • message_id (String)

    The id of the message to update.

  • request_body (Hash)

    The values to update the message with

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

    Query params to pass to the request.

Returns:

  • (Array(Hash, String))

    The updated message and API Request ID.



80
81
82
83
84
85
86
# File 'lib/nylas/resources/messages.rb', line 80

def update(identifier:, message_id:, request_body:, query_params: nil)
  put(
    path: "#{api_uri}/v3/grants/#{identifier}/messages/#{message_id}",
    request_body: request_body,
    query_params: query_params
  )
end