Class: Gitter::API::User

Inherits:
Base
  • Object
show all
Includes:
Collectable
Defined in:
lib/gitter/api/user.rb

Overview

Model representation of the /user/* REST endpoints in the gitter API

Defined Under Namespace

Modules: ClientMethods

Instance Attribute Summary collapse

Attributes inherited from Base

#client

Instance Method Summary collapse

Methods included from Collectable

included

Methods inherited from Base

#api_prefix

Constructor Details

#initialize(client, data) ⇒ User

INTERNAL METHOD

Initialize a new Gitter::API::User

Gitter::API::Client#user will return on of these objects, as well as some methods on Gitter::API::Room and when instanciating a Gitter::API::Message, so favor instanciating that way.

Parameters

client (Gitter::API::Client)

Configured client object

data (Hash)

Initialization data

Options

(string keys only)

id (String)

User id

display_name (String)

Gitter/GitHub user real name

username (String)

Gitter/GitHub username (without ‘@’)

url (String)

Path to the user on Gitter



42
43
44
45
46
47
48
49
# File 'lib/gitter/api/user.rb', line 42

def initialize client, data
  super

  @id           = data["id"] || data["userId"]
  @display_name = data["displayName"]
  @username     = data["username"] || data["screenName"]
  @url          = data["url"]
end

Instance Attribute Details

#display_nameObject (readonly)

Name of the user



12
13
14
# File 'lib/gitter/api/user.rb', line 12

def display_name
  @display_name
end

#idObject (readonly)

ID (from the API)



9
10
11
# File 'lib/gitter/api/user.rb', line 9

def id
  @id
end

#urlObject (readonly)

The relative path the the user’s page in the gitter webapp



18
19
20
# File 'lib/gitter/api/user.rb', line 18

def url
  @url
end

#usernameObject (readonly)

Username (minus the ‘@’)



15
16
17
# File 'lib/gitter/api/user.rb', line 15

def username
  @username
end

Instance Method Details

#roomsObject

Fetch the all of the room records for a given user

Includes one on one conversations, since those are considered “rooms” as well (based on their schema)

Returns a Gitter::API::Room::Collection



57
58
59
60
61
# File 'lib/gitter/api/user.rb', line 57

def rooms
  data = client.get "#{api_prefix}/rooms"

  Room::Collection.new self, data
end