Class: Lita::Handlers::Amesh::Uploaders::SlackUploader

Inherits:
Object
  • Object
show all
Defined in:
lib/lita/handlers/amesh/uploaders/slack_uploader.rb

Instance Method Summary collapse

Constructor Details

#initialize(token:) ⇒ SlackUploader

Returns a new instance of SlackUploader.



11
12
13
14
15
16
# File 'lib/lita/handlers/amesh/uploaders/slack_uploader.rb', line 11

def initialize(token:)
  Slack.configure do |config|
    config.token = token
  end
  @client = Slack::Web::Client.new
end

Instance Method Details

#upload_image(image_path) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/lita/handlers/amesh/uploaders/slack_uploader.rb', line 18

def upload_image(image_path)
  filename = "#{Time.now.strftime("%Y%m%d%H%M")}.jpg"

  client.files_upload(
    channels: '#general',
    as_user: false,
    file: Faraday::UploadIO.new(image_path, 'image/jpeg'),
    title: 'アメッシュ',
    filename: filename
  )
end