lib/chatwork/client/file_methods.rb in chatwork-0.9.0 vs lib/chatwork/client/file_methods.rb in chatwork-0.10.0

- old
+ new

@@ -62,6 +62,41 @@ # "upload_time": 1384414750 # } 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 + + # Upload a new file to room + # + # @see http://developer.chatwork.com/ja/endpoint_rooms.html#POST-rooms-room_id-files + # @see http://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 + # 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") + # + # @example response format + # { + # "file_id": 1234 + # } + # + def create_file(room_id:, file:, message: nil, &block) + params = { + file: file, + message: message, + } + + post("/rooms/#{room_id}/files", params, &block) + end + + alias_method :upload_file, :create_file end