Sha256: dc0cfaa3f77f45dabef78402ae33abff7a4d94f4bc1c1f9984a70724be359b52

Contents?: true

Size: 1.39 KB

Versions: 3

Compression:

Stored size: 1.39 KB

Contents

require 'restful_model'

module Nylas
  class Draft < Message

    parameter :thread_id
    parameter :version
    parameter :reply_to_message_id
    parameter :file_ids
    parameter :tracking

    def attach(file)
      file.save! unless file.id
      @file_ids ||= []
      @file_ids.push(file.id)
    end

    def as_json(options = {})
      # FIXME @karim: this is a bit of a hack --- Draft inherits Message
      # was okay until we overrode Message#as_json to allow updating folders/labels.
      # This broke draft sending, which relies on RestfulModel::as_json to work.
      grandparent = self.class.superclass.superclass
      meth = grandparent.instance_method(:as_json)
      meth.bind(self).call
    end

    def send!
      url = @_api.url_for_path("/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|
        response = Nylas.interpret_response(result, response, {:expected_class => Object})
        self.inflate(response)
      end

      self
    end

    def destroy
      ::RestClient::Request.execute(method: :delete, url: self.url, payload: ({ :version => self.version }).to_json) do |response, request, result|
        response = Nylas.interpret_response(result, response, options={:raw_response=>true})
      end
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
nylas-3.2.0 lib/draft.rb
nylas-3.1.1 lib/draft.rb
nylas-3.1.0 lib/draft.rb