Skip to content

Commit 88524a5

Browse files
author
Rajat Goel
authored
Merge pull request #78 from dropbox/update-schema
Update to latest API spec
2 parents 0798489 + d184fdf commit 88524a5

File tree

8 files changed

+2403
-270
lines changed

8 files changed

+2403
-270
lines changed

dropbox/auth/client.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ type Client interface {
3434
// TokenFromOauth1 : Creates an OAuth 2.0 access token from the supplied
3535
// OAuth 1.0 access token.
3636
TokenFromOauth1(arg *TokenFromOAuth1Arg) (res *TokenFromOAuth1Result, err error)
37-
// TokenRevoke : Disables the access token used to authenticate the call.
37+
// TokenRevoke : Disables the access token used to authenticate the call. If
38+
// there is a corresponding refresh token for the access token, this
39+
// disables that refresh token, as well as any other access tokens for that
40+
// refresh token.
3841
TokenRevoke() (err error)
3942
}
4043

dropbox/files/client.go

Lines changed: 153 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,10 @@ type Client interface {
122122
// Download : Download a file from a user's Dropbox.
123123
Download(arg *DownloadArg) (res *FileMetadata, content io.ReadCloser, err error)
124124
// DownloadZip : Download a folder from the user's Dropbox, as a zip file.
125-
// The folder must be less than 20 GB in size and have fewer than 10,000
126-
// total files. The input cannot be a single file. Any single file must be
127-
// less than 4GB in size.
125+
// The folder must be less than 20 GB in size and any single file within
126+
// must be less than 4 GB in size. The resulting zip must have fewer than
127+
// 10,000 total file and folder entries, including the top level folder. The
128+
// input cannot be a single file.
128129
DownloadZip(arg *DownloadZipArg) (res *DownloadZipResult, content io.ReadCloser, err error)
129130
// Export : Export a file from a user's Dropbox. This route only supports
130131
// exporting files that cannot be downloaded directly and whose
@@ -180,16 +181,19 @@ type Client interface {
180181
GetTemporaryUploadLink(arg *GetTemporaryUploadLinkArg) (res *GetTemporaryUploadLinkResult, err error)
181182
// GetThumbnail : Get a thumbnail for an image. This method currently
182183
// supports files with the following file extensions: jpg, jpeg, png, tiff,
183-
// tif, gif and bmp. Photos that are larger than 20MB in size won't be
184-
// converted to a thumbnail.
184+
// tif, gif, webp, ppm and bmp. Photos that are larger than 20MB in size
185+
// won't be converted to a thumbnail.
185186
GetThumbnail(arg *ThumbnailArg) (res *FileMetadata, content io.ReadCloser, err error)
186-
// GetThumbnail : Get a thumbnail for a file.
187+
// GetThumbnail : Get a thumbnail for an image. This method currently
188+
// supports files with the following file extensions: jpg, jpeg, png, tiff,
189+
// tif, gif, webp, ppm and bmp. Photos that are larger than 20MB in size
190+
// won't be converted to a thumbnail.
187191
GetThumbnailV2(arg *ThumbnailV2Arg) (res *PreviewResult, content io.ReadCloser, err error)
188192
// GetThumbnailBatch : Get thumbnails for a list of images. We allow up to
189193
// 25 thumbnails in a single batch. This method currently supports files
190-
// with the following file extensions: jpg, jpeg, png, tiff, tif, gif and
191-
// bmp. Photos that are larger than 20MB in size won't be converted to a
192-
// thumbnail.
194+
// with the following file extensions: jpg, jpeg, png, tiff, tif, gif, webp,
195+
// ppm and bmp. Photos that are larger than 20MB in size won't be converted
196+
// to a thumbnail.
193197
GetThumbnailBatch(arg *GetThumbnailBatchArg) (res *GetThumbnailBatchResult, err error)
194198
// ListFolder : Starts returning the contents of a folder. If the result's
195199
// `ListFolderResult.has_more` field is true, call `listFolderContinue` with
@@ -275,6 +279,10 @@ type Client interface {
275279
// `moveBatch`. If success, it returns list of results for each entry.
276280
// Deprecated: Use `MoveBatchCheckV2` instead
277281
MoveBatchCheck(arg *async.PollArg) (res *RelocationBatchJobStatus, err error)
282+
// PaperCreate : Creates a new Paper doc with the provided content.
283+
PaperCreate(arg *PaperCreateArg, content io.Reader) (res *PaperCreateResult, err error)
284+
// PaperUpdate : Updates an existing Paper doc with the provided content.
285+
PaperUpdate(arg *PaperUpdateArg, content io.Reader) (res *PaperUpdateResult, err error)
278286
// PermanentlyDelete : Permanently delete the file or folder at a given path
279287
// (see https://www.dropbox.com/en/help/40). If the given file or folder is
280288
// not yet deleted, this route will first delete it. It is possible for this
@@ -398,9 +406,9 @@ type Client interface {
398406
// `uploadSessionFinish` to save all the data to a file in Dropbox. A single
399407
// request should not upload more than 150 MB. The maximum size of a file
400408
// one can upload to an upload session is 350 GB. An upload session can be
401-
// used for a maximum of 48 hours. Attempting to use an
409+
// used for a maximum of 7 days. Attempting to use an
402410
// `UploadSessionStartResult.session_id` with `uploadSessionAppend` or
403-
// `uploadSessionFinish` more than 48 hours after its creation will return a
411+
// `uploadSessionFinish` more than 7 days after its creation will return a
404412
// `UploadSessionLookupError.not_found`. Calls to this endpoint will count
405413
// as data transport calls for any Dropbox Business teams with a limit on
406414
// the number of data transport calls allowed per month. For more
@@ -3224,6 +3232,140 @@ func (dbx *apiImpl) MoveBatchCheck(arg *async.PollArg) (res *RelocationBatchJobS
32243232
return
32253233
}
32263234

3235+
//PaperCreateAPIError is an error-wrapper for the paper/create route
3236+
type PaperCreateAPIError struct {
3237+
dropbox.APIError
3238+
EndpointError *PaperCreateError `json:"error"`
3239+
}
3240+
3241+
func (dbx *apiImpl) PaperCreate(arg *PaperCreateArg, content io.Reader) (res *PaperCreateResult, err error) {
3242+
cli := dbx.Client
3243+
3244+
dbx.Config.LogDebug("arg: %v", arg)
3245+
b, err := json.Marshal(arg)
3246+
if err != nil {
3247+
return
3248+
}
3249+
3250+
headers := map[string]string{
3251+
"Content-Type": "application/octet-stream",
3252+
"Dropbox-API-Arg": dropbox.HTTPHeaderSafeJSON(b),
3253+
}
3254+
if dbx.Config.AsMemberID != "" {
3255+
headers["Dropbox-API-Select-User"] = dbx.Config.AsMemberID
3256+
}
3257+
3258+
req, err := (*dropbox.Context)(dbx).NewRequest("api", "upload", true, "files", "paper/create", headers, content)
3259+
if err != nil {
3260+
return
3261+
}
3262+
dbx.Config.LogInfo("req: %v", req)
3263+
3264+
resp, err := cli.Do(req)
3265+
if err != nil {
3266+
return
3267+
}
3268+
3269+
dbx.Config.LogInfo("resp: %v", resp)
3270+
defer resp.Body.Close()
3271+
body, err := ioutil.ReadAll(resp.Body)
3272+
if err != nil {
3273+
return
3274+
}
3275+
3276+
dbx.Config.LogDebug("body: %s", body)
3277+
if resp.StatusCode == http.StatusOK {
3278+
err = json.Unmarshal(body, &res)
3279+
if err != nil {
3280+
return
3281+
}
3282+
3283+
return
3284+
}
3285+
if resp.StatusCode == http.StatusConflict {
3286+
var apiError PaperCreateAPIError
3287+
err = json.Unmarshal(body, &apiError)
3288+
if err != nil {
3289+
return
3290+
}
3291+
err = apiError
3292+
return
3293+
}
3294+
err = auth.HandleCommonAuthErrors(dbx.Config, resp, body)
3295+
if err != nil {
3296+
return
3297+
}
3298+
err = dropbox.HandleCommonAPIErrors(dbx.Config, resp, body)
3299+
return
3300+
}
3301+
3302+
//PaperUpdateAPIError is an error-wrapper for the paper/update route
3303+
type PaperUpdateAPIError struct {
3304+
dropbox.APIError
3305+
EndpointError *PaperUpdateError `json:"error"`
3306+
}
3307+
3308+
func (dbx *apiImpl) PaperUpdate(arg *PaperUpdateArg, content io.Reader) (res *PaperUpdateResult, err error) {
3309+
cli := dbx.Client
3310+
3311+
dbx.Config.LogDebug("arg: %v", arg)
3312+
b, err := json.Marshal(arg)
3313+
if err != nil {
3314+
return
3315+
}
3316+
3317+
headers := map[string]string{
3318+
"Content-Type": "application/octet-stream",
3319+
"Dropbox-API-Arg": dropbox.HTTPHeaderSafeJSON(b),
3320+
}
3321+
if dbx.Config.AsMemberID != "" {
3322+
headers["Dropbox-API-Select-User"] = dbx.Config.AsMemberID
3323+
}
3324+
3325+
req, err := (*dropbox.Context)(dbx).NewRequest("api", "upload", true, "files", "paper/update", headers, content)
3326+
if err != nil {
3327+
return
3328+
}
3329+
dbx.Config.LogInfo("req: %v", req)
3330+
3331+
resp, err := cli.Do(req)
3332+
if err != nil {
3333+
return
3334+
}
3335+
3336+
dbx.Config.LogInfo("resp: %v", resp)
3337+
defer resp.Body.Close()
3338+
body, err := ioutil.ReadAll(resp.Body)
3339+
if err != nil {
3340+
return
3341+
}
3342+
3343+
dbx.Config.LogDebug("body: %s", body)
3344+
if resp.StatusCode == http.StatusOK {
3345+
err = json.Unmarshal(body, &res)
3346+
if err != nil {
3347+
return
3348+
}
3349+
3350+
return
3351+
}
3352+
if resp.StatusCode == http.StatusConflict {
3353+
var apiError PaperUpdateAPIError
3354+
err = json.Unmarshal(body, &apiError)
3355+
if err != nil {
3356+
return
3357+
}
3358+
err = apiError
3359+
return
3360+
}
3361+
err = auth.HandleCommonAuthErrors(dbx.Config, resp, body)
3362+
if err != nil {
3363+
return
3364+
}
3365+
err = dropbox.HandleCommonAPIErrors(dbx.Config, resp, body)
3366+
return
3367+
}
3368+
32273369
//PermanentlyDeleteAPIError is an error-wrapper for the permanently_delete route
32283370
type PermanentlyDeleteAPIError struct {
32293371
dropbox.APIError

0 commit comments

Comments
 (0)