class Slackr::FileUploader
Attributes
channels[R]
comment[R]
connection[RW]
filename[R]
filepath[R]
filetype[R]
title[R]
Public Class Methods
new(connection, filepath, options={})
click to toggle source
# File lib/slackr/file_uploader.rb, line 12 def initialize(connection, filepath, options={}) @connection = connection @filepath = filepath @channels = options['channels'] @filetype = options['filetype'] @filename = options['filename'] @title = options['title'] @comment = options['initial_comment'] end
Public Instance Methods
upload()
click to toggle source
# File lib/slackr/file_uploader.rb, line 22 def upload response = connection.http_request(multipart) if response.code != "200" raise Slackr::ServiceError, "Slack.com - #{response.code} - #{response.body}" end true end
Private Instance Methods
additional_params()
click to toggle source
# File lib/slackr/file_uploader.rb, line 41 def additional_params {}.tap do |hash| hash['channels'] = channels if channels hash['filetype'] = filetype if filetype hash['filename'] = filename if filename hash['title'] = title if title hash['initial_comment'] = comment if comment end end
multipart()
click to toggle source
# File lib/slackr/file_uploader.rb, line 33 def multipart Net::HTTP::Post::Multipart.new(service_url.path, { 'file' => UploadIO.new(File.open(filepath), "application/data"), 'token' => connection.token }.merge(additional_params)) end
service_url()
click to toggle source
# File lib/slackr/file_uploader.rb, line 51 def service_url URI.parse("#{connection.base_url}/api/files.upload") end