Class: Inbox::Thread

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

Instance Method Summary collapse

Methods included from TimeAttrAccessor

time_attr_accessor

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 Inbox::RestfulModel

Instance Method Details

#archive!Object



62
63
64
# File 'lib/api_thread.rb', line 62

def archive!
  update_tags!(['archive'], ['inbox'])
end

#as_json(options = {}) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/api_thread.rb', line 78

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

#draftsObject



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

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

#inflate(json) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/api_thread.rb', line 19

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

#mark_as_read!Object



54
55
56
# File 'lib/api_thread.rb', line 54

def mark_as_read!
  update_tags!([], ['unread'])
end

#mark_as_seen!Object



58
59
60
# File 'lib/api_thread.rb', line 58

def mark_as_seen!
  update_tags!([], ['unseen'])
end

#messagesObject



39
40
41
# File 'lib/api_thread.rb', line 39

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

#star!Object



70
71
72
# File 'lib/api_thread.rb', line 70

def star!
  update_tags!(['starred'], [''])
end

#unarchive!Object



66
67
68
# File 'lib/api_thread.rb', line 66

def unarchive!
  update_tags!(['inbox'], ['archive'])
end

#unstar!Object



74
75
76
# File 'lib/api_thread.rb', line 74

def unstar!
  update_tags!([], ['starred'])
end

#update_tags!(tags_to_add = [], tags_to_remove = []) ⇒ Object



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

def update_tags!(tags_to_add = [], tags_to_remove = [])
  update('PUT', '', {
    :add_tags => tags_to_add,
    :remove_tags => tags_to_remove
  })
end