Class: Nylas::Draft

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

Overview

Ruby representatin of a Nylas Draft object

Direct Known Subclasses

OutboxMessage

Instance Attribute Summary

Attributes included from Model

#api

Instance Method Summary collapse

Methods included from Model

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

Instance Method Details

#createObject



54
55
56
57
58
# File 'lib/nylas/draft.rb', line 54

def create
  extract_file_ids!

  super
end

#destroyObject



76
77
78
# File 'lib/nylas/draft.rb', line 76

def destroy
  execute(method: :delete, path: resource_path, payload: attributes.serialize_for_api(keys: [:version]))
end

#saveObject



80
81
82
83
84
# File 'lib/nylas/draft.rb', line 80

def save
  extract_file_ids!

  super
end

#send!Object



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

def send!
  return execute(method: :post, path: "/send", payload: to_json) unless id

  data = { draft_id: id, version: version }
  data[:tracking] = tracking.to_h if tracking
  execute(method: :post, path: "/send", payload: JSON.dump(data))
end

#starred?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/nylas/draft.rb', line 68

def starred?
  starred
end

#unread?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/nylas/draft.rb', line 72

def unread?
  unread
end

#update(**data) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'lib/nylas/draft.rb', line 43

def update(**data)
  # If files are provided, replace files with file IDs
  self.files = data[:files] if data[:files]
  extract_file_ids!
  data[:file_ids] = file_ids
  # If version is not provided, add version or request will fail
  data[:version] = version unless data[:version]

  super
end