Sha256: a9fbbf1aaa9e4920653aa0b1156f4f0d455939047601542d18ec07d80ff326cf

Contents?: true

Size: 837 Bytes

Versions: 18

Compression:

Stored size: 837 Bytes

Contents

require 'contextio/api/resource'

class ContextIO
  class Contact
    include ContextIO::API::Resource

    self.primary_key = :email
    self.association_name = :contact

    belongs_to :account

    lazy_attributes :emails, :name, :thumbnail, :last_received, :last_sent,
                    :count
    private :last_received, :last_sent

    def email
      @email ||= emails.first
    end

    def last_received_at
      last_received ? Time.at(last_received) : nil
    end

    def last_sent_at
      last_sent ? Time.at(last_sent) : nil
    end

    # Poor man's has_many
    def threads
      account.threads.where(email: email)
    end

    # Poor man's has_many
    def messages
      account.messages.where(email: email)
    end

    # Poor man's has_many
    def files
      account.files.where(email: email)
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
contextio-2.0.0 lib/contextio/contact.rb
contextio-1.8.1 lib/contextio/contact.rb
contextio-1.8.0 lib/contextio/contact.rb
contextio-1.7.2 lib/contextio/contact.rb
contextio-1.7.1 lib/contextio/contact.rb
contextio-1.7.0 lib/contextio/contact.rb
contextio-1.6.0 lib/contextio/contact.rb
contextio-1.5.0 lib/contextio/contact.rb
contextio-1.4.0 lib/contextio/contact.rb
contextio-1.3.0 lib/contextio/contact.rb
contextio-1.2.4 lib/contextio/contact.rb
contextio-1.2.3 lib/contextio/contact.rb
contextio-1.2.2 lib/contextio/contact.rb
contextio-1.2.1 lib/contextio/contact.rb
contextio-1.2.0 lib/contextio/contact.rb
contextio-1.1.0 lib/contextio/contact.rb
contextio-1.0.1 lib/contextio/contact.rb
contextio-1.0.0 lib/contextio/contact.rb