Class: Gmail::Draft

Inherits:
APIResource show all
Includes:
Base::Create, Base::Delete, Base::Get, Base::List, Base::Update
Defined in:
lib/gmail/draft.rb

Instance Method Summary collapse

Methods included from Base::Update

#update, #update!

Methods included from Base::Get

included

Methods included from Base::Delete

#delete, included

Methods included from Base::Create

included

Methods included from Base::List

included

Methods inherited from APIResource

base_method, class_name

Methods inherited from GmailObject

#[], #[]=, #as_json, #detailed, #initialize, #inspect, #refresh, #to_hash, #to_json, #to_s, #values

Constructor Details

This class inherits a constructor from Gmail::GmailObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Gmail::GmailObject

Instance Method Details

#deliverObject



46
47
48
49
# File 'lib/gmail/draft.rb', line 46

def deliver
  response = Gmail.request(self.class.base_method.to_h['gmail.users.drafts.send'],{},{id: id})
  Message.get(response[:id])
end

#messageObject



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/gmail/draft.rb', line 9

def message
  if @values.message.is_a?(Message)
    @values.message
  else
    @values.message = Util.convert_to_gmail_object(to_hash[:message], key="message")
    if @values.message.payload.nil?
      self.detailed!
      message
    end
    @values.message
  end
end

#save(opts = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/gmail/draft.rb', line 22

def save(opts={})
  msg = {raw: message.raw}
  if message.threadId
    msg[:threadId] = message.threadId
  end
  if message.labelIds
    msg[:labelIds] = message.labelIds
  end
  body = {message: msg}
  update(body)
end

#save!(opts = {}) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/gmail/draft.rb', line 34

def save!(opts={})
  msg = {raw: message.raw}
  if message.threadId
    msg[:threadId] = message.threadId
  end
  if message.labelIds
    msg[:labelIds] = message.labelIds
  end
  body = {message: msg}
  update!(body)
end