Class: Inbox::Message

Inherits:
RestfulModel show all
Defined in:
lib/message.rb

Direct Known Subclasses

Draft

Instance Method Summary collapse

Methods inherited from RestfulModel

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

Methods included from TimeAttrAccessor

#time_attr_accessor

Methods included from Parameters

included, #parameters

Constructor Details

This class inherits a constructor from Inbox::RestfulModel

Instance Method Details

#as_json(options = {}) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/message.rb', line 44

def as_json(options = {})
  hash = {}

  # unread, starred and labels/folder are the only attribute
  # you can modify.
  if not @unread.nil?
    hash["unread"] = @unread
  end

  if not @starred.nil?
    hash["starred"] = @starred
  end

  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

#filesObject



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

def files
  @files ||= RestfulModelCollection.new(File, @_api, {:message_id=>@id})
end

#inflate(json) ⇒ Object



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

def inflate(json)
  super
  @to ||= []
  @cc ||= []
  @bcc ||= []
  @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

#rawObject



74
75
76
77
78
79
80
# File 'lib/message.rb', line 74

def raw
  model = nil
  collection = RestfulModelCollection.new(Message, @_api, {:message_id=>@id})
  RestClient.get("#{collection.url}/#{id}/", :accept => 'message/rfc822'){ |response,request,result|
    response
  }
end