Class: Slackr::FileUploader

Inherits:
Object
  • Object
show all
Defined in:
lib/slackr/file_uploader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection, filepath, options = {}) ⇒ FileUploader

Returns a new instance of FileUploader.



12
13
14
15
16
17
18
19
20
# 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

Instance Attribute Details

#channelsObject (readonly)

Returns the value of attribute channels.



10
11
12
# File 'lib/slackr/file_uploader.rb', line 10

def channels
  @channels
end

#commentObject (readonly)

Returns the value of attribute comment.



10
11
12
# File 'lib/slackr/file_uploader.rb', line 10

def comment
  @comment
end

#connectionObject

Returns the value of attribute connection.



9
10
11
# File 'lib/slackr/file_uploader.rb', line 9

def connection
  @connection
end

#filenameObject (readonly)

Returns the value of attribute filename.



10
11
12
# File 'lib/slackr/file_uploader.rb', line 10

def filename
  @filename
end

#filepathObject (readonly)

Returns the value of attribute filepath.



10
11
12
# File 'lib/slackr/file_uploader.rb', line 10

def filepath
  @filepath
end

#filetypeObject (readonly)

Returns the value of attribute filetype.



10
11
12
# File 'lib/slackr/file_uploader.rb', line 10

def filetype
  @filetype
end

#titleObject (readonly)

Returns the value of attribute title.



10
11
12
# File 'lib/slackr/file_uploader.rb', line 10

def title
  @title
end

Instance Method Details

#uploadObject



22
23
24
25
26
27
28
29
# 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