lib/api_thread.rb in nylas-0.17.4 vs lib/api_thread.rb in nylas-0.18.0
- old
+ new
@@ -9,13 +9,35 @@
parameter :participants
parameter :snippet
parameter :tags
parameter :message_ids
parameter :draft_ids
+ parameter :labels
+ parameter :folder
time_attr_accessor :last_message_timestamp
time_attr_accessor :first_message_timestamp
+ def inflate(json)
+ super
+ @labels ||= []
+ @folder ||= nil
+
+ # This is a special case --- we receive label data from the API
+ # as JSON but we want it to behave like an API object.
+ @labels.map! do |label_json|
+ label = Label.new(@_api)
+ label.inflate(label_json)
+ label
+ end
+
+ if not folder.nil?
+ folder = folder.new(@_api)
+ folder.inflate(@folder)
+ @folder = folder
+ end
+ end
+
def messages
@messages ||= RestfulModelCollection.new(Message, @_api, @namespace_id, {:thread_id=>@id})
end
def drafts
@@ -50,7 +72,24 @@
end
def unstar!
update_tags!([], ['starred'])
end
+
+ def as_json(options = {})
+ hash = {}
+
+ if not @labels.nil? and @labels != []
+ hash["labels"] = @labels.map do |label|
+ label.id
+ end
+ end
+
+ if not @folder.nil?
+ hash["folder"] = @folder.id
+ end
+
+ hash
+ end
+
end
-end
\ No newline at end of file
+end