diff --git a/lib/rocketchat/channel.rb b/lib/rocketchat/messages/channel.rb similarity index 100% rename from lib/rocketchat/channel.rb rename to lib/rocketchat/messages/channel.rb diff --git a/lib/rocketchat/room.rb b/lib/rocketchat/room.rb new file mode 100644 index 0000000..fc44f73 --- /dev/null +++ b/lib/rocketchat/room.rb @@ -0,0 +1,9 @@ +require 'yaml' + +module RocketChat + class Room + def show + data.to_yaml + end + end +end \ No newline at end of file diff --git a/lib/rocketweekly.rb b/lib/rocketweekly.rb index d4346bd..5337829 100644 --- a/lib/rocketweekly.rb +++ b/lib/rocketweekly.rb @@ -1,6 +1,7 @@ -$:.unshift File.dirname(__FILE__) unless $:.include? File.dirname(__FILE__) - +require 'yaml' require 'rocketchat' -require 'rocketchat/channel' +$:.unshift File.dirname(__FILE__) unless $:.include? File.dirname(__FILE__) +require 'rocketchat/room' +require 'rocketchat/messages/channel' require 'rocketweekly/connect' \ No newline at end of file diff --git a/run.rb b/run.rb index 78e0df9..041e926 100644 --- a/run.rb +++ b/run.rb @@ -1,21 +1,30 @@ -require 'yaml' require_relative './lib/rocketweekly' -rocket = RocketWeekly::Connect.new - -output = {} -rocket.channels_list.each do |channel| - output[channel.name] = { - 'id' => channel.id, - 'owner' => channel.owner ? channel.owner['username'] : '----' - } - puts '--------------' - puts channel.name - rocket.channel_history(channel.id).each do |m| - printf "%s %-20s\n", m['u']['username'], m['msg'] - puts - end - break +case ARGV[0] +when 'list' + rocket = RocketWeekly::Connect.new + list = rocket.channels_list + puts rocket.channels_list.map &:show + puts '---------------------' + puts "total: #{list.count} canaux" +when 'history' + rocket = RocketWeekly::Connect.new + week = ARGV[1] + channel = ARGV[2] + puts channel +else + puts "Usage: #{ARGV[0]} []" + puts + puts " possible commands:" + puts " list - list all channels information" + puts " history - give messages for the given week" end -puts '--------------' +# puts '--------------' +# puts channel.show +# # rocket.channel_history(channel.id).each do |m| +# # printf "%s %-20s\n", m['u']['username'], m['msg'] +# # puts +# # end +# end +