class Nylas::Thread

Public Instance Methods

as_json(options = {}) click to toggle source
# File lib/api_thread.rb, line 60
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
drafts() click to toggle source
# File lib/api_thread.rb, line 56
def drafts
  @drafts ||= RestfulModelCollection.new(Draft, @_api, {:thread_id=>@id})
end
inflate(json) click to toggle source
Calls superclass method
# 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
messages(expanded: false) click to toggle source
# File lib/api_thread.rb, line 44
def messages(expanded: false)
  @messages ||= Hash.new do |h, is_expanded|
    h[is_expanded] = \
      if is_expanded
        RestfulModelCollection.new(ExpandedMessage, @_api, thread_id: @id, view: 'expanded')
      else
        RestfulModelCollection.new(Message, @_api, thread_id: @id)
      end
  end
  @messages[expanded]
end