Class: ContextIO::Lite::Message
- Inherits:
-
Object
- Object
- ContextIO::Lite::Message
show all
- Includes:
- API::Resource
- Defined in:
- lib/contextio/lite/message.rb
Constant Summary
collapse
- FLAG_KEYS =
%w(seen answered flagged draft deleted)
Instance Attribute Summary
#api, #api_attributes, #primary_key, #resource_url, #with_constraints
Instance Method Summary
collapse
#delete, #initialize, #with
Instance Method Details
#body(options = {}) ⇒ Object
40
41
42
43
44
45
46
47
48
|
# File 'lib/contextio/lite/message.rb', line 40
def body(options={})
@body ||= if @with_constraints.has_key?(:include_body) && @with_constraints[:include_body]==1 then
options.has_key?('type') ?
self.api_attributes['bodies'].select { |b| b['type']==options['type'] } :
self.api_attributes['bodies']
else
api.request(:get, "#{resource_url}/body", options)['bodies']
end
end
|
#body_html ⇒ Object
36
37
38
|
# File 'lib/contextio/lite/message.rb', line 36
def body_html
self.body(type:'text/html').map{|b| b['content']}.join
end
|
#body_plain ⇒ Object
32
33
34
|
# File 'lib/contextio/lite/message.rb', line 32
def body_plain
self.body(type:'text/plain').map{|b| b['content']}.join
end
|
#flags ⇒ Object
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/contextio/lite/message.rb', line 50
def flags
if @with_constraints.has_key?(:include_flags) && @with_constraints[:include_flags]==1
@flags = self.api_attributes['flags']
else
@flags ||= api.request(:get, "#{resource_url}/flags")['flags']
@flags['seen'] = @flags.delete 'read' if @flags.has_key? 'read'
@flags = Hash[FLAG_KEYS.map{|f| [f, @flags.include?(f) && @flags[f]]}]
end
@flags
end
|
61
62
63
64
65
|
# File 'lib/contextio/lite/message.rb', line 61
def
@headers ||= @with_constraints.has_key?(:include_headers) && @with_constraints[:include_headers]==1 ?
self.api_attributes['headers'] :
api.request(:get, "#{resource_url}/headers")['headers']
end
|
#raw ⇒ Object
67
68
69
|
# File 'lib/contextio/lite/message.rb', line 67
def raw
api.raw_request(:get, "#{resource_url}/raw")
end
|
#read ⇒ Object
71
72
73
|
# File 'lib/contextio/lite/message.rb', line 71
def read
api.request(:post, "#{resource_url}/read")['success']
end
|
#sent ⇒ Object
22
23
24
|
# File 'lib/contextio/lite/message.rb', line 22
def sent
@sent ||= Time.at(sent_at)
end
|