Class: Operationcode::Slack::User

Inherits:
Object
  • Object
show all
Defined in:
lib/operationcode/slack/user.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ User

Returns a new instance of User.



6
7
8
9
10
11
12
13
14
15
# File 'lib/operationcode/slack/user.rb', line 6

def initialize(data)
  # If we get a string should we go look the users info up?
  if data.is_a? String
    @id = data
    populate_name!
  else
    @id = data['id']
    @name = data['name']
  end
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/operationcode/slack/user.rb', line 4

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/operationcode/slack/user.rb', line 4

def name
  @name
end

Instance Method Details

#populate_name!Object



17
18
19
20
# File 'lib/operationcode/slack/user.rb', line 17

def populate_name!
  res = Operationcode::Slack::Api::UsersInfo.post(with_data: { user: @id })
  @name = res['user']['real_name'] if res['user']
end