@@ -32,7 +32,7 @@ def copy(from_path, to_path)
32
32
# @return [Dropbox::FolderMetadata]
33
33
def create_folder ( path )
34
34
resp = request ( '/files/create_folder' , path : path )
35
- parse_tagged_response ( resp , 'folder' )
35
+ FolderMetadata . new ( resp )
36
36
end
37
37
38
38
# Delete the file or folder at a given path.
@@ -51,7 +51,7 @@ def delete(path)
51
51
# @return [HTTP::Response::Body] body
52
52
def download ( path )
53
53
resp , body = content_request ( '/files/download' , path : path )
54
- return parse_tagged_response ( resp , 'file' ) , body
54
+ return FileMetadata . new ( resp ) , body
55
55
end
56
56
57
57
# Get information about a user's account.
@@ -60,24 +60,24 @@ def download(path)
60
60
# @return [Dropbox::BasicAccount]
61
61
def get_account ( account_id )
62
62
resp = request ( '/users/get_account' , account_id : account_id )
63
- parse_tagged_response ( resp , 'basic_account' )
63
+ BasicAccount . new ( resp )
64
64
end
65
65
66
66
# Get information about multiple user accounts.
67
67
#
68
68
# @param [Array<String>] account_ids
69
69
# @return [Array<Dropbox::BasicAccount>]
70
70
def get_account_batch ( account_ids )
71
- resp = request ( '/users/get_account_batch' , account_ids : ids )
72
- resp . map { |a | parse_tagged_response ( a , 'basic_account' ) }
71
+ resp = request ( '/users/get_account_batch' , account_ids : account_ids )
72
+ resp . map { |a | BasicAccount . new ( a ) }
73
73
end
74
74
75
75
# Get information about the current user's account.
76
76
#
77
77
# @return [Dropbox::FullAccount]
78
78
def get_current_account
79
79
resp = request ( '/users/get_current_account' )
80
- parse_tagged_response ( resp , 'full_account' )
80
+ FullAccount . new ( resp )
81
81
end
82
82
83
83
# Get the metadata for a file or folder.
@@ -96,7 +96,7 @@ def get_metadata(path)
96
96
# @return [HTTP::Response::Body] body
97
97
def get_preview ( path )
98
98
resp , body = content_request ( '/files/get_preview' , path : path )
99
- return parse_tagged_response ( resp , 'file' ) , body
99
+ return FileMetadata . new ( resp ) , body
100
100
end
101
101
102
102
# Get the space usage information for the current user's account.
@@ -114,7 +114,7 @@ def get_space_usage
114
114
# @return [String] link
115
115
def get_temporary_link ( path )
116
116
resp = request ( '/files/get_temporary_link' , path : path )
117
- return parse_tagged_response ( resp [ 'metadata' ] , 'file' ) , resp [ 'link' ]
117
+ return FileMetadata . new ( resp [ 'metadata' ] ) , resp [ 'link' ]
118
118
end
119
119
120
120
# Get a thumbnail for an image.
@@ -126,7 +126,7 @@ def get_temporary_link(path)
126
126
# @return [HTTP::Response::Body] body
127
127
def get_thumbnail ( path , format = 'jpeg' , size = 'w64h64' )
128
128
resp , body = content_request ( '/files/get_thumbnail' , path : path , format : format , size : size )
129
- return parse_tagged_response ( resp , 'file' ) , body
129
+ return FileMetadata . new ( resp ) , body
130
130
end
131
131
132
132
# Get the contents of a folder.
@@ -145,7 +145,7 @@ def list_folder(path)
145
145
# @return [Boolean] is_deleted
146
146
def list_revisions ( path )
147
147
resp = request ( '/files/list_revisions' , path : path )
148
- entries = resp [ 'entries' ] . map { |e | parse_tagged_response ( e , 'file' ) }
148
+ entries = resp [ 'entries' ] . map { |e | FileMetadata . new ( e ) }
149
149
return entries , resp [ 'is_deleted' ]
150
150
end
151
151
@@ -155,7 +155,7 @@ def list_revisions(path)
155
155
# @param [String] to_path
156
156
# @return [Dropbox::Metadata]
157
157
def move ( from_path , to_path )
158
- resp = request ( '/files/move' , from_path : from , to_path : to )
158
+ resp = request ( '/files/move' , from_path : from_path , to_path : to_path )
159
159
parse_tagged_response ( resp )
160
160
end
161
161
@@ -166,7 +166,7 @@ def move(from_path, to_path)
166
166
# @return [Dropbox::FileMetadata]
167
167
def restore ( path , rev )
168
168
resp = request ( '/files/restore' , path : path , rev : rev )
169
- parse_tagged_response ( resp , 'file' )
169
+ FileMetadata . new ( resp )
170
170
end
171
171
172
172
# Disable the access token used to authenticate the call.
@@ -187,7 +187,7 @@ def save_url(path, url)
187
187
resp = request ( '/files/save_url' , path : path , url : url )
188
188
case resp [ '.tag' ]
189
189
when 'complete'
190
- parse_tagged_response ( resp [ 'complete' ] , 'file' )
190
+ FileMetadata . new ( resp [ 'complete' ] )
191
191
when 'async_job_id'
192
192
resp [ 'async_job_id' ]
193
193
else
@@ -202,7 +202,7 @@ def save_url(path, url)
202
202
# @param [Integer] max_results
203
203
# @return [Array<Dropbox::Metadata>] matches
204
204
def search ( query , path = '' , max_results = 100 )
205
- resp = request ( '/files/search' , path : path , query : query , max_results : max )
205
+ resp = request ( '/files/search' , path : path , query : query , max_results : max_results )
206
206
resp [ 'matches' ] . map { |m | parse_tagged_response ( m [ 'metadata' ] ) }
207
207
end
208
208
@@ -219,12 +219,12 @@ def upload(path, body, mode='add', autorename=false, client_modified=nil, mute=f
219
219
client_modified = client_modified . iso8601 if client_modified . is_a? ( Time )
220
220
resp = upload_request ( '/files/upload' , body , path : path , mode : mode ,
221
221
autorename : autorename , client_modified : client_modified , mute : mute )
222
- parse_tagged_response ( resp , 'file' )
222
+ FileMetadata . new ( resp )
223
223
end
224
224
225
225
private
226
- def parse_tagged_response ( resp , tag = resp [ '.tag' ] )
227
- case tag
226
+ def parse_tagged_response ( resp )
227
+ case resp [ '. tag' ]
228
228
when 'file'
229
229
FileMetadata . new ( resp )
230
230
when 'folder'
@@ -236,7 +236,7 @@ def parse_tagged_response(resp, tag=resp['.tag'])
236
236
when 'full_account'
237
237
FullAccount . new ( resp )
238
238
else
239
- raise ClientError . unknown_response_type ( tag )
239
+ raise ClientError . unknown_response_type ( resp [ '. tag' ] )
240
240
end
241
241
end
242
242
0 commit comments