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') ⇒ Object



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

def all(exclude_archived=false, types='public_channel')
  response = request :get,
    'conversations.list',
    exclude_archived: exclude_archived ? 1 : 0,
    types: types

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

#archive(id) ⇒ Object



13
14
15
# File 'lib/laziness/api/conversations.rb', line 13

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

#close(id) ⇒ Object



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

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

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



21
22
23
24
25
26
27
28
29
# File 'lib/laziness/api/conversations.rb', line 21

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



31
32
33
34
# File 'lib/laziness/api/conversations.rb', line 31

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

#invite(id, users) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/laziness/api/conversations.rb', line 36

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

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

#join(id) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/laziness/api/conversations.rb', line 45

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

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

#kick(id, user) ⇒ Object



53
54
55
# File 'lib/laziness/api/conversations.rb', line 53

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

#leave(id) ⇒ Object



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

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

#members(id) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/laziness/api/conversations.rb', line 61

def members(id)
  response = request :get,
    'conversations.members',
    channel: id

  JSON.parse(response.body)["members"]
end

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



69
70
71
72
73
74
75
76
77
# File 'lib/laziness/api/conversations.rb', line 69

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



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

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

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

#set_purpose(id, purpose) ⇒ Object



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

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

#set_topic(id, topic) ⇒ Object



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

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

#unarchive(id) ⇒ Object



106
107
108
# File 'lib/laziness/api/conversations.rb', line 106

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