Use github.com/golang/oauth2
This commit is contained in:
parent
2d1aafcc97
commit
eb9bd0a1ae
|
@ -11,9 +11,9 @@ To register a new client application, please visit https://www.dropbox.com/devel
|
||||||
|
|
||||||
Installation
|
Installation
|
||||||
------------
|
------------
|
||||||
This library depends on a fork of the goauth2 library, it can be installed with the go get command:
|
This library depends on the oauth2 package, it can be installed with the go get command:
|
||||||
|
|
||||||
$ go get code.google.com/p/stacktic-goauth2
|
$ go get github.com/golang/oauth2
|
||||||
|
|
||||||
This package can be installed with the go get command:
|
This package can be installed with the go get command:
|
||||||
|
|
||||||
|
|
74
dropbox.go
74
dropbox.go
|
@ -39,7 +39,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"code.google.com/p/stacktic-goauth2/oauth"
|
"github.com/golang/oauth2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ErrNotAuth is the error returned when the OAuth token is not provided
|
// ErrNotAuth is the error returned when the OAuth token is not provided
|
||||||
|
@ -178,57 +178,75 @@ type Link struct {
|
||||||
|
|
||||||
// Dropbox client.
|
// Dropbox client.
|
||||||
type Dropbox struct {
|
type Dropbox struct {
|
||||||
RootDirectory string // dropbox or sandbox.
|
RootDirectory string // dropbox or sandbox.
|
||||||
Locale string // Locale sent to the API to translate/format messages.
|
Locale string // Locale sent to the API to translate/format messages.
|
||||||
APIURL string // Normal API URL.
|
APIURL string // Normal API URL.
|
||||||
APIContentURL string // URL for transferring files.
|
APIContentURL string // URL for transferring files.
|
||||||
APINotifyURL string // URL for realtime notification.
|
APINotifyURL string // URL for realtime notification.
|
||||||
Session oauth.Transport // OAuth 2.0 session.
|
config *oauth2.Config
|
||||||
|
token *oauth2.Token
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewDropbox returns a new Dropbox configured.
|
// NewDropbox returns a new Dropbox configured.
|
||||||
func NewDropbox() *Dropbox {
|
func NewDropbox() *Dropbox {
|
||||||
return &Dropbox{
|
db := &Dropbox{
|
||||||
RootDirectory: "dropbox", // dropbox or sandbox.
|
RootDirectory: "dropbox", // dropbox or sandbox.
|
||||||
Locale: "en",
|
Locale: "en",
|
||||||
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",
|
||||||
Session: oauth.Transport{
|
|
||||||
Config: &oauth.Config{
|
|
||||||
AuthURL: "https://www.dropbox.com/1/oauth2/authorize",
|
|
||||||
TokenURL: "https://api.dropbox.com/1/oauth2/token",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
return db
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetAppInfo sets the clientid (app_key) and clientsecret (app_secret).
|
// SetAppInfo sets the clientid (app_key) and clientsecret (app_secret).
|
||||||
// You have to register an application on https://www.dropbox.com/developers/apps.
|
// You have to register an application on https://www.dropbox.com/developers/apps.
|
||||||
func (db *Dropbox) SetAppInfo(clientid, clientsecret string) {
|
func (db *Dropbox) SetAppInfo(clientid, clientsecret string) error {
|
||||||
db.Session.Config.ClientId = clientid
|
var err error
|
||||||
db.Session.Config.ClientSecret = clientsecret
|
|
||||||
|
db.config, err = oauth2.NewConfig(
|
||||||
|
&oauth2.Options{
|
||||||
|
ClientID: clientid,
|
||||||
|
ClientSecret: clientsecret,
|
||||||
|
},
|
||||||
|
"https://www.dropbox.com/1/oauth2/authorize",
|
||||||
|
"https://api.dropbox.com/1/oauth2/token")
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetAccessToken sets access token to avoid calling Auth method.
|
// SetAccessToken sets access token to avoid calling Auth method.
|
||||||
func (db *Dropbox) SetAccessToken(accesstoken string) {
|
func (db *Dropbox) SetAccessToken(accesstoken string) {
|
||||||
db.Session.Token = &oauth.Token{AccessToken: accesstoken}
|
db.token = &oauth2.Token{AccessToken: accesstoken}
|
||||||
}
|
}
|
||||||
|
|
||||||
// AccessToken returns the OAuth access token.
|
// AccessToken returns the OAuth access token.
|
||||||
func (db *Dropbox) AccessToken() string {
|
func (db *Dropbox) AccessToken() string {
|
||||||
return db.Session.Token.AccessToken
|
return db.token.AccessToken
|
||||||
|
}
|
||||||
|
|
||||||
|
func (db *Dropbox) client() *http.Client {
|
||||||
|
var t oauth2.Transport
|
||||||
|
|
||||||
|
t = db.config.NewTransport()
|
||||||
|
t.SetToken(db.token)
|
||||||
|
return &http.Client{Transport: t}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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.
|
||||||
func (db *Dropbox) Auth() error {
|
func (db *Dropbox) Auth() error {
|
||||||
var code string
|
var code string
|
||||||
|
var t oauth2.Transport
|
||||||
|
var err error
|
||||||
|
|
||||||
fmt.Printf("Please visit:\n%s\nEnter the code: ",
|
fmt.Printf("Please visit:\n%s\nEnter the code: ",
|
||||||
db.Session.Config.AuthCodeURL(""))
|
db.config.AuthCodeURL(""))
|
||||||
fmt.Scanln(&code)
|
fmt.Scanln(&code)
|
||||||
_, err := db.Session.Exchange(code)
|
if t, err = db.config.NewTransportWithCode(code); err != nil {
|
||||||
return err
|
return err
|
||||||
|
}
|
||||||
|
db.token = t.Token()
|
||||||
|
db.token.TokenType = "Bearer"
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Error - all errors generated by HTTP transactions are of this type.
|
// Error - all errors generated by HTTP transactions are of this type.
|
||||||
|
@ -314,7 +332,7 @@ func (db *Dropbox) CommitChunkedUpload(uploadid, dst string, overwrite bool, par
|
||||||
}
|
}
|
||||||
rawurl = fmt.Sprintf("%s/commit_chunked_upload/%s/%s?%s", db.APIContentURL, db.RootDirectory, urlEncode(dst), params.Encode())
|
rawurl = fmt.Sprintf("%s/commit_chunked_upload/%s/%s?%s", db.APIContentURL, db.RootDirectory, urlEncode(dst), params.Encode())
|
||||||
|
|
||||||
if response, err = db.Session.Client().Post(rawurl, "", nil); err != nil {
|
if response, err = db.client().Post(rawurl, "", nil); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer response.Body.Close()
|
defer response.Body.Close()
|
||||||
|
@ -347,7 +365,7 @@ func (db *Dropbox) ChunkedUpload(session *ChunkUploadResponse, input io.ReadClos
|
||||||
}
|
}
|
||||||
r = &io.LimitedReader{R: input, N: int64(chunksize)}
|
r = &io.LimitedReader{R: input, N: int64(chunksize)}
|
||||||
|
|
||||||
if response, err = db.Session.Client().Post(rawurl, "application/octet-stream", r); err != nil {
|
if response, err = db.client().Post(rawurl, "application/octet-stream", r); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer response.Body.Close()
|
defer response.Body.Close()
|
||||||
|
@ -401,7 +419,7 @@ func (db *Dropbox) FilesPut(input io.ReadCloser, size int64, dst string, overwri
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
request.Header.Set("Content-Length", strconv.FormatInt(size, 10))
|
request.Header.Set("Content-Length", strconv.FormatInt(size, 10))
|
||||||
if response, err = db.Session.Client().Do(request); err != nil {
|
if response, err = db.client().Do(request); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer response.Body.Close()
|
defer response.Body.Close()
|
||||||
|
@ -459,7 +477,7 @@ func (db *Dropbox) Thumbnails(src, format, size string) (io.ReadCloser, int64, *
|
||||||
src = src[1:]
|
src = src[1:]
|
||||||
}
|
}
|
||||||
rawurl = fmt.Sprintf("%s/thumbnails/%s/%s?format=%s&size=%s", db.APIContentURL, db.RootDirectory, urlEncode(src), urlEncode(format), urlEncode(size))
|
rawurl = fmt.Sprintf("%s/thumbnails/%s/%s?format=%s&size=%s", db.APIContentURL, db.RootDirectory, urlEncode(src), urlEncode(format), urlEncode(size))
|
||||||
if response, err = db.Session.Client().Get(rawurl); err != nil {
|
if response, err = db.client().Get(rawurl); err != nil {
|
||||||
return nil, 0, nil, err
|
return nil, 0, nil, err
|
||||||
}
|
}
|
||||||
if response.StatusCode == http.StatusOK {
|
if response.StatusCode == http.StatusOK {
|
||||||
|
@ -524,7 +542,7 @@ func (db *Dropbox) Download(src, rev string, offset int) (io.ReadCloser, int64,
|
||||||
request.Header.Set("Range", fmt.Sprintf("bytes=%d-", offset))
|
request.Header.Set("Range", fmt.Sprintf("bytes=%d-", offset))
|
||||||
}
|
}
|
||||||
|
|
||||||
if response, err = db.Session.Client().Do(request); err != nil {
|
if response, err = db.client().Do(request); err != nil {
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
if response.StatusCode == http.StatusOK {
|
if response.StatusCode == http.StatusOK {
|
||||||
|
@ -603,7 +621,7 @@ func (db *Dropbox) doRequest(method, path string, params *url.Values, receiver i
|
||||||
if request, err = http.NewRequest(method, rawurl, nil); err != nil {
|
if request, err = http.NewRequest(method, rawurl, nil); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if response, err = db.Session.Client().Do(request); err != nil {
|
if response, err = db.client().Do(request); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer response.Body.Close()
|
defer response.Body.Close()
|
||||||
|
|
|
@ -132,7 +132,7 @@ func TestAccountInfo(t *testing.T) {
|
||||||
t.Fatalf("could not run test marshalling issue")
|
t.Fatalf("could not run test marshalling issue")
|
||||||
}
|
}
|
||||||
|
|
||||||
db.Session.Transport = FakeHTTP{t: t, Method: "GET", Host: "api.dropbox.com", Path: "/1/account/info",
|
http.DefaultTransport = FakeHTTP{t: t, Method: "GET", Host: "api.dropbox.com", Path: "/1/account/info",
|
||||||
Params: map[string]string{"locale": "en"},
|
Params: map[string]string{"locale": "en"},
|
||||||
ResponseData: js}
|
ResponseData: js}
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ func TestCopy(t *testing.T) {
|
||||||
ResponseData: js}
|
ResponseData: js}
|
||||||
|
|
||||||
db = newDropbox(t)
|
db = newDropbox(t)
|
||||||
db.Session.Transport = fake
|
http.DefaultTransport = fake
|
||||||
if received, err = db.Copy(from, to, false); err != nil {
|
if received, err = db.Copy(from, to, false); err != nil {
|
||||||
t.Errorf("API error: %s", err)
|
t.Errorf("API error: %s", err)
|
||||||
} else if !reflect.DeepEqual(expected, *received) {
|
} else if !reflect.DeepEqual(expected, *received) {
|
||||||
|
@ -174,7 +174,7 @@ func TestCopy(t *testing.T) {
|
||||||
|
|
||||||
delete(fake.Params, "from_path")
|
delete(fake.Params, "from_path")
|
||||||
fake.Params["from_copy_ref"] = from
|
fake.Params["from_copy_ref"] = from
|
||||||
db.Session.Transport = fake
|
http.DefaultTransport = fake
|
||||||
if received, err = db.Copy(from, to, true); err != nil {
|
if received, err = db.Copy(from, to, true); err != nil {
|
||||||
t.Errorf("API error: %s", err)
|
t.Errorf("API error: %s", err)
|
||||||
} else if !reflect.DeepEqual(expected, *received) {
|
} else if !reflect.DeepEqual(expected, *received) {
|
||||||
|
@ -197,7 +197,7 @@ func TestCopyRef(t *testing.T) {
|
||||||
t.Fatalf("could not run test due to marshalling issue")
|
t.Fatalf("could not run test due to marshalling issue")
|
||||||
}
|
}
|
||||||
|
|
||||||
db.Session.Transport = FakeHTTP{Method: "GET", Host: "api.dropbox.com", Path: "/1/copy_ref/dropbox/" + filename, t: t,
|
http.DefaultTransport = FakeHTTP{Method: "GET", Host: "api.dropbox.com", Path: "/1/copy_ref/dropbox/" + filename, t: t,
|
||||||
Params: map[string]string{"locale": "en"}, ResponseData: js}
|
Params: map[string]string{"locale": "en"}, ResponseData: js}
|
||||||
if received, err = db.CopyRef(filename); err != nil {
|
if received, err = db.CopyRef(filename); err != nil {
|
||||||
t.Errorf("API error: %s", err)
|
t.Errorf("API error: %s", err)
|
||||||
|
@ -221,7 +221,7 @@ func TestCreateFolder(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
db = newDropbox(t)
|
db = newDropbox(t)
|
||||||
db.Session.Transport = FakeHTTP{Method: "POST", Host: "api.dropbox.com", Path: "/1/fileops/create_folder",
|
http.DefaultTransport = FakeHTTP{Method: "POST", Host: "api.dropbox.com", Path: "/1/fileops/create_folder",
|
||||||
Params: map[string]string{"root": "dropbox", "path": foldername, "locale": "en"}, t: t, ResponseData: js}
|
Params: map[string]string{"root": "dropbox", "path": foldername, "locale": "en"}, t: t, ResponseData: js}
|
||||||
if received, err = db.CreateFolder(foldername); err != nil {
|
if received, err = db.CreateFolder(foldername); err != nil {
|
||||||
t.Errorf("API error: %s", err)
|
t.Errorf("API error: %s", err)
|
||||||
|
@ -246,7 +246,7 @@ func TestDelete(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
db = newDropbox(t)
|
db = newDropbox(t)
|
||||||
db.Session.Transport = FakeHTTP{t: t, Method: "POST", Host: "api.dropbox.com", Path: "/1/fileops/delete",
|
http.DefaultTransport = FakeHTTP{t: t, Method: "POST", Host: "api.dropbox.com", Path: "/1/fileops/delete",
|
||||||
Params: map[string]string{"root": "dropbox", "path": path, "locale": "en"},
|
Params: map[string]string{"root": "dropbox", "path": path, "locale": "en"},
|
||||||
ResponseData: js}
|
ResponseData: js}
|
||||||
if received, err = db.Delete(path); err != nil {
|
if received, err = db.Delete(path); err != nil {
|
||||||
|
@ -282,7 +282,7 @@ func TestFilesPut(t *testing.T) {
|
||||||
|
|
||||||
db = newDropbox(t)
|
db = newDropbox(t)
|
||||||
|
|
||||||
db.Session.Transport = fake
|
http.DefaultTransport = fake
|
||||||
received, err = db.FilesPut(ioutil.NopCloser(bytes.NewBuffer(content)), int64(len(content)), filename, false, "")
|
received, err = db.FilesPut(ioutil.NopCloser(bytes.NewBuffer(content)), int64(len(content)), filename, false, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("API error: %s", err)
|
t.Errorf("API error: %s", err)
|
||||||
|
@ -291,7 +291,7 @@ func TestFilesPut(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fake.Params["parent_rev"] = "12345"
|
fake.Params["parent_rev"] = "12345"
|
||||||
db.Session.Transport = fake
|
http.DefaultTransport = fake
|
||||||
received, err = db.FilesPut(ioutil.NopCloser(bytes.NewBuffer(content)), int64(len(content)), filename, false, "12345")
|
received, err = db.FilesPut(ioutil.NopCloser(bytes.NewBuffer(content)), int64(len(content)), filename, false, "12345")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("API error: %s", err)
|
t.Errorf("API error: %s", err)
|
||||||
|
@ -300,7 +300,7 @@ func TestFilesPut(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fake.Params["overwrite"] = "true"
|
fake.Params["overwrite"] = "true"
|
||||||
db.Session.Transport = fake
|
http.DefaultTransport = fake
|
||||||
received, err = db.FilesPut(ioutil.NopCloser(bytes.NewBuffer(content)), int64(len(content)), filename, true, "12345")
|
received, err = db.FilesPut(ioutil.NopCloser(bytes.NewBuffer(content)), int64(len(content)), filename, true, "12345")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("API error: %s", err)
|
t.Errorf("API error: %s", err)
|
||||||
|
@ -329,7 +329,7 @@ func TestMedia(t *testing.T) {
|
||||||
t.Fatalf("could not run test due to marshalling issue: %s", err)
|
t.Fatalf("could not run test due to marshalling issue: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
db.Session.Transport = FakeHTTP{Method: "POST", Host: "api.dropbox.com", Path: "/1/media/dropbox/" + filename,
|
http.DefaultTransport = FakeHTTP{Method: "POST", Host: "api.dropbox.com", Path: "/1/media/dropbox/" + filename,
|
||||||
Params: map[string]string{"locale": "en"}, t: t, ResponseData: js}
|
Params: map[string]string{"locale": "en"}, t: t, ResponseData: js}
|
||||||
if received, err = db.Media(filename); err != nil {
|
if received, err = db.Media(filename); err != nil {
|
||||||
t.Errorf("API error: %s", err)
|
t.Errorf("API error: %s", err)
|
||||||
|
@ -359,7 +359,7 @@ func TestMetadata(t *testing.T) {
|
||||||
|
|
||||||
db = newDropbox(t)
|
db = newDropbox(t)
|
||||||
|
|
||||||
db.Session.Transport = fake
|
http.DefaultTransport = fake
|
||||||
if received, err = db.Metadata(path, false, false, "", "", 10); err != nil {
|
if received, err = db.Metadata(path, false, false, "", "", 10); err != nil {
|
||||||
t.Errorf("API error: %s", err)
|
t.Errorf("API error: %s", err)
|
||||||
} else if !reflect.DeepEqual(expected, *received) {
|
} else if !reflect.DeepEqual(expected, *received) {
|
||||||
|
@ -367,7 +367,7 @@ func TestMetadata(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fake.Params["list"] = "true"
|
fake.Params["list"] = "true"
|
||||||
db.Session.Transport = fake
|
http.DefaultTransport = fake
|
||||||
if received, err = db.Metadata(path, true, false, "", "", 10); err != nil {
|
if received, err = db.Metadata(path, true, false, "", "", 10); err != nil {
|
||||||
t.Errorf("API error: %s", err)
|
t.Errorf("API error: %s", err)
|
||||||
} else if !reflect.DeepEqual(expected, *received) {
|
} else if !reflect.DeepEqual(expected, *received) {
|
||||||
|
@ -375,7 +375,7 @@ func TestMetadata(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fake.Params["include_deleted"] = "true"
|
fake.Params["include_deleted"] = "true"
|
||||||
db.Session.Transport = fake
|
http.DefaultTransport = fake
|
||||||
if received, err = db.Metadata(path, true, true, "", "", 10); err != nil {
|
if received, err = db.Metadata(path, true, true, "", "", 10); err != nil {
|
||||||
t.Errorf("API error: %s", err)
|
t.Errorf("API error: %s", err)
|
||||||
} else if !reflect.DeepEqual(expected, *received) {
|
} else if !reflect.DeepEqual(expected, *received) {
|
||||||
|
@ -383,7 +383,7 @@ func TestMetadata(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fake.Params["file_limit"] = "20"
|
fake.Params["file_limit"] = "20"
|
||||||
db.Session.Transport = fake
|
http.DefaultTransport = fake
|
||||||
if received, err = db.Metadata(path, true, true, "", "", 20); err != nil {
|
if received, err = db.Metadata(path, true, true, "", "", 20); err != nil {
|
||||||
t.Errorf("API error: %s", err)
|
t.Errorf("API error: %s", err)
|
||||||
} else if !reflect.DeepEqual(expected, *received) {
|
} else if !reflect.DeepEqual(expected, *received) {
|
||||||
|
@ -391,7 +391,7 @@ func TestMetadata(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fake.Params["rev"] = "12345"
|
fake.Params["rev"] = "12345"
|
||||||
db.Session.Transport = fake
|
http.DefaultTransport = fake
|
||||||
if received, err = db.Metadata(path, true, true, "", "12345", 20); err != nil {
|
if received, err = db.Metadata(path, true, true, "", "12345", 20); err != nil {
|
||||||
t.Errorf("API error: %s", err)
|
t.Errorf("API error: %s", err)
|
||||||
} else if !reflect.DeepEqual(expected, *received) {
|
} else if !reflect.DeepEqual(expected, *received) {
|
||||||
|
@ -399,7 +399,7 @@ func TestMetadata(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fake.Params["hash"] = "6789"
|
fake.Params["hash"] = "6789"
|
||||||
db.Session.Transport = fake
|
http.DefaultTransport = fake
|
||||||
if received, err = db.Metadata(path, true, true, "6789", "12345", 20); err != nil {
|
if received, err = db.Metadata(path, true, true, "6789", "12345", 20); err != nil {
|
||||||
t.Errorf("API error: %s", err)
|
t.Errorf("API error: %s", err)
|
||||||
} else if !reflect.DeepEqual(expected, *received) {
|
} else if !reflect.DeepEqual(expected, *received) {
|
||||||
|
@ -407,7 +407,7 @@ func TestMetadata(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fake.Params["file_limit"] = "10000"
|
fake.Params["file_limit"] = "10000"
|
||||||
db.Session.Transport = fake
|
http.DefaultTransport = fake
|
||||||
if received, err = db.Metadata(path, true, true, "6789", "12345", 0); err != nil {
|
if received, err = db.Metadata(path, true, true, "6789", "12345", 0); err != nil {
|
||||||
t.Errorf("API error: %s", err)
|
t.Errorf("API error: %s", err)
|
||||||
} else if !reflect.DeepEqual(expected, *received) {
|
} else if !reflect.DeepEqual(expected, *received) {
|
||||||
|
@ -415,7 +415,7 @@ func TestMetadata(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fake.Params["file_limit"] = strconv.FormatInt(int64(MetadataLimitMax), 10)
|
fake.Params["file_limit"] = strconv.FormatInt(int64(MetadataLimitMax), 10)
|
||||||
db.Session.Transport = fake
|
http.DefaultTransport = fake
|
||||||
if received, err = db.Metadata(path, true, true, "6789", "12345", MetadataLimitMax+1); err != nil {
|
if received, err = db.Metadata(path, true, true, "6789", "12345", MetadataLimitMax+1); err != nil {
|
||||||
t.Errorf("API error: %s", err)
|
t.Errorf("API error: %s", err)
|
||||||
} else if !reflect.DeepEqual(expected, *received) {
|
} else if !reflect.DeepEqual(expected, *received) {
|
||||||
|
@ -440,7 +440,7 @@ func TestMove(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
db = newDropbox(t)
|
db = newDropbox(t)
|
||||||
db.Session.Transport = FakeHTTP{t: t, Method: "POST", Host: "api.dropbox.com", Path: "/1/fileops/move",
|
http.DefaultTransport = FakeHTTP{t: t, Method: "POST", Host: "api.dropbox.com", Path: "/1/fileops/move",
|
||||||
Params: map[string]string{"root": "dropbox", "from_path": from, "to_path": to, "locale": "en"},
|
Params: map[string]string{"root": "dropbox", "from_path": from, "to_path": to, "locale": "en"},
|
||||||
ResponseData: js}
|
ResponseData: js}
|
||||||
if received, err = db.Move(from, to); err != nil {
|
if received, err = db.Move(from, to); err != nil {
|
||||||
|
@ -465,7 +465,7 @@ func TestRestore(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
db = newDropbox(t)
|
db = newDropbox(t)
|
||||||
db.Session.Transport = FakeHTTP{t: t, Method: "POST", Host: "api.dropbox.com", Path: "/1/restore/dropbox/" + path,
|
http.DefaultTransport = FakeHTTP{t: t, Method: "POST", Host: "api.dropbox.com", Path: "/1/restore/dropbox/" + path,
|
||||||
Params: map[string]string{"rev": expected.Revision, "locale": "en"},
|
Params: map[string]string{"rev": expected.Revision, "locale": "en"},
|
||||||
ResponseData: js}
|
ResponseData: js}
|
||||||
if received, err = db.Restore(path, expected.Revision); err != nil {
|
if received, err = db.Restore(path, expected.Revision); err != nil {
|
||||||
|
@ -496,7 +496,7 @@ func TestRevisions(t *testing.T) {
|
||||||
|
|
||||||
db = newDropbox(t)
|
db = newDropbox(t)
|
||||||
|
|
||||||
db.Session.Transport = fake
|
http.DefaultTransport = fake
|
||||||
if received, err = db.Revisions(path, 10); err != nil {
|
if received, err = db.Revisions(path, 10); err != nil {
|
||||||
t.Errorf("API error: %s", err)
|
t.Errorf("API error: %s", err)
|
||||||
} else if !reflect.DeepEqual(expected, received) {
|
} else if !reflect.DeepEqual(expected, received) {
|
||||||
|
@ -538,7 +538,7 @@ func TestSearch(t *testing.T) {
|
||||||
fake := FakeHTTP{Method: "GET", Host: "api.dropbox.com", Path: "/1/search/dropbox/" + dirname, t: t,
|
fake := FakeHTTP{Method: "GET", Host: "api.dropbox.com", Path: "/1/search/dropbox/" + dirname, t: t,
|
||||||
Params: map[string]string{"locale": "en", "query": "foo bar", "file_limit": "10", "include_deleted": "false"}, ResponseData: js}
|
Params: map[string]string{"locale": "en", "query": "foo bar", "file_limit": "10", "include_deleted": "false"}, ResponseData: js}
|
||||||
|
|
||||||
db.Session.Transport = fake
|
http.DefaultTransport = fake
|
||||||
if received, err = db.Search(dirname, "foo bar", 10, false); err != nil {
|
if received, err = db.Search(dirname, "foo bar", 10, false); err != nil {
|
||||||
t.Errorf("API error: %s", err)
|
t.Errorf("API error: %s", err)
|
||||||
} else if !reflect.DeepEqual(expected, received) {
|
} else if !reflect.DeepEqual(expected, received) {
|
||||||
|
@ -546,7 +546,7 @@ func TestSearch(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fake.Params["include_deleted"] = "true"
|
fake.Params["include_deleted"] = "true"
|
||||||
db.Session.Transport = fake
|
http.DefaultTransport = fake
|
||||||
if received, err = db.Search(dirname, "foo bar", 10, true); err != nil {
|
if received, err = db.Search(dirname, "foo bar", 10, true); err != nil {
|
||||||
t.Errorf("API error: %s", err)
|
t.Errorf("API error: %s", err)
|
||||||
} else if !reflect.DeepEqual(expected, received) {
|
} else if !reflect.DeepEqual(expected, received) {
|
||||||
|
@ -554,7 +554,7 @@ func TestSearch(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fake.Params["file_limit"] = strconv.FormatInt(int64(SearchLimitDefault), 10)
|
fake.Params["file_limit"] = strconv.FormatInt(int64(SearchLimitDefault), 10)
|
||||||
db.Session.Transport = fake
|
http.DefaultTransport = fake
|
||||||
if received, err = db.Search(dirname, "foo bar", 0, true); err != nil {
|
if received, err = db.Search(dirname, "foo bar", 0, true); err != nil {
|
||||||
t.Errorf("API error: %s", err)
|
t.Errorf("API error: %s", err)
|
||||||
} else if !reflect.DeepEqual(expected, received) {
|
} else if !reflect.DeepEqual(expected, received) {
|
||||||
|
@ -585,7 +585,7 @@ func TestShares(t *testing.T) {
|
||||||
fake := FakeHTTP{Method: "POST", Host: "api.dropbox.com", Path: "/1/shares/dropbox/" + filename,
|
fake := FakeHTTP{Method: "POST", Host: "api.dropbox.com", Path: "/1/shares/dropbox/" + filename,
|
||||||
Params: map[string]string{"locale": "en"}, t: t, ResponseData: js}
|
Params: map[string]string{"locale": "en"}, t: t, ResponseData: js}
|
||||||
|
|
||||||
db.Session.Transport = fake
|
http.DefaultTransport = fake
|
||||||
if received, err = db.Shares(filename, false); err != nil {
|
if received, err = db.Shares(filename, false); err != nil {
|
||||||
t.Errorf("API error: %s", err)
|
t.Errorf("API error: %s", err)
|
||||||
} else if !reflect.DeepEqual(expected, *received) {
|
} else if !reflect.DeepEqual(expected, *received) {
|
||||||
|
@ -593,7 +593,7 @@ func TestShares(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fake.Params["short_url"] = "true"
|
fake.Params["short_url"] = "true"
|
||||||
db.Session.Transport = fake
|
http.DefaultTransport = fake
|
||||||
if received, err = db.Shares(filename, true); err != nil {
|
if received, err = db.Shares(filename, true); err != nil {
|
||||||
t.Errorf("API error: %s", err)
|
t.Errorf("API error: %s", err)
|
||||||
} else if !reflect.DeepEqual(expected, *received) {
|
} else if !reflect.DeepEqual(expected, *received) {
|
||||||
|
|
Reference in New Issue
Block a user