1
0
mirror of https://github.com/rclone/rclone.git synced 2025-12-20 02:03:17 +00:00

vendor: update all dependencies to latest versions

This commit is contained in:
Nick Craig-Wood
2018-01-16 13:20:59 +00:00
parent 8e83fb6fb9
commit 7d3a17725d
4878 changed files with 1974229 additions and 201215 deletions

View File

@@ -5,12 +5,13 @@ go:
- 1.7.x
- 1.8.x
- 1.9.x
install: go get -u golang.org/x/oauth2
before_script: go get -u github.com/mitchellh/gox
script: gox -osarch="darwin/amd64 linux/amd64 windows/amd64" ./dropbox/...
install:
- go get -u golang.org/x/oauth2
before_script:
- go get -u github.com/mitchellh/gox
script:
- gox -osarch="darwin/amd64 linux/amd64 windows/amd64" ./dropbox/...
jobs:
include:
- stage: run tests
go: 1.9.x
install: go get -u golang.org/x/oauth2
script: go test ./dropbox/...

View File

@@ -1,4 +1,4 @@
# Dropbox SDK for Go [UNOFFICIAL] [![GoDoc](https://godoc.org/github.com/dropbox/dropbox-sdk-go-unofficial/dropbox?status.svg)](https://godoc.org/github.com/dropbox/dropbox-sdk-go-unofficial/dropbox) [![Build Status](https://travis-ci.org/dropbox/dropbox-sdk-go-unofficial.svg?branch=master)](https://travis-ci.org/dropbox/dropbox-sdk-go-unofficial)
# Dropbox SDK for Go [UNOFFICIAL] [![GoDoc](https://godoc.org/github.com/dropbox/dropbox-sdk-go-unofficial/dropbox?status.svg)](https://godoc.org/github.com/dropbox/dropbox-sdk-go-unofficial/dropbox) [![Build Status](https://travis-ci.org/dropbox/dropbox-sdk-go-unofficial.svg?branch=master)](https://travis-ci.org/dropbox/dropbox-sdk-go-unofficial) [![Go Report Card](https://goreportcard.com/badge/github.com/dropbox/dropbox-sdk-go-unofficial)](https://goreportcard.com/report/github.com/dropbox/dropbox-sdk-go-unofficial)
An **UNOFFICIAL** Go SDK for integrating with the Dropbox API v2. Tested with Go 1.5+

View File

