Skip to content

Commit 73ed71f

Browse files
author
Diwaker Gupta
committed
Update API spec.
Modify generator script to use the Stone cli directly.
1 parent 753dd36 commit 73ed71f

File tree

11 files changed

+784
-251
lines changed

11 files changed

+784
-251
lines changed

dropbox/auth/types.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,32 @@ const (
3535
AuthErrorInvalidSelectAdmin = "invalid_select_admin"
3636
AuthErrorOther = "other"
3737
)
38+
39+
// RateLimitError : Error occurred because the app is being rate limited.
40+
type RateLimitError struct {
41+
// Reason : The reason why the app is being rate limited.
42+
Reason *RateLimitReason `json:"reason"`
43+
// RetryAfter : The number of seconds that the app should wait before making
44+
// another request.
45+
RetryAfter uint64 `json:"retry_after"`
46+
}
47+
48+
// NewRateLimitError returns a new RateLimitError instance
49+
func NewRateLimitError(Reason *RateLimitReason) *RateLimitError {
50+
s := new(RateLimitError)
51+
s.Reason = Reason
52+
s.RetryAfter = 1
53+
return s
54+
}
55+
56+
// RateLimitReason : has no documentation (yet)
57+
type RateLimitReason struct {
58+
dropbox.Tagged
59+
}
60+
61+
// Valid tag values for RateLimitReason
62+
const (
63+
RateLimitReasonTooManyRequests = "too_many_requests"
64+
RateLimitReasonTooManyWriteOperations = "too_many_write_operations"
65+
RateLimitReasonOther = "other"
66+
)

