Class: Nylas::Thread

Inherits:
RestfulModel show all
Extended by:
TimeAttrAccessor
Includes:
ReadUnreadMethods
Defined in:
lib/api_thread.rb

Instance Attribute Summary

Attributes inherited from RestfulModel

#raw_json

Instance Method Summary collapse

Methods included from TimeAttrAccessor

time_attr_accessor

Methods included from ReadUnreadMethods

#mark_as_read!, #mark_as_unread!, #star!, #unstar!, #update_param!

Methods inherited from RestfulModel

#==, collection_name, #destroy, #initialize, #save!, #update, #url

Methods included from Parameters

included, #parameters

Constructor Details

This class inherits a constructor from Nylas::RestfulModel

Instance Method Details

#as_json(options = {}) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/api_thread.rb', line 52

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

#draftsObject



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

def drafts
  @drafts ||= RestfulModelCollection.new(Draft, @_api, {:thread_id=>@id})
end

#inflate(json) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/api_thread.rb', line 24

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? and folder.is_a?(Hash)
   folder = Folder.new(@_api)
   folder.inflate(@folder)
   @folder = folder
  end
end

#messagesObject



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

def messages
  @messages ||= RestfulModelCollection.new(Message, @_api, {:thread_id=>@id})
end