Skip to content

Commit 03c2c25

Browse files
committed
misc: refactoring way to pass config to the dropbox client
1 parent ce242a5 commit 03c2c25

1 file changed

Lines changed: 12 additions & 11 deletions

File tree

dropbox.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/dropbox/dropbox-sdk-go-unofficial/dropbox"
1010
"github.com/dropbox/dropbox-sdk-go-unofficial/dropbox/files"
11+
"golang.org/x/oauth2"
1112
)
1213

1314
type DropboxWatcher struct {
@@ -30,9 +31,11 @@ type DropboxObject struct {
3031

3132
type DropboxConfiguration struct {
3233
Debug Bool `json:"debug"`
33-
Token string `json:"token"`
34+
JToken string `json:"token"`
3435
ClientId string `json:"client_id"`
3536
ClientSecret string `json:"client_secret"`
37+
38+
token *oauth2.Token
3639
}
3740

3841
func newDropboxWatcher(dir string, interval time.Duration) (Watcher, error) {
@@ -62,12 +65,16 @@ func (w *DropboxWatcher) SetConfig(m map[string]string) error {
6265
return err
6366
}
6467

65-
if config.Token == "" {
68+
if config.JToken == "" {
6669
return fmt.Errorf("token not specified")
6770
}
6871
w.config = &config
6972

70-
fmt.Printf("%v", config)
73+
tok := &oauth2.Token{}
74+
if err := json.Unmarshal([]byte(config.JToken), tok); err != nil {
75+
return err
76+
}
77+
w.config.token = tok
7178
return nil
7279
}
7380

@@ -161,14 +168,8 @@ func (w *DropboxWatcher) enumerateFiles(prefix string, callback func(object *Dro
161168
}
162169

163170
config := dropbox.Config{
164-
Token: w.config.Token,
165-
LogLevel: logLevel,
166-
Logger: nil,
167-
AsMemberID: "",
168-
Domain: "",
169-
Client: nil,
170-
HeaderGenerator: nil,
171-
URLGenerator: nil,
171+
Token: w.config.token.AccessToken,
172+
LogLevel: logLevel,
172173
}
173174
dbx := files.New(config)
174175
arg := files.NewListFolderArg(prefix)

0 commit comments

Comments
 (0)