Class: ContextIO::Message

Inherits:
Object
  • Object
show all
Includes:
API::Resource
Defined in:
lib/contextio/message.rb

Instance Attribute Summary

Attributes included from API::Resource

#api_attributes, #primary_key, #resource_url

Instance Method Summary collapse

Instance Method Details

#copy_to(folder, source = nil) ⇒ Object

You can call this with a Folder object, in which case, the source from the folder will be used, or you can pass in a folder name and source label.



65
66
67
68
69
70
71
72
73
74
75
# File 'lib/contextio/message.rb', line 65

def copy_to(folder, source = nil)
  if folder.is_a?(ContextIO::Folder)
    folder_name = folder.name
    source_label = folder.source.label
  else
    folder_name = folder.to_s
    source_label = source.to_s
  end

  api.request(:post, resource_url, dst_folder: folder_name, dst_source: source_label)['success']
end

#deleteObject



91
92
93
# File 'lib/contextio/message.rb', line 91

def delete
  api.request(:delete, resource_url)['success']
end

#flagsObject



30
31
32
# File 'lib/contextio/message.rb', line 30

def flags
  api.request(:get, "#{resource_url}/flags")
end

#foldersObject



45
46
47
# File 'lib/contextio/message.rb', line 45

def folders
  api.request(:get, "#{resource_url}/folders").collect { |f| f['name'] }
end

#headersObject



49
50
51
# File 'lib/contextio/message.rb', line 49

def headers
  api.request(:get, "#{resource_url}/headers")
end

#indexed_atObject



26
27
28
# File 'lib/contextio/message.rb', line 26

def indexed_at
  @indexed_at ||= Time.at(date_indexed)
end

#move_to(folder, source = nil) ⇒ Object

You can call this with a Folder object, in which case, the source from the folder will be used, or you can pass in a folder name and source label.



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/contextio/message.rb', line 79

def move_to(folder, source = nil)
  if folder.is_a?(ContextIO::Folder)
    folder_name = folder.name
    source_label = folder.source.label
  else
    folder_name = folder.to_s
    source_label = source.to_s
  end

  api.request(:post, resource_url, dst_folder: folder_name, dst_source: source_label, move: 1)['success']
end

#rawObject



59
60
61
# File 'lib/contextio/message.rb', line 59

def raw
  api.raw_request(:get, "#{resource_url}/source")
end

#received_atObject



22
23
24
# File 'lib/contextio/message.rb', line 22

def received_at
  @received_at ||= Time.at(date_received)
end

#set_flags(flag_hash) ⇒ Object

As of this writing, the documented valid flags are: seen, answered, flagged, deleted, and draft. However, this will send whatever you send it.



36
37
38
39
40
41
42
43
# File 'lib/contextio/message.rb', line 36

def set_flags(flag_hash)
  args = flag_hash.inject({}) do |memo, (flag_name, value)|
    memo[flag_name] = value ? 1 : 0
    memo
  end

  api.request(:post, "#{resource_url}/flags", args)['success']
end

#threadObject

Returns a list of all messages and a list of all email_message_ids in the same thread as this message. Note that it does not create a Thread object or a MessageCollection object in its current state.



97
98
99
# File 'lib/contextio/message.rb', line 97

def thread
  api.request(:get, "#{resource_url}/thread")
end