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, #execute, #initialize, run_root, team_token_pairs, team_token_pairs_file

Constructor Details

This class inherits a constructor from Slackup

Instance Method Details

#groups_dirObject



55
56
57
58
59
# File 'lib/slackup/groups.rb', line 55

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



41
42
43
# File 'lib/slackup/groups.rb', line 41

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

#write!Object



33
34
35
36
37
38
39
# File 'lib/slackup/groups.rb', line 33

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

#write_messages(group) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/slackup/groups.rb', line 46

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