Class: Hipmost::Cmds::Private
- Inherits:
-
Object
- Object
- Hipmost::Cmds::Private
- Defined in:
- lib/hipmost/cmds/private.rb
Instance Method Summary collapse
- #import(args) ⇒ Object
-
#initialize(path:, verbose: false) ⇒ Private
constructor
A new instance of Private.
- #list(_args) ⇒ Object
- #run(args) ⇒ Object
Constructor Details
#initialize(path:, verbose: false) ⇒ Private
Returns a new instance of Private.
4 5 6 7 8 |
# File 'lib/hipmost/cmds/private.rb', line 4 def initialize(path:, verbose: false) $path = Pathname.new(path). @outpath = $path.join("..", "Private Chats.jsonl"). @verbose = verbose end |
Instance Method Details
#import(args) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/hipmost/cmds/private.rb', line 31 def import(args) File.open(@outpath, "w") do |jsonl| puts "Writing version header..." if @verbose jsonl.puts %[{ "type": "version", "version": 1 }] puts "Writing room members..." if @verbose Hipchat.users.each do |_,user| jsonl.puts(user.to_jsonl) end puts "Writing 1-on-1 room members..." if @verbose Hipchat.direct_channels.each do |members| puts members.inspect if @verbose jsonl.puts(%[{ "type": "direct_channel", "direct_channel": { "members": #{members.inspect} }}]) end puts "Writing 1-on-1 room posts (oldest to newest)..." if @verbose Hipchat.direct_posts(jsonl, @verbose) end true end |
#list(_args) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/hipmost/cmds/private.rb', line 22 def list(_args) puts "Listing Private chats" if @verbose Hipchat.direct_channels.each do |members| puts members.inspect end true end |
#run(args) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/hipmost/cmds/private.rb', line 10 def run(args) subcommand = args.shift if ["list", "import"].include?(subcommand) else puts "Command invalid for `private`, must be `import` or `list`" exit 1 end send(subcommand, args) end |