dropbox/files/client.go

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,24 @@ type Client interface {
161161
// to the given file path. A single request should not upload more than 150
162162
// MB of file contents.
163163
UploadSessionFinish(arg *UploadSessionFinishArg, content io.Reader) (res *FileMetadata, err error)
164+
// UploadSessionFinishBatch : This route helps you commit many files at once
165+
// into a user's Dropbox. Use `uploadSessionStart` and
166+
// `uploadSessionAppendV2` to upload file contents. We recommend uploading
167+
// many files in parallel to increase throughput. Once the file contents
168+
// have been uploaded, rather than calling `uploadSessionFinish`, use this
169+
// route to finish all your upload sessions in a single request.
170+
// `UploadSessionStartArg.close` or `UploadSessionAppendArg.close` needs to
171+
// be true for last `uploadSessionStart` or `uploadSessionAppendV2` call.
172+
// This route will return job_id immediately and do the async commit job in
173+
// background. We have another route `uploadSessionFinishBatchCheck` to
174+
// check the job status. For the same account, this route should be executed
175+
// serially. That means you should not start next job before current job
176+
// finishes. Also we only allow up to 1000 entries in a single request
177+
UploadSessionFinishBatch(arg *UploadSessionFinishBatchArg) (res *async.LaunchEmptyResult, err error)
178+
// UploadSessionFinishBatchCheck : Returns the status of an asynchronous job
179+
// for `uploadSessionFinishBatch`. If success, it returns list of result for
180+
// each entry
181+
UploadSessionFinishBatchCheck(arg *async.PollArg) (res *UploadSessionFinishBatchJobStatus, err error)
164182
// UploadSessionStart : Upload sessions allow you to upload a single file
165183
// using multiple requests. This call starts a new upload session with the
166184
// given data. You can then use `uploadSessionAppendV2` to add more data
@@ -2714,6 +2732,160 @@ func (dbx *apiImpl) UploadSessionFinish(arg *UploadSessionFinishArg, content io.
27142732
return
27152733
}
27162734

2735+
//UploadSessionFinishBatchAPIError is an error-wrapper for the upload_session/finish_batch route
2736+
type UploadSessionFinishBatchAPIError struct {
2737+
dropbox.APIError
2738+
EndpointError struct{} `json:"error"`
2739+
}
2740+
2741+
func (dbx *apiImpl) UploadSessionFinishBatch(arg *UploadSessionFinishBatchArg) (res *async.LaunchEmptyResult, err error) {
2742+
cli := dbx.Client
2743+
2744+
if dbx.Config.Verbose {
2745+
log.Printf("arg: %v", arg)
2746+
}
2747+
b, err := json.Marshal(arg)
2748+
if err != nil {
2749+
return
2750+
}
2751+
2752+
req, err := http.NewRequest("POST", (*dropbox.Context)(dbx).GenerateURL("api", "files", "upload_session/finish_batch"), bytes.NewReader(b))
2753+
if err != nil {
2754+
return
2755+
}
2756+
2757+
req.Header.Set("Content-Type", "application/json")
2758+
if dbx.Config.AsMemberID != "" {
2759+
req.Header.Set("Dropbox-API-Select-User", dbx.Config.AsMemberID)
2760+
}
2761+
if dbx.Config.Verbose {
2762+
log.Printf("req: %v", req)
2763+
}
2764+
resp, err := cli.Do(req)
2765+
if dbx.Config.Verbose {
2766+
log.Printf("resp: %v", resp)
2767+
}
2768+
if err != nil {
2769+
return
2770+
}
2771+
2772+
defer resp.Body.Close()
2773+
body, err := ioutil.ReadAll(resp.Body)
2774+
if err != nil {
2775+
return
2776+
}
2777+
2778+
if dbx.Config.Verbose {
2779+
log.Printf("body: %s", body)
2780+
}
2781+
if resp.StatusCode != 200 {
2782+
if resp.StatusCode == 409 {
2783+
var apiError UploadSessionFinishBatchAPIError
2784+
err = json.Unmarshal(body, &apiError)
2785+
if err != nil {
2786+
return
2787+
}
2788+
err = apiError
2789+
return
2790+
}
2791+
var apiError dropbox.APIError
2792+
if resp.StatusCode == 400 {
2793+
apiError.ErrorSummary = string(body)
2794+
err = apiError
2795+
return
2796+
}
2797+
err = json.Unmarshal(body, &apiError)
2798+
if err != nil {
2799+
return
2800+
}
2801+
err = apiError
2802+
return
2803+
}
2804+
err = json.Unmarshal(body, &res)
2805+
if err != nil {
2806+
return
2807+
}
2808+
2809+
return
2810+
}
2811+
2812+
//UploadSessionFinishBatchCheckAPIError is an error-wrapper for the upload_session/finish_batch/check route
2813+
type UploadSessionFinishBatchCheckAPIError struct {
2814+
dropbox.APIError
2815+
EndpointError *async.PollError `json:"error"`
2816+
}
2817+
2818+
func (dbx *apiImpl) UploadSessionFinishBatchCheck(arg *async.PollArg) (res *UploadSessionFinishBatchJobStatus, err error) {
2819+
cli := dbx.Client
2820+
2821+
if dbx.Config.Verbose {
2822+
log.Printf("arg: %v", arg)
2823+
}
2824+
b, err := json.Marshal(arg)
2825+
if err != nil {
2826+
return
2827+
}
2828+
2829+
req, err := http.NewRequest("POST", (*dropbox.Context)(dbx).GenerateURL("api", "files", "upload_session/finish_batch/check"), bytes.NewReader(b))
2830+
if err != nil {
2831+
return
2832+
}
2833+
2834+
req.Header.Set("Content-Type", "application/json")
2835+
if dbx.Config.AsMemberID != "" {
2836+
req.Header.Set("Dropbox-API-Select-User", dbx.Config.AsMemberID)
2837+
}
2838+
if dbx.Config.Verbose {
2839+
log.Printf("req: %v", req)
2840+
}
2841+
resp, err := cli.Do(req)
2842+
if dbx.Config.Verbose {
2843+
log.Printf("resp: %v", resp)
2844+
}
2845+
if err != nil {
2846+
return
2847+
}
2848+
2849+
defer resp.Body.Close()
2850+
body, err := ioutil.ReadAll(resp.Body)
2851+
if err != nil {
2852+
return
2853+
}
2854+
2855+
if dbx.Config.Verbose {
2856+
log.Printf("body: %s", body)
2857+
}
2858+
if resp.StatusCode != 200 {
2859+
if resp.StatusCode == 409 {
2860+
var apiError UploadSessionFinishBatchCheckAPIError
2861+
err = json.Unmarshal(body, &apiError)
2862+
if err != nil {
2863+
return
2864+
}
2865+
err = apiError
2866+
return
2867+
}
2868+
var apiError dropbox.APIError
2869+
if resp.StatusCode == 400 {
2870+
apiError.ErrorSummary = string(body)
2871+
err = apiError
2872+
return
2873+
}
2874+
err = json.Unmarshal(body, &apiError)
2875+
if err != nil {
2876+
return
2877+
}
2878+
err = apiError
2879+
return
2880+
}
2881+
err = json.Unmarshal(body, &res)
2882+
if err != nil {
2883+
return
2884+
}
2885+
2886+
return
2887+
}
2888+
27172889
//UploadSessionStartAPIError is an error-wrapper for the upload_session/start route
27182890
type UploadSessionStartAPIError struct {
27192891
dropbox.APIError

dropbox/files/types.go

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2079,6 +2079,110 @@ func NewUploadSessionFinishArg(Cursor *UploadSessionCursor, Commit *CommitInfo)
20792079
return s
20802080
}
20812081

2082+
// UploadSessionFinishBatchArg : has no documentation (yet)
2083+
type UploadSessionFinishBatchArg struct {
2084+
// Entries : Commit information for each file in the batch.
2085+
Entries []*UploadSessionFinishArg `json:"entries"`
2086+
}
2087+
2088+
// NewUploadSessionFinishBatchArg returns a new UploadSessionFinishBatchArg instance
2089+
func NewUploadSessionFinishBatchArg(Entries []*UploadSessionFinishArg) *UploadSessionFinishBatchArg {
2090+
s := new(UploadSessionFinishBatchArg)
2091+
s.Entries = Entries
2092+
return s
2093+
}
2094+
2095+
// UploadSessionFinishBatchJobStatus : has no documentation (yet)
2096+
type UploadSessionFinishBatchJobStatus struct {
2097+
dropbox.Tagged
2098+
// Complete : The `uploadSessionFinishBatch` has finished.
2099+
Complete *UploadSessionFinishBatchResult `json:"complete,omitempty"`
2100+
}
2101+
2102+
// Valid tag values for UploadSessionFinishBatchJobStatus
2103+
const (
2104+
UploadSessionFinishBatchJobStatusComplete = "complete"
2105+
)
2106+
2107+
// UnmarshalJSON deserializes into a UploadSessionFinishBatchJobStatus instance
2108+
func (u *UploadSessionFinishBatchJobStatus) UnmarshalJSON(body []byte) error {
2109+
type wrap struct {
2110+
dropbox.Tagged
2111+
// Complete : The `uploadSessionFinishBatch` has finished.
2112+
Complete json.RawMessage `json:"complete,omitempty"`
2113+
}
2114+
var w wrap
2115+
if err := json.Unmarshal(body, &w); err != nil {
2116+
return err
2117+
}
2118+
u.Tag = w.Tag
2119+
switch u.Tag {
2120+
case "complete":
2121+
if err := json.Unmarshal(body, &u.Complete); err != nil {
2122+
return err
2123+
}
2124+
2125+
}
2126+
return nil
2127+
}
2128+
2129+
// UploadSessionFinishBatchResult : has no documentation (yet)
2130+
type UploadSessionFinishBatchResult struct {
2131+
// Entries : Commit result for each file in the batch.
2132+
Entries []*UploadSessionFinishBatchResultEntry `json:"entries"`
2133+
}
2134+
2135+
// NewUploadSessionFinishBatchResult returns a new UploadSessionFinishBatchResult instance
2136+
func NewUploadSessionFinishBatchResult(Entries []*UploadSessionFinishBatchResultEntry) *UploadSessionFinishBatchResult {
2137+
s := new(UploadSessionFinishBatchResult)
2138+
s.Entries = Entries
2139+
return s
2140+
}
2141+
2142+
// UploadSessionFinishBatchResultEntry : has no documentation (yet)
2143+
type UploadSessionFinishBatchResultEntry struct {
2144+
dropbox.Tagged
2145+
// Success : has no documentation (yet)
2146+
Success *FileMetadata `json:"success,omitempty"`
2147+
// Failure : has no documentation (yet)
2148+
Failure *UploadSessionFinishError `json:"failure,omitempty"`
2149+
}
2150+
2151+
// Valid tag values for UploadSessionFinishBatchResultEntry
2152+
const (
2153+
UploadSessionFinishBatchResultEntrySuccess = "success"
2154+
UploadSessionFinishBatchResultEntryFailure = "failure"
2155+
)
2156+
2157+
// UnmarshalJSON deserializes into a UploadSessionFinishBatchResultEntry instance
2158+
func (u *UploadSessionFinishBatchResultEntry) UnmarshalJSON(body []byte) error {
2159+
type wrap struct {
2160+
dropbox.Tagged
2161+
// Success : has no documentation (yet)
2162+
Success json.RawMessage `json:"success,omitempty"`
2163+
// Failure : has no documentation (yet)
2164+
Failure json.RawMessage `json:"failure,omitempty"`
2165+
}
2166+
var w wrap
2167+
if err := json.Unmarshal(body, &w); err != nil {
2168+
return err
2169+
}
2170+
u.Tag = w.Tag
2171+
switch u.Tag {
2172+
case "success":
2173+
if err := json.Unmarshal(body, &u.Success); err != nil {
2174+
return err
2175+
}
2176+
2177+
case "failure":
2178+
if err := json.Unmarshal(w.Failure, &u.Failure); err != nil {
2179+
return err
2180+
}
2181+
2182+
}
2183+
return nil
2184+
}
2185+
20822186
// UploadSessionFinishError : has no documentation (yet)
20832187
type UploadSessionFinishError struct {
20842188
dropbox.Tagged

0 commit comments

Comments
 (0)