Module: ChatWork::Client::FileMethods

Included in:
ChatWork::Client
Defined in:
lib/chatwork/client/file_methods.rb

Instance Method Summary collapse

Instance Method Details

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

Upload a new file to room

Examples:

how to upload a file

client = ChatWork::Client.new(api_key: "XXX")
client.create_file(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
95
96
97
98
99
# File 'lib/chatwork/client/file_methods.rb', line 92

def create_file(room_id:, file:, message: nil, &block)
  params = {
    file:    file,
    message: message,
  }

  post("/rooms/#{room_id}/files", params, &block)
end

#find_file(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:



64
65
66
# File 'lib/chatwork/client/file_methods.rb', line 64

def find_file(room_id:, file_id:, create_download_url: nil, &block)
  get("/rooms/#{room_id}/files/#{file_id}", create_download_url: boolean_to_integer(create_download_url), &block)
end

#get_files(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:



31
32
33
# File 'lib/chatwork/client/file_methods.rb', line 31

def get_files(room_id:, account_id:, &block)
  get("/rooms/#{room_id}/files", account_id: , &block)
end