Class: Slackup::Ims

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

Defined Under Namespace

Classes: Im

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

#format_username(user) ⇒ Object



57
58
59
# File 'lib/slackup/ims.rb', line 57

def format_username(user)
  user_name(user).downcase.gsub(/\s+/, "-")
end

#ims_dirObject



61
62
63
64
65
# File 'lib/slackup/ims.rb', line 61

def ims_dir
  @ims_dir ||= "ims"
  FileUtils.mkdir_p(@ims_dir)
  @ims_dir
end

#listHash Also known as: ims

"ok"=>true,
"ims"=>[
  {"id"=>"D1234567890", "is_im"=>true, "user"=>"USLACKBOT", "created"=>1372105335, "is_user_deleted"=>false,
]

}

Returns:

  • (Hash)


15
16
17
# File 'lib/slackup/ims.rb', line 15

def list
  @list ||= client.im_list["ims"].map { |im| Im.new(im) }
end

#messages(im_id) ⇒ Hash

{

"ok": true,
"latest": "1358547726.000003",
"messages": [
  {
    "type": "message",
    "ts": "1358546515.000008",
    "user": "U2147483896",
    "text": "<@U0453RHGQ> has some thoughts on that kind of stuff"
  },
  ]
"has_more": false

Examples:

return

Parameters:

  • im_id (String)

    is the ‘channel’ of the im, e.g. “D1234567890”

Returns:

  • (Hash)


43
44
45
# File 'lib/slackup/ims.rb', line 43

def messages(im_id)
  client.im_history(channel: im_id)
end

#write!Object



20
21
22
23
24
25
26
# File 'lib/slackup/ims.rb', line 20

def write!
  Dir.chdir(ims_dir) do
    ims.each do |im|
      write_messages(im)
    end
  end
end

#write_messages(im) ⇒ Object



47
48
49
50
51
52
53
54
55
# File 'lib/slackup/ims.rb', line 47

def write_messages(im)
  im_username = format_username(im.user)
  with_messages im_username, messages(im.id) do |messages|
    formatted_messages = format_messages(messages)
    File.open(backup_filename(im_username), "w")  do |f|
      f.write serialize(formatted_messages)
    end unless formatted_messages.empty?
  end
end