Class: Embulk::Plugin::InputSlackHistory

Inherits:
InputPlugin
  • Object
show all
Defined in:
lib/embulk/input/slack_history.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(task, schema, index, page_builder) ⇒ InputSlackHistory

Returns a new instance of InputSlackHistory.



208
209
210
211
212
# 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

Class Method Details

.transaction(config, &control) ⇒ Object



170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# 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

Instance Method Details

#runObject



214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# 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