Class: Embulk::Input::SlackMessage
- Inherits:
-
InputPlugin
- Object
- InputPlugin
- Embulk::Input::SlackMessage
- Defined in:
- lib/embulk/input/slack_message.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.columns ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/embulk/input/slack_message.rb', line 32 def self.columns [ Column.new(0, "datetime", :timestamp), Column.new(1, "channel_id", :string), Column.new(2, "channel_name", :string), Column.new(3, "user_id", :string), Column.new(4, "user_name", :string), Column.new(5, "message", :string) ] end |
.guess(config) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/embulk/input/slack_message.rb', line 43 def self.guess(config) channels = [ { name: 'general', type: 'channel', latest: Time.now.strftime('%F %T'), oldest: 0, count: 100, inclusive: 0, unreads: 0 } ] { channel: channels.first, token: 'SLACK_API_TOKEN', repeat: 0, columns: Embulk::Schema.new(self.columns) } end |
.transaction(config) {|task, columns, 1| ... } ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/embulk/input/slack_message.rb', line 8 def self.transaction(config, &control) task = { 'channel' => config.param('channel', :hash), 'token' => config.param('token', :string), 'repeat_at' => config.param('repeat_at', :long, default: 0) } yield(task, columns, 1) channel = task['channel'] repeat_at = task['repeat_at'] latest = channel['latest'] ? Time.parse(channel['latest']).to_f : Time.now.to_f oldest = channel['oldest'] ? Time.parse(channel['oldest']).to_f : 0 if repeat_at.zero? time_diff = latest.to_i - oldest.to_i channel = { oldest: Time.at(latest), latest: Time.at(latest + time_diff) } else channel = { oldest: oldest + repeat_at, latest: latest + repeat_at } end { channel: channel } end |
Instance Method Details
#init ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/embulk/input/slack_message.rb', line 58 def init @channel = task["channel"] token = task['token'] raise StandardError.new, 'slack token is not found' unless token Slack.token = token end |
#run ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/embulk/input/slack_message.rb', line 67 def run latest = @channel['latest'] ? Time.parse(@channel['latest']).to_f : Time.now.to_f oldest = @channel['oldest'] ? Time.parse(@channel['oldest']).to_f : 0 inclusive = @channel['inclusive'] || 0 count = @channel['count'] || 100 unreads = @channel['unreads'] || 0 = { latest: latest, oldest: oldest, inclusive: inclusive, count: count, unreads: unreads } Slack.(@channel['name'], @channel['type'], ).each do || page_builder.add end page_builder.finish task_report = {} return task_report end |