@@ -118,11 +118,12 @@ func (u *PathRootError) UnmarshalJSON(body []byte) error {
// RootInfo : Information about current user's root.
type RootInfo struct {
// RootNamespaceId : The namespace id for user's root namespace. It will be
// the namespace id of the shared team root if the user is member of a CDM
// team. Otherwise it will be same as `RootInfo.home_namespace_id`.
// RootNamespaceId : The namespace ID for user's root namespace. It will be
// the namespace ID of the shared team root if the user is member of a team
// with a separate team root. Otherwise it will be same as
// `RootInfo.home_namespace_id`.
RootNamespaceId string `json:"root_namespace_id"`
// HomeNamespaceId : The namespace id for user's home namespace.
// HomeNamespaceId : The namespace ID for user's home namespace.
HomeNamespaceId string `json:"home_namespace_id"`
}
@@ -205,7 +206,8 @@ func IsRootInfoFromJSON(data []byte) (IsRootInfo, error) {
return nil, nil
}
// TeamRootInfo : Root info when user is member of a CDM team.
// TeamRootInfo : Root info when user is member of a team with a separate root
// namespace ID.
type TeamRootInfo struct {
RootInfo
// HomePath : The path for user's home directory under the shared team root.
@@ -221,7 +223,8 @@ func NewTeamRootInfo(RootNamespaceId string, HomeNamespaceId string, HomePath st
return s
}
// UserRootInfo : Root info when user is not member of a CDM team.
// UserRootInfo : Root info when user is not member of a team or the user is a
// member of a team and the team does not have a separate root namespace.
type UserRootInfo struct {
RootInfo
}

View File

@@ -145,7 +145,7 @@ type FileRequestDeadline struct {
// Deadline : The deadline for this file request.
Deadline time.Time `json:"deadline"`
// AllowLateUploads : If set, allow uploads after the deadline has passed.
// These uploads will be marked overdue.
// These uploads will be marked overdue.
AllowLateUploads *GracePeriod `json:"allow_late_uploads,omitempty"`
}

View File

@@ -100,6 +100,10 @@ type Client interface {
DeleteV2(arg *DeleteArg) (res *DeleteResult, err error)
// Download : Download a file from a user's Dropbox.
Download(arg *DownloadArg) (res *FileMetadata, content io.ReadCloser, err error)
// DownloadZip : Download a folder from the user's Dropbox, as a zip file.
// The folder must be less than 1 GB in size and have fewer than 10,000
// total files. The input cannot be a single file.
DownloadZip(arg *DownloadZipArg) (res *DownloadZipResult, content io.ReadCloser, err error)
// GetMetadata : Returns the metadata for a file or folder. Note: Metadata
// for the root folder is unsupported.
GetMetadata(arg *GetMetadataArg) (res IsMetadata, err error)
@@ -1408,6 +1412,79 @@ func (dbx *apiImpl) Download(arg *DownloadArg) (res *FileMetadata, content io.Re
return
}
//DownloadZipAPIError is an error-wrapper for the download_zip route
type DownloadZipAPIError struct {
dropbox.APIError
EndpointError *DownloadZipError `json:"error"`
}
func (dbx *apiImpl) DownloadZip(arg *DownloadZipArg) (res *DownloadZipResult, content io.ReadCloser, err error) {
cli := dbx.Client
dbx.Config.LogDebug("arg: %v", arg)
b, err := json.Marshal(arg)
if err != nil {
return
}
headers := map[string]string{
"Dropbox-API-Arg": string(b),
}
if dbx.Config.AsMemberID != "" {
headers["Dropbox-API-Select-User"] = dbx.Config.AsMemberID
}
req, err := (*dropbox.Context)(dbx).NewRequest("content", "download", true, "files", "download_zip", headers, nil)
if err != nil {
return
}
dbx.Config.LogInfo("req: %v", req)
resp, err := cli.Do(req)
if err != nil {
return
}
dbx.Config.LogInfo("resp: %v", resp)
body := []byte(resp.Header.Get("Dropbox-API-Result"))
content = resp.Body
dbx.Config.LogDebug("body: %v", body)
if resp.StatusCode == http.StatusOK {
err = json.Unmarshal(body, &res)
if err != nil {
return
}
return
}
if resp.StatusCode == http.StatusConflict {
defer resp.Body.Close()
body, err = ioutil.ReadAll(resp.Body)
if err != nil {
return
}
var apiError DownloadZipAPIError
err = json.Unmarshal(body, &apiError)
if err != nil {
return
}
err = apiError
return
}
var apiError dropbox.APIError
if resp.StatusCode == http.StatusBadRequest || resp.StatusCode == http.StatusInternalServerError {
apiError.ErrorSummary = string(body)
err = apiError
return
}
err = json.Unmarshal(body, &apiError)
if err != nil {
return
}
err = apiError
return
}
//GetMetadataAPIError is an error-wrapper for the get_metadata route
type GetMetadataAPIError struct {
dropbox.APIError

View File

@@ -1,109 +0,0 @@
// Copyright (c) Dropbox, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package files
import "encoding/json"
type listFolderResult struct {
Entries []json.RawMessage `json:"entries"`
Cursor string `json:"cursor"`
HasMore bool `json:"has_more"`
}
// UnmarshalJSON deserializes into a ListFolderResult instance
func (r *ListFolderResult) UnmarshalJSON(b []byte) error {
var l listFolderResult
if err := json.Unmarshal(b, &l); err != nil {
return err
}
r.Cursor = l.Cursor
r.HasMore = l.HasMore
r.Entries = make([]IsMetadata, len(l.Entries))
for i, e := range l.Entries {
metadata, err := IsMetadataFromJSON(e)
if err != nil {
return err
}
r.Entries[i] = metadata
}
return nil
}
type searchMatch struct {
MatchType *SearchMatchType `json:"match_type"`
Metadata json.RawMessage `json:"metadata"`
}
// UnmarshalJSON deserializes into a SearchMatch instance
func (s *SearchMatch) UnmarshalJSON(b []byte) error {
var m searchMatch
if err := json.Unmarshal(b, &m); err != nil {
return err
}
s.MatchType = m.MatchType
metadata, err := IsMetadataFromJSON(m.Metadata)
if err != nil {
return err
}
s.Metadata = metadata
return nil
}
type deleteResult struct {
FileOpsResult
Metadata json.RawMessage `json:"metadata"`
}
// UnmarshalJSON deserializes into a DeleteResult instance
func (s *DeleteResult) UnmarshalJSON(b []byte) error {
var m deleteResult
if err := json.Unmarshal(b, &m); err != nil {
return err
}
s.FileOpsResult = m.FileOpsResult
metadata, err := IsMetadataFromJSON(m.Metadata)
if err != nil {
return err
}
s.Metadata = metadata
return nil
}
type relocationResult struct {
FileOpsResult
// Metadata : Metadata of the relocated object.
Metadata json.RawMessage `json:"metadata"`
}
// UnmarshalJSON deserializes into a RelocationResult instance
func (s *RelocationResult) UnmarshalJSON(b []byte) error {
var m relocationResult
if err := json.Unmarshal(b, &m); err != nil {
return err
}
s.FileOpsResult = m.FileOpsResult
metadata, err := IsMetadataFromJSON(m.Metadata)
if err != nil {
return err
}
s.Metadata = metadata
return nil
}

View File

@@ -449,6 +449,24 @@ func NewDeleteBatchResultData(Metadata IsMetadata) *DeleteBatchResultData {
return s
}
// UnmarshalJSON deserializes into a DeleteBatchResultData instance
func (u *DeleteBatchResultData) UnmarshalJSON(b []byte) error {
type wrap struct {
// Metadata : Metadata of the deleted object.
Metadata json.RawMessage `json:"metadata"`
}
var w wrap
if err := json.Unmarshal(b, &w); err != nil {
return err
}
Metadata, err := IsMetadataFromJSON(w.Metadata)
if err != nil {
return err
}
u.Metadata = Metadata
return nil
}
// DeleteBatchResultEntry : has no documentation (yet)
type DeleteBatchResultEntry struct {
dropbox.Tagged
@@ -560,6 +578,24 @@ func NewDeleteResult(Metadata IsMetadata) *DeleteResult {
return s
}
// UnmarshalJSON deserializes into a DeleteResult instance
func (u *DeleteResult) UnmarshalJSON(b []byte) error {
type wrap struct {
// Metadata : Metadata of the deleted object.
Metadata json.RawMessage `json:"metadata"`
}
var w wrap
if err := json.Unmarshal(b, &w); err != nil {
return err
}
Metadata, err := IsMetadataFromJSON(w.Metadata)
if err != nil {
return err
}
u.Metadata = Metadata
return nil
}
// Metadata : Metadata for a file or folder.
type Metadata struct {
// Name : The last component of the path (including extension). This never
@@ -757,6 +793,71 @@ func (u *DownloadError) UnmarshalJSON(body []byte) error {
return nil
}
// DownloadZipArg : has no documentation (yet)
type DownloadZipArg struct {
// Path : The path of the folder to download.
Path string `json:"path"`
}
// NewDownloadZipArg returns a new DownloadZipArg instance
func NewDownloadZipArg(Path string) *DownloadZipArg {
s := new(DownloadZipArg)
s.Path = Path
return s
}
// DownloadZipError : has no documentation (yet)
type DownloadZipError struct {
dropbox.Tagged
// Path : has no documentation (yet)
Path *LookupError `json:"path,omitempty"`
}
// Valid tag values for DownloadZipError
const (
DownloadZipErrorPath = "path"
DownloadZipErrorTooLarge = "too_large"
DownloadZipErrorTooManyFiles = "too_many_files"
DownloadZipErrorOther = "other"
)
// UnmarshalJSON deserializes into a DownloadZipError instance
func (u *DownloadZipError) UnmarshalJSON(body []byte) error {
type wrap struct {
dropbox.Tagged
// Path : has no documentation (yet)
Path json.RawMessage `json:"path,omitempty"`
}
var w wrap
var err error
if err = json.Unmarshal(body, &w); err != nil {
return err
}
u.Tag = w.Tag
switch u.Tag {
case "path":
err = json.Unmarshal(w.Path, &u.Path)
if err != nil {
return err
}
}
return nil
}
// DownloadZipResult : has no documentation (yet)
type DownloadZipResult struct {
// Metadata : has no documentation (yet)
Metadata *FolderMetadata `json:"metadata"`
}
// NewDownloadZipResult returns a new DownloadZipResult instance
func NewDownloadZipResult(Metadata *FolderMetadata) *DownloadZipResult {
s := new(DownloadZipResult)
s.Metadata = Metadata
return s
}
// FileMetadata : has no documentation (yet)
type FileMetadata struct {
Metadata
@@ -965,6 +1066,32 @@ func NewGetCopyReferenceResult(Metadata IsMetadata, CopyReference string, Expire
return s
}
// UnmarshalJSON deserializes into a GetCopyReferenceResult instance
func (u *GetCopyReferenceResult) UnmarshalJSON(b []byte) error {
type wrap struct {
// Metadata : Metadata of the file or folder.
Metadata json.RawMessage `json:"metadata"`
// CopyReference : A copy reference to the file or folder.
CopyReference string `json:"copy_reference"`
// Expires : The expiration date of the copy reference. This value is
// currently set to be far enough in the future so that expiration is
// effectively not an issue.
Expires time.Time `json:"expires"`
}
var w wrap
if err := json.Unmarshal(b, &w); err != nil {
return err
}
Metadata, err := IsMetadataFromJSON(w.Metadata)
if err != nil {
return err
}
u.Metadata = Metadata
u.CopyReference = w.CopyReference
u.Expires = w.Expires
return nil
}
// GetTemporaryLinkArg : has no documentation (yet)
type GetTemporaryLinkArg struct {
// Path : The path to the file you want a temporary link to.
@@ -1369,6 +1496,35 @@ func NewListFolderResult(Entries []IsMetadata, Cursor string, HasMore bool) *Lis
return s
}
// UnmarshalJSON deserializes into a ListFolderResult instance
func (u *ListFolderResult) UnmarshalJSON(b []byte) error {
type wrap struct {
// Entries : The files and (direct) subfolders in the folder.
Entries []json.RawMessage `json:"entries"`
// Cursor : Pass the cursor into `listFolderContinue` to see what's
// changed in the folder since your previous query.
Cursor string `json:"cursor"`
// HasMore : If true, then there are more entries available. Pass the
// cursor to `listFolderContinue` to retrieve the rest.
HasMore bool `json:"has_more"`
}
var w wrap
if err := json.Unmarshal(b, &w); err != nil {
return err
}
u.Entries = make([]IsMetadata, len(w.Entries))
for i, e := range w.Entries {
v, err := IsMetadataFromJSON(e)
if err != nil {
return err
}
u.Entries[i] = v
}
u.Cursor = w.Cursor
u.HasMore = w.HasMore
return nil
}
// ListRevisionsArg : has no documentation (yet)
type ListRevisionsArg struct {
// Path : The path to the file you want to see the revisions of.
@@ -2017,6 +2173,24 @@ func NewRelocationBatchResultData(Metadata IsMetadata) *RelocationBatchResultDat
return s
}
// UnmarshalJSON deserializes into a RelocationBatchResultData instance
func (u *RelocationBatchResultData) UnmarshalJSON(b []byte) error {
type wrap struct {
// Metadata : Metadata of the relocated object.
Metadata json.RawMessage `json:"metadata"`
}
var w wrap
if err := json.Unmarshal(b, &w); err != nil {
return err
}
Metadata, err := IsMetadataFromJSON(w.Metadata)
if err != nil {
return err
}
u.Metadata = Metadata
return nil
}
// RelocationResult : has no documentation (yet)
type RelocationResult struct {
FileOpsResult
@@ -2031,6 +2205,24 @@ func NewRelocationResult(Metadata IsMetadata) *RelocationResult {
return s
}
// UnmarshalJSON deserializes into a RelocationResult instance
func (u *RelocationResult) UnmarshalJSON(b []byte) error {
type wrap struct {
// Metadata : Metadata of the relocated object.
Metadata json.RawMessage `json:"metadata"`
}
var w wrap
if err := json.Unmarshal(b, &w); err != nil {
return err
}
Metadata, err := IsMetadataFromJSON(w.Metadata)
if err != nil {
return err
}
u.Metadata = Metadata
return nil
}
// RestoreArg : has no documentation (yet)
type RestoreArg struct {
// Path : The path to the file you want to restore.
@@ -2168,6 +2360,25 @@ func NewSaveCopyReferenceResult(Metadata IsMetadata) *SaveCopyReferenceResult {
return s
}
// UnmarshalJSON deserializes into a SaveCopyReferenceResult instance
func (u *SaveCopyReferenceResult) UnmarshalJSON(b []byte) error {
type wrap struct {
// Metadata : The metadata of the saved file or folder in the user's
// Dropbox.
Metadata json.RawMessage `json:"metadata"`
}
var w wrap
if err := json.Unmarshal(b, &w); err != nil {
return err
}
Metadata, err := IsMetadataFromJSON(w.Metadata)
if err != nil {
return err
}
u.Metadata = Metadata
return nil
}
// SaveUrlArg : has no documentation (yet)
type SaveUrlArg struct {
// Path : The path in Dropbox where the URL will be saved to.
@@ -2402,6 +2613,27 @@ func NewSearchMatch(MatchType *SearchMatchType, Metadata IsMetadata) *SearchMatc
return s
}
// UnmarshalJSON deserializes into a SearchMatch instance
func (u *SearchMatch) UnmarshalJSON(b []byte) error {
type wrap struct {
// MatchType : The type of the match.
MatchType *SearchMatchType `json:"match_type"`
// Metadata : The metadata for the matched file or folder.
Metadata json.RawMessage `json:"metadata"`
}
var w wrap
if err := json.Unmarshal(b, &w); err != nil {
return err
}
u.MatchType = w.MatchType
Metadata, err := IsMetadataFromJSON(w.Metadata)
if err != nil {
return err
}
u.Metadata = Metadata
return nil
}
// SearchMatchType : Indicates what type of match was found for a given item.
type SearchMatchType struct {
dropbox.Tagged
@@ -2552,12 +2784,15 @@ type UploadError struct {
dropbox.Tagged
// Path : Unable to save the uploaded contents to a file.
Path *UploadWriteFailed `json:"path,omitempty"`
// PropertiesError : The supplied property group is invalid.
PropertiesError *file_properties.InvalidPropertyGroupError `json:"properties_error,omitempty"`
}
// Valid tag values for UploadError
const (
UploadErrorPath = "path"
UploadErrorOther = "other"
UploadErrorPath = "path"
UploadErrorPropertiesError = "properties_error"
UploadErrorOther = "other"
)
// UnmarshalJSON deserializes into a UploadError instance
@@ -2566,6 +2801,8 @@ func (u *UploadError) UnmarshalJSON(body []byte) error {
dropbox.Tagged
// Path : Unable to save the uploaded contents to a file.
Path json.RawMessage `json:"path,omitempty"`
// PropertiesError : The supplied property group is invalid.
PropertiesError json.RawMessage `json:"properties_error,omitempty"`
}
var w wrap
var err error
@@ -2577,6 +2814,12 @@ func (u *UploadError) UnmarshalJSON(body []byte) error {
case "path":
err = json.Unmarshal(body, &u.Path)
if err != nil {
return err
}
case "properties_error":
err = json.Unmarshal(w.PropertiesError, &u.PropertiesError)
if err != nil {
return err
}
@@ -2589,15 +2832,15 @@ type UploadErrorWithProperties struct {
dropbox.Tagged
// Path : Unable to save the uploaded contents to a file.
Path *UploadWriteFailed `json:"path,omitempty"`
// PropertiesError : has no documentation (yet)
// PropertiesError : The supplied property group is invalid.
PropertiesError *file_properties.InvalidPropertyGroupError `json:"properties_error,omitempty"`
}
// Valid tag values for UploadErrorWithProperties
const (
UploadErrorWithPropertiesPath = "path"
UploadErrorWithPropertiesOther = "other"
UploadErrorWithPropertiesPropertiesError = "properties_error"
UploadErrorWithPropertiesOther = "other"
)
// UnmarshalJSON deserializes into a UploadErrorWithProperties instance
@@ -2606,7 +2849,7 @@ func (u *UploadErrorWithProperties) UnmarshalJSON(body []byte) error {
dropbox.Tagged
// Path : Unable to save the uploaded contents to a file.
Path json.RawMessage `json:"path,omitempty"`
// PropertiesError : has no documentation (yet)
// PropertiesError : The supplied property group is invalid.
PropertiesError json.RawMessage `json:"properties_error,omitempty"`
}
var w wrap

View File

@@ -21,6 +21,7 @@
package dropbox
import (
"context"
"fmt"
"io"
"log"
@@ -35,8 +36,8 @@ const (
hostAPI = "api"
hostContent = "content"
hostNotify = "notify"
sdkVersion = "4.1.0"
specVersion = "5389e5b"
sdkVersion = "4.5.0"
specVersion = "a1d5111"
)
// Version returns the current SDK version and API Spec version
@@ -77,12 +78,12 @@ const (
LogInfo
)
func (l LogLevel) ShouldLog(v LogLevel) bool {
func (l LogLevel) shouldLog(v LogLevel) bool {
return l > v || l&v == v
}
func (c *Config) doLog(l LogLevel, format string, v ...interface{}) {
if !c.LogLevel.ShouldLog(l) {
if !c.LogLevel.shouldLog(l) {
return
}
@@ -152,7 +153,7 @@ func NewContext(c Config) Context {
if client == nil {
var conf = &oauth2.Config{Endpoint: OAuthEndpoint(domain)}
tok := &oauth2.Token{AccessToken: c.Token}
client = conf.Client(oauth2.NoContext, tok)
client = conf.Client(context.Background(), tok)
}
headerGenerator := c.HeaderGenerator

View File

@@ -18,32 +18,38 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package sharing
package dropbox_test
import "encoding/json"
import (
"fmt"
"net/http"
"net/http/httptest"
"strings"
"testing"
type listSharedLinksResult struct {
Links []sharedLinkMetadataUnion `json:"links"`
HasMore bool `json:"has_more"`
Cursor string `json:"cursor,omitempty"`
"github.com/dropbox/dropbox-sdk-go-unofficial/dropbox"
"github.com/dropbox/dropbox-sdk-go-unofficial/dropbox/users"
)
func generateURL(base string, namespace string, route string) string {
return fmt.Sprintf("%s/%s/%s", base, namespace, route)
}
// UnmarshalJSON deserializes into a ListSharedLinksResult instance
func (r *ListSharedLinksResult) UnmarshalJSON(b []byte) error {
var l listSharedLinksResult
if err := json.Unmarshal(b, &l); err != nil {
return err
func TestInternalError(t *testing.T) {
eString := "internal server error"
ts := httptest.NewServer(http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
http.Error(w, eString, http.StatusInternalServerError)
}))
defer ts.Close()
config := dropbox.Config{Client: ts.Client(), LogLevel: dropbox.LogDebug,
URLGenerator: func(hostType string, style string, namespace string, route string) string {
return generateURL(ts.URL, namespace, route)
}}
client := users.New(config)
v, e := client.GetCurrentAccount()
if v != nil || strings.Trim(e.Error(), "\n") != eString {
t.Errorf("v: %v e: '%s'\n", v, e.Error())
}
r.Cursor = l.Cursor
r.HasMore = l.HasMore
r.Links = make([]IsSharedLinkMetadata, len(l.Links))
for i, e := range l.Links {
switch e.Tag {
case "file":
r.Links[i] = e.File
case "folder":
r.Links[i] = e.Folder
}
}
return nil
}

View File

@@ -1431,6 +1431,27 @@ func NewGetSharedLinksResult(Links []IsLinkMetadata) *GetSharedLinksResult {
return s
}
// UnmarshalJSON deserializes into a GetSharedLinksResult instance
func (u *GetSharedLinksResult) UnmarshalJSON(b []byte) error {
type wrap struct {
// Links : Shared links applicable to the path argument.
Links []json.RawMessage `json:"links"`
}
var w wrap
if err := json.Unmarshal(b, &w); err != nil {
return err
}
u.Links = make([]IsLinkMetadata, len(w.Links))
for i, e := range w.Links {
v, err := IsLinkMetadataFromJSON(e)
if err != nil {
return err
}
u.Links[i] = v
}
return nil
}
// GroupInfo : The information about a group. Groups is a way to manage a list
// of users who need same access permission to the shared folder.
type GroupInfo struct {
@@ -2398,6 +2419,36 @@ func NewListSharedLinksResult(Links []IsSharedLinkMetadata, HasMore bool) *ListS
return s
}
// UnmarshalJSON deserializes into a ListSharedLinksResult instance
func (u *ListSharedLinksResult) UnmarshalJSON(b []byte) error {
type wrap struct {
// Links : Shared links applicable to the path argument.
Links []json.RawMessage `json:"links"`
// HasMore : Is true if there are additional shared links that have not
// been returned yet. Pass the cursor into `listSharedLinks` to retrieve
// them.
HasMore bool `json:"has_more"`
// Cursor : Pass the cursor into `listSharedLinks` to obtain the
// additional links. Cursor is returned only if no path is given.
Cursor string `json:"cursor,omitempty"`
}
var w wrap
if err := json.Unmarshal(b, &w); err != nil {
return err
}
u.Links = make([]IsSharedLinkMetadata, len(w.Links))
for i, e := range w.Links {
v, err := IsSharedLinkMetadataFromJSON(e)
if err != nil {
return err
}
u.Links[i] = v
}
u.HasMore = w.HasMore
u.Cursor = w.Cursor
return nil
}
// MemberAccessLevelResult : Contains information about a member's access level
// to content after an operation.
type MemberAccessLevelResult struct {

View File

@@ -2191,7 +2191,7 @@ func (u *MembersAddJobStatus) UnmarshalJSON(body []byte) error {
// Complete : The asynchronous job has finished. For each member that
// was specified in the parameter `MembersAddArg` that was provided to
// `membersAdd`, a corresponding item is returned in this list.
Complete json.RawMessage `json:"complete,omitempty"`
Complete []json.RawMessage `json:"complete,omitempty"`
}
var w wrap
var err error
@@ -2238,7 +2238,7 @@ func (u *MembersAddLaunch) UnmarshalJSON(body []byte) error {
type wrap struct {
dropbox.Tagged
// Complete : has no documentation (yet)
Complete json.RawMessage `json:"complete,omitempty"`
Complete []json.RawMessage `json:"complete,omitempty"`
}
var w wrap
var err error

File diff suppressed because it is too large Load Diff

View File

@@ -128,6 +128,75 @@ func NewFullAccount(AccountId string, Name *Name, Email string, EmailVerified bo
return s
}
// UnmarshalJSON deserializes into a FullAccount instance
func (u *FullAccount) UnmarshalJSON(b []byte) error {
type wrap struct {
// AccountId : The user's unique Dropbox ID.
AccountId string `json:"account_id"`
// Name : Details of a user's name.
Name *Name `json:"name"`
// Email : The user's e-mail address. Do not rely on this without
// checking the `email_verified` field. Even then, it's possible that
// the user has since lost access to their e-mail.
Email string `json:"email"`
// EmailVerified : Whether the user has verified their e-mail address.
EmailVerified bool `json:"email_verified"`
// Disabled : Whether the user has been disabled.
Disabled bool `json:"disabled"`
// Locale : The language that the user specified. Locale tags will be
// `IETF language tags`
// <http://en.wikipedia.org/wiki/IETF_language_tag>.
Locale string `json:"locale"`
// ReferralLink : The user's `referral link`
// <https://www.dropbox.com/referrals>.
ReferralLink string `json:"referral_link"`
// IsPaired : Whether the user has a personal and work account. If the
// current account is personal, then `team` will always be nil, but
// `is_paired` will indicate if a work account is linked.
IsPaired bool `json:"is_paired"`
// AccountType : What type of account this user has.
AccountType *users_common.AccountType `json:"account_type"`
// RootInfo : The root info for this account.
RootInfo json.RawMessage `json:"root_info"`
// ProfilePhotoUrl : URL for the photo representing the user, if one is
// set.
ProfilePhotoUrl string `json:"profile_photo_url,omitempty"`
// Country : The user's two-letter country code, if available. Country
// codes are based on `ISO 3166-1`
// <http://en.wikipedia.org/wiki/ISO_3166-1>.
Country string `json:"country,omitempty"`
// Team : If this account is a member of a team, information about that
// team.
Team *FullTeam `json:"team,omitempty"`
// TeamMemberId : This account's unique team member id. This field will
// only be present if `team` is present.
TeamMemberId string `json:"team_member_id,omitempty"`
}
var w wrap
if err := json.Unmarshal(b, &w); err != nil {
return err
}
u.AccountId = w.AccountId
u.Name = w.Name
u.Email = w.Email
u.EmailVerified = w.EmailVerified
u.Disabled = w.Disabled
u.Locale = w.Locale
u.ReferralLink = w.ReferralLink
u.IsPaired = w.IsPaired
u.AccountType = w.AccountType
RootInfo, err := common.IsRootInfoFromJSON(w.RootInfo)
if err != nil {
return err
}
u.RootInfo = RootInfo
u.ProfilePhotoUrl = w.ProfilePhotoUrl
u.Country = w.Country
u.Team = w.Team
u.TeamMemberId = w.TeamMemberId
return nil
}
// Team : Information about a team.
type Team struct {
// Id : The team's unique ID.

View File

@@ -15,7 +15,7 @@ stone -v -a :all go_types.stoneg.py "$gen_dir" "$spec_dir"/*.stone
stone -v -a :all go_client.stoneg.py "$gen_dir" "$spec_dir"/*.stone
# Update SDK and API spec versions
sdk_version=${1:-"4.0.0"}
sdk_version=${1:-"4.2.0"}
pushd ${spec_dir}
spec_version=$(git rev-parse --short HEAD)
popd

View File

@@ -12,6 +12,7 @@ from stone.ir import (
unwrap_nullable,
is_composite_type,
is_list_type,
is_primitive_type,
is_struct_type,
Void,
)
@@ -68,10 +69,14 @@ def _rename_if_reserved(s):
return s
def fmt_type(data_type, namespace=None, use_interface=False):
def fmt_type(data_type, namespace=None, use_interface=False, raw=False):
data_type, nullable = unwrap_nullable(data_type)
if is_list_type(data_type):
return '[]%s' % fmt_type(data_type.data_type, namespace, use_interface)
if raw and is_primitive_type(data_type.data_type):
return "json.RawMessage"
return '[]%s' % fmt_type(data_type.data_type, namespace, use_interface, raw)
if raw:
return "json.RawMessage"
type_name = data_type.name
if use_interface and _needs_base_type(data_type):
type_name = 'Is' + type_name

View File

@@ -1,109 +0,0 @@
// Copyright (c) Dropbox, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package files
import "encoding/json"
type listFolderResult struct {
Entries []json.RawMessage `json:"entries"`
Cursor string `json:"cursor"`
HasMore bool `json:"has_more"`
}
// UnmarshalJSON deserializes into a ListFolderResult instance
func (r *ListFolderResult) UnmarshalJSON(b []byte) error {
var l listFolderResult
if err := json.Unmarshal(b, &l); err != nil {
return err
}
r.Cursor = l.Cursor
r.HasMore = l.HasMore
r.Entries = make([]IsMetadata, len(l.Entries))
for i, e := range l.Entries {
metadata, err := IsMetadataFromJSON(e)
if err != nil {
return err
}
r.Entries[i] = metadata
}
return nil
}
type searchMatch struct {
MatchType *SearchMatchType `json:"match_type"`
Metadata json.RawMessage `json:"metadata"`
}
// UnmarshalJSON deserializes into a SearchMatch instance
func (s *SearchMatch) UnmarshalJSON(b []byte) error {
var m searchMatch
if err := json.Unmarshal(b, &m); err != nil {
return err
}
s.MatchType = m.MatchType
metadata, err := IsMetadataFromJSON(m.Metadata)
if err != nil {
return err
}
s.Metadata = metadata
return nil
}
type deleteResult struct {
FileOpsResult
Metadata json.RawMessage `json:"metadata"`
}
// UnmarshalJSON deserializes into a DeleteResult instance
func (s *DeleteResult) UnmarshalJSON(b []byte) error {
var m deleteResult
if err := json.Unmarshal(b, &m); err != nil {
return err
}
s.FileOpsResult = m.FileOpsResult
metadata, err := IsMetadataFromJSON(m.Metadata)
if err != nil {
return err
}
s.Metadata = metadata
return nil
}
type relocationResult struct {
FileOpsResult
// Metadata : Metadata of the relocated object.
Metadata json.RawMessage `json:"metadata"`
}
// UnmarshalJSON deserializes into a RelocationResult instance
func (s *RelocationResult) UnmarshalJSON(b []byte) error {
var m relocationResult
if err := json.Unmarshal(b, &m); err != nil {
return err
}
s.FileOpsResult = m.FileOpsResult
metadata, err := IsMetadataFromJSON(m.Metadata)
if err != nil {
return err
}
s.Metadata = metadata
return nil
}

View File

@@ -21,6 +21,7 @@
package dropbox
import (
"context"
"fmt"
"io"
"log"
@@ -77,12 +78,12 @@ const (
LogInfo
)
func (l LogLevel) ShouldLog(v LogLevel) bool {
return l > v || l & v == v
func (l LogLevel) shouldLog(v LogLevel) bool {
return l > v || l&v == v
}
func (c *Config) doLog(l LogLevel, format string, v ...interface{}) {
if !c.LogLevel.ShouldLog(l) {
if !c.LogLevel.shouldLog(l) {
return
}
@@ -152,7 +153,7 @@ func NewContext(c Config) Context {
if client == nil {
var conf = &oauth2.Config{Endpoint: OAuthEndpoint(domain)}
tok := &oauth2.Token{AccessToken: c.Token}
client = conf.Client(oauth2.NoContext, tok)
client = conf.Client(context.Background(), tok)
}
headerGenerator := c.HeaderGenerator

View File

@@ -1,49 +0,0 @@
// Copyright (c) Dropbox, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package sharing
import "encoding/json"
type listSharedLinksResult struct {
Links []sharedLinkMetadataUnion `json:"links"`
HasMore bool `json:"has_more"`
Cursor string `json:"cursor,omitempty"`
}
// UnmarshalJSON deserializes into a ListSharedLinksResult instance
func (r *ListSharedLinksResult) UnmarshalJSON(b []byte) error {
var l listSharedLinksResult
if err := json.Unmarshal(b, &l); err != nil {
return err
}
r.Cursor = l.Cursor
r.HasMore = l.HasMore
r.Links = make([]IsSharedLinkMetadata, len(l.Links))
for i, e := range l.Links {
switch e.Tag {
case "file":
r.Links[i] = e.File
case "folder":
r.Links[i] = e.Folder
}
}
return nil
}

View File

@@ -4,6 +4,7 @@ import shutil
from stone.backend import CodeBackend
from stone.ir import (
is_boolean_type,
is_list_type,
is_nullable_type,
is_primitive_type,
is_struct_type,
@@ -16,6 +17,8 @@ from go_helpers import (
fmt_type,
fmt_var,
generate_doc,
needs_base_type,
_needs_base_type
)
@@ -26,10 +29,6 @@ class GoTypesBackend(CodeBackend):
self.target_folder_path)
for namespace in api.namespaces.values():
self._generate_namespace(namespace)
if namespace.name == 'files' or namespace.name == 'sharing':
self.logger.info('Copying metadata.go to files')
shutil.copy(os.path.join(rsrc_folder, namespace.name, 'metadata.go'),
os.path.join(self.target_folder_path, namespace.name))
def _generate_namespace(self, namespace):
file_name = os.path.join(self.target_folder_path, namespace.name,
@@ -90,6 +89,39 @@ class GoTypesBackend(CodeBackend):
self.emit('// ExtraHeaders can be used to pass Range, If-None-Match headers')
self.emit('ExtraHeaders map[string]string `json:"-"`')
self._generate_struct_builder(struct)
self.emit()
if needs_base_type(struct):
self.emit('// UnmarshalJSON deserializes into a %s instance' % struct.name)
with self.block('func (u *%s) UnmarshalJSON(b []byte) error' % struct.name):
with self.block('type wrap struct'):
for field in struct.all_fields:
self._generate_field(field, namespace=struct.namespace,
raw=_needs_base_type(field.data_type))
self.emit('var w wrap')
with self.block('if err := json.Unmarshal(b, &w); err != nil'):
self.emit('return err')
for field in struct.all_fields:
dt = field.data_type
fn = fmt_var(field.name)
tn = fmt_type(dt, namespace=struct.namespace, use_interface=True)
if _needs_base_type(dt):
if is_list_type(dt):
self.emit("u.{0} = make({1}, len(w.{0}))".format(fn, tn))
# Grab the underlying type to get the correct Is...FromJSON method
tn = fmt_type(dt.data_type, namespace=struct.namespace, use_interface=True)
with self.block("for i, e := range w.{0}".format(fn)):
self.emit("v, err := {1}FromJSON(e)".format(fn, tn))
with self.block('if err != nil'):
self.emit('return err')
self.emit("u.{0}[i] = v".format(fn))
else:
self.emit("{0}, err := {1}FromJSON(w.{0})".format(fn, tn))
with self.block('if err != nil'):
self.emit('return err')
self.emit("u.{0} = {0}".format(fn))
else:
self.emit("u.{0} = w.{0}".format(fn))
self.emit('return nil')
def _generate_struct_builder(self, struct):
fields = ["%s %s" % (fmt_var(field.name),
@@ -122,14 +154,11 @@ class GoTypesBackend(CodeBackend):
def _generate_field(self, field, union_field=False, namespace=None, raw=False):
generate_doc(self, field)
field_name = fmt_var(field.name)
type_name = fmt_type(field.data_type, namespace, use_interface=True)
type_name = fmt_type(field.data_type, namespace, use_interface=True, raw=raw)
json_tag = '`json:"%s"`' % field.name
if is_nullable_type(field.data_type) or union_field:
json_tag = '`json:"%s,omitempty"`' % field.name
if raw:
self.emit('%s json.RawMessage %s' % (field_name, json_tag))
else:
self.emit('%s %s %s' % (field_name, type_name, json_tag))
self.emit('%s %s %s' % (field_name, type_name, json_tag))
def _generate_union(self, union):
self._generate_union_helper(union)
@@ -187,8 +216,7 @@ class GoTypesBackend(CodeBackend):
if is_union_type(field.data_type):
self.emit('err = json.Unmarshal(w.{0}, &u.{0})'
.format(field_name))
elif is_struct_type(field.data_type) and \
field.data_type.has_enumerated_subtypes():
elif _needs_base_type(field.data_type):
self.emit("u.{0}, err = Is{1}FromJSON(body)"
.format(field_name, field.data_type.name))
else: