Class: Slack::API::Conversations

Inherits:
Base
  • Object
show all
Defined in:
lib/laziness/api/conversations.rb

Instance Attribute Summary

Attributes inherited from Base

#access_token

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Slack::API::Base

Instance Method Details

#all(exclude_archived = false, types = 'public_channel', page: nil) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/laziness/api/conversations.rb', line 4

def all(exclude_archived=false, types='public_channel', page: nil)
  responses = with_paging(page) do |pager|
    request :get,
      'conversations.list',
      exclude_archived: exclude_archived ? 1 : 0,
      types: types,
      **pager.to_h
  end

  Slack::Conversation.parse_all responses, 'channels'
end

#archive(id) ⇒ Object



16
17
18
# File 'lib/laziness/api/conversations.rb', line 16

def archive(id)
  with_nil_response { request :post, 'conversations.archive', channel: id }
end

#close(id) ⇒ Object



20
21
22
# File 'lib/laziness/api/conversations.rb', line 20

def close(id)
  with_nil_response { request :post, 'conversations.close', channel: id }
end

#create(name, is_private = false, user_ids = []) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/laziness/api/conversations.rb', line 24

def create(name, is_private=false, user_ids=[])
  response = request :post,
    'conversations.create',
    name: name,
    is_private: is_private,
    user_ids: user_ids

  Slack::Conversation.parse response, 'channel'
end

#find(id) ⇒ Object



34
35
36
37
# File 'lib/laziness/api/conversations.rb', line 34

def find(id)
  response = request :get, 'conversations.info', channel: id
  Slack::Conversation.parse response, 'channel'
end

#invite(id, users) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/laziness/api/conversations.rb', line 39

def invite(id, users)
  response = request :post,
    'conversations.invite',
    channel: id,
    users: users.join(",")

  Slack::Conversation.parse response, 'channel'
end

#join(id) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/laziness/api/conversations.rb', line 48

def join(id)
  response = request :post,
    'conversations.join',
    channel: id

  Slack::Conversation.parse response, 'channel'
end

#kick(id, user) ⇒ Object



56
57
58
# File 'lib/laziness/api/conversations.rb', line 56

def kick(id, user)
  with_nil_response { request :post, 'conversations.kick', channel: id, user: user }
end

#leave(id) ⇒ Object



60
61
62
# File 'lib/laziness/api/conversations.rb', line 60

def leave(id)
  with_nil_response { request :post, 'conversations.leave', channel: id }
end

#members(id, page: nil) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/laziness/api/conversations.rb', line 64

def members(id, page: nil)
  responses = with_paging(page) do |pager|
    request :get,
            'conversations.members',
            channel: id,
            **pager.to_h
  end

  responses.map do |response|
    JSON.parse(response.body)["members"]
  end.flatten
end

#open(users = [], id = nil, return_im: false) ⇒ Object



77
78
79
80
81
82
83
84
85
# File 'lib/laziness/api/conversations.rb', line 77

def open(users=[], id=nil, return_im: false)
  response = request :post,
    'conversations.open',
    channel: id,
    users: (users || []).join(","),
    return_im: return_im

  Slack::Conversation.parse response, 'channel'
end

#rename(id, name) ⇒ Object



87
88
89
90
91
92
93
94
# File 'lib/laziness/api/conversations.rb', line 87

def rename(id, name)
  response = request :post,
    'conversations.rename',
    channel: id,
    name: name

  Slack::Conversation.parse response, 'channel'
end

#set_purpose(id, purpose) ⇒ Object



96
97
98
99
100
101
102
103
# File 'lib/laziness/api/conversations.rb', line 96

def set_purpose(id, purpose)
  with_nil_response do
    request :post,
    'conversations.setPurpose',
    channel: id,
    purpose: purpose
  end
end

#set_topic(id, topic) ⇒ Object



105
106
107
108
109
110
111
112
# File 'lib/laziness/api/conversations.rb', line 105

def set_topic(id, topic)
  with_nil_response do
    request :post,
    'conversations.setTopic',
    channel: id,
    topic: topic
  end
end

#unarchive(id) ⇒ Object



114
115
116
# File 'lib/laziness/api/conversations.rb', line 114

def unarchive(id)
  with_nil_response { request :post, 'conversations.unarchive', channel: id }
end