Sha256: 4e40face592b52b3bf9380f8b1e91ff3dd5fa913c661918be7f4d176b45a42d8

Contents?: true

Size: 1.29 KB

Versions: 3

Compression:

Stored size: 1.29 KB

Contents

module RocketChat
  #
  # Rocket.Chat User
  #
  class User
    # Raw user data
    attr_reader :data

    #
    # @param [Hash] data Raw user data
    #
    def initialize(data)
      @data = Util.stringify_hash_keys data
    end

    # User ID
    def id
      data['_id']
    end

    # User name
    def name
      data['name']
    end

    # User emails
    def emails
      data['emails'] || []
    end

    # User email
    def email
      emails.first && emails.first['address']
    end

    # User email verified
    def email_verified?
      emails.first && emails.first['verified']
    end

    # User status
    def status
      data['status']
    end

    # User connection status
    def status_connection
      data['statusConnection']
    end

    # User username
    def username
      data['username']
    end

    # User UTC offset
    def utc_offset
      data['utcOffset']
    end

    # User active
    def active?
      data['active']
    end

    # User roles
    def roles
      data['roles']
    end

    def inspect
      format(
        '#<%<class_name>s:0x%<object_id>p @id="%<id>s" @username="%<username>s" @active="%<active>s">',
        class_name: self.class.name,
        object_id: object_id,
        id: id,
        username: username,
        active: active?
      )
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rocketchat-0.1.18 lib/rocket_chat/user.rb
rocketchat-0.1.17 lib/rocket_chat/user.rb
rocketchat-0.1.16 lib/rocket_chat/user.rb