class Embulk::Plugin::InputSlackHistory

Public Class Methods

new(task, schema, index, page_builder) click to toggle source
Calls superclass method
# File lib/embulk/input/slack_history.rb, line 208
def initialize(task, schema, index, page_builder)
  super
  @slack = SlackApi.new(task['token'])
  @noerror = @slack.pre()
end
transaction(config) { |task, columns, threads| ... } click to toggle source
# File lib/embulk/input/slack_history.rb, line 170
def self.transaction(config, &control)

  @noerror = true

  threads = 1

  token = config.param('token', :string)
  continuous = config.param('continuous', :bool, default: false)
  filepath = config.param('filepath', :string, default: '/tmp')
  preview = config.param('preview', :string, default: 'no')

  task = {
    'token' => token,
    'continuous' => continuous,
    'filepath' => filepath,
    'preview' => preview
  }

  columns = [
    Column.new(0, 'channelid', :string),
    Column.new(1, 'channelname', :string),
    Column.new(2, 'private', :string),
    Column.new(3, 'datetime', :timestamp),
    Column.new(4, 'username', :string),
    Column.new(5, 'userid', :string),
    Column.new(6, 'message', :string),
  ]

  puts "Slack history input started."
  commit_reports = yield(task, columns, threads)
  puts "Slack history input finished."

  next_config_diff = {}
  return next_config_diff

end

Public Instance Methods

run() click to toggle source
# File lib/embulk/input/slack_history.rb, line 214
def run

  if !@noerror then
    @page_builder.finish
    return
  end

  messages = @slack.get_history(@task['continuous'], @task['filepath'])

  messages.each{|message|
    @page_builder.add([
      message['channelid'],
      message['channelname'],
      message['private'],
      Time.at(message['ts'].to_f),
      message['username'],
      message['userid'],
      message['message']
      ])
  }

  @page_builder.finish

  commit_report = {}
  return commit_report
end