Class: Slackup::Users

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

Defined Under Namespace

Classes: User

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

#listObject Also known as: users

{

"ok": true,
"members": [
  {
    "id": "U023BECGF",
    "name": "bobby",
    "deleted": false,
    "color": "9f69e7",
    "profile": {
      "first_name": "Bobby",
      "last_name": "Tables",
      "real_name": "Bobby Tables",
      "email": "[email protected]",
      "skype": "my-skype-name",
      "phone": "+1 (123) 456 7890",
      "image_24": "https:\/\/...",
      "image_32": "https:\/\/...",
      "image_48": "https:\/\/...",
      "image_72": "https:\/\/...",
      "image_192": "https:\/\/..."
    },
    "is_admin": true,
    "is_owner": true,
    "has_2fa": false,
    "has_files": true
  },
]

}



51
52
53
# File 'lib/slackup/users.rb', line 51

def list
  @list ||= client.users_list["members"].map { |member| User.new(member) }
end

#user_name(user_id) ⇒ Object

gets user name for an id, if mapping is known, else returns the input



63
64
65
66
67
68
69
70
# File 'lib/slackup/users.rb', line 63

def user_name(user_id)
  @user_names ||= users.each_with_object({}) {|user, lookup|
    lookup[user.id] = user.name
  }
  @user_names.fetch(user_id) {
    user_id
  }
end

#write!Object



56
57
58
59
60
# File 'lib/slackup/users.rb', line 56

def write!
  File.open(backup_filename("users"), "w")  do |f|
    f.write(serialize(users.map(&:to_hash)))
  end
end