Class: Slackup::Ims
Defined Under Namespace
Classes: Im
Constant Summary
Constants inherited from Slackup
Error, RUN_ROOT, SEMAPHORE, VERSION
Instance Attribute Summary
Attributes inherited from Slackup
Instance Method Summary collapse
- #format_username(user) ⇒ Object
- #ims_dir ⇒ Object
-
#list ⇒ Hash
(also: #ims)
{ “ok”=>true, “ims”=>[ “is_im”=>true, “user”=>“USLACKBOT”, “created”=>1372105335, “is_user_deleted”=>false, ] }.
-
#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.
- #write! ⇒ Object
- #write_ims? ⇒ Boolean
- #write_messages(im) ⇒ Object
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_dir ⇒ Object
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 |
#list ⇒ Hash Also known as: ims
"ok"=>true,
"ims"=>[
{"id"=>"D1234567890", "is_im"=>true, "user"=>"USLACKBOT", "created"=>1372105335, "is_user_deleted"=>false,
]
}
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
55 56 57 |
# File 'lib/slackup/ims.rb', line 55 def (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)] (im) end end end |
#write_ims? ⇒ 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 (im) im_username = format_username(im.user) im_username, (im.id) do || = () File.open(backup_filename(im_username), "w") do |f| f.write serialize() end unless .empty? end end |