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

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

Instance Method Details

#expandedObject



68
69
70
71
72
73
74
75
# File 'lib/nylas/message.rb', line 68

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



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

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



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

def save
  handle_folder

  super
end

#starred?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/nylas/message.rb', line 47

def starred?
  starred
end

#unread?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/nylas/message.rb', line 51

def unread?
  unread
end

#update(payload) ⇒ Object



55
56
57
58
59
60
61
62
# File 'lib/nylas/message.rb', line 55

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

  super(**payload)
end

#update_folder(folder_id) ⇒ Object



64
65
66
# File 'lib/nylas/message.rb', line 64

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