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, configure_client, #execute, #initialize, run_root, team_config, team_config_file

Constructor Details

This class inherits a constructor from Slackup

Instance Method Details

#format_username(user) ⇒ Object



69
70
71
# File 'lib/slackup/ims.rb', line 69

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

#ims_dirObject



73
74
75
76
77
# File 'lib/slackup/ims.rb', line 73

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)


55
56
57
# File 'lib/slackup/ims.rb', line 55

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

#write!Object



30
31
32
33
34
35
36
37
38
# File 'lib/slackup/ims.rb', line 30

def write!
  return unless write_ims?
  Dir.chdir(ims_dir) do
    ims.each do |im|
      # p [:ims, im.user, format_username(im.user)]
      write_messages(im)
    end
  end
end

#write_ims?Boolean

Returns:

  • (Boolean)


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

def write_ims?
  if config.fetch("ims", true)
    p [name, :ims, "Writing"]
    true
  else
    p [name, :ims, "Skipping"]
    false
  end
end

#write_messages(im) ⇒ Object



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

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