Class: Lita::Adapters::Slack::API Private

Inherits:
Object
  • Object
show all
Defined in:
lib/lita/adapters/slack/api.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Constructor Details

#initialize(config, stubs = nil) ⇒ API

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of API.


13
14
15
16
17
18
19
20
21
# File 'lib/lita/adapters/slack/api.rb', line 13

def initialize(config, stubs = nil)
  @config = config
  @stubs = stubs
  @post_message_config = {}
  @post_message_config[:parse] = config.parse unless config.parse.nil?
  @post_message_config[:link_names] = config.link_names ? 1 : 0 unless config.link_names.nil?
  @post_message_config[:unfurl_links] = config.unfurl_links unless config.unfurl_links.nil?
  @post_message_config[:unfurl_media] = config.unfurl_media unless config.unfurl_media.nil?
end

Instance Method Details

#channels_info(channel_id) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


29
30
31
# File 'lib/lita/adapters/slack/api.rb', line 29

def channels_info(channel_id)
  call_api("channels.info", channel: channel_id)
end

#channels_listObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


33
34
35
# File 'lib/lita/adapters/slack/api.rb', line 33

def channels_list
  call_api("channels.list")
end

#groups_listObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


37
38
39
# File 'lib/lita/adapters/slack/api.rb', line 37

def groups_list
  call_api("groups.list")
end

#im_listObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


45
46
47
# File 'lib/lita/adapters/slack/api.rb', line 45

def im_list
  call_api("im.list")
end

#im_open(user_id) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


23
24
25
26
27
# File 'lib/lita/adapters/slack/api.rb', line 23

def im_open(user_id)
  response_data = call_api("im.open", user: user_id)

  SlackIM.new(response_data["channel"]["id"], user_id)
end

#mpim_listObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


41
42
43
# File 'lib/lita/adapters/slack/api.rb', line 41

def mpim_list
  call_api("mpim.list")
end

#rtm_startObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/lita/adapters/slack/api.rb', line 72

def rtm_start
  response_data = call_api("rtm.start")

  TeamData.new(
    SlackIM.from_data_array(response_data["ims"]),
    SlackUser.from_data(response_data["self"]),
    SlackUser.from_data_array(response_data["users"]),
    SlackChannel.from_data_array(response_data["channels"]) +
      SlackChannel.from_data_array(response_data["groups"]),
    response_data["url"],
  )
end

#send_attachments(room_or_user, attachments) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


49
50
51
52
53
54
55
56
# File 'lib/lita/adapters/slack/api.rb', line 49

def send_attachments(room_or_user, attachments)
  call_api(
    "chat.postMessage",
    as_user: true,
    channel: room_or_user.id,
    attachments: MultiJson.dump(attachments.map(&:to_hash)),
  )
end

#send_messages(channel_id, messages) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


58
59
60
61
62
63
64
65
66
# File 'lib/lita/adapters/slack/api.rb', line 58

def send_messages(channel_id, messages)
  call_api(
    "chat.postMessage",
    **post_message_config,
    as_user: true,
    channel: channel_id,
    text: messages.join("\n"),
  )
end

#set_topic(channel, topic) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


68
69
70
# File 'lib/lita/adapters/slack/api.rb', line 68

def set_topic(channel, topic)
  call_api("channels.setTopic", channel: channel, topic: topic)
end