Module: ChatWork::File

Defined in:
lib/chatwork/file.rb

Class Method Summary collapse

Class Method Details

.create(room_id:, file:, message: nil) {|response_body, response_header| ... } ⇒ Hashie::Mash Also known as: upload

Upload a new file to room

Examples:

how to upload a file

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

response format

{
  "file_id": 1234
}

Parameters:

  • room_id (Integer)
  • file (Faraday::UploadIO)
  • message (String) (defaults to: nil)

Yields:

  • (response_body, response_header)

    if block was given, return response body and response header through block arguments

Yield Parameters:

  • response_body (Hashie::Mash)

    response body

  • response_header (Hash<String, String>)

    response header (e.g. X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset)

Returns:

  • (Hashie::Mash)

See Also:



92
93
94
# 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

.find(room_id:, file_id:, create_download_url: nil) {|response_body, response_header| ... } ⇒ Hashie::Mash

Get information about the specified file

Examples:

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
}

Parameters:

  • room_id (Integer)
  • file_id (Integer)
  • create_download_url (Boolean) (defaults to: nil)

    whether or not to create a download link. If set to true, download like will be created for 30 seconds

Yields:

  • (response_body, response_header)

    if block was given, return response body and response header through block arguments

Yield Parameters:

  • response_body (Hashie::Mash)

    response body

  • response_header (Hash<String, String>)

    response header (e.g. X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset)

Returns:

  • (Hashie::Mash)

See Also:



65
66
67
# 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:) {|response_body, response_header| ... } ⇒ Array<Hashie::Mash>

Get the list of files associated with the specified chat

Examples:

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
  }
]

Parameters:

  • room_id (Integer)
  • account_id (Integer)

Yields:

  • (response_body, response_header)

    if block was given, return response body and response header through block arguments

Yield Parameters:

  • response_body (Array<Hashie::Mash>)

    response body

  • response_header (Hash<String, String>)

    response header (e.g. X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset)

Returns:

  • (Array<Hashie::Mash>)

See Also:



32
33
34
# 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: , &block)
end