Class: Slk::Api::Dnd

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

Overview

Wrapper for Slack dnd.* (Do Not Disturb) API endpoints

Instance Method Summary collapse

Constructor Details

#initialize(api_client, workspace) ⇒ Dnd

Returns a new instance of Dnd.



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

def initialize(api_client, workspace)
  @api = api_client
  @workspace = workspace
end

Instance Method Details

#end_snoozeObject



21
22
23
# File 'lib/slk/api/dnd.rb', line 21

def end_snooze
  @api.post(@workspace, 'dnd.endSnooze')
end

#infoObject



12
13
14
# File 'lib/slk/api/dnd.rb', line 12

def info
  @api.post(@workspace, 'dnd.info')
end

#set_snooze(duration) ⇒ Object

rubocop:disable Naming/AccessorMethodName



16
17
18
19
# File 'lib/slk/api/dnd.rb', line 16

def set_snooze(duration) # rubocop:disable Naming/AccessorMethodName
  minutes = duration.to_minutes
  @api.post(@workspace, 'dnd.setSnooze', { num_minutes: minutes })
end

#snooze_remainingObject



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

def snooze_remaining
  data = info
  return nil unless data['snooze_enabled']

  endtime = data['snooze_endtime']
  return nil unless endtime

  remaining = endtime - Time.now.to_i
  remaining.positive? ? Models::Duration.new(seconds: remaining) : nil
end

#snoozing?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/slk/api/dnd.rb', line 25

def snoozing?
  info['snooze_enabled'] == true
end