Class: Nylas::Outbox

Inherits:
Object
  • Object
show all
Defined in:
lib/nylas/outbox.rb

Overview

Methods for Outbox functionality

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api:) ⇒ Outbox

Returns a new instance of Outbox.



9
10
11
# File 'lib/nylas/outbox.rb', line 9

def initialize(api:)
  self.api = api
end

Instance Attribute Details

#apiObject

Returns the value of attribute api.



7
8
9
# File 'lib/nylas/outbox.rb', line 7

def api
  @api
end

Instance Method Details

#delete(job_status_id) ⇒ void

This method returns an undefined value.

Delete a scheduled Outbox message

Parameters:

  • job_status_id (String)

    The ID of the outbox job status to delete



60
61
62
63
64
65
# File 'lib/nylas/outbox.rb', line 60

def delete(job_status_id)
  api.execute(
    method: :delete,
    path: "#{outbox_path}/#{job_status_id}"
  )
end

#delete_send_grid_sub_user(email) ⇒ void

This method returns an undefined value.

SendGrid - Delete SendGrid Subuser and UAS Grant

Parameters:

  • email (String)

    Email address for SendGrid subuser to delete



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

def delete_send_grid_sub_user(email)
  api.execute(
    method: :delete,
    path: "#{outbox_path}/onboard/subuser",
    payload: JSON.dump({ email: email })
  )
end

#outbox_pathObject



13
14
15
# File 'lib/nylas/outbox.rb', line 13

def outbox_path
  @outbox_path ||= "/v2/outbox"
end

#send(draft, send_at: nil, retry_limit_datetime: nil) ⇒ OutboxJobStatus

rubocop:disable Layout/LineLength Send a message via Outbox rubocop:enable Layout/LineLength

Parameters:

  • draft (Draft, OutboxMessage)

    The message to send

  • send_at (Numeric) (defaults to: nil)

    The date and time to send the message. If not set, Outbox will send this message immediately.

  • retry_limit_datetime (Numeric) (defaults to: nil)

    The date and time to stop retry attempts for a message. If not set, it defaults to 24 hours after send_at.

Returns:



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/nylas/outbox.rb', line 24

def send(draft, send_at: nil, retry_limit_datetime: nil)
  message = draft.to_h(enforce_read_only: true)
  message.merge!(validate_set_date_time(send_at, retry_limit_datetime))
  outbox_response = api.execute(
    method: :post,
    path: outbox_path,
    payload: JSON.dump(message)
  )

  OutboxJobStatus.new(**outbox_response)
end

#send_grid_verification_statusSendGridVerifiedStatus

SendGrid - Check Authentication and Verification Status

Returns:



69
70
71
72
73
74
75
76
77
78
# File 'lib/nylas/outbox.rb', line 69

def send_grid_verification_status
  response = api.execute(
    method: :get,
    path: "#{outbox_path}/onboard/verified_status"
  )

  raise "Verification status not present in response" if response.key?("results")

  SendGridVerifiedStatus.new(**response[:results])
end

#update(job_status_id, message: nil, send_at: nil, retry_limit_datetime: nil) ⇒ OutboxJobStatus

rubocop:disable Layout/LineLength Update a scheduled Outbox message rubocop:enable Layout/LineLength

Parameters:

  • job_status_id (String)

    The ID of the outbox job status

  • message (Draft, OutboxMessage) (defaults to: nil)

    The message object with updated values

  • send_at (Numeric) (defaults to: nil)

    The date and time to send the message. If not set, Outbox will send this message immediately.

  • retry_limit_datetime (Numeric) (defaults to: nil)

    The date and time to stop retry attempts for a message. If not set, it defaults to 24 hours after send_at.

Returns:

  • (OutboxJobStatus)

    The updated outbox job status status and message data



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

def update(job_status_id, message: nil, send_at: nil, retry_limit_datetime: nil)
  payload = {}
  payload.merge!(message.to_h(enforce_read_only: true)) if message
  payload.merge!(validate_set_date_time(send_at, retry_limit_datetime))
  outbox_response = api.execute(
    method: :patch,
    path: "#{outbox_path}/#{job_status_id}",
    payload: JSON.dump(payload)
  )

  OutboxJobStatus.new(**outbox_response)
end