module ChatWork::File

Public Class Methods

create(room_id:, file:, message: nil, &block) click to toggle source

Upload a new file to room

@see developer.chatwork.com/ja/endpoint_rooms.html#POST-rooms-room_id-files @see download.chatwork.com/ChatWork_API_Documentation.pdf

@param room_id [Integer] @param file [Faraday::UploadIO] @param message [String]

@yield [response_body, response_header] if block was given, return response body and response header through block arguments @yieldparam response_body [Hashie::Mash] response body @yieldparam response_header [Hash<String, String>] response header (e.g. X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset)

@return [Hashie::Mash]

@example how to upload a file

ChatWork::File.create(room_id: 11111111, file: Faraday::UploadIO.new("/path/to/file.txt", "text/plain"), message: "Test")

@example response format

{
  "file_id": 1234
}
# File lib/chatwork/file.rb, line 92
def self.create(room_id:, file:, message: nil, &block)
  ChatWork.client.create_file(room_id: room_id, file: file, message: message, &block)
end
Also aliased as: upload
find(room_id:, file_id:, create_download_url: nil, &block) click to toggle source

Get information about the specified file

@see developer.chatwork.com/ja/endpoint_rooms.html#GET-rooms-room_id-files-file_id @see download.chatwork.com/ChatWork_API_Documentation.pdf

@param room_id [Integer] @param file_id [Integer] @param create_download_url [Boolean] whether or not to create a download link.

If set to true, download like will be created for 30 seconds

@yield [response_body, response_header] if block was given, return response body and response header through block arguments @yieldparam response_body [Hashie::Mash] response body @yieldparam response_header [Hash<String, String>] response header (e.g. X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset)

@return [Hashie::Mash]

@example response format

{
  "file_id":3,
  "account": {
    "account_id":123,
    "name":"Bob",
    "avatar_image_url": "https://example.com/ico_avatar.png"
  },
  "message_id": "22",
  "filename": "README.md",
  "filesize": 2232,
  "upload_time": 1384414750
}
# File lib/chatwork/file.rb, line 65
def self.find(room_id:, file_id:, create_download_url: nil, &block)
  ChatWork.client.find_file(room_id: room_id, file_id: file_id, create_download_url: create_download_url, &block)
end
get(room_id:, account_id:, &block) click to toggle source

Get the list of files associated with the specified chat

@param room_id [Integer] @param account_id [Integer]

@see developer.chatwork.com/ja/endpoint_rooms.html#GET-rooms-room_id-files @see download.chatwork.com/ChatWork_API_Documentation.pdf

@yield [response_body, response_header] if block was given, return response body and response header through block arguments @yieldparam response_body [Array<Hashie::Mash>] response body @yieldparam response_header [Hash<String, String>] response header (e.g. X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset)

@return [Array<Hashie::Mash>]

@example response format

[
  {
    "file_id": 3,
    "account": {
      "account_id": 123,
      "name": "Bob",
      "avatar_image_url": "https://example.com/ico_avatar.png"
    },
    "message_id": "22",
    "filename": "README.md",
    "filesize": 2232,
    "upload_time": 1384414750
  }
]
# File lib/chatwork/file.rb, line 32
def self.get(room_id:, account_id:, &block)
  ChatWork.client.get_files(room_id: room_id, account_id: account_id, &block)
end
upload(room_id:, file:, message: nil, &block)
Alias for: create