Class: Inbox::Draft

Inherits:
Message show all
Defined in:
lib/draft.rb

Instance Method Summary collapse

Methods inherited from Message

#files, #inflate, #raw

Methods inherited from RestfulModel

#==, #as_json, collection_name, #destroy, #inflate, #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

#attach(file) ⇒ Object



9
10
11
12
# File 'lib/draft.rb', line 9

def attach(file)
  file.save! unless file.id
  @file_ids.push(file.id)
end

#send!Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/draft.rb', line 14

def send!
  url = @_api.url_for_path("/n/#{@namespace_id}/send")
  if @id
    data = {:draft_id => @id, :version => @version}
  else
    data = as_json()
  end

  ::RestClient.post(url, data.to_json, :content_type => :json) do |response, request, result|
    json = Inbox.interpret_response(result, response, :expected_class => Object)
    self.inflate(json)
  end

  self
end