-
Notifications
You must be signed in to change notification settings - Fork 27
/
file.rb
100 lines (97 loc) · 3.77 KB
/
file.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
module ChatWork
module File
# Get the list of files associated with the specified chat
#
# @param room_id [Integer]
# @param account_id [Integer]
#
# @see http://developer.chatwork.com/ja/endpoint_rooms.html#GET-rooms-room_id-files
# @see http://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
# }
# ]
def self.get(room_id:, account_id:, &block)
ChatWork.client.get_files(room_id: room_id, account_id: account_id, &block)
end
# Get information about the specified file
#
# @see http://developer.chatwork.com/ja/endpoint_rooms.html#GET-rooms-room_id-files-file_id
# @see http://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
# }
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
# 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
# ChatWork::File.create(room_id: 11111111, file: Faraday::UploadIO.new("/path/to/file.txt", "text/plain"), message: "Test")
#
# @example response format
# {
# "file_id": 1234
# }
#
def self.create(room_id:, file:, message: nil, &block)
ChatWork.client.create_file(room_id: room_id, file: file, message: message, &block)
end
class << self
alias_method :upload, :create
end
end
end