1
1
defmodule ElixirDropbox.Files do
2
+ @ moduledoc """
3
+ This module contains endpoints and data types
4
+ for basic file operations.
5
+ """
2
6
import ElixirDropbox
3
7
import ElixirDropbox.Utils
4
8
@@ -38,13 +42,17 @@ defmodule ElixirDropbox.Files do
38
42
end
39
43
40
44
@ doc """
41
- Delete folder returns map
45
+ Delete the file or folder at a given path.
46
+ If the path is a folder, all its contents will be deleted too.
47
+ A successful response indicates that the file or folder was deleted.
48
+ The returned metadata will be the corresponding FileMetadata
49
+ or FolderMetadata for the item at time of deletion, and not a DeletedMetadata object.
42
50
43
- ## Example
51
+ ## Example
44
52
45
- ElixirDropbox.Files.delete_folder client, "/Path "
53
+ ElixirDropbox.Files.delete_folder client, "/Homework/math/Prime_Numbers.txt "
46
54
47
- More info at: https://www.dropbox.com/developers/documentation/http/documentation#files-delete
55
+ More info at: https://www.dropbox.com/developers/documentation/http/documentation#files-delete_v2
48
56
"""
49
57
def delete_folder ( client , path ) do
50
58
body = % { "path" => path }
@@ -102,12 +110,36 @@ defmodule ElixirDropbox.Files do
102
110
post ( client , "/files/move" , result )
103
111
end
104
112
113
+ @ doc """
114
+ Restore a file to a specific revision.
115
+
116
+ ## Example
117
+
118
+ ElixirDropbox.Files.restore(client, "/root/word.docx", "a1c10ce0dd78")
119
+
120
+ More info at: https://www.dropbox.com/developers/documentation/http/documentation#files-restore
121
+ """
105
122
def restore ( client , path , rev ) do
106
123
body = % { "path" => path , "rev" => rev }
107
124
result = to_string ( Poison.Encoder . encode ( body , [ ] ) )
108
125
post ( client , "/files/restore" , result )
109
126
end
110
127
128
+ @ doc """
129
+ Searches for files and folders.
130
+
131
+ ## Example
132
+
133
+ ElixirDropbox.Files.search(client, "/root", "word.docx")
134
+
135
+ More info at: https://www.dropbox.com/developers/documentation/http/documentation#files-search
136
+ """
137
+ def search ( client , path , query , start \\ 0 , max_results \\ 100 , mode \\ "filename" ) do
138
+ body = % { "path" => path , "query" => query , "start" => start , "max_results" => max_results , "mode" => mode }
139
+ result = to_string ( Poison.Encoder . encode ( body , [ ] ) )
140
+ post ( client , "/files/search" , result )
141
+ end
142
+
111
143
@ doc """
112
144
Create a new file with the contents provided in the request.
113
145
@@ -128,6 +160,15 @@ defmodule ElixirDropbox.Files do
128
160
upload_request ( client , Application . get_env ( :elixir_dropbox , :upload_url ) , "files/upload" , file , headers )
129
161
end
130
162
163
+ @ doc """
164
+ Download a file from a user's Dropbox.
165
+
166
+ ## Example
167
+
168
+ ElixirDropbox.Files.download client, "/mypdf.pdf"
169
+
170
+ More info at: https://www.dropbox.com/developers/documentation/http/documentation#files-download
171
+ """
131
172
def download ( client , path ) do
132
173
dropbox_headers = % {
133
174
:path => path
@@ -136,6 +177,15 @@ defmodule ElixirDropbox.Files do
136
177
download_request ( client , Application . get_env ( :elixir_dropbox , :upload_url ) , "files/download" , [ ] , headers )
137
178
end
138
179
180
+ @ doc """
181
+ Get a thumbnail for an image.
182
+
183
+ ## Example
184
+
185
+ ElixirDropbox.Files.get_thumbnail client, "/image.jpg"
186
+
187
+ More info at: https://www.dropbox.com/developers/documentation/http/documentation#files-get_thumbnail
188
+ """
139
189
def get_thumbnail ( client , path , format \\ "jpeg" , size \\ "w64h64" ) do
140
190
dropbox_headers = % {
141
191
:path => path ,
@@ -146,6 +196,31 @@ defmodule ElixirDropbox.Files do
146
196
download_request ( client , Application . get_env ( :elixir_dropbox , :upload_url ) , "files/get_thumbnail" , [ ] , headers )
147
197
end
148
198
199
+ @ doc """
200
+ Get thumbnails for a list of images. We allow up to 25 thumbnails in a single batch.
201
+
202
+ ## Example
203
+ batch = %{ "path" => "/image.jpg", "format" => "jpeg", "size" => "w64h64"}
204
+ entries = [batch]
205
+ ElixirDropbox.Files.get_thumbnail_batch client, entries
206
+
207
+ More info at: https://www.dropbox.com/developers/documentation/http/documentation#files-get_thumbnail_batch
208
+ """
209
+ def get_thumbnail_batch ( client , entries ) do
210
+ body = % { "entries" => entries }
211
+ result = to_string ( Poison.Encoder . encode ( body , [ ] ) )
212
+ post_url ( client , Application . get_env ( :elixir_dropbox , :upload_url ) , "/files/get_thumbnail_batch" , result )
213
+ end
214
+
215
+ @ doc """
216
+ Get a preview for a file.
217
+
218
+ ## Example
219
+
220
+ ElixirDropbox.Files.get_preview client, "/mypdf.pdf"
221
+
222
+ More info at: https://www.dropbox.com/developers/documentation/http/documentation#files-get_preview
223
+ """
149
224
def get_preview ( client , path ) do
150
225
dropbox_headers = % {
151
226
:path => path
@@ -154,8 +229,32 @@ defmodule ElixirDropbox.Files do
154
229
download_request ( client , Application . get_env ( :elixir_dropbox , :upload_url ) , "files/get_preview" , [ ] , headers )
155
230
end
156
231
157
- def get_metadata ( client , path , include_media_info \\ false ) do
158
- body = % { "path" => path , "include_media_info" => include_media_info }
232
+ @ doc """
233
+ Get a temporary link to stream content of a file. This link will expire in four hours and afterwards you will get 410 Gone. Content-Type of the link is determined automatically by the file's mime type.
234
+
235
+ ## Example
236
+
237
+ ElixirDropbox.Files.get_temporary_link client, "/video.mp4"
238
+
239
+ More info at: https://www.dropbox.com/developers/documentation/http/documentation#files-get_preview
240
+ """
241
+ def get_temporary_link ( client , path ) do
242
+ body = % { "path" => path }
243
+ result = to_string ( Poison.Encoder . encode ( body , [ ] ) )
244
+ post ( client , "/files/get_temporary_link" , result )
245
+ end
246
+
247
+ @ doc """
248
+ Returns the metadata for a file or folder.
249
+
250
+ ## Example
251
+
252
+ ElixirDropbox.Files.get_metadata client, "/mypdf.pdf"
253
+
254
+ More info at: https://www.dropbox.com/developers/documentation/http/documentation#files-get_metadata
255
+ """
256
+ def get_metadata ( client , path , include_media_info \\ false , include_deleted \\ false , include_has_explicit_shared_members \\ false ) do
257
+ body = % { "path" => path , "include_media_info" => include_media_info , "include_deleted" => include_deleted , "include_has_explicit_shared_members" => include_has_explicit_shared_members }
159
258
result = to_string ( Poison.Encoder . encode ( body , [ ] ) )
160
259
post ( client , "/files/get_metadata" , result )
161
260
end
0 commit comments