class ChatWorkToSlack::Importer

Attributes

c2s[R]
channel[R]
chatwork_api_key[R]
export_files[R]
gcw[R]
room_id[R]
users[R]
workdir[R]

Public Class Methods

new(gcw, args) click to toggle source
# File lib/chatwork_to_slack/importer.rb, line 6
def initialize(gcw, args)
  @room_id = args[:room_id]
  @channel = args[:channel]
  @workdir = args[:workdir]
  @export_files = args[:export_files]
  @users = args[:users]
  @chatwork_api_key = args[:chatwork_api_key]
  @gcw = gcw

  gcw.login

  if !room_id || !channel
    chatwork_list
  else
    create_workdir
    export
    convert
  end
end

Public Instance Methods

chatwork_csv_path() click to toggle source
# File lib/chatwork_to_slack/importer.rb, line 45
def chatwork_csv_path
  File.join(workdir, "#{room_id}.csv")
end
chatwork_files_path() click to toggle source
# File lib/chatwork_to_slack/importer.rb, line 49
def chatwork_files_path
  File.join(workdir, "#{room_id}_files")
end
chatwork_list() click to toggle source
# File lib/chatwork_to_slack/importer.rb, line 26
def chatwork_list
  puts gcw.room_list.map { |i| i.join(' ') }
end
convert() click to toggle source
# File lib/chatwork_to_slack/importer.rb, line 57
def convert
  gcw.info "create #{slack_csv_path}"
  File.write(slack_csv_path, c2s.to_csv)
end
create_workdir() click to toggle source
# File lib/chatwork_to_slack/importer.rb, line 30
def create_workdir
  unless File.exists?(workdir)
    gcw.info "mkdir #{workdir}"
    FileUtils.mkdir_p(workdir)
  end
end
export() click to toggle source
# File lib/chatwork_to_slack/importer.rb, line 37
def export
  if export_files
    gcw.export_csv(room_id, chatwork_csv_path, { include_file: true, dir: chatwork_files_path })
  else
    gcw.export_csv(room_id, chatwork_csv_path)
  end
end
slack_csv_path() click to toggle source
# File lib/chatwork_to_slack/importer.rb, line 53
def slack_csv_path
  File.join(workdir, "#{channel}.csv")
end