Class: SlackExport::Exporter
- Inherits:
-
Object
- Object
- SlackExport::Exporter
- Defined in:
- lib/slack_export/exporter.rb
Instance Attribute Summary collapse
-
#base_path ⇒ Object
readonly
Returns the value of attribute base_path.
-
#channel ⇒ Object
readonly
Returns the value of attribute channel.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#logger ⇒ Object
Returns the value of attribute logger.
Instance Method Summary collapse
- #export(new_channel_name = nil) ⇒ Object
- #export_path ⇒ Object
-
#initialize(api_key, channel, base_path, logger = nil) ⇒ Exporter
constructor
A new instance of Exporter.
Constructor Details
#initialize(api_key, channel, base_path, logger = nil) ⇒ Exporter
Returns a new instance of Exporter.
11 12 13 14 15 16 |
# File 'lib/slack_export/exporter.rb', line 11 def initialize(api_key, channel, base_path, logger=nil) @client = SlackClient.new(api_key, channel) @channel = channel @base_path = base_path self.logger = logger end |
Instance Attribute Details
#base_path ⇒ Object (readonly)
Returns the value of attribute base_path.
8 9 10 |
# File 'lib/slack_export/exporter.rb', line 8 def base_path @base_path end |
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
8 9 10 |
# File 'lib/slack_export/exporter.rb', line 8 def channel @channel end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
8 9 10 |
# File 'lib/slack_export/exporter.rb', line 8 def client @client end |
#logger ⇒ Object
Returns the value of attribute logger.
9 10 11 |
# File 'lib/slack_export/exporter.rb', line 9 def logger @logger end |
Instance Method Details
#export(new_channel_name = nil) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/slack_export/exporter.rb', line 18 def export(new_channel_name=nil) raise StandardError("Directory #{base_path} does not exist") unless Dir.exist?(base_path) log "Exporting #{channel} to folder #{base_path}" # CHANNELS channels = client.get_channels.select {|c| c["name"] == channel} log "Exporting #{channels.count} channels" File.open(channels_path, "w") {|f| f.write(channels.to_json)} # MESSAGES = client. log "Exporting #{.count} messages" Dir.mkdir() unless Dir.exist?() File.open(, "w") do |file| file.write(.to_json) end # USERS users = client.get_users log "Exporting #{users.count} users" users = users.select do |u| .any? {|m| m["user"] == u["id"]} end File.open(users_path, "w") {|f| f.write(users.to_json)} # BUNDLE TO ZIP log "Bundling export file to #{export_path}" Zip::File.open(export_path, Zip::File::CREATE) do |zip| zip.add(users_filename, users_path) zip.add(channels_filename, channels_path) zip.add(, ) end end |
#export_path ⇒ Object
52 53 54 |
# File 'lib/slack_export/exporter.rb', line 52 def export_path File.join(base_path, "#{channel}.zip") end |