Class: Inbox::Message
Instance Attribute Summary
Attributes inherited from RestfulModel
#raw_json
Instance Method Summary
collapse
#mark_as_read!, #mark_as_unread!, #star!, #unstar!, #update_param!
#==, collection_name, #destroy, #initialize, #save!, #update, #url
#time_attr_accessor
Methods included from Parameters
included, #parameters
Instance Method Details
#as_json(options = {}) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/message.rb', line 48
def as_json(options = {})
hash = {}
if not @unread.nil?
hash["unread"] = @unread
end
if not @starred.nil?
hash["starred"] = @starred
end
if not @labels.nil? and @labels != []
hash["label_ids"] = @labels.map do |label|
label.id
end
end
if not @folder.nil?
hash["folder_id"] = @folder.id
end
hash
end
|
#expanded ⇒ Object
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/message.rb', line 91
def expanded
expanded_url = url(action='?view=expanded')
RestClient.get(expanded_url){ |response,request,result|
json = Inbox.interpret_response(result, response, :expected_class => Object)
expanded_message = Inbox::ExpandedMessage.new(@_api)
expanded_message.inflate(json)
expanded_message
}
end
|
#files? ⇒ Boolean
78
79
80
|
# File 'lib/message.rb', line 78
def files?
!@raw_json['files'].empty?
end
|
#inflate(json) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/message.rb', line 25
def inflate(json)
super
@to ||= []
@cc ||= []
@bcc ||= []
@labels ||= []
@folder ||= nil
@labels.map! do |label_json|
label = Label.new(@_api)
label.inflate(label_json)
label
end
if not folder.nil? and folder.is_a?(Hash)
folder = Folder.new(@_api)
folder.inflate(@folder)
@folder = folder
end
end
|
#raw ⇒ Object
82
83
84
85
86
87
88
89
|
# File 'lib/message.rb', line 82
def raw
model = nil
collection = RestfulModelCollection.new(Message, @_api, {:message_id=>@id})
RestClient.get("#{collection.url}/#{id}/", :accept => 'message/rfc822'){ |response,request,result|
Inbox.interpret_http_status(result)
response
}
end
|