Class: Nylas::Message

Inherits:
Object
  • Object
show all
Includes:
Model
Defined in:
lib/nylas/message.rb

Overview

Ruby representatin of a Nylas Message object

Constant Summary collapse

UPDATABLE_ATTRIBUTES =
%i[label_ids folder_id starred unread metadata].freeze

Instance Attribute Summary

Attributes included from Model

#api

Instance Method Summary collapse

Methods included from Model

#auth_method, #create, #destroy, #execute, included, #model_class, #persisted?, #reload, #resource_path, #resources_path, #save_all_attributes, #to_json, #update_all_attributes

Instance Method Details

#expandedObject



75
76
77
78
79
80
81
82
# File 'lib/nylas/message.rb', line 75

def expanded
  return self unless headers.nil?

  assign(**api.execute(method: :get, path: resource_path, query: { view: "expanded" }))
  # Transfer reference to the API to attributes that need it
  transfer_attributes
  self
end

#handle_folderObject



90
91
92
93
94
95
96
# File 'lib/nylas/message.rb', line 90

def handle_folder
  return if folder.nil?

  self.folder_id = folder.id if folder_id.nil? && !self.to_h.dig(:folder, :id).nil?

  self.folder = nil
end

#saveObject



84
85
86
87
88
# File 'lib/nylas/message.rb', line 84

def save
  handle_folder

  super
end

#starred?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/nylas/message.rb', line 54

def starred?
  starred
end

#unread?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/nylas/message.rb', line 58

def unread?
  unread
end

#update(payload) ⇒ Object



62
63
64
65
66
67
68
69
# File 'lib/nylas/message.rb', line 62

def update(payload)
  FilterAttributes.new(
    attributes: payload.keys,
    allowed_attributes: UPDATABLE_ATTRIBUTES
  ).check

  super(**payload)
end

#update_folder(folder_id) ⇒ Object



71
72
73
# File 'lib/nylas/message.rb', line 71

def update_folder(folder_id)
  update(folder_id: folder_id)
end