Skip to content

Commit 7572dc8

Browse files
author
Diwaker Gupta
committed
Update spec and regenerate SDK.
1 parent fe9db01 commit 7572dc8

File tree

10 files changed

+1435
-25
lines changed

10 files changed

+1435
-25
lines changed

dropbox/auth/client.go

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
package auth
2222

2323
import (
24+
"bytes"
2425
"encoding/json"
2526
"io/ioutil"
2627
"log"
@@ -31,12 +32,92 @@ import (
3132

3233
// Client interface describes all routes in this namespace
3334
type Client interface {
35+
// TokenFromOauth1 : Creates an OAuth 2.0 access token from the supplied
36+
// OAuth 1.0 access token.
37+
TokenFromOauth1(arg *TokenFromOAuth1Arg) (res *TokenFromOAuth1Result, err error)
3438
// TokenRevoke : Disables the access token used to authenticate the call.
3539
TokenRevoke() (err error)
3640
}
3741

3842
type apiImpl dropbox.Context
3943

44+
//TokenFromOauth1APIError is an error-wrapper for the token/from_oauth1 route
45+
type TokenFromOauth1APIError struct {
46+
dropbox.APIError
47+
EndpointError *TokenFromOAuth1Error `json:"error"`
48+
}
49+
50+
func (dbx *apiImpl) TokenFromOauth1(arg *TokenFromOAuth1Arg) (res *TokenFromOAuth1Result, err error) {
51+
cli := dbx.Client
52+
53+
if dbx.Config.Verbose {
54+
log.Printf("arg: %v", arg)
55+
}
56+
b, err := json.Marshal(arg)
57+
if err != nil {
58+
return
59+
}
60+
61+
req, err := http.NewRequest("POST", (*dropbox.Context)(dbx).GenerateURL("api", "auth", "token/from_oauth1"), bytes.NewReader(b))
62+
if err != nil {
63+
return
64+
}
65+
66+
req.Header.Set("Content-Type", "application/json")
67+
if dbx.Config.AsMemberID != "" {
68+
req.Header.Set("Dropbox-API-Select-User", dbx.Config.AsMemberID)
69+
}
70+
if dbx.Config.Verbose {
71+
log.Printf("req: %v", req)
72+
}
73+
resp, err := cli.Do(req)
74+
if dbx.Config.Verbose {
75+
log.Printf("resp: %v", resp)
76+
}
77+
if err != nil {
78+
return
79+
}
80+
81+
defer resp.Body.Close()
82+
body, err := ioutil.ReadAll(resp.Body)
83+
if err != nil {
84+
return
85+
}
86+
87+
if dbx.Config.Verbose {
88+
log.Printf("body: %s", body)
89+
}
90+
if resp.StatusCode == http.StatusOK {
91+
err = json.Unmarshal(body, &res)
92+
if err != nil {
93+
return
94+
}
95+
96+
return
97+
}
98+
if resp.StatusCode == http.StatusConflict {
99+
var apiError TokenFromOauth1APIError
100+
err = json.Unmarshal(body, &apiError)
101+
if err != nil {
102+
return
103+
}
104+
err = apiError
105+
return
106+
}
107+
var apiError dropbox.APIError
108+
if resp.StatusCode == http.StatusBadRequest {
109+
apiError.ErrorSummary = string(body)
110+
err = apiError
111+
return
112+
}
113+
err = json.Unmarshal(body, &apiError)
114+
if err != nil {
115+
return
116+
}
117+
err = apiError
118+
return
119+
}
120+
40121
//TokenRevokeAPIError is an error-wrapper for the token/revoke route
41122
type TokenRevokeAPIError struct {
42123
dropbox.APIError

dropbox/auth/types.go

Lines changed: 118 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,57 @@
2121
// Package auth : has no documentation (yet)
2222
package auth
2323

24-
import "github.com/dropbox/dropbox-sdk-go-unofficial/dropbox"
24+
import (
25+
"encoding/json"
26+
27+
"github.com/dropbox/dropbox-sdk-go-unofficial/dropbox"
28+
)
29+
30+
// AccessError : Error occurred because the account doesn't have permission to
31+
// access the resource.
32+
type AccessError struct {
33+
dropbox.Tagged
34+
// InvalidAccountType : Current account type cannot access the resource.
35+
InvalidAccountType *InvalidAccountTypeError `json:"invalid_account_type,omitempty"`
36+
// PaperAccessDenied : Current account cannot access Paper.
37+
PaperAccessDenied *PaperAccessError `json:"paper_access_denied,omitempty"`
38+
}
39+
40+
// Valid tag values for AccessError
41+
const (
42+
AccessErrorInvalidAccountType = "invalid_account_type"
43+
AccessErrorPaperAccessDenied = "paper_access_denied"
44+
AccessErrorOther = "other"
45+
)
46+
47+
// UnmarshalJSON deserializes into a AccessError instance
48+
func (u *AccessError) UnmarshalJSON(body []byte) error {
49+
type wrap struct {
50+
dropbox.Tagged
51+
// InvalidAccountType : Current account type cannot access the resource.
52+
InvalidAccountType json.RawMessage `json:"invalid_account_type,omitempty"`
53+
// PaperAccessDenied : Current account cannot access Paper.
54+
PaperAccessDenied json.RawMessage `json:"paper_access_denied,omitempty"`
55+
}
56+
var w wrap
57+
if err := json.Unmarshal(body, &w); err != nil {
58+
return err
59+
}
60+
u.Tag = w.Tag
61+
switch u.Tag {
62+
case "invalid_account_type":
63+
if err := json.Unmarshal(w.InvalidAccountType, &u.InvalidAccountType); err != nil {
64+
return err
65+
}
66+
67+
case "paper_access_denied":
68+
if err := json.Unmarshal(w.PaperAccessDenied, &u.PaperAccessDenied); err != nil {
69+
return err
70+
}
71+
72+
}
73+
return nil
74+
}
2575

2676
// AuthError : Errors occurred during authentication.
2777
type AuthError struct {
@@ -37,6 +87,30 @@ const (
3787
AuthErrorOther = "other"
3888
)
3989

90+
// InvalidAccountTypeError : has no documentation (yet)
91+
type InvalidAccountTypeError struct {
92+
dropbox.Tagged
93+
}
94+
95+
// Valid tag values for InvalidAccountTypeError
96+
const (
97+
InvalidAccountTypeErrorEndpoint = "endpoint"
98+
InvalidAccountTypeErrorFeature = "feature"
99+
InvalidAccountTypeErrorOther = "other"
100+
)
101+
102+
// PaperAccessError : has no documentation (yet)
103+
type PaperAccessError struct {
104+
dropbox.Tagged
105+
}
106+
107+
// Valid tag values for PaperAccessError
108+
const (
109+
PaperAccessErrorPaperDisabled = "paper_disabled"
110+
PaperAccessErrorNotPaperUser = "not_paper_user"
111+
PaperAccessErrorOther = "other"
112+
)
113+
40114
// RateLimitError : Error occurred because the app is being rate limited.
41115
type RateLimitError struct {
42116
// Reason : The reason why the app is being rate limited.
@@ -65,3 +139,46 @@ const (
65139
RateLimitReasonTooManyWriteOperations = "too_many_write_operations"
66140
RateLimitReasonOther = "other"
67141
)
142+
143+
// TokenFromOAuth1Arg : has no documentation (yet)
144+
type TokenFromOAuth1Arg struct {
145+
// Oauth1Token : The supplied OAuth 1.0 access token.
146+
Oauth1Token string `json:"oauth1_token"`
147+
// Oauth1TokenSecret : The token secret associated with the supplied access
148+
// token.
149+
Oauth1TokenSecret string `json:"oauth1_token_secret"`
150+
}
151+
152+
// NewTokenFromOAuth1Arg returns a new TokenFromOAuth1Arg instance
153+
func NewTokenFromOAuth1Arg(Oauth1Token string, Oauth1TokenSecret string) *TokenFromOAuth1Arg {
154+
s := new(TokenFromOAuth1Arg)
155+
s.Oauth1Token = Oauth1Token
156+
s.Oauth1TokenSecret = Oauth1TokenSecret
157+
return s
158+
}
159+
160+
// TokenFromOAuth1Error : has no documentation (yet)
161+
type TokenFromOAuth1Error struct {
162+
dropbox.Tagged
163+
}
164+
165+
// Valid tag values for TokenFromOAuth1Error
166+
const (
167+
TokenFromOAuth1ErrorInvalidOauth1TokenInfo = "invalid_oauth1_token_info"
168+
TokenFromOAuth1ErrorAppIdMismatch = "app_id_mismatch"
169+
TokenFromOAuth1ErrorOther = "other"
170+
)
171+
172+
// TokenFromOAuth1Result : has no documentation (yet)
173+
type TokenFromOAuth1Result struct {
174+
// Oauth2Token : The OAuth 2.0 token generated from the supplied OAuth 1.0
175+
// token.
176+
Oauth2Token string `json:"oauth2_token"`
177+
}
178+
179+
// NewTokenFromOAuth1Result returns a new TokenFromOAuth1Result instance
180+
func NewTokenFromOAuth1Result(Oauth2Token string) *TokenFromOAuth1Result {
181+
s := new(TokenFromOAuth1Result)
182+
s.Oauth2Token = Oauth2Token
183+
return s
184+
}

dropbox/files/client.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ type Client interface {
5656
// shared folders to new locations. This route will return job ID
5757
// immediately and do the async copy job in background. Please use
5858
// `copyBatchCheck` to check the job status.
59-
CopyBatch(arg *RelocationBatchArg) (res *async.LaunchEmptyResult, err error)
59+
CopyBatch(arg *RelocationBatchArg) (res *RelocationBatchLaunch, err error)
6060
// CopyBatchCheck : Returns the status of an asynchronous job for
6161
// `copyBatch`. If success, it returns list of results for each entry.
6262
CopyBatchCheck(arg *async.PollArg) (res *RelocationBatchJobStatus, err error)
@@ -78,7 +78,7 @@ type Client interface {
7878
// DeleteBatch : Delete multiple files/folders at once. This route is
7979
// asynchronous, which returns a job ID immediately and runs the delete
8080
// batch asynchronously. Use `deleteBatchCheck` to check the job status.
81-
DeleteBatch(arg *DeleteBatchArg) (res *async.LaunchEmptyResult, err error)
81+
DeleteBatch(arg *DeleteBatchArg) (res *DeleteBatchLaunch, err error)
8282
// DeleteBatchCheck : Returns the status of an asynchronous job for
8383
// `deleteBatch`. If success, it returns list of result for each entry.
8484
DeleteBatchCheck(arg *async.PollArg) (res *DeleteBatchJobStatus, err error)
@@ -147,7 +147,7 @@ type Client interface {
147147
// entry fails, the whole transaction will abort. This route will return job
148148
// ID immediately and do the async moving job in background. Please use
149149
// `moveBatchCheck` to check the job status.
150-
MoveBatch(arg *RelocationBatchArg) (res *async.LaunchEmptyResult, err error)
150+
MoveBatch(arg *RelocationBatchArg) (res *RelocationBatchLaunch, err error)
151151
// MoveBatchCheck : Returns the status of an asynchronous job for
152152
// `moveBatch`. If success, it returns list of results for each entry.
153153
MoveBatchCheck(arg *async.PollArg) (res *RelocationBatchJobStatus, err error)
@@ -216,7 +216,7 @@ type Client interface {
216216
// status. For the same account, this route should be executed serially.
217217
// That means you should not start the next job before current job finishes.
218218
// We allow up to 1000 entries in a single request.
219-
UploadSessionFinishBatch(arg *UploadSessionFinishBatchArg) (res *async.LaunchEmptyResult, err error)
219+
UploadSessionFinishBatch(arg *UploadSessionFinishBatchArg) (res *UploadSessionFinishBatchLaunch, err error)
220220
// UploadSessionFinishBatchCheck : Returns the status of an asynchronous job
221221
// for `uploadSessionFinishBatch`. If success, it returns list of result for
222222
// each entry.
@@ -492,7 +492,7 @@ type CopyBatchAPIError struct {
492492
EndpointError struct{} `json:"error"`
493493
}
494494

495-
func (dbx *apiImpl) CopyBatch(arg *RelocationBatchArg) (res *async.LaunchEmptyResult, err error) {
495+
func (dbx *apiImpl) CopyBatch(arg *RelocationBatchArg) (res *RelocationBatchLaunch, err error) {
496496
cli := dbx.Client
497497

498498
if dbx.Config.Verbose {
@@ -965,7 +965,7 @@ type DeleteBatchAPIError struct {
965965
EndpointError struct{} `json:"error"`
966966
}
967967

968-
func (dbx *apiImpl) DeleteBatch(arg *DeleteBatchArg) (res *async.LaunchEmptyResult, err error) {
968+
func (dbx *apiImpl) DeleteBatch(arg *DeleteBatchArg) (res *DeleteBatchLaunch, err error) {
969969
cli := dbx.Client
970970

971971
if dbx.Config.Verbose {
@@ -1974,7 +1974,7 @@ type MoveBatchAPIError struct {
19741974
EndpointError struct{} `json:"error"`
19751975
}
19761976

1977-
func (dbx *apiImpl) MoveBatch(arg *RelocationBatchArg) (res *async.LaunchEmptyResult, err error) {
1977+
func (dbx *apiImpl) MoveBatch(arg *RelocationBatchArg) (res *RelocationBatchLaunch, err error) {
19781978
cli := dbx.Client
19791979

19801980
if dbx.Config.Verbose {
@@ -3243,7 +3243,7 @@ type UploadSessionFinishBatchAPIError struct {
32433243
EndpointError struct{} `json:"error"`
32443244
}
32453245

3246-
func (dbx *apiImpl) UploadSessionFinishBatch(arg *UploadSessionFinishBatchArg) (res *async.LaunchEmptyResult, err error) {
3246+
func (dbx *apiImpl) UploadSessionFinishBatch(arg *UploadSessionFinishBatchArg) (res *UploadSessionFinishBatchLaunch, err error) {
32473247
cli := dbx.Client
32483248

32493249
if dbx.Config.Verbose {

0 commit comments

Comments
 (0)