Class: Slk::Api::Users

Inherits:
Object
  • Object
show all
Defined in:
lib/slk/api/users.rb

Overview

Wrapper for Slack users.* API endpoints

Instance Method Summary collapse

Constructor Details

#initialize(api_client, workspace, on_debug: nil) ⇒ Users

Returns a new instance of Users.



7
8
9
10
11
# File 'lib/slk/api/users.rb', line 7

def initialize(api_client, workspace, on_debug: nil)
  @api = api_client
  @workspace = workspace
  @on_debug = on_debug
end

Instance Method Details

#clear_statusObject



39
40
41
# File 'lib/slk/api/users.rb', line 39

def clear_status
  set_status(text: '', emoji: '', duration: nil)
end

#conversations(cursor: nil, limit: 1000) ⇒ Object



98
99
100
101
102
# File 'lib/slk/api/users.rb', line 98

def conversations(cursor: nil, limit: 1000)
  params = { limit: limit, types: 'public_channel,private_channel,mpim,im' }
  params[:cursor] = cursor if cursor
  @api.post_form(@workspace, 'users.conversations', params)
end

#get_prefsObject

rubocop:disable Naming/AccessorMethodName



66
67
68
# File 'lib/slk/api/users.rb', line 66

def get_prefs # rubocop:disable Naming/AccessorMethodName
  @api.post(@workspace, 'users.prefs.get')
end

#get_presenceObject

rubocop:disable Naming/AccessorMethodName



43
44
45
46
47
48
49
50
# File 'lib/slk/api/users.rb', line 43

def get_presence # rubocop:disable Naming/AccessorMethodName
  response = @api.post(@workspace, 'users.getPresence')
  {
    presence: response['presence'],
    manual_away: response['manual_away'],
    online: response['online']
  }
end

#get_profileObject

rubocop:disable Naming/AccessorMethodName



13
14
15
16
# File 'lib/slk/api/users.rb', line 13

def get_profile # rubocop:disable Naming/AccessorMethodName
  response = @api.post(@workspace, 'users.profile.get')
  response['profile']
end

#get_statusObject

rubocop:disable Naming/AccessorMethodName



18
19
20
21
22
23
24
25
# File 'lib/slk/api/users.rb', line 18

def get_status # rubocop:disable Naming/AccessorMethodName
  profile = get_profile
  Models::Status.new(
    text: profile['status_text'] || '',
    emoji: profile['status_emoji'] || '',
    expiration: profile['status_expiration'] || 0
  )
end

#info(user_id) ⇒ Object



62
63
64
# File 'lib/slk/api/users.rb', line 62

def info(user_id)
  @api.post_form(@workspace, 'users.info', { user: user_id })
end

#list(cursor: nil, limit: 1000) ⇒ Object



56
57
58
59
60
# File 'lib/slk/api/users.rb', line 56

def list(cursor: nil, limit: 1000)
  params = { limit: limit }
  params[:cursor] = cursor if cursor
  @api.post(@workspace, 'users.list', params)
end

#muted_channelsObject



70
71
72
73
# File 'lib/slk/api/users.rb', line 70

def muted_channels
  prefs = get_prefs
  parse_legacy_muted_channels(prefs) || parse_new_muted_channels(prefs) || []
end

#set_presence(presence) ⇒ Object

rubocop:disable Naming/AccessorMethodName



52
53
54
# File 'lib/slk/api/users.rb', line 52

def set_presence(presence) # rubocop:disable Naming/AccessorMethodName
  @api.post(@workspace, 'users.setPresence', { presence: presence })
end

#set_status(text:, emoji: nil, duration: nil) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/slk/api/users.rb', line 27

def set_status(text:, emoji: nil, duration: nil)
  expiration = duration&.to_expiration || 0

  @api.post(@workspace, 'users.profile.set', {
              profile: {
                status_text: text,
                status_emoji: emoji || '',
                status_expiration: expiration
              }
            })
end