Archived
1
0

Merge pull request #17 from meshelton/context

Adds a method to supply a context to the db.client
This commit is contained in:
Arnaud Ysmal 2015-04-15 19:46:30 +02:00
commit ba894b878f

View File

@ -39,6 +39,7 @@ import (
"strings" "strings"
"time" "time"
"golang.org/x/net/context"
"golang.org/x/oauth2" "golang.org/x/oauth2"
) )
@ -189,6 +190,7 @@ type Dropbox struct {
APINotifyURL string // URL for realtime notification. APINotifyURL string // URL for realtime notification.
config *oauth2.Config config *oauth2.Config
token *oauth2.Token token *oauth2.Token
ctx context.Context
} }
// NewDropbox returns a new Dropbox configured. // NewDropbox returns a new Dropbox configured.
@ -199,6 +201,7 @@ func NewDropbox() *Dropbox {
APIURL: "https://api.dropbox.com/1", APIURL: "https://api.dropbox.com/1",
APIContentURL: "https://api-content.dropbox.com/1", APIContentURL: "https://api-content.dropbox.com/1",
APINotifyURL: "https://api-notify.dropbox.com/1", APINotifyURL: "https://api-notify.dropbox.com/1",
ctx: oauth2.NoContext,
} }
return db return db
} }
@ -223,13 +226,17 @@ func (db *Dropbox) SetAccessToken(accesstoken string) {
db.token = &oauth2.Token{AccessToken: accesstoken} db.token = &oauth2.Token{AccessToken: accesstoken}
} }
func (db *Dropbox) SetContext(ctx context.Context) {
db.ctx = ctx
}
// AccessToken returns the OAuth access token. // AccessToken returns the OAuth access token.
func (db *Dropbox) AccessToken() string { func (db *Dropbox) AccessToken() string {
return db.token.AccessToken return db.token.AccessToken
} }
func (db *Dropbox) client() *http.Client { func (db *Dropbox) client() *http.Client {
return db.config.Client(oauth2.NoContext, db.token) return db.config.Client(db.ctx, db.token)
} }
// Auth displays the URL to authorize this application to connect to your account. // Auth displays the URL to authorize this application to connect to your account.