Class: Slackup::Channels
Constant Summary
Constants inherited
from Slackup
Error, RUN_ROOT, SEMAPHORE, VERSION
Instance Attribute Summary
Attributes inherited from Slackup
#client, #name
Instance Method Summary
collapse
Methods inherited from Slackup
backup, #configure_client, configure_client, #execute, #initialize, run_root, team_config, team_config_file
Constructor Details
This class inherits a constructor from Slackup
Instance Method Details
8
9
10
|
# File 'lib/slackup/channels.rb', line 8
def configured_channels
@configured_channels ||= config.fetch("channels", [])
end
|
#list ⇒ Object
Also known as:
channels
3
4
5
|
# File 'lib/slackup/channels.rb', line 3
def list
@list ||= client.channels_list["channels"]
end
|
#messages(channel) ⇒ Object
34
35
36
|
# File 'lib/slackup/channels.rb', line 34
def messages(channel)
client.channels_history(channel: channel["id"], count: "1000")
end
|
#write! ⇒ Object
27
28
29
30
31
32
|
# File 'lib/slackup/channels.rb', line 27
def write!
channels.each do |channel|
next unless write_channel?(channel)
write_messages(channel)
end
end
|
#write_channel?(channel) ⇒ Boolean
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/slackup/channels.rb', line 12
def write_channel?(channel)
whitelisted_channel = channel["name"] if configured_channels.empty?
whitelisted_channel ||= configured_channels.find do |channel_name|
channel["name_normalized"] == channel_name or
channel["name"] == channel_name
end
if whitelisted_channel
p [name, :channels, "Writing #{whitelisted_channel}"]
true
else
p [name, :channels, "Skipping #{channel["name"]}"]
false
end
end
|
#write_messages(channel) ⇒ Object
38
39
40
41
42
43
44
45
|
# File 'lib/slackup/channels.rb', line 38
def write_messages(channel)
with_messages channel["name_normalized"], messages(channel) do |messages|
File.open(backup_filename(channel["name"]), "w") do |f|
formatted_messages = format_messages(messages)
f.write serialize(formatted_messages)
end
end
end
|