Sha256: a8e511da476a70958559f24de91a2f04597f0d67d010c19fd5130dea55507621

Contents?: true

Size: 1.12 KB

Versions: 3

Compression:

Stored size: 1.12 KB

Contents

require 'restful_model'

module Inbox
  class Thread < RestfulModel

    attr_accessor :subject
    attr_accessor :participants
    attr_accessor :last_message_timestamp
    attr_accessor :first_message_timestamp
    attr_accessor :snippet
    attr_accessor :tags
    attr_accessor :message_ids
    attr_accessor :draft_ids

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

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

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

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

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

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

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

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

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
inbox-0.4.2 lib/thread.rb
inbox-0.4.1 lib/thread.rb
inbox-0.4.0 lib/thread.rb