Class: Slk::Api::Client
- Inherits:
-
Object
- Object
- Slk::Api::Client
- Defined in:
- lib/slk/api/client.rb
Overview
Wrapper for Slack client.counts and auth.test API endpoints
Instance Method Summary collapse
- #auth_test ⇒ Object
- #counts ⇒ Object
-
#initialize(api_client, workspace) ⇒ Client
constructor
A new instance of Client.
- #team_id ⇒ Object
- #total_unread_count ⇒ Object
- #unread_channels ⇒ Object
- #unread_dms ⇒ Object
Constructor Details
#initialize(api_client, workspace) ⇒ Client
Returns a new instance of Client.
7 8 9 10 |
# File 'lib/slk/api/client.rb', line 7 def initialize(api_client, workspace) @api = api_client @workspace = workspace end |
Instance Method Details
#auth_test ⇒ Object
16 17 18 |
# File 'lib/slk/api/client.rb', line 16 def auth_test @api.post(@workspace, 'auth.test') end |
#counts ⇒ Object
12 13 14 |
# File 'lib/slk/api/client.rb', line 12 def counts @api.post(@workspace, 'client.counts') end |
#team_id ⇒ Object
20 21 22 |
# File 'lib/slk/api/client.rb', line 20 def team_id @team_id ||= auth_test['team_id'] end |
#total_unread_count ⇒ Object
39 40 41 42 |
# File 'lib/slk/api/client.rb', line 39 def total_unread_count response = counts sum_mentions(response, 'channels') + sum_mentions(response, 'ims') + sum_mentions(response, 'mpims') end |
#unread_channels ⇒ Object
24 25 26 27 28 29 |
# File 'lib/slk/api/client.rb', line 24 def unread_channels response = counts channels = response['channels'] || [] channels.select { |ch| (ch['mention_count'] || 0).positive? || ch['has_unreads'] } end |
#unread_dms ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/slk/api/client.rb', line 31 def unread_dms response = counts dms = response['ims'] || [] mpims = response['mpims'] || [] (dms + mpims).select { |dm| (dm['mention_count'] || 0).positive? || dm['has_unreads'] } end |