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.



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

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



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

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

#flagsObject



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

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

#foldersObject



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

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

#headersObject



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

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

#indexed_atObject



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

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.



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

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



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

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

#received_atObject



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

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.



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

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