Class: Slackup::Groups

Inherits:
Slackup show all
Defined in:
lib/slackup/groups.rb

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

#configured_groupsObject



33
34
35
# File 'lib/slackup/groups.rb', line 33

def configured_groups
  @configured_groups ||= config.fetch("groups", [])
end

#groups_dirObject



74
75
76
77
78
# File 'lib/slackup/groups.rb', line 74

def groups_dir
  @groups_dir ||= "groups"
  FileUtils.mkdir_p(@groups_dir)
  @groups_dir
end

#listObject Also known as: groups

{

"ok": true,
"groups": [
    {
        "id": "G0ABC",
        "name": "some-group",
        "is_group": true,
        "created": 1436923155,
        "creator": "UABC",
        "is_archived": false,
        "members": [
        ],
        "topic": {
            "value": "",
            "creator": "",
            "last_set": 0
        },
        "purpose": {
            "value": "Some group",
            "creator": "UABC",
            "last_set": 1437105751
        }
    }
]

}



28
29
30
# File 'lib/slackup/groups.rb', line 28

def list
  @list ||= client.groups_list["groups"]
end

#messages(group) ⇒ Object



60
61
62
# File 'lib/slackup/groups.rb', line 60

def messages(group)
  client.groups_history(channel: group["id"], count: "1000")
end

#write!Object



51
52
53
54
55
56
57
58
# File 'lib/slackup/groups.rb', line 51

def write!
  Dir.chdir(groups_dir) do
    groups.each do |group|
      next unless write_group?(group)
      write_messages(group)
    end
  end
end

#write_group?(group) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/slackup/groups.rb', line 37

def write_group?(group)
  whitelisted_group = group["name"] if configured_groups.empty?
  whitelisted_group ||= @configured_groups.find do |group_name|
    group["name"] == group_name
  end
  if whitelisted_group
    p [name, :groups, "Writing #{whitelisted_group}"]
    true
  else
    p [name, :groups, "Skipping #{group["name"]}"]
    false
  end
end

#write_messages(group) ⇒ Object



65
66
67
68
69
70
71
72
# File 'lib/slackup/groups.rb', line 65

def write_messages(group)
  with_messages group, messages(group) do |messages|
    File.open(backup_filename(group["name"]), "w")  do |f|
      formatted_messages = format_messages(messages)
      f.write serialize(formatted_messages)
    end
  end
end