mirror of
https://github.com/rclone/rclone.git
synced 2024-11-07 17:14:44 +01:00
vendor: remove ncw/dropbox-sdk-go-unofficial dependency
This commit is contained in:
parent
76226e0147
commit
41b2645dec
14
Gopkg.lock
generated
14
Gopkg.lock
generated
@ -73,6 +73,12 @@
|
||||
revision = "d2709f9f1f31ebcda9651b03077758c1f3a0018c"
|
||||
version = "v3.0.0"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/dropbox/dropbox-sdk-go-unofficial"
|
||||
packages = ["dropbox","dropbox/async","dropbox/files","dropbox/properties"]
|
||||
revision = "87c5a55c1cbe542a328e304b8717218b6a2ef21e"
|
||||
version = "v2.0.0"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/go-ini/ini"
|
||||
packages = ["."]
|
||||
@ -121,12 +127,6 @@
|
||||
revision = "9e777a8366cce605130a531d2cd6363d07ad7317"
|
||||
version = "v0.0.2"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/ncw/dropbox-sdk-go-unofficial"
|
||||
packages = ["dropbox","dropbox/async","dropbox/files","dropbox/properties"]
|
||||
revision = "5d9f46f9862ae5f65e264e178de6ce2c41a32d40"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/ncw/go-acd"
|
||||
@ -292,6 +292,6 @@
|
||||
[solve-meta]
|
||||
analyzer-name = "dep"
|
||||
analyzer-version = 1
|
||||
inputs-digest = "0b3a6116075cedb5990bd6edb0e5cfdaa04c7b28462a9c6cb02b8cbb63a2dab6"
|
||||
inputs-digest = "06ce607d1f66fd98f5b2375759b612bf1df211f9d431ddcc54724e4f97a4bd4e"
|
||||
solver-name = "gps-cdcl"
|
||||
solver-version = 1
|
||||
|
6
vendor/github.com/ncw/dropbox-sdk-go-unofficial/.gitignore
generated
vendored
6
vendor/github.com/ncw/dropbox-sdk-go-unofficial/.gitignore
generated
vendored
@ -1,6 +0,0 @@
|
||||
# swap
|
||||
[._]*.s[a-w][a-z]
|
||||
[._]s[a-w][a-z]
|
||||
|
||||
.pyc
|
||||
__pycache__
|
3
vendor/github.com/ncw/dropbox-sdk-go-unofficial/.gitmodules
generated
vendored
3
vendor/github.com/ncw/dropbox-sdk-go-unofficial/.gitmodules
generated
vendored
@ -1,3 +0,0 @@
|
||||
[submodule "generator/dropbox-api-spec"]
|
||||
path = generator/dropbox-api-spec
|
||||
url = https://github.com/dropbox/dropbox-api-spec
|
15
vendor/github.com/ncw/dropbox-sdk-go-unofficial/.travis.yml
generated
vendored
15
vendor/github.com/ncw/dropbox-sdk-go-unofficial/.travis.yml
generated
vendored
@ -1,15 +0,0 @@
|
||||
language: go
|
||||
|
||||
go:
|
||||
- 1.6.4
|
||||
- 1.7.5
|
||||
- 1.8
|
||||
|
||||
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/...
|
20
vendor/github.com/ncw/dropbox-sdk-go-unofficial/LICENSE
generated
vendored
20
vendor/github.com/ncw/dropbox-sdk-go-unofficial/LICENSE
generated
vendored
@ -1,20 +0,0 @@
|
||||
Copyright (c) 2009-2016 Dropbox Inc., http://www.dropbox.com/
|
||||
|
||||
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.
|
95
vendor/github.com/ncw/dropbox-sdk-go-unofficial/README.md
generated
vendored
95
vendor/github.com/ncw/dropbox-sdk-go-unofficial/README.md
generated
vendored
@ -1,95 +0,0 @@
|
||||
# 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)
|
||||
|
||||
An **UNOFFICIAL** Go SDK for integrating with the Dropbox API v2. Tested with Go 1.5+
|
||||
|
||||
:warning: WARNING: This SDK is **NOT yet official**. What does this mean?
|
||||
|
||||
* There is no formal Dropbox [support](https://www.dropbox.com/developers/support) for this SDK at this point
|
||||
* Bugs may or may not get fixed
|
||||
* Not all SDK features may be implemented and implemented features may be buggy or incorrect
|
||||
|
||||
|
||||
### Uh OK, so why are you releasing this?
|
||||
|
||||
* the SDK, while unofficial, _is_ usable. See [dbxcli](https://github.com/dropbox/dbxcli) for an example application built using the SDK
|
||||
* we would like to get feedback from the community and evaluate the level of interest/enthusiasm before investing into official supporting one more SDK
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
$ go get github.com/dropbox/dropbox-sdk-go-unofficial/dropbox/...
|
||||
```
|
||||
|
||||
For most applications, you should just import the relevant namespace(s) only. The SDK exports the following sub-packages:
|
||||
|
||||
* `github.com/dropbox/dropbox-sdk-go-unofficial/dropbox/auth`
|
||||
* `github.com/dropbox/dropbox-sdk-go-unofficial/dropbox/files`
|
||||
* `github.com/dropbox/dropbox-sdk-go-unofficial/dropbox/sharing`
|
||||
* `github.com/dropbox/dropbox-sdk-go-unofficial/dropbox/team`
|
||||
* `github.com/dropbox/dropbox-sdk-go-unofficial/dropbox/users`
|
||||
|
||||
Additionally, the base `github.com/dropbox/dropbox-sdk-go-unofficial/dropbox` package exports some configuration and helper methods.
|
||||
|
||||
## Usage
|
||||
|
||||
First, you need to [register a new "app"](https://dropbox.com/developers/apps) to start making API requests. Once you have created an app, you can either use the SDK via an access token (useful for testing) or via the regular OAuth2 flow (recommended for production).
|
||||
|
||||
### Using OAuth token
|
||||
|
||||
Once you've created an app, you can get an access token from the app's console. Note that this token will only work for the Dropbox account the token is associated with.
|
||||
|
||||
```go
|
||||
import "github.com/dropbox/dropbox-sdk-go-unofficial/dropbox"
|
||||
import "github.com/dropbox/dropbox-sdk-go-unofficial/dropbox/users"
|
||||
|
||||
func main() {
|
||||
config := dropbox.Config{Token: token, Verbose: true} // second arg enables verbose logging in the SDK
|
||||
dbx := users.New(config)
|
||||
// start making API calls
|
||||
}
|
||||
```
|
||||
|
||||
### Using OAuth2 flow
|
||||
|
||||
For this, you will need your `APP_KEY` and `APP_SECRET` from the developers console. Your app will then have to take users though the oauth flow, as part of which users will explicitly grant permissions to your app. At the end of this process, users will get a token that the app can then use for subsequent authentication. See [this](https://godoc.org/golang.org/x/oauth2#example-Config) for an example of oauth2 flow in Go.
|
||||
|
||||
Once you have the token, usage is same as above.
|
||||
|
||||
### Making API calls
|
||||
|
||||
Each Dropbox API takes in a request type and returns a response type. For instance, [/users/get_account](https://www.dropbox.com/developers/documentation/http/documentation#users-get_account) takes as input a `GetAccountArg` and returns a `BasicAccount`. The typical pattern for making API calls is:
|
||||
|
||||
* Instantiate the argument via the `New*` convenience functions in the SDK
|
||||
* Invoke the API
|
||||
* Process the response (or handle error, as below)
|
||||
|
||||
Here's an example:
|
||||
|
||||
```go
|
||||
arg := users.NewGetAccountArg(accountId)
|
||||
if resp, err := dbx.GetAccount(arg); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("Name: %v", resp.Name)
|
||||
```
|
||||
|
||||
### Error Handling
|
||||
|
||||
As described in the [API docs](https://www.dropbox.com/developers/documentation/http/documentation#error-handling), all HTTP errors _except_ 409 are returned as-is to the client (with a helpful text message where possible). In case of a 409, the SDK will return an endpoint-specific error as described in the API. This will be made available as `EndpointError` member in the error.
|
||||
|
||||
## Note on using the Teams API
|
||||
|
||||
To use the Team API, you will need to create a Dropbox Business App. The OAuth token from this app will _only_ work for the Team API.
|
||||
|
||||
Please read the [API docs](https://www.dropbox.com/developers/documentation/http/teams) carefully to appropriate secure your apps and tokens when using the Team API.
|
||||
|
||||
## Code Generation
|
||||
|
||||
This SDK is automatically generated using the public [Dropbox API spec](https://github.com/dropbox/dropbox-api-spec) and [Stone](https://github.com/dropbox/stone). See this [README](https://github.com/dropbox/dropbox-sdk-go-unofficial/blob/master/generator/README.md)
|
||||
for more details on how code is generated.
|
||||
|
||||
## Caveats
|
||||
|
||||
* To re-iterate, this is an **UNOFFICIAL** SDK and thus has no official support from Dropbox
|
||||
* Only supports the v2 API. Parts of the v2 API are still in beta, and thus subject to change
|
||||
* This SDK itself is in beta, and so interfaces may change at any point
|
132
vendor/github.com/ncw/dropbox-sdk-go-unofficial/dropbox/async/types.go
generated
vendored
132
vendor/github.com/ncw/dropbox-sdk-go-unofficial/dropbox/async/types.go
generated
vendored
@ -1,132 +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 async : has no documentation (yet)
|
||||
package async
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/ncw/dropbox-sdk-go-unofficial/dropbox"
|
||||
)
|
||||
|
||||
// LaunchResultBase : Result returned by methods that launch an asynchronous
|
||||
// job. A method who may either launch an asynchronous job, or complete the
|
||||
// request synchronously, can use this union by extending it, and adding a
|
||||
// 'complete' field with the type of the synchronous response. See
|
||||
// `LaunchEmptyResult` for an example.
|
||||
type LaunchResultBase struct {
|
||||
dropbox.Tagged
|
||||
// AsyncJobId : This response indicates that the processing is asynchronous.
|
||||
// The string is an id that can be used to obtain the status of the
|
||||
// asynchronous job.
|
||||
AsyncJobId string `json:"async_job_id,omitempty"`
|
||||
}
|
||||
|
||||
// Valid tag values for LaunchResultBase
|
||||
const (
|
||||
LaunchResultBaseAsyncJobId = "async_job_id"
|
||||
)
|
||||
|
||||
// UnmarshalJSON deserializes into a LaunchResultBase instance
|
||||
func (u *LaunchResultBase) UnmarshalJSON(body []byte) error {
|
||||
type wrap struct {
|
||||
dropbox.Tagged
|
||||
}
|
||||
var w wrap
|
||||
var err error
|
||||
if err = json.Unmarshal(body, &w); err != nil {
|
||||
return err
|
||||
}
|
||||
u.Tag = w.Tag
|
||||
switch u.Tag {
|
||||
case "async_job_id":
|
||||
err = json.Unmarshal(body, &u.AsyncJobId)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// LaunchEmptyResult : Result returned by methods that may either launch an
|
||||
// asynchronous job or complete synchronously. Upon synchronous completion of
|
||||
// the job, no additional information is returned.
|
||||
type LaunchEmptyResult struct {
|
||||
dropbox.Tagged
|
||||
}
|
||||
|
||||
// Valid tag values for LaunchEmptyResult
|
||||
const (
|
||||
LaunchEmptyResultComplete = "complete"
|
||||
)
|
||||
|
||||
// PollArg : Arguments for methods that poll the status of an asynchronous job.
|
||||
type PollArg struct {
|
||||
// AsyncJobId : Id of the asynchronous job. This is the value of a response
|
||||
// returned from the method that launched the job.
|
||||
AsyncJobId string `json:"async_job_id"`
|
||||
}
|
||||
|
||||
// NewPollArg returns a new PollArg instance
|
||||
func NewPollArg(AsyncJobId string) *PollArg {
|
||||
s := new(PollArg)
|
||||
s.AsyncJobId = AsyncJobId
|
||||
return s
|
||||
}
|
||||
|
||||
// PollResultBase : Result returned by methods that poll for the status of an
|
||||
// asynchronous job. Unions that extend this union should add a 'complete' field
|
||||
// with a type of the information returned upon job completion. See
|
||||
// `PollEmptyResult` for an example.
|
||||
type PollResultBase struct {
|
||||
dropbox.Tagged
|
||||
}
|
||||
|
||||
// Valid tag values for PollResultBase
|
||||
const (
|
||||
PollResultBaseInProgress = "in_progress"
|
||||
)
|
||||
|
||||
// PollEmptyResult : Result returned by methods that poll for the status of an
|
||||
// asynchronous job. Upon completion of the job, no additional information is
|
||||
// returned.
|
||||
type PollEmptyResult struct {
|
||||
dropbox.Tagged
|
||||
}
|
||||
|
||||
// Valid tag values for PollEmptyResult
|
||||
const (
|
||||
PollEmptyResultComplete = "complete"
|
||||
)
|
||||
|
||||
// PollError : Error returned by methods for polling the status of asynchronous
|
||||
// job.
|
||||
type PollError struct {
|
||||
dropbox.Tagged
|
||||
}
|
||||
|
||||
// Valid tag values for PollError
|
||||
const (
|
||||
PollErrorInvalidAsyncJobId = "invalid_async_job_id"
|
||||
PollErrorInternalError = "internal_error"
|
||||
PollErrorOther = "other"
|
||||
)
|
193
vendor/github.com/ncw/dropbox-sdk-go-unofficial/dropbox/auth/client.go
generated
vendored
193
vendor/github.com/ncw/dropbox-sdk-go-unofficial/dropbox/auth/client.go
generated
vendored
@ -1,193 +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 auth
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/ncw/dropbox-sdk-go-unofficial/dropbox"
|
||||
)
|
||||
|
||||
// Client interface describes all routes in this namespace
|
||||
type Client interface {
|
||||
// TokenFromOauth1 : Creates an OAuth 2.0 access token from the supplied
|
||||
// OAuth 1.0 access token.
|
||||
TokenFromOauth1(arg *TokenFromOAuth1Arg) (res *TokenFromOAuth1Result, err error)
|
||||
// TokenRevoke : Disables the access token used to authenticate the call.
|
||||
TokenRevoke() (err error)
|
||||
}
|
||||
|
||||
type apiImpl dropbox.Context
|
||||
|
||||
//TokenFromOauth1APIError is an error-wrapper for the token/from_oauth1 route
|
||||
type TokenFromOauth1APIError struct {
|
||||
dropbox.APIError
|
||||
EndpointError *TokenFromOAuth1Error `json:"error"`
|
||||
}
|
||||
|
||||
func (dbx *apiImpl) TokenFromOauth1(arg *TokenFromOAuth1Arg) (res *TokenFromOAuth1Result, err error) {
|
||||
cli := dbx.Client
|
||||
|
||||
if dbx.Config.Verbose {
|
||||
log.Printf("arg: %v", arg)
|
||||
}
|
||||
b, err := json.Marshal(arg)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
headers := map[string]string{
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
if dbx.Config.AsMemberID != "" {
|
||||
headers["Dropbox-API-Select-User"] = dbx.Config.AsMemberID
|
||||
}
|
||||
|
||||
req, err := (*dropbox.Context)(dbx).NewRequest("api", "rpc", true, "auth", "token/from_oauth1", headers, bytes.NewReader(b))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if dbx.Config.Verbose {
|
||||
log.Printf("req: %v", req)
|
||||
}
|
||||
|
||||
resp, err := cli.Do(req)
|
||||
if dbx.Config.Verbose {
|
||||
log.Printf("resp: %v", resp)
|
||||
}
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if dbx.Config.Verbose {
|
||||
log.Printf("body: %s", body)
|
||||
}
|
||||
if resp.StatusCode == http.StatusOK {
|
||||
err = json.Unmarshal(body, &res)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
if resp.StatusCode == http.StatusConflict {
|
||||
var apiError TokenFromOauth1APIError
|
||||
err = json.Unmarshal(body, &apiError)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = apiError
|
||||
return
|
||||
}
|
||||
var apiError dropbox.APIError
|
||||
if resp.StatusCode == http.StatusBadRequest {
|
||||
apiError.ErrorSummary = string(body)
|
||||
err = apiError
|
||||
return
|
||||
}
|
||||
err = json.Unmarshal(body, &apiError)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = apiError
|
||||
return
|
||||
}
|
||||
|
||||
//TokenRevokeAPIError is an error-wrapper for the token/revoke route
|
||||
type TokenRevokeAPIError struct {
|
||||
dropbox.APIError
|
||||
EndpointError struct{} `json:"error"`
|
||||
}
|
||||
|
||||
func (dbx *apiImpl) TokenRevoke() (err error) {
|
||||
cli := dbx.Client
|
||||
|
||||
headers := map[string]string{}
|
||||
if dbx.Config.AsMemberID != "" {
|
||||
headers["Dropbox-API-Select-User"] = dbx.Config.AsMemberID
|
||||
}
|
||||
|
||||
req, err := (*dropbox.Context)(dbx).NewRequest("api", "rpc", true, "auth", "token/revoke", headers, nil)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if dbx.Config.Verbose {
|
||||
log.Printf("req: %v", req)
|
||||
}
|
||||
|
||||
resp, err := cli.Do(req)
|
||||
if dbx.Config.Verbose {
|
||||
log.Printf("resp: %v", resp)
|
||||
}
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if dbx.Config.Verbose {
|
||||
log.Printf("body: %s", body)
|
||||
}
|
||||
if resp.StatusCode == http.StatusOK {
|
||||
return
|
||||
}
|
||||
if resp.StatusCode == http.StatusConflict {
|
||||
var apiError TokenRevokeAPIError
|
||||
err = json.Unmarshal(body, &apiError)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = apiError
|
||||
return
|
||||
}
|
||||
var apiError dropbox.APIError
|
||||
if resp.StatusCode == http.StatusBadRequest {
|
||||
apiError.ErrorSummary = string(body)
|
||||
err = apiError
|
||||
return
|
||||
}
|
||||
err = json.Unmarshal(body, &apiError)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = apiError
|
||||
return
|
||||
}
|
||||
|
||||
// New returns a Client implementation for this namespace
|
||||
func New(c dropbox.Config) *apiImpl {
|
||||
ctx := apiImpl(dropbox.NewContext(c))
|
||||
return &ctx
|
||||
}
|
187
vendor/github.com/ncw/dropbox-sdk-go-unofficial/dropbox/auth/types.go
generated
vendored
187
vendor/github.com/ncw/dropbox-sdk-go-unofficial/dropbox/auth/types.go
generated
vendored
@ -1,187 +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 auth : has no documentation (yet)
|
||||
package auth
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/ncw/dropbox-sdk-go-unofficial/dropbox"
|
||||
)
|
||||
|
||||
// AccessError : Error occurred because the account doesn't have permission to
|
||||
// access the resource.
|
||||
type AccessError struct {
|
||||
dropbox.Tagged
|
||||
// InvalidAccountType : Current account type cannot access the resource.
|
||||
InvalidAccountType *InvalidAccountTypeError `json:"invalid_account_type,omitempty"`
|
||||
// PaperAccessDenied : Current account cannot access Paper.
|
||||
PaperAccessDenied *PaperAccessError `json:"paper_access_denied,omitempty"`
|
||||
}
|
||||
|
||||
// Valid tag values for AccessError
|
||||
const (
|
||||
AccessErrorInvalidAccountType = "invalid_account_type"
|
||||
AccessErrorPaperAccessDenied = "paper_access_denied"
|
||||
AccessErrorOther = "other"
|
||||
)
|
||||
|
||||
// UnmarshalJSON deserializes into a AccessError instance
|
||||
func (u *AccessError) UnmarshalJSON(body []byte) error {
|
||||
type wrap struct {
|
||||
dropbox.Tagged
|
||||
// InvalidAccountType : Current account type cannot access the resource.
|
||||
InvalidAccountType json.RawMessage `json:"invalid_account_type,omitempty"`
|
||||
// PaperAccessDenied : Current account cannot access Paper.
|
||||
PaperAccessDenied json.RawMessage `json:"paper_access_denied,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 "invalid_account_type":
|
||||
err = json.Unmarshal(w.InvalidAccountType, &u.InvalidAccountType)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
case "paper_access_denied":
|
||||
err = json.Unmarshal(w.PaperAccessDenied, &u.PaperAccessDenied)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// AuthError : Errors occurred during authentication.
|
||||
type AuthError struct {
|
||||
dropbox.Tagged
|
||||
}
|
||||
|
||||
// Valid tag values for AuthError
|
||||
const (
|
||||
AuthErrorInvalidAccessToken = "invalid_access_token"
|
||||
AuthErrorInvalidSelectUser = "invalid_select_user"
|
||||
AuthErrorInvalidSelectAdmin = "invalid_select_admin"
|
||||
AuthErrorUserSuspended = "user_suspended"
|
||||
AuthErrorOther = "other"
|
||||
)
|
||||
|
||||
// InvalidAccountTypeError : has no documentation (yet)
|
||||
type InvalidAccountTypeError struct {
|
||||
dropbox.Tagged
|
||||
}
|
||||
|
||||
// Valid tag values for InvalidAccountTypeError
|
||||
const (
|
||||
InvalidAccountTypeErrorEndpoint = "endpoint"
|
||||
InvalidAccountTypeErrorFeature = "feature"
|
||||
InvalidAccountTypeErrorOther = "other"
|
||||
)
|
||||
|
||||
// PaperAccessError : has no documentation (yet)
|
||||
type PaperAccessError struct {
|
||||
dropbox.Tagged
|
||||
}
|
||||
|
||||
// Valid tag values for PaperAccessError
|
||||
const (
|
||||
PaperAccessErrorPaperDisabled = "paper_disabled"
|
||||
PaperAccessErrorNotPaperUser = "not_paper_user"
|
||||
PaperAccessErrorOther = "other"
|
||||
)
|
||||
|
||||
// RateLimitError : Error occurred because the app is being rate limited.
|
||||
type RateLimitError struct {
|
||||
// Reason : The reason why the app is being rate limited.
|
||||
Reason *RateLimitReason `json:"reason"`
|
||||
// RetryAfter : The number of seconds that the app should wait before making
|
||||
// another request.
|
||||
RetryAfter uint64 `json:"retry_after"`
|
||||
}
|
||||
|
||||
// NewRateLimitError returns a new RateLimitError instance
|
||||
func NewRateLimitError(Reason *RateLimitReason) *RateLimitError {
|
||||
s := new(RateLimitError)
|
||||
s.Reason = Reason
|
||||
s.RetryAfter = 1
|
||||
return s
|
||||
}
|
||||
|
||||
// RateLimitReason : has no documentation (yet)
|
||||
type RateLimitReason struct {
|
||||
dropbox.Tagged
|
||||
}
|
||||
|
||||
// Valid tag values for RateLimitReason
|
||||
const (
|
||||
RateLimitReasonTooManyRequests = "too_many_requests"
|
||||
RateLimitReasonTooManyWriteOperations = "too_many_write_operations"
|
||||
RateLimitReasonOther = "other"
|
||||
)
|
||||
|
||||
// TokenFromOAuth1Arg : has no documentation (yet)
|
||||
type TokenFromOAuth1Arg struct {
|
||||
// Oauth1Token : The supplied OAuth 1.0 access token.
|
||||
Oauth1Token string `json:"oauth1_token"`
|
||||
// Oauth1TokenSecret : The token secret associated with the supplied access
|
||||
// token.
|
||||
Oauth1TokenSecret string `json:"oauth1_token_secret"`
|
||||
}
|
||||
|
||||
// NewTokenFromOAuth1Arg returns a new TokenFromOAuth1Arg instance
|
||||
func NewTokenFromOAuth1Arg(Oauth1Token string, Oauth1TokenSecret string) *TokenFromOAuth1Arg {
|
||||
s := new(TokenFromOAuth1Arg)
|
||||
s.Oauth1Token = Oauth1Token
|
||||
s.Oauth1TokenSecret = Oauth1TokenSecret
|
||||
return s
|
||||
}
|
||||
|
||||
// TokenFromOAuth1Error : has no documentation (yet)
|
||||
type TokenFromOAuth1Error struct {
|
||||
dropbox.Tagged
|
||||
}
|
||||
|
||||
// Valid tag values for TokenFromOAuth1Error
|
||||
const (
|
||||
TokenFromOAuth1ErrorInvalidOauth1TokenInfo = "invalid_oauth1_token_info"
|
||||
TokenFromOAuth1ErrorAppIdMismatch = "app_id_mismatch"
|
||||
TokenFromOAuth1ErrorOther = "other"
|
||||
)
|
||||
|
||||
// TokenFromOAuth1Result : has no documentation (yet)
|
||||
type TokenFromOAuth1Result struct {
|
||||
// Oauth2Token : The OAuth 2.0 token generated from the supplied OAuth 1.0
|
||||
// token.
|
||||
Oauth2Token string `json:"oauth2_token"`
|
||||
}
|
||||
|
||||
// NewTokenFromOAuth1Result returns a new TokenFromOAuth1Result instance
|
||||
func NewTokenFromOAuth1Result(Oauth2Token string) *TokenFromOAuth1Result {
|
||||
s := new(TokenFromOAuth1Result)
|
||||
s.Oauth2Token = Oauth2Token
|
||||
return s
|
||||
}
|
132
vendor/github.com/ncw/dropbox-sdk-go-unofficial/dropbox/common/types.go
generated
vendored
132
vendor/github.com/ncw/dropbox-sdk-go-unofficial/dropbox/common/types.go
generated
vendored
@ -1,132 +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 common : has no documentation (yet)
|
||||
package common
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/ncw/dropbox-sdk-go-unofficial/dropbox"
|
||||
)
|
||||
|
||||
// InvalidPathRootError : has no documentation (yet)
|
||||
type InvalidPathRootError struct {
|
||||
// PathRoot : The latest path root id for user's team if the user is still
|
||||
// in a team.
|
||||
PathRoot string `json:"path_root,omitempty"`
|
||||
}
|
||||
|
||||
// NewInvalidPathRootError returns a new InvalidPathRootError instance
|
||||
func NewInvalidPathRootError() *InvalidPathRootError {
|
||||
s := new(InvalidPathRootError)
|
||||
return s
|
||||
}
|
||||
|
||||
// PathRoot : has no documentation (yet)
|
||||
type PathRoot struct {
|
||||
dropbox.Tagged
|
||||
// Team : Paths are relative to the given team directory. (This results in
|
||||
// `PathRootError.invalid` if the user is not a member of the team
|
||||
// associated with that path root id.)
|
||||
Team string `json:"team,omitempty"`
|
||||
// SharedFolder : Paths are relative to given shared folder id (This results
|
||||
// in `PathRootError.no_permission` if you don't have access to this shared
|
||||
// folder.)
|
||||
SharedFolder string `json:"shared_folder,omitempty"`
|
||||
}
|
||||
|
||||
// Valid tag values for PathRoot
|
||||
const (
|
||||
PathRootHome = "home"
|
||||
PathRootMemberHome = "member_home"
|
||||
PathRootTeam = "team"
|
||||
PathRootUserHome = "user_home"
|
||||
PathRootSharedFolder = "shared_folder"
|
||||
PathRootOther = "other"
|
||||
)
|
||||
|
||||
// UnmarshalJSON deserializes into a PathRoot instance
|
||||
func (u *PathRoot) UnmarshalJSON(body []byte) error {
|
||||
type wrap struct {
|
||||
dropbox.Tagged
|
||||
}
|
||||
var w wrap
|
||||
var err error
|
||||
if err = json.Unmarshal(body, &w); err != nil {
|
||||
return err
|
||||
}
|
||||
u.Tag = w.Tag
|
||||
switch u.Tag {
|
||||
case "team":
|
||||
err = json.Unmarshal(body, &u.Team)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
case "shared_folder":
|
||||
err = json.Unmarshal(body, &u.SharedFolder)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// PathRootError : has no documentation (yet)
|
||||
type PathRootError struct {
|
||||
dropbox.Tagged
|
||||
// Invalid : The path root id value in Dropbox-API-Path-Root header is no
|
||||
// longer valid.
|
||||
Invalid *InvalidPathRootError `json:"invalid,omitempty"`
|
||||
}
|
||||
|
||||
// Valid tag values for PathRootError
|
||||
const (
|
||||
PathRootErrorInvalid = "invalid"
|
||||
PathRootErrorNoPermission = "no_permission"
|
||||
PathRootErrorOther = "other"
|
||||
)
|
||||
|
||||
// UnmarshalJSON deserializes into a PathRootError instance
|
||||
func (u *PathRootError) UnmarshalJSON(body []byte) error {
|
||||
type wrap struct {
|
||||
dropbox.Tagged
|
||||
// Invalid : The path root id value in Dropbox-API-Path-Root header is
|
||||
// no longer valid.
|
||||
Invalid json.RawMessage `json:"invalid,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 "invalid":
|
||||
err = json.Unmarshal(body, &u.Invalid)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
3614
vendor/github.com/ncw/dropbox-sdk-go-unofficial/dropbox/files/client.go
generated
vendored
3614
vendor/github.com/ncw/dropbox-sdk-go-unofficial/dropbox/files/client.go
generated
vendored
File diff suppressed because it is too large
Load Diff
75
vendor/github.com/ncw/dropbox-sdk-go-unofficial/dropbox/files/metadata.go
generated
vendored
75
vendor/github.com/ncw/dropbox-sdk-go-unofficial/dropbox/files/metadata.go
generated
vendored
@ -1,75 +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 []metadataUnion `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 {
|
||||
switch e.Tag {
|
||||
case "file":
|
||||
r.Entries[i] = e.File
|
||||
case "folder":
|
||||
r.Entries[i] = e.Folder
|
||||
case "deleted":
|
||||
r.Entries[i] = e.Deleted
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type searchMatch struct {
|
||||
MatchType *SearchMatchType `json:"match_type"`
|
||||
Metadata metadataUnion `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
|
||||
e := m.Metadata
|
||||
switch e.Tag {
|
||||
case "file":
|
||||
s.Metadata = e.File
|
||||
case "folder":
|
||||
s.Metadata = e.Folder
|
||||
case "deleted":
|
||||
s.Metadata = e.Deleted
|
||||
}
|
||||
return nil
|
||||
}
|
2983
vendor/github.com/ncw/dropbox-sdk-go-unofficial/dropbox/files/types.go
generated
vendored
2983
vendor/github.com/ncw/dropbox-sdk-go-unofficial/dropbox/files/types.go
generated
vendored
File diff suppressed because it is too large
Load Diff
1199
vendor/github.com/ncw/dropbox-sdk-go-unofficial/dropbox/paper/client.go
generated
vendored
1199
vendor/github.com/ncw/dropbox-sdk-go-unofficial/dropbox/paper/client.go
generated
vendored
File diff suppressed because it is too large
Load Diff
729
vendor/github.com/ncw/dropbox-sdk-go-unofficial/dropbox/paper/types.go
generated
vendored
729
vendor/github.com/ncw/dropbox-sdk-go-unofficial/dropbox/paper/types.go
generated
vendored
@ -1,729 +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 paper : This namespace contains endpoints and data types for managing
|
||||
// docs and folders in Dropbox Paper.
|
||||
package paper
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"github.com/ncw/dropbox-sdk-go-unofficial/dropbox"
|
||||
"github.com/ncw/dropbox-sdk-go-unofficial/dropbox/sharing"
|
||||
)
|
||||
|
||||
// AddMember : has no documentation (yet)
|
||||
type AddMember struct {
|
||||
// PermissionLevel : Permission for the user.
|
||||
PermissionLevel *PaperDocPermissionLevel `json:"permission_level"`
|
||||
// Member : User which should be added to the Paper doc. Specify only email
|
||||
// address or Dropbox account ID.
|
||||
Member *sharing.MemberSelector `json:"member"`
|
||||
}
|
||||
|
||||
// NewAddMember returns a new AddMember instance
|
||||
func NewAddMember(Member *sharing.MemberSelector) *AddMember {
|
||||
s := new(AddMember)
|
||||
s.Member = Member
|
||||
s.PermissionLevel = &PaperDocPermissionLevel{Tagged: dropbox.Tagged{"edit"}}
|
||||
return s
|
||||
}
|
||||
|
||||
// RefPaperDoc : has no documentation (yet)
|
||||
type RefPaperDoc struct {
|
||||
// DocId : The Paper doc ID.
|
||||
DocId string `json:"doc_id"`
|
||||
}
|
||||
|
||||
// NewRefPaperDoc returns a new RefPaperDoc instance
|
||||
func NewRefPaperDoc(DocId string) *RefPaperDoc {
|
||||
s := new(RefPaperDoc)
|
||||
s.DocId = DocId
|
||||
return s
|
||||
}
|
||||
|
||||
// AddPaperDocUser : has no documentation (yet)
|
||||
type AddPaperDocUser struct {
|
||||
RefPaperDoc
|
||||
// Members : User which should be added to the Paper doc. Specify only email
|
||||
// address or Dropbox account ID.
|
||||
Members []*AddMember `json:"members"`
|
||||
// CustomMessage : A personal message that will be emailed to each
|
||||
// successfully added member.
|
||||
CustomMessage string `json:"custom_message,omitempty"`
|
||||
// Quiet : Clients should set this to true if no email message shall be sent
|
||||
// to added users.
|
||||
Quiet bool `json:"quiet"`
|
||||
}
|
||||
|
||||
// NewAddPaperDocUser returns a new AddPaperDocUser instance
|
||||
func NewAddPaperDocUser(DocId string, Members []*AddMember) *AddPaperDocUser {
|
||||
s := new(AddPaperDocUser)
|
||||
s.DocId = DocId
|
||||
s.Members = Members
|
||||
s.Quiet = false
|
||||
return s
|
||||
}
|
||||
|
||||
// AddPaperDocUserMemberResult : Per-member result for `docsUsersAdd`.
|
||||
type AddPaperDocUserMemberResult struct {
|
||||
// Member : One of specified input members.
|
||||
Member *sharing.MemberSelector `json:"member"`
|
||||
// Result : The outcome of the action on this member.
|
||||
Result *AddPaperDocUserResult `json:"result"`
|
||||
}
|
||||
|
||||
// NewAddPaperDocUserMemberResult returns a new AddPaperDocUserMemberResult instance
|
||||
func NewAddPaperDocUserMemberResult(Member *sharing.MemberSelector, Result *AddPaperDocUserResult) *AddPaperDocUserMemberResult {
|
||||
s := new(AddPaperDocUserMemberResult)
|
||||
s.Member = Member
|
||||
s.Result = Result
|
||||
return s
|
||||
}
|
||||
|
||||
// AddPaperDocUserResult : has no documentation (yet)
|
||||
type AddPaperDocUserResult struct {
|
||||
dropbox.Tagged
|
||||
}
|
||||
|
||||
// Valid tag values for AddPaperDocUserResult
|
||||
const (
|
||||
AddPaperDocUserResultSuccess = "success"
|
||||
AddPaperDocUserResultUnknownError = "unknown_error"
|
||||
AddPaperDocUserResultSharingOutsideTeamDisabled = "sharing_outside_team_disabled"
|
||||
AddPaperDocUserResultDailyLimitReached = "daily_limit_reached"
|
||||
AddPaperDocUserResultUserIsOwner = "user_is_owner"
|
||||
AddPaperDocUserResultFailedUserDataRetrieval = "failed_user_data_retrieval"
|
||||
AddPaperDocUserResultPermissionAlreadyGranted = "permission_already_granted"
|
||||
AddPaperDocUserResultOther = "other"
|
||||
)
|
||||
|
||||
// Cursor : has no documentation (yet)
|
||||
type Cursor struct {
|
||||
// Value : The actual cursor value.
|
||||
Value string `json:"value"`
|
||||
// Expiration : Expiration time of `value`. Some cursors might have
|
||||
// expiration time assigned. This is a UTC value after which the cursor is
|
||||
// no longer valid and the API starts returning an error. If cursor expires
|
||||
// a new one needs to be obtained and pagination needs to be restarted. Some
|
||||
// cursors might be short-lived some cursors might be long-lived. This
|
||||
// really depends on the sorting type and order, e.g.: 1. on one hand,
|
||||
// listing docs created by the user, sorted by the created time ascending
|
||||
// will have undefinite expiration because the results cannot change while
|
||||
// the iteration is happening. This cursor would be suitable for long term
|
||||
// polling. 2. on the other hand, listing docs sorted by the last modified
|
||||
// time will have a very short expiration as docs do get modified very often
|
||||
// and the modified time can be changed while the iteration is happening
|
||||
// thus altering the results.
|
||||
Expiration time.Time `json:"expiration,omitempty"`
|
||||
}
|
||||
|
||||
// NewCursor returns a new Cursor instance
|
||||
func NewCursor(Value string) *Cursor {
|
||||
s := new(Cursor)
|
||||
s.Value = Value
|
||||
return s
|
||||
}
|
||||
|
||||
// PaperApiBaseError : has no documentation (yet)
|
||||
type PaperApiBaseError struct {
|
||||
dropbox.Tagged
|
||||
}
|
||||
|
||||
// Valid tag values for PaperApiBaseError
|
||||
const (
|
||||
PaperApiBaseErrorInsufficientPermissions = "insufficient_permissions"
|
||||
PaperApiBaseErrorOther = "other"
|
||||
)
|
||||
|
||||
// DocLookupError : has no documentation (yet)
|
||||
type DocLookupError struct {
|
||||
dropbox.Tagged
|
||||
}
|
||||
|
||||
// Valid tag values for DocLookupError
|
||||
const (
|
||||
DocLookupErrorDocNotFound = "doc_not_found"
|
||||
)
|
||||
|
||||
// DocSubscriptionLevel : The subscription level of a Paper doc.
|
||||
type DocSubscriptionLevel struct {
|
||||
dropbox.Tagged
|
||||
}
|
||||
|
||||
// Valid tag values for DocSubscriptionLevel
|
||||
const (
|
||||
DocSubscriptionLevelDefault = "default"
|
||||
DocSubscriptionLevelIgnore = "ignore"
|
||||
DocSubscriptionLevelEvery = "every"
|
||||
DocSubscriptionLevelNoEmail = "no_email"
|
||||
)
|
||||
|
||||
// ExportFormat : The desired export format of the Paper doc.
|
||||
type ExportFormat struct {
|
||||
dropbox.Tagged
|
||||
}
|
||||
|
||||
// Valid tag values for ExportFormat
|
||||
const (
|
||||
ExportFormatHtml = "html"
|
||||
ExportFormatMarkdown = "markdown"
|
||||
ExportFormatOther = "other"
|
||||
)
|
||||
|
||||
// Folder : Data structure representing a Paper folder.
|
||||
type Folder struct {
|
||||
// Id : Paper folder ID. This ID uniquely identifies the folder.
|
||||
Id string `json:"id"`
|
||||
// Name : Paper folder name.
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
// NewFolder returns a new Folder instance
|
||||
func NewFolder(Id string, Name string) *Folder {
|
||||
s := new(Folder)
|
||||
s.Id = Id
|
||||
s.Name = Name
|
||||
return s
|
||||
}
|
||||
|
||||
// FolderSharingPolicyType : The sharing policy of a Paper folder. Note: The
|
||||
// sharing policy of subfolders is inherited from the root folder.
|
||||
type FolderSharingPolicyType struct {
|
||||
dropbox.Tagged
|
||||
}
|
||||
|
||||
// Valid tag values for FolderSharingPolicyType
|
||||
const (
|
||||
FolderSharingPolicyTypeTeam = "team"
|
||||
FolderSharingPolicyTypeInviteOnly = "invite_only"
|
||||
)
|
||||
|
||||
// FolderSubscriptionLevel : The subscription level of a Paper folder.
|
||||
type FolderSubscriptionLevel struct {
|
||||
dropbox.Tagged
|
||||
}
|
||||
|
||||
// Valid tag values for FolderSubscriptionLevel
|
||||
const (
|
||||
FolderSubscriptionLevelNone = "none"
|
||||
FolderSubscriptionLevelActivityOnly = "activity_only"
|
||||
FolderSubscriptionLevelDailyEmails = "daily_emails"
|
||||
FolderSubscriptionLevelWeeklyEmails = "weekly_emails"
|
||||
)
|
||||
|
||||
// FoldersContainingPaperDoc : Metadata about Paper folders containing the
|
||||
// specififed Paper doc.
|
||||
type FoldersContainingPaperDoc struct {
|
||||
// FolderSharingPolicyType : The sharing policy of the folder containing the
|
||||
// Paper doc.
|
||||
FolderSharingPolicyType *FolderSharingPolicyType `json:"folder_sharing_policy_type,omitempty"`
|
||||
// Folders : The folder path. If present the first folder is the root
|
||||
// folder.
|
||||
Folders []*Folder `json:"folders,omitempty"`
|
||||
}
|
||||
|
||||
// NewFoldersContainingPaperDoc returns a new FoldersContainingPaperDoc instance
|
||||
func NewFoldersContainingPaperDoc() *FoldersContainingPaperDoc {
|
||||
s := new(FoldersContainingPaperDoc)
|
||||
return s
|
||||
}
|
||||
|
||||
// InviteeInfoWithPermissionLevel : has no documentation (yet)
|
||||
type InviteeInfoWithPermissionLevel struct {
|
||||
// Invitee : Email address invited to the Paper doc.
|
||||
Invitee *sharing.InviteeInfo `json:"invitee"`
|
||||
// PermissionLevel : Permission level for the invitee.
|
||||
PermissionLevel *PaperDocPermissionLevel `json:"permission_level"`
|
||||
}
|
||||
|
||||
// NewInviteeInfoWithPermissionLevel returns a new InviteeInfoWithPermissionLevel instance
|
||||
func NewInviteeInfoWithPermissionLevel(Invitee *sharing.InviteeInfo, PermissionLevel *PaperDocPermissionLevel) *InviteeInfoWithPermissionLevel {
|
||||
s := new(InviteeInfoWithPermissionLevel)
|
||||
s.Invitee = Invitee
|
||||
s.PermissionLevel = PermissionLevel
|
||||
return s
|
||||
}
|
||||
|
||||
// ListDocsCursorError : has no documentation (yet)
|
||||
type ListDocsCursorError struct {
|
||||
dropbox.Tagged
|
||||
// CursorError : has no documentation (yet)
|
||||
CursorError *PaperApiCursorError `json:"cursor_error,omitempty"`
|
||||
}
|
||||
|
||||
// Valid tag values for ListDocsCursorError
|
||||
const (
|
||||
ListDocsCursorErrorCursorError = "cursor_error"
|
||||
ListDocsCursorErrorOther = "other"
|
||||
)
|
||||
|
||||
// UnmarshalJSON deserializes into a ListDocsCursorError instance
|
||||
func (u *ListDocsCursorError) UnmarshalJSON(body []byte) error {
|
||||
type wrap struct {
|
||||
dropbox.Tagged
|
||||
// CursorError : has no documentation (yet)
|
||||
CursorError json.RawMessage `json:"cursor_error,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 "cursor_error":
|
||||
err = json.Unmarshal(w.CursorError, &u.CursorError)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ListPaperDocsArgs : has no documentation (yet)
|
||||
type ListPaperDocsArgs struct {
|
||||
// FilterBy : Allows user to specify how the Paper docs should be filtered.
|
||||
FilterBy *ListPaperDocsFilterBy `json:"filter_by"`
|
||||
// SortBy : Allows user to specify how the Paper docs should be sorted.
|
||||
SortBy *ListPaperDocsSortBy `json:"sort_by"`
|
||||
// SortOrder : Allows user to specify the sort order of the result.
|
||||
SortOrder *ListPaperDocsSortOrder `json:"sort_order"`
|
||||
// Limit : Size limit per batch. The maximum number of docs that can be
|
||||
// retrieved per batch is 1000. Higher value results in invalid arguments
|
||||
// error.
|
||||
Limit int32 `json:"limit"`
|
||||
}
|
||||
|
||||
// NewListPaperDocsArgs returns a new ListPaperDocsArgs instance
|
||||
func NewListPaperDocsArgs() *ListPaperDocsArgs {
|
||||
s := new(ListPaperDocsArgs)
|
||||
s.FilterBy = &ListPaperDocsFilterBy{Tagged: dropbox.Tagged{"docs_accessed"}}
|
||||
s.SortBy = &ListPaperDocsSortBy{Tagged: dropbox.Tagged{"accessed"}}
|
||||
s.SortOrder = &ListPaperDocsSortOrder{Tagged: dropbox.Tagged{"ascending"}}
|
||||
s.Limit = 1000
|
||||
return s
|
||||
}
|
||||
|
||||
// ListPaperDocsContinueArgs : has no documentation (yet)
|
||||
type ListPaperDocsContinueArgs struct {
|
||||
// Cursor : The cursor obtained from `docsList` or `docsListContinue`.
|
||||
// Allows for pagination.
|
||||
Cursor string `json:"cursor"`
|
||||
}
|
||||
|
||||
// NewListPaperDocsContinueArgs returns a new ListPaperDocsContinueArgs instance
|
||||
func NewListPaperDocsContinueArgs(Cursor string) *ListPaperDocsContinueArgs {
|
||||
s := new(ListPaperDocsContinueArgs)
|
||||
s.Cursor = Cursor
|
||||
return s
|
||||
}
|
||||
|
||||
// ListPaperDocsFilterBy : has no documentation (yet)
|
||||
type ListPaperDocsFilterBy struct {
|
||||
dropbox.Tagged
|
||||
}
|
||||
|
||||
// Valid tag values for ListPaperDocsFilterBy
|
||||
const (
|
||||
ListPaperDocsFilterByDocsAccessed = "docs_accessed"
|
||||
ListPaperDocsFilterByDocsCreated = "docs_created"
|
||||
ListPaperDocsFilterByOther = "other"
|
||||
)
|
||||
|
||||
// ListPaperDocsResponse : has no documentation (yet)
|
||||
type ListPaperDocsResponse struct {
|
||||
// DocIds : The list of Paper doc IDs that can be used to access the given
|
||||
// Paper docs or supplied to other API methods. The list is sorted in the
|
||||
// order specified by the initial call to `docsList`.
|
||||
DocIds []string `json:"doc_ids"`
|
||||
// Cursor : Pass the cursor into `docsListContinue` to paginate through all
|
||||
// files. The cursor preserves all properties as specified in the original
|
||||
// call to `docsList`.
|
||||
Cursor *Cursor `json:"cursor"`
|
||||
// HasMore : Will be set to True if a subsequent call with the provided
|
||||
// cursor to `docsListContinue` returns immediately with some results. If
|
||||
// set to False please allow some delay before making another call to
|
||||
// `docsListContinue`.
|
||||
HasMore bool `json:"has_more"`
|
||||
}
|
||||
|
||||
// NewListPaperDocsResponse returns a new ListPaperDocsResponse instance
|
||||
func NewListPaperDocsResponse(DocIds []string, Cursor *Cursor, HasMore bool) *ListPaperDocsResponse {
|
||||
s := new(ListPaperDocsResponse)
|
||||
s.DocIds = DocIds
|
||||
s.Cursor = Cursor
|
||||
s.HasMore = HasMore
|
||||
return s
|
||||
}
|
||||
|
||||
// ListPaperDocsSortBy : has no documentation (yet)
|
||||
type ListPaperDocsSortBy struct {
|
||||
dropbox.Tagged
|
||||
}
|
||||
|
||||
// Valid tag values for ListPaperDocsSortBy
|
||||
const (
|
||||
ListPaperDocsSortByAccessed = "accessed"
|
||||
ListPaperDocsSortByModified = "modified"
|
||||
ListPaperDocsSortByCreated = "created"
|
||||
ListPaperDocsSortByOther = "other"
|
||||
)
|
||||
|
||||
// ListPaperDocsSortOrder : has no documentation (yet)
|
||||
type ListPaperDocsSortOrder struct {
|
||||
dropbox.Tagged
|
||||
}
|
||||
|
||||
// Valid tag values for ListPaperDocsSortOrder
|
||||
const (
|
||||
ListPaperDocsSortOrderAscending = "ascending"
|
||||
ListPaperDocsSortOrderDescending = "descending"
|
||||
ListPaperDocsSortOrderOther = "other"
|
||||
)
|
||||
|
||||
// ListUsersCursorError : has no documentation (yet)
|
||||
type ListUsersCursorError struct {
|
||||
dropbox.Tagged
|
||||
// CursorError : has no documentation (yet)
|
||||
CursorError *PaperApiCursorError `json:"cursor_error,omitempty"`
|
||||
}
|
||||
|
||||
// Valid tag values for ListUsersCursorError
|
||||
const (
|
||||
ListUsersCursorErrorDocNotFound = "doc_not_found"
|
||||
ListUsersCursorErrorCursorError = "cursor_error"
|
||||
)
|
||||
|
||||
// UnmarshalJSON deserializes into a ListUsersCursorError instance
|
||||
func (u *ListUsersCursorError) UnmarshalJSON(body []byte) error {
|
||||
type wrap struct {
|
||||
dropbox.Tagged
|
||||
// CursorError : has no documentation (yet)
|
||||
CursorError json.RawMessage `json:"cursor_error,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 "cursor_error":
|
||||
err = json.Unmarshal(w.CursorError, &u.CursorError)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ListUsersOnFolderArgs : has no documentation (yet)
|
||||
type ListUsersOnFolderArgs struct {
|
||||
RefPaperDoc
|
||||
// Limit : Size limit per batch. The maximum number of users that can be
|
||||
// retrieved per batch is 1000. Higher value results in invalid arguments
|
||||
// error.
|
||||
Limit int32 `json:"limit"`
|
||||
}
|
||||
|
||||
// NewListUsersOnFolderArgs returns a new ListUsersOnFolderArgs instance
|
||||
func NewListUsersOnFolderArgs(DocId string) *ListUsersOnFolderArgs {
|
||||
s := new(ListUsersOnFolderArgs)
|
||||
s.DocId = DocId
|
||||
s.Limit = 1000
|
||||
return s
|
||||
}
|
||||
|
||||
// ListUsersOnFolderContinueArgs : has no documentation (yet)
|
||||
type ListUsersOnFolderContinueArgs struct {
|
||||
RefPaperDoc
|
||||
// Cursor : The cursor obtained from `docsFolderUsersList` or
|
||||
// `docsFolderUsersListContinue`. Allows for pagination.
|
||||
Cursor string `json:"cursor"`
|
||||
}
|
||||
|
||||
// NewListUsersOnFolderContinueArgs returns a new ListUsersOnFolderContinueArgs instance
|
||||
func NewListUsersOnFolderContinueArgs(DocId string, Cursor string) *ListUsersOnFolderContinueArgs {
|
||||
s := new(ListUsersOnFolderContinueArgs)
|
||||
s.DocId = DocId
|
||||
s.Cursor = Cursor
|
||||
return s
|
||||
}
|
||||
|
||||
// ListUsersOnFolderResponse : has no documentation (yet)
|
||||
type ListUsersOnFolderResponse struct {
|
||||
// Invitees : List of email addresses that are invited on the Paper folder.
|
||||
Invitees []*sharing.InviteeInfo `json:"invitees"`
|
||||
// Users : List of users that are invited on the Paper folder.
|
||||
Users []*sharing.UserInfo `json:"users"`
|
||||
// Cursor : Pass the cursor into `docsFolderUsersListContinue` to paginate
|
||||
// through all users. The cursor preserves all properties as specified in
|
||||
// the original call to `docsFolderUsersList`.
|
||||
Cursor *Cursor `json:"cursor"`
|
||||
// HasMore : Will be set to True if a subsequent call with the provided
|
||||
// cursor to `docsFolderUsersListContinue` returns immediately with some
|
||||
// results. If set to False please allow some delay before making another
|
||||
// call to `docsFolderUsersListContinue`.
|
||||
HasMore bool `json:"has_more"`
|
||||
}
|
||||
|
||||
// NewListUsersOnFolderResponse returns a new ListUsersOnFolderResponse instance
|
||||
func NewListUsersOnFolderResponse(Invitees []*sharing.InviteeInfo, Users []*sharing.UserInfo, Cursor *Cursor, HasMore bool) *ListUsersOnFolderResponse {
|
||||
s := new(ListUsersOnFolderResponse)
|
||||
s.Invitees = Invitees
|
||||
s.Users = Users
|
||||
s.Cursor = Cursor
|
||||
s.HasMore = HasMore
|
||||
return s
|
||||
}
|
||||
|
||||
// ListUsersOnPaperDocArgs : has no documentation (yet)
|
||||
type ListUsersOnPaperDocArgs struct {
|
||||
RefPaperDoc
|
||||
// Limit : Size limit per batch. The maximum number of users that can be
|
||||
// retrieved per batch is 1000. Higher value results in invalid arguments
|
||||
// error.
|
||||
Limit int32 `json:"limit"`
|
||||
// FilterBy : Specify this attribute if you want to obtain users that have
|
||||
// already accessed the Paper doc.
|
||||
FilterBy *UserOnPaperDocFilter `json:"filter_by"`
|
||||
}
|
||||
|
||||
// NewListUsersOnPaperDocArgs returns a new ListUsersOnPaperDocArgs instance
|
||||
func NewListUsersOnPaperDocArgs(DocId string) *ListUsersOnPaperDocArgs {
|
||||
s := new(ListUsersOnPaperDocArgs)
|
||||
s.DocId = DocId
|
||||
s.Limit = 1000
|
||||
s.FilterBy = &UserOnPaperDocFilter{Tagged: dropbox.Tagged{"shared"}}
|
||||
return s
|
||||
}
|
||||
|
||||
// ListUsersOnPaperDocContinueArgs : has no documentation (yet)
|
||||
type ListUsersOnPaperDocContinueArgs struct {
|
||||
RefPaperDoc
|
||||
// Cursor : The cursor obtained from `docsUsersList` or
|
||||
// `docsUsersListContinue`. Allows for pagination.
|
||||
Cursor string `json:"cursor"`
|
||||
}
|
||||
|
||||
// NewListUsersOnPaperDocContinueArgs returns a new ListUsersOnPaperDocContinueArgs instance
|
||||
func NewListUsersOnPaperDocContinueArgs(DocId string, Cursor string) *ListUsersOnPaperDocContinueArgs {
|
||||
s := new(ListUsersOnPaperDocContinueArgs)
|
||||
s.DocId = DocId
|
||||
s.Cursor = Cursor
|
||||
return s
|
||||
}
|
||||
|
||||
// ListUsersOnPaperDocResponse : has no documentation (yet)
|
||||
type ListUsersOnPaperDocResponse struct {
|
||||
// Invitees : List of email addresses with their respective permission
|
||||
// levels that are invited on the Paper doc.
|
||||
Invitees []*InviteeInfoWithPermissionLevel `json:"invitees"`
|
||||
// Users : List of users with their respective permission levels that are
|
||||
// invited on the Paper folder.
|
||||
Users []*UserInfoWithPermissionLevel `json:"users"`
|
||||
// DocOwner : The Paper doc owner. This field is populated on every single
|
||||
// response.
|
||||
DocOwner *sharing.UserInfo `json:"doc_owner"`
|
||||
// Cursor : Pass the cursor into `docsUsersListContinue` to paginate through
|
||||
// all users. The cursor preserves all properties as specified in the
|
||||
// original call to `docsUsersList`.
|
||||
Cursor *Cursor `json:"cursor"`
|
||||
// HasMore : Will be set to True if a subsequent call with the provided
|
||||
// cursor to `docsUsersListContinue` returns immediately with some results.
|
||||
// If set to False please allow some delay before making another call to
|
||||
// `docsUsersListContinue`.
|
||||
HasMore bool `json:"has_more"`
|
||||
}
|
||||
|
||||
// NewListUsersOnPaperDocResponse returns a new ListUsersOnPaperDocResponse instance
|
||||
func NewListUsersOnPaperDocResponse(Invitees []*InviteeInfoWithPermissionLevel, Users []*UserInfoWithPermissionLevel, DocOwner *sharing.UserInfo, Cursor *Cursor, HasMore bool) *ListUsersOnPaperDocResponse {
|
||||
s := new(ListUsersOnPaperDocResponse)
|
||||
s.Invitees = Invitees
|
||||
s.Users = Users
|
||||
s.DocOwner = DocOwner
|
||||
s.Cursor = Cursor
|
||||
s.HasMore = HasMore
|
||||
return s
|
||||
}
|
||||
|
||||
// PaperApiCursorError : has no documentation (yet)
|
||||
type PaperApiCursorError struct {
|
||||
dropbox.Tagged
|
||||
}
|
||||
|
||||
// Valid tag values for PaperApiCursorError
|
||||
const (
|
||||
PaperApiCursorErrorExpiredCursor = "expired_cursor"
|
||||
PaperApiCursorErrorInvalidCursor = "invalid_cursor"
|
||||
PaperApiCursorErrorWrongUserInCursor = "wrong_user_in_cursor"
|
||||
PaperApiCursorErrorReset = "reset"
|
||||
PaperApiCursorErrorOther = "other"
|
||||
)
|
||||
|
||||
// PaperDocExport : has no documentation (yet)
|
||||
type PaperDocExport struct {
|
||||
RefPaperDoc
|
||||
// ExportFormat : has no documentation (yet)
|
||||
ExportFormat *ExportFormat `json:"export_format"`
|
||||
}
|
||||
|
||||
// NewPaperDocExport returns a new PaperDocExport instance
|
||||
func NewPaperDocExport(DocId string, ExportFormat *ExportFormat) *PaperDocExport {
|
||||
s := new(PaperDocExport)
|
||||
s.DocId = DocId
|
||||
s.ExportFormat = ExportFormat
|
||||
return s
|
||||
}
|
||||
|
||||
// PaperDocExportResult : has no documentation (yet)
|
||||
type PaperDocExportResult struct {
|
||||
// Owner : The Paper doc owner's email address.
|
||||
Owner string `json:"owner"`
|
||||
// Title : The Paper doc title.
|
||||
Title string `json:"title"`
|
||||
// Revision : The Paper doc revision. Simply an ever increasing number.
|
||||
Revision int64 `json:"revision"`
|
||||
// MimeType : MIME type of the export. This corresponds to `ExportFormat`
|
||||
// specified in the request.
|
||||
MimeType string `json:"mime_type"`
|
||||
}
|
||||
|
||||
// NewPaperDocExportResult returns a new PaperDocExportResult instance
|
||||
func NewPaperDocExportResult(Owner string, Title string, Revision int64, MimeType string) *PaperDocExportResult {
|
||||
s := new(PaperDocExportResult)
|
||||
s.Owner = Owner
|
||||
s.Title = Title
|
||||
s.Revision = Revision
|
||||
s.MimeType = MimeType
|
||||
return s
|
||||
}
|
||||
|
||||
// PaperDocPermissionLevel : has no documentation (yet)
|
||||
type PaperDocPermissionLevel struct {
|
||||
dropbox.Tagged
|
||||
}
|
||||
|
||||
// Valid tag values for PaperDocPermissionLevel
|
||||
const (
|
||||
PaperDocPermissionLevelEdit = "edit"
|
||||
PaperDocPermissionLevelViewAndComment = "view_and_comment"
|
||||
PaperDocPermissionLevelOther = "other"
|
||||
)
|
||||
|
||||
// PaperDocSharingPolicy : has no documentation (yet)
|
||||
type PaperDocSharingPolicy struct {
|
||||
RefPaperDoc
|
||||
// SharingPolicy : The default sharing policy to be set for the Paper doc.
|
||||
SharingPolicy *SharingPolicy `json:"sharing_policy"`
|
||||
}
|
||||
|
||||
// NewPaperDocSharingPolicy returns a new PaperDocSharingPolicy instance
|
||||
func NewPaperDocSharingPolicy(DocId string, SharingPolicy *SharingPolicy) *PaperDocSharingPolicy {
|
||||
s := new(PaperDocSharingPolicy)
|
||||
s.DocId = DocId
|
||||
s.SharingPolicy = SharingPolicy
|
||||
return s
|
||||
}
|
||||
|
||||
// RemovePaperDocUser : has no documentation (yet)
|
||||
type RemovePaperDocUser struct {
|
||||
RefPaperDoc
|
||||
// Member : User which should be removed from the Paper doc. Specify only
|
||||
// email address or Dropbox account ID.
|
||||
Member *sharing.MemberSelector `json:"member"`
|
||||
}
|
||||
|
||||
// NewRemovePaperDocUser returns a new RemovePaperDocUser instance
|
||||
func NewRemovePaperDocUser(DocId string, Member *sharing.MemberSelector) *RemovePaperDocUser {
|
||||
s := new(RemovePaperDocUser)
|
||||
s.DocId = DocId
|
||||
s.Member = Member
|
||||
return s
|
||||
}
|
||||
|
||||
// SharingPolicy : Sharing policy of Paper doc.
|
||||
type SharingPolicy struct {
|
||||
// PublicSharingPolicy : This value applies to the non-team members.
|
||||
PublicSharingPolicy *SharingPublicPolicyType `json:"public_sharing_policy,omitempty"`
|
||||
// TeamSharingPolicy : This value applies to the team members only. The
|
||||
// value is null for all personal accounts.
|
||||
TeamSharingPolicy *SharingTeamPolicyType `json:"team_sharing_policy,omitempty"`
|
||||
}
|
||||
|
||||
// NewSharingPolicy returns a new SharingPolicy instance
|
||||
func NewSharingPolicy() *SharingPolicy {
|
||||
s := new(SharingPolicy)
|
||||
return s
|
||||
}
|
||||
|
||||
// SharingTeamPolicyType : The sharing policy type of the Paper doc.
|
||||
type SharingTeamPolicyType struct {
|
||||
dropbox.Tagged
|
||||
}
|
||||
|
||||
// Valid tag values for SharingTeamPolicyType
|
||||
const (
|
||||
SharingTeamPolicyTypePeopleWithLinkCanEdit = "people_with_link_can_edit"
|
||||
SharingTeamPolicyTypePeopleWithLinkCanViewAndComment = "people_with_link_can_view_and_comment"
|
||||
SharingTeamPolicyTypeInviteOnly = "invite_only"
|
||||
)
|
||||
|
||||
// SharingPublicPolicyType : has no documentation (yet)
|
||||
type SharingPublicPolicyType struct {
|
||||
dropbox.Tagged
|
||||
}
|
||||
|
||||
// Valid tag values for SharingPublicPolicyType
|
||||
const (
|
||||
SharingPublicPolicyTypeDisabled = "disabled"
|
||||
)
|
||||
|
||||
// UserInfoWithPermissionLevel : has no documentation (yet)
|
||||
type UserInfoWithPermissionLevel struct {
|
||||
// User : User shared on the Paper doc.
|
||||
User *sharing.UserInfo `json:"user"`
|
||||
// PermissionLevel : Permission level for the user.
|
||||
PermissionLevel *PaperDocPermissionLevel `json:"permission_level"`
|
||||
}
|
||||
|
||||
// NewUserInfoWithPermissionLevel returns a new UserInfoWithPermissionLevel instance
|
||||
func NewUserInfoWithPermissionLevel(User *sharing.UserInfo, PermissionLevel *PaperDocPermissionLevel) *UserInfoWithPermissionLevel {
|
||||
s := new(UserInfoWithPermissionLevel)
|
||||
s.User = User
|
||||
s.PermissionLevel = PermissionLevel
|
||||
return s
|
||||
}
|
||||
|
||||
// UserOnPaperDocFilter : has no documentation (yet)
|
||||
type UserOnPaperDocFilter struct {
|
||||
dropbox.Tagged
|
||||
}
|
||||
|
||||
// Valid tag values for UserOnPaperDocFilter
|
||||
const (
|
||||
UserOnPaperDocFilterVisited = "visited"
|
||||
UserOnPaperDocFilterShared = "shared"
|
||||
UserOnPaperDocFilterOther = "other"
|
||||
)
|
213
vendor/github.com/ncw/dropbox-sdk-go-unofficial/dropbox/properties/types.go
generated
vendored
213
vendor/github.com/ncw/dropbox-sdk-go-unofficial/dropbox/properties/types.go
generated
vendored
@ -1,213 +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 properties : This namespace contains helper entities for property and
|
||||
// property/template endpoints.
|
||||
package properties
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/ncw/dropbox-sdk-go-unofficial/dropbox"
|
||||
)
|
||||
|
||||
// GetPropertyTemplateArg : has no documentation (yet)
|
||||
type GetPropertyTemplateArg struct {
|
||||
// TemplateId : An identifier for property template added by route
|
||||
// properties/template/add.
|
||||
TemplateId string `json:"template_id"`
|
||||
}
|
||||
|
||||
// NewGetPropertyTemplateArg returns a new GetPropertyTemplateArg instance
|
||||
func NewGetPropertyTemplateArg(TemplateId string) *GetPropertyTemplateArg {
|
||||
s := new(GetPropertyTemplateArg)
|
||||
s.TemplateId = TemplateId
|
||||
return s
|
||||
}
|
||||
|
||||
// PropertyGroupTemplate : Describes property templates that can be filled and
|
||||
// associated with a file.
|
||||
type PropertyGroupTemplate struct {
|
||||
// Name : A display name for the property template. Property template names
|
||||
// can be up to 256 bytes.
|
||||
Name string `json:"name"`
|
||||
// Description : Description for new property template. Property template
|
||||
// descriptions can be up to 1024 bytes.
|
||||
Description string `json:"description"`
|
||||
// Fields : This is a list of custom properties associated with a property
|
||||
// template. There can be up to 64 properties in a single property template.
|
||||
Fields []*PropertyFieldTemplate `json:"fields"`
|
||||
}
|
||||
|
||||
// NewPropertyGroupTemplate returns a new PropertyGroupTemplate instance
|
||||
func NewPropertyGroupTemplate(Name string, Description string, Fields []*PropertyFieldTemplate) *PropertyGroupTemplate {
|
||||
s := new(PropertyGroupTemplate)
|
||||
s.Name = Name
|
||||
s.Description = Description
|
||||
s.Fields = Fields
|
||||
return s
|
||||
}
|
||||
|
||||
// GetPropertyTemplateResult : The Property template for the specified template.
|
||||
type GetPropertyTemplateResult struct {
|
||||
PropertyGroupTemplate
|
||||
}
|
||||
|
||||
// NewGetPropertyTemplateResult returns a new GetPropertyTemplateResult instance
|
||||
func NewGetPropertyTemplateResult(Name string, Description string, Fields []*PropertyFieldTemplate) *GetPropertyTemplateResult {
|
||||
s := new(GetPropertyTemplateResult)
|
||||
s.Name = Name
|
||||
s.Description = Description
|
||||
s.Fields = Fields
|
||||
return s
|
||||
}
|
||||
|
||||
// ListPropertyTemplateIds : has no documentation (yet)
|
||||
type ListPropertyTemplateIds struct {
|
||||
// TemplateIds : List of identifiers for templates added by route
|
||||
// properties/template/add.
|
||||
TemplateIds []string `json:"template_ids"`
|
||||
}
|
||||
|
||||
// NewListPropertyTemplateIds returns a new ListPropertyTemplateIds instance
|
||||
func NewListPropertyTemplateIds(TemplateIds []string) *ListPropertyTemplateIds {
|
||||
s := new(ListPropertyTemplateIds)
|
||||
s.TemplateIds = TemplateIds
|
||||
return s
|
||||
}
|
||||
|
||||
// PropertyTemplateError : has no documentation (yet)
|
||||
type PropertyTemplateError struct {
|
||||
dropbox.Tagged
|
||||
// TemplateNotFound : Property template does not exist for given identifier.
|
||||
TemplateNotFound string `json:"template_not_found,omitempty"`
|
||||
}
|
||||
|
||||
// Valid tag values for PropertyTemplateError
|
||||
const (
|
||||
PropertyTemplateErrorTemplateNotFound = "template_not_found"
|
||||
PropertyTemplateErrorRestrictedContent = "restricted_content"
|
||||
PropertyTemplateErrorOther = "other"
|
||||
)
|
||||
|
||||
// UnmarshalJSON deserializes into a PropertyTemplateError instance
|
||||
func (u *PropertyTemplateError) UnmarshalJSON(body []byte) error {
|
||||
type wrap struct {
|
||||
dropbox.Tagged
|
||||
}
|
||||
var w wrap
|
||||
var err error
|
||||
if err = json.Unmarshal(body, &w); err != nil {
|
||||
return err
|
||||
}
|
||||
u.Tag = w.Tag
|
||||
switch u.Tag {
|
||||
case "template_not_found":
|
||||
err = json.Unmarshal(body, &u.TemplateNotFound)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ModifyPropertyTemplateError : has no documentation (yet)
|
||||
type ModifyPropertyTemplateError struct {
|
||||
dropbox.Tagged
|
||||
}
|
||||
|
||||
// Valid tag values for ModifyPropertyTemplateError
|
||||
const (
|
||||
ModifyPropertyTemplateErrorConflictingPropertyNames = "conflicting_property_names"
|
||||
ModifyPropertyTemplateErrorTooManyProperties = "too_many_properties"
|
||||
ModifyPropertyTemplateErrorTooManyTemplates = "too_many_templates"
|
||||
ModifyPropertyTemplateErrorTemplateAttributeTooLarge = "template_attribute_too_large"
|
||||
)
|
||||
|
||||
// PropertyField : has no documentation (yet)
|
||||
type PropertyField struct {
|
||||
// Name : This is the name or key of a custom property in a property
|
||||
// template. File property names can be up to 256 bytes.
|
||||
Name string `json:"name"`
|
||||
// Value : Value of a custom property attached to a file. Values can be up
|
||||
// to 1024 bytes.
|
||||
Value string `json:"value"`
|
||||
}
|
||||
|
||||
// NewPropertyField returns a new PropertyField instance
|
||||
func NewPropertyField(Name string, Value string) *PropertyField {
|
||||
s := new(PropertyField)
|
||||
s.Name = Name
|
||||
s.Value = Value
|
||||
return s
|
||||
}
|
||||
|
||||
// PropertyFieldTemplate : Describe a single property field type which that can
|
||||
// be part of a property template.
|
||||
type PropertyFieldTemplate struct {
|
||||
// Name : This is the name or key of a custom property in a property
|
||||
// template. File property names can be up to 256 bytes.
|
||||
Name string `json:"name"`
|
||||
// Description : This is the description for a custom property in a property
|
||||
// template. File property description can be up to 1024 bytes.
|
||||
Description string `json:"description"`
|
||||
// Type : This is the data type of the value of this property. This type
|
||||
// will be enforced upon property creation and modifications.
|
||||
Type *PropertyType `json:"type"`
|
||||
}
|
||||
|
||||
// NewPropertyFieldTemplate returns a new PropertyFieldTemplate instance
|
||||
func NewPropertyFieldTemplate(Name string, Description string, Type *PropertyType) *PropertyFieldTemplate {
|
||||
s := new(PropertyFieldTemplate)
|
||||
s.Name = Name
|
||||
s.Description = Description
|
||||
s.Type = Type
|
||||
return s
|
||||
}
|
||||
|
||||
// PropertyGroup : Collection of custom properties in filled property templates.
|
||||
type PropertyGroup struct {
|
||||
// TemplateId : A unique identifier for a property template type.
|
||||
TemplateId string `json:"template_id"`
|
||||
// Fields : This is a list of custom properties associated with a file.
|
||||
// There can be up to 32 properties for a template.
|
||||
Fields []*PropertyField `json:"fields"`
|
||||
}
|
||||
|
||||
// NewPropertyGroup returns a new PropertyGroup instance
|
||||
func NewPropertyGroup(TemplateId string, Fields []*PropertyField) *PropertyGroup {
|
||||
s := new(PropertyGroup)
|
||||
s.TemplateId = TemplateId
|
||||
s.Fields = Fields
|
||||
return s
|
||||
}
|
||||
|
||||
// PropertyType : Data type of the given property added. This endpoint is in
|
||||
// beta and only properties of type strings is supported.
|
||||
type PropertyType struct {
|
||||
dropbox.Tagged
|
||||
}
|
||||
|
||||
// Valid tag values for PropertyType
|
||||
const (
|
||||
PropertyTypeString = "string"
|
||||
PropertyTypeOther = "other"
|
||||
)
|
170
vendor/github.com/ncw/dropbox-sdk-go-unofficial/dropbox/sdk.go
generated
vendored
170
vendor/github.com/ncw/dropbox-sdk-go-unofficial/dropbox/sdk.go
generated
vendored
@ -1,170 +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 dropbox
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"golang.org/x/oauth2"
|
||||
)
|
||||
|
||||
const (
|
||||
apiVersion = 2
|
||||
defaultDomain = ".dropboxapi.com"
|
||||
hostAPI = "api"
|
||||
hostContent = "content"
|
||||
hostNotify = "notify"
|
||||
sdkVersion = "1.0.0-beta"
|
||||
specVersion = "8c790b1"
|
||||
)
|
||||
|
||||
// Version returns the current SDK version and API Spec version
|
||||
func Version() (string, string) {
|
||||
return sdkVersion, specVersion
|
||||
}
|
||||
|
||||
// Config contains parameters for configuring the SDK.
|
||||
type Config struct {
|
||||
// OAuth2 access token
|
||||
Token string
|
||||
// Enable verbose logging in SDK
|
||||
Verbose bool
|
||||
// Used with APIs that support operations as another user
|
||||
AsMemberID string
|
||||
// No need to set -- for testing only
|
||||
Domain string
|
||||
// No need to set -- for testing only
|
||||
Client *http.Client
|
||||
// No need to set -- for testing only
|
||||
HeaderGenerator func(hostType string, style string, namespace string, route string) map[string]string
|
||||
// No need to set -- for testing only
|
||||
URLGenerator func(hostType string, style string, namespace string, route string) string
|
||||
}
|
||||
|
||||
// Context is the base client context used to implement per-namespace clients.
|
||||
type Context struct {
|
||||
Config Config
|
||||
Client *http.Client
|
||||
HeaderGenerator func(hostType string, style string, namespace string, route string) map[string]string
|
||||
URLGenerator func(hostType string, style string, namespace string, route string) string
|
||||
}
|
||||
|
||||
// NewRequest returns an appropriate Request object for the given namespace/route.
|
||||
func (c *Context) NewRequest(
|
||||
hostType string,
|
||||
style string,
|
||||
authed bool,
|
||||
namespace string,
|
||||
route string,
|
||||
headers map[string]string,
|
||||
body io.Reader,
|
||||
) (*http.Request, error) {
|
||||
url := c.URLGenerator(hostType, style, namespace, route)
|
||||
req, err := http.NewRequest("POST", url, body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for k, v := range headers {
|
||||
req.Header.Add(k, v)
|
||||
}
|
||||
for k, v := range c.HeaderGenerator(hostType, style, namespace, route) {
|
||||
req.Header.Add(k, v)
|
||||
}
|
||||
if req.Header.Get("Host") != "" {
|
||||
req.Host = req.Header.Get("Host")
|
||||
}
|
||||
if !authed {
|
||||
req.Header.Del("Authorization")
|
||||
}
|
||||
return req, nil
|
||||
}
|
||||
|
||||
// NewContext returns a new Context with the given Config.
|
||||
func NewContext(c Config) Context {
|
||||
domain := c.Domain
|
||||
if domain == "" {
|
||||
domain = defaultDomain
|
||||
}
|
||||
|
||||
client := c.Client
|
||||
if client == nil {
|
||||
var conf = &oauth2.Config{Endpoint: OAuthEndpoint(domain)}
|
||||
tok := &oauth2.Token{AccessToken: c.Token}
|
||||
client = conf.Client(oauth2.NoContext, tok)
|
||||
}
|
||||
|
||||
headerGenerator := c.HeaderGenerator
|
||||
if headerGenerator == nil {
|
||||
headerGenerator = func(hostType string, style string, namespace string, route string) map[string]string {
|
||||
return map[string]string{}
|
||||
}
|
||||
}
|
||||
|
||||
urlGenerator := c.URLGenerator
|
||||
if urlGenerator == nil {
|
||||
hostMap := map[string]string{
|
||||
hostAPI: hostAPI + domain,
|
||||
hostContent: hostContent + domain,
|
||||
hostNotify: hostNotify + domain,
|
||||
}
|
||||
urlGenerator = func(hostType string, style string, namespace string, route string) string {
|
||||
fqHost := hostMap[hostType]
|
||||
return fmt.Sprintf("https://%s/%d/%s/%s", fqHost, apiVersion, namespace, route)
|
||||
}
|
||||
}
|
||||
|
||||
return Context{c, client, headerGenerator, urlGenerator}
|
||||
}
|
||||
|
||||
// OAuthEndpoint constructs an `oauth2.Endpoint` for the given domain
|
||||
func OAuthEndpoint(domain string) oauth2.Endpoint {
|
||||
if domain == "" {
|
||||
domain = defaultDomain
|
||||
}
|
||||
authURL := fmt.Sprintf("https://meta%s/1/oauth2/authorize", domain)
|
||||
tokenURL := fmt.Sprintf("https://api%s/1/oauth2/token", domain)
|
||||
if domain == defaultDomain {
|
||||
authURL = "https://www.dropbox.com/1/oauth2/authorize"
|
||||
}
|
||||
return oauth2.Endpoint{AuthURL: authURL, TokenURL: tokenURL}
|
||||
}
|
||||
|
||||
// Tagged is used for tagged unions.
|
||||
type Tagged struct {
|
||||
Tag string `json:".tag"`
|
||||
}
|
||||
|
||||
// APIError is the base type for endpoint-specific errors.
|
||||
type APIError struct {
|
||||
ErrorSummary string `json:"error_summary"`
|
||||
}
|
||||
|
||||
func (e APIError) Error() string {
|
||||
return e.ErrorSummary
|
||||
}
|
||||
|
||||
func init() {
|
||||
// These are not registered in the oauth library by default
|
||||
oauth2.RegisterBrokenAuthHeaderProvider("https://api.dropboxapi.com")
|
||||
oauth2.RegisterBrokenAuthHeaderProvider("https://api-dbdev.dev.corp.dropbox.com")
|
||||
}
|
3586
vendor/github.com/ncw/dropbox-sdk-go-unofficial/dropbox/sharing/client.go
generated
vendored
3586
vendor/github.com/ncw/dropbox-sdk-go-unofficial/dropbox/sharing/client.go
generated
vendored
File diff suppressed because it is too large
Load Diff
49
vendor/github.com/ncw/dropbox-sdk-go-unofficial/dropbox/sharing/metadata.go
generated
vendored
49
vendor/github.com/ncw/dropbox-sdk-go-unofficial/dropbox/sharing/metadata.go
generated
vendored
@ -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
|
||||
}
|
4066
vendor/github.com/ncw/dropbox-sdk-go-unofficial/dropbox/sharing/types.go
generated
vendored
4066
vendor/github.com/ncw/dropbox-sdk-go-unofficial/dropbox/sharing/types.go
generated
vendored
File diff suppressed because it is too large
Load Diff
4417
vendor/github.com/ncw/dropbox-sdk-go-unofficial/dropbox/team/client.go
generated
vendored
4417
vendor/github.com/ncw/dropbox-sdk-go-unofficial/dropbox/team/client.go
generated
vendored
File diff suppressed because it is too large
Load Diff
3336
vendor/github.com/ncw/dropbox-sdk-go-unofficial/dropbox/team/types.go
generated
vendored
3336
vendor/github.com/ncw/dropbox-sdk-go-unofficial/dropbox/team/types.go
generated
vendored
File diff suppressed because it is too large
Load Diff
91
vendor/github.com/ncw/dropbox-sdk-go-unofficial/dropbox/team_common/types.go
generated
vendored
91
vendor/github.com/ncw/dropbox-sdk-go-unofficial/dropbox/team_common/types.go
generated
vendored
@ -1,91 +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 team_common : has no documentation (yet)
|
||||
package team_common
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/ncw/dropbox-sdk-go-unofficial/dropbox"
|
||||
)
|
||||
|
||||
// GroupManagementType : The group type determines how a group is managed.
|
||||
type GroupManagementType struct {
|
||||
dropbox.Tagged
|
||||
}
|
||||
|
||||
// Valid tag values for GroupManagementType
|
||||
const (
|
||||
GroupManagementTypeUserManaged = "user_managed"
|
||||
GroupManagementTypeCompanyManaged = "company_managed"
|
||||
GroupManagementTypeSystemManaged = "system_managed"
|
||||
GroupManagementTypeOther = "other"
|
||||
)
|
||||
|
||||
// GroupSummary : Information about a group.
|
||||
type GroupSummary struct {
|
||||
// GroupName : has no documentation (yet)
|
||||
GroupName string `json:"group_name"`
|
||||
// GroupId : has no documentation (yet)
|
||||
GroupId string `json:"group_id"`
|
||||
// GroupExternalId : External ID of group. This is an arbitrary ID that an
|
||||
// admin can attach to a group.
|
||||
GroupExternalId string `json:"group_external_id,omitempty"`
|
||||
// MemberCount : The number of members in the group.
|
||||
MemberCount uint32 `json:"member_count,omitempty"`
|
||||
// GroupManagementType : Who is allowed to manage the group.
|
||||
GroupManagementType *GroupManagementType `json:"group_management_type"`
|
||||
}
|
||||
|
||||
// NewGroupSummary returns a new GroupSummary instance
|
||||
func NewGroupSummary(GroupName string, GroupId string, GroupManagementType *GroupManagementType) *GroupSummary {
|
||||
s := new(GroupSummary)
|
||||
s.GroupName = GroupName
|
||||
s.GroupId = GroupId
|
||||
s.GroupManagementType = GroupManagementType
|
||||
return s
|
||||
}
|
||||
|
||||
// GroupType : The group type determines how a group is created and managed.
|
||||
type GroupType struct {
|
||||
dropbox.Tagged
|
||||
}
|
||||
|
||||
// Valid tag values for GroupType
|
||||
const (
|
||||
GroupTypeTeam = "team"
|
||||
GroupTypeUserManaged = "user_managed"
|
||||
GroupTypeOther = "other"
|
||||
)
|
||||
|
||||
// TimeRange : Time range.
|
||||
type TimeRange struct {
|
||||
// StartTime : Optional starting time (inclusive).
|
||||
StartTime time.Time `json:"start_time,omitempty"`
|
||||
// EndTime : Optional ending time (exclusive).
|
||||
EndTime time.Time `json:"end_time,omitempty"`
|
||||
}
|
||||
|
||||
// NewTimeRange returns a new TimeRange instance
|
||||
func NewTimeRange() *TimeRange {
|
||||
s := new(TimeRange)
|
||||
return s
|
||||
}
|
202
vendor/github.com/ncw/dropbox-sdk-go-unofficial/dropbox/team_log/client.go
generated
vendored
202
vendor/github.com/ncw/dropbox-sdk-go-unofficial/dropbox/team_log/client.go
generated
vendored
@ -1,202 +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 team_log
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/ncw/dropbox-sdk-go-unofficial/dropbox"
|
||||
)
|
||||
|
||||
// Client interface describes all routes in this namespace
|
||||
type Client interface {
|
||||
// GetEvents : Retrieves team events. Permission : Team Auditing.
|
||||
GetEvents(arg *GetTeamEventsArg) (res *GetTeamEventsResult, err error)
|
||||
// GetEventsContinue : Once a cursor has been retrieved from `getEvents`,
|
||||
// use this to paginate through all events. Permission : Team Auditing.
|
||||
GetEventsContinue(arg *GetTeamEventsContinueArg) (res *GetTeamEventsResult, err error)
|
||||
}
|
||||
|
||||
type apiImpl dropbox.Context
|
||||
|
||||
//GetEventsAPIError is an error-wrapper for the get_events route
|
||||
type GetEventsAPIError struct {
|
||||
dropbox.APIError
|
||||
EndpointError *GetTeamEventsError `json:"error"`
|
||||
}
|
||||
|
||||
func (dbx *apiImpl) GetEvents(arg *GetTeamEventsArg) (res *GetTeamEventsResult, err error) {
|
||||
cli := dbx.Client
|
||||
|
||||
if dbx.Config.Verbose {
|
||||
log.Printf("arg: %v", arg)
|
||||
}
|
||||
b, err := json.Marshal(arg)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
headers := map[string]string{
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
|
||||
req, err := (*dropbox.Context)(dbx).NewRequest("api", "rpc", true, "team_log", "get_events", headers, bytes.NewReader(b))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if dbx.Config.Verbose {
|
||||
log.Printf("req: %v", req)
|
||||
}
|
||||
|
||||
resp, err := cli.Do(req)
|
||||
if dbx.Config.Verbose {
|
||||
log.Printf("resp: %v", resp)
|
||||
}
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if dbx.Config.Verbose {
|
||||
log.Printf("body: %s", body)
|
||||
}
|
||||
if resp.StatusCode == http.StatusOK {
|
||||
err = json.Unmarshal(body, &res)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
if resp.StatusCode == http.StatusConflict {
|
||||
var apiError GetEventsAPIError
|
||||
err = json.Unmarshal(body, &apiError)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = apiError
|
||||
return
|
||||
}
|
||||
var apiError dropbox.APIError
|
||||
if resp.StatusCode == http.StatusBadRequest {
|
||||
apiError.ErrorSummary = string(body)
|
||||
err = apiError
|
||||
return
|
||||
}
|
||||
err = json.Unmarshal(body, &apiError)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = apiError
|
||||
return
|
||||
}
|
||||
|
||||
//GetEventsContinueAPIError is an error-wrapper for the get_events/continue route
|
||||
type GetEventsContinueAPIError struct {
|
||||
dropbox.APIError
|
||||
EndpointError *GetTeamEventsContinueError `json:"error"`
|
||||
}
|
||||
|
||||
func (dbx *apiImpl) GetEventsContinue(arg *GetTeamEventsContinueArg) (res *GetTeamEventsResult, err error) {
|
||||
cli := dbx.Client
|
||||
|
||||
if dbx.Config.Verbose {
|
||||
log.Printf("arg: %v", arg)
|
||||
}
|
||||
b, err := json.Marshal(arg)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
headers := map[string]string{
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
|
||||
req, err := (*dropbox.Context)(dbx).NewRequest("api", "rpc", true, "team_log", "get_events/continue", headers, bytes.NewReader(b))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if dbx.Config.Verbose {
|
||||
log.Printf("req: %v", req)
|
||||
}
|
||||
|
||||
resp, err := cli.Do(req)
|
||||
if dbx.Config.Verbose {
|
||||
log.Printf("resp: %v", resp)
|
||||
}
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if dbx.Config.Verbose {
|
||||
log.Printf("body: %s", body)
|
||||
}
|
||||
if resp.StatusCode == http.StatusOK {
|
||||
err = json.Unmarshal(body, &res)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
if resp.StatusCode == http.StatusConflict {
|
||||
var apiError GetEventsContinueAPIError
|
||||
err = json.Unmarshal(body, &apiError)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = apiError
|
||||
return
|
||||
}
|
||||
var apiError dropbox.APIError
|
||||
if resp.StatusCode == http.StatusBadRequest {
|
||||
apiError.ErrorSummary = string(body)
|
||||
err = apiError
|
||||
return
|
||||
}
|
||||
err = json.Unmarshal(body, &apiError)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = apiError
|
||||
return
|
||||
}
|
||||
|
||||
// New returns a Client implementation for this namespace
|
||||
func New(c dropbox.Config) *apiImpl {
|
||||
ctx := apiImpl(dropbox.NewContext(c))
|
||||
return &ctx
|
||||
}
|
8836
vendor/github.com/ncw/dropbox-sdk-go-unofficial/dropbox/team_log/types.go
generated
vendored
8836
vendor/github.com/ncw/dropbox-sdk-go-unofficial/dropbox/team_log/types.go
generated
vendored
File diff suppressed because it is too large
Load Diff
118
vendor/github.com/ncw/dropbox-sdk-go-unofficial/dropbox/team_policies/types.go
generated
vendored
118
vendor/github.com/ncw/dropbox-sdk-go-unofficial/dropbox/team_policies/types.go
generated
vendored
@ -1,118 +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 team_policies : has no documentation (yet)
|
||||
package team_policies
|
||||
|
||||
import "github.com/ncw/dropbox-sdk-go-unofficial/dropbox"
|
||||
|
||||
// EmmState : has no documentation (yet)
|
||||
type EmmState struct {
|
||||
dropbox.Tagged
|
||||
}
|
||||
|
||||
// Valid tag values for EmmState
|
||||
const (
|
||||
EmmStateDisabled = "disabled"
|
||||
EmmStateOptional = "optional"
|
||||
EmmStateRequired = "required"
|
||||
EmmStateOther = "other"
|
||||
)
|
||||
|
||||
// SharedFolderJoinPolicy : Policy governing which shared folders a team member
|
||||
// can join.
|
||||
type SharedFolderJoinPolicy struct {
|
||||
dropbox.Tagged
|
||||
}
|
||||
|
||||
// Valid tag values for SharedFolderJoinPolicy
|
||||
const (
|
||||
SharedFolderJoinPolicyFromTeamOnly = "from_team_only"
|
||||
SharedFolderJoinPolicyFromAnyone = "from_anyone"
|
||||
SharedFolderJoinPolicyOther = "other"
|
||||
)
|
||||
|
||||
// SharedFolderMemberPolicy : Policy governing who can be a member of a folder
|
||||
// shared by a team member.
|
||||
type SharedFolderMemberPolicy struct {
|
||||
dropbox.Tagged
|
||||
}
|
||||
|
||||
// Valid tag values for SharedFolderMemberPolicy
|
||||
const (
|
||||
SharedFolderMemberPolicyTeam = "team"
|
||||
SharedFolderMemberPolicyAnyone = "anyone"
|
||||
SharedFolderMemberPolicyOther = "other"
|
||||
)
|
||||
|
||||
// SharedLinkCreatePolicy : Policy governing the visibility of shared links.
|
||||
// This policy can apply to newly created shared links, or all shared links.
|
||||
type SharedLinkCreatePolicy struct {
|
||||
dropbox.Tagged
|
||||
}
|
||||
|
||||
// Valid tag values for SharedLinkCreatePolicy
|
||||
const (
|
||||
SharedLinkCreatePolicyDefaultPublic = "default_public"
|
||||
SharedLinkCreatePolicyDefaultTeamOnly = "default_team_only"
|
||||
SharedLinkCreatePolicyTeamOnly = "team_only"
|
||||
SharedLinkCreatePolicyOther = "other"
|
||||
)
|
||||
|
||||
// TeamMemberPolicies : Policies governing team members.
|
||||
type TeamMemberPolicies struct {
|
||||
// Sharing : Policies governing sharing.
|
||||
Sharing *TeamSharingPolicies `json:"sharing"`
|
||||
// EmmState : This describes the Enterprise Mobility Management (EMM) state
|
||||
// for this team. This information can be used to understand if an
|
||||
// organization is integrating with a third-party EMM vendor to further
|
||||
// manage and apply restrictions upon the team's Dropbox usage on mobile
|
||||
// devices. This is a new feature and in the future we'll be adding more new
|
||||
// fields and additional documentation.
|
||||
EmmState *EmmState `json:"emm_state"`
|
||||
}
|
||||
|
||||
// NewTeamMemberPolicies returns a new TeamMemberPolicies instance
|
||||
func NewTeamMemberPolicies(Sharing *TeamSharingPolicies, EmmState *EmmState) *TeamMemberPolicies {
|
||||
s := new(TeamMemberPolicies)
|
||||
s.Sharing = Sharing
|
||||
s.EmmState = EmmState
|
||||
return s
|
||||
}
|
||||
|
||||
// TeamSharingPolicies : Policies governing sharing within and outside of the
|
||||
// team.
|
||||
type TeamSharingPolicies struct {
|
||||
// SharedFolderMemberPolicy : Who can join folders shared by team members.
|
||||
SharedFolderMemberPolicy *SharedFolderMemberPolicy `json:"shared_folder_member_policy"`
|
||||
// SharedFolderJoinPolicy : Which shared folders team members can join.
|
||||
SharedFolderJoinPolicy *SharedFolderJoinPolicy `json:"shared_folder_join_policy"`
|
||||
// SharedLinkCreatePolicy : Who can view shared links owned by team members.
|
||||
SharedLinkCreatePolicy *SharedLinkCreatePolicy `json:"shared_link_create_policy"`
|
||||
}
|
||||
|
||||
// NewTeamSharingPolicies returns a new TeamSharingPolicies instance
|
||||
func NewTeamSharingPolicies(SharedFolderMemberPolicy *SharedFolderMemberPolicy, SharedFolderJoinPolicy *SharedFolderJoinPolicy, SharedLinkCreatePolicy *SharedLinkCreatePolicy) *TeamSharingPolicies {
|
||||
s := new(TeamSharingPolicies)
|
||||
s.SharedFolderMemberPolicy = SharedFolderMemberPolicy
|
||||
s.SharedFolderJoinPolicy = SharedFolderJoinPolicy
|
||||
s.SharedLinkCreatePolicy = SharedLinkCreatePolicy
|
||||
return s
|
||||
}
|
353
vendor/github.com/ncw/dropbox-sdk-go-unofficial/dropbox/users/client.go
generated
vendored
353
vendor/github.com/ncw/dropbox-sdk-go-unofficial/dropbox/users/client.go
generated
vendored
@ -1,353 +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 users
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/ncw/dropbox-sdk-go-unofficial/dropbox"
|
||||
)
|
||||
|
||||
// Client interface describes all routes in this namespace
|
||||
type Client interface {
|
||||
// GetAccount : Get information about a user's account.
|
||||
GetAccount(arg *GetAccountArg) (res *BasicAccount, err error)
|
||||
// GetAccountBatch : Get information about multiple user accounts. At most
|
||||
// 300 accounts may be queried per request.
|
||||
GetAccountBatch(arg *GetAccountBatchArg) (res []*BasicAccount, err error)
|
||||
// GetCurrentAccount : Get information about the current user's account.
|
||||
GetCurrentAccount() (res *FullAccount, err error)
|
||||
// GetSpaceUsage : Get the space usage information for the current user's
|
||||
// account.
|
||||
GetSpaceUsage() (res *SpaceUsage, err error)
|
||||
}
|
||||
|
||||
type apiImpl dropbox.Context
|
||||
|
||||
//GetAccountAPIError is an error-wrapper for the get_account route
|
||||
type GetAccountAPIError struct {
|
||||
dropbox.APIError
|
||||
EndpointError *GetAccountError `json:"error"`
|
||||
}
|
||||
|
||||
func (dbx *apiImpl) GetAccount(arg *GetAccountArg) (res *BasicAccount, err error) {
|
||||
cli := dbx.Client
|
||||
|
||||
if dbx.Config.Verbose {
|
||||
log.Printf("arg: %v", arg)
|
||||
}
|
||||
b, err := json.Marshal(arg)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
headers := map[string]string{
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
if dbx.Config.AsMemberID != "" {
|
||||
headers["Dropbox-API-Select-User"] = dbx.Config.AsMemberID
|
||||
}
|
||||
|
||||
req, err := (*dropbox.Context)(dbx).NewRequest("api", "rpc", true, "users", "get_account", headers, bytes.NewReader(b))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if dbx.Config.Verbose {
|
||||
log.Printf("req: %v", req)
|
||||
}
|
||||
|
||||
resp, err := cli.Do(req)
|
||||
if dbx.Config.Verbose {
|
||||
log.Printf("resp: %v", resp)
|
||||
}
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if dbx.Config.Verbose {
|
||||
log.Printf("body: %s", body)
|
||||
}
|
||||
if resp.StatusCode == http.StatusOK {
|
||||
err = json.Unmarshal(body, &res)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
if resp.StatusCode == http.StatusConflict {
|
||||
var apiError GetAccountAPIError
|
||||
err = json.Unmarshal(body, &apiError)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = apiError
|
||||
return
|
||||
}
|
||||
var apiError dropbox.APIError
|
||||
if resp.StatusCode == http.StatusBadRequest {
|
||||
apiError.ErrorSummary = string(body)
|
||||
err = apiError
|
||||
return
|
||||
}
|
||||
err = json.Unmarshal(body, &apiError)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = apiError
|
||||
return
|
||||
}
|
||||
|
||||
//GetAccountBatchAPIError is an error-wrapper for the get_account_batch route
|
||||
type GetAccountBatchAPIError struct {
|
||||
dropbox.APIError
|
||||
EndpointError *GetAccountBatchError `json:"error"`
|
||||
}
|
||||
|
||||
func (dbx *apiImpl) GetAccountBatch(arg *GetAccountBatchArg) (res []*BasicAccount, err error) {
|
||||
cli := dbx.Client
|
||||
|
||||
if dbx.Config.Verbose {
|
||||
log.Printf("arg: %v", arg)
|
||||
}
|
||||
b, err := json.Marshal(arg)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
headers := map[string]string{
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
if dbx.Config.AsMemberID != "" {
|
||||
headers["Dropbox-API-Select-User"] = dbx.Config.AsMemberID
|
||||
}
|
||||
|
||||
req, err := (*dropbox.Context)(dbx).NewRequest("api", "rpc", true, "users", "get_account_batch", headers, bytes.NewReader(b))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if dbx.Config.Verbose {
|
||||
log.Printf("req: %v", req)
|
||||
}
|
||||
|
||||
resp, err := cli.Do(req)
|
||||
if dbx.Config.Verbose {
|
||||
log.Printf("resp: %v", resp)
|
||||
}
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if dbx.Config.Verbose {
|
||||
log.Printf("body: %s", body)
|
||||
}
|
||||
if resp.StatusCode == http.StatusOK {
|
||||
err = json.Unmarshal(body, &res)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
if resp.StatusCode == http.StatusConflict {
|
||||
var apiError GetAccountBatchAPIError
|
||||
err = json.Unmarshal(body, &apiError)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = apiError
|
||||
return
|
||||
}
|
||||
var apiError dropbox.APIError
|
||||
if resp.StatusCode == http.StatusBadRequest {
|
||||
apiError.ErrorSummary = string(body)
|
||||
err = apiError
|
||||
return
|
||||
}
|
||||
err = json.Unmarshal(body, &apiError)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = apiError
|
||||
return
|
||||
}
|
||||
|
||||
//GetCurrentAccountAPIError is an error-wrapper for the get_current_account route
|
||||
type GetCurrentAccountAPIError struct {
|
||||
dropbox.APIError
|
||||
EndpointError struct{} `json:"error"`
|
||||
}
|
||||
|
||||
func (dbx *apiImpl) GetCurrentAccount() (res *FullAccount, err error) {
|
||||
cli := dbx.Client
|
||||
|
||||
headers := map[string]string{}
|
||||
if dbx.Config.AsMemberID != "" {
|
||||
headers["Dropbox-API-Select-User"] = dbx.Config.AsMemberID
|
||||
}
|
||||
|
||||
req, err := (*dropbox.Context)(dbx).NewRequest("api", "rpc", true, "users", "get_current_account", headers, nil)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if dbx.Config.Verbose {
|
||||
log.Printf("req: %v", req)
|
||||
}
|
||||
|
||||
resp, err := cli.Do(req)
|
||||
if dbx.Config.Verbose {
|
||||
log.Printf("resp: %v", resp)
|
||||
}
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if dbx.Config.Verbose {
|
||||
log.Printf("body: %s", body)
|
||||
}
|
||||
if resp.StatusCode == http.StatusOK {
|
||||
err = json.Unmarshal(body, &res)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
if resp.StatusCode == http.StatusConflict {
|
||||
var apiError GetCurrentAccountAPIError
|
||||
err = json.Unmarshal(body, &apiError)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = apiError
|
||||
return
|
||||
}
|
||||
var apiError dropbox.APIError
|
||||
if resp.StatusCode == http.StatusBadRequest {
|
||||
apiError.ErrorSummary = string(body)
|
||||
err = apiError
|
||||
return
|
||||
}
|
||||
err = json.Unmarshal(body, &apiError)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = apiError
|
||||
return
|
||||
}
|
||||
|
||||
//GetSpaceUsageAPIError is an error-wrapper for the get_space_usage route
|
||||
type GetSpaceUsageAPIError struct {
|
||||
dropbox.APIError
|
||||
EndpointError struct{} `json:"error"`
|
||||
}
|
||||
|
||||
func (dbx *apiImpl) GetSpaceUsage() (res *SpaceUsage, err error) {
|
||||
cli := dbx.Client
|
||||
|
||||
headers := map[string]string{}
|
||||
if dbx.Config.AsMemberID != "" {
|
||||
headers["Dropbox-API-Select-User"] = dbx.Config.AsMemberID
|
||||
}
|
||||
|
||||
req, err := (*dropbox.Context)(dbx).NewRequest("api", "rpc", true, "users", "get_space_usage", headers, nil)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if dbx.Config.Verbose {
|
||||
log.Printf("req: %v", req)
|
||||
}
|
||||
|
||||
resp, err := cli.Do(req)
|
||||
if dbx.Config.Verbose {
|
||||
log.Printf("resp: %v", resp)
|
||||
}
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if dbx.Config.Verbose {
|
||||
log.Printf("body: %s", body)
|
||||
}
|
||||
if resp.StatusCode == http.StatusOK {
|
||||
err = json.Unmarshal(body, &res)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
if resp.StatusCode == http.StatusConflict {
|
||||
var apiError GetSpaceUsageAPIError
|
||||
err = json.Unmarshal(body, &apiError)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = apiError
|
||||
return
|
||||
}
|
||||
var apiError dropbox.APIError
|
||||
if resp.StatusCode == http.StatusBadRequest {
|
||||
apiError.ErrorSummary = string(body)
|
||||
err = apiError
|
||||
return
|
||||
}
|
||||
err = json.Unmarshal(body, &apiError)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = apiError
|
||||
return
|
||||
}
|
||||
|
||||
// New returns a Client implementation for this namespace
|
||||
func New(c dropbox.Config) *apiImpl {
|
||||
ctx := apiImpl(dropbox.NewContext(c))
|
||||
return &ctx
|
||||
}
|
357
vendor/github.com/ncw/dropbox-sdk-go-unofficial/dropbox/users/types.go
generated
vendored
357
vendor/github.com/ncw/dropbox-sdk-go-unofficial/dropbox/users/types.go
generated
vendored
@ -1,357 +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 users : This namespace contains endpoints and data types for user
|
||||
// management.
|
||||
package users
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/ncw/dropbox-sdk-go-unofficial/dropbox"
|
||||
"github.com/ncw/dropbox-sdk-go-unofficial/dropbox/team_policies"
|
||||
"github.com/ncw/dropbox-sdk-go-unofficial/dropbox/users_common"
|
||||
)
|
||||
|
||||
// Account : The amount of detail revealed about an account depends on the user
|
||||
// being queried and the user making the query.
|
||||
type Account 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"`
|
||||
// ProfilePhotoUrl : URL for the photo representing the user, if one is set.
|
||||
ProfilePhotoUrl string `json:"profile_photo_url,omitempty"`
|
||||
// Disabled : Whether the user has been disabled.
|
||||
Disabled bool `json:"disabled"`
|
||||
}
|
||||
|
||||
// NewAccount returns a new Account instance
|
||||
func NewAccount(AccountId string, Name *Name, Email string, EmailVerified bool, Disabled bool) *Account {
|
||||
s := new(Account)
|
||||
s.AccountId = AccountId
|
||||
s.Name = Name
|
||||
s.Email = Email
|
||||
s.EmailVerified = EmailVerified
|
||||
s.Disabled = Disabled
|
||||
return s
|
||||
}
|
||||
|
||||
// BasicAccount : Basic information about any account.
|
||||
type BasicAccount struct {
|
||||
Account
|
||||
// IsTeammate : Whether this user is a teammate of the current user. If this
|
||||
// account is the current user's account, then this will be true.
|
||||
IsTeammate bool `json:"is_teammate"`
|
||||
// TeamMemberId : The user's unique team member id. This field will only be
|
||||
// present if the user is part of a team and `is_teammate` is true.
|
||||
TeamMemberId string `json:"team_member_id,omitempty"`
|
||||
}
|
||||
|
||||
// NewBasicAccount returns a new BasicAccount instance
|
||||
func NewBasicAccount(AccountId string, Name *Name, Email string, EmailVerified bool, Disabled bool, IsTeammate bool) *BasicAccount {
|
||||
s := new(BasicAccount)
|
||||
s.AccountId = AccountId
|
||||
s.Name = Name
|
||||
s.Email = Email
|
||||
s.EmailVerified = EmailVerified
|
||||
s.Disabled = Disabled
|
||||
s.IsTeammate = IsTeammate
|
||||
return s
|
||||
}
|
||||
|
||||
// FullAccount : Detailed information about the current user's account.
|
||||
type FullAccount struct {
|
||||
Account
|
||||
// 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"`
|
||||
// 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"`
|
||||
// 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"`
|
||||
// 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"`
|
||||
}
|
||||
|
||||
// NewFullAccount returns a new FullAccount instance
|
||||
func NewFullAccount(AccountId string, Name *Name, Email string, EmailVerified bool, Disabled bool, Locale string, ReferralLink string, IsPaired bool, AccountType *users_common.AccountType) *FullAccount {
|
||||
s := new(FullAccount)
|
||||
s.AccountId = AccountId
|
||||
s.Name = Name
|
||||
s.Email = Email
|
||||
s.EmailVerified = EmailVerified
|
||||
s.Disabled = Disabled
|
||||
s.Locale = Locale
|
||||
s.ReferralLink = ReferralLink
|
||||
s.IsPaired = IsPaired
|
||||
s.AccountType = AccountType
|
||||
return s
|
||||
}
|
||||
|
||||
// Team : Information about a team.
|
||||
type Team struct {
|
||||
// Id : The team's unique ID.
|
||||
Id string `json:"id"`
|
||||
// Name : The name of the team.
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
// NewTeam returns a new Team instance
|
||||
func NewTeam(Id string, Name string) *Team {
|
||||
s := new(Team)
|
||||
s.Id = Id
|
||||
s.Name = Name
|
||||
return s
|
||||
}
|
||||
|
||||
// FullTeam : Detailed information about a team.
|
||||
type FullTeam struct {
|
||||
Team
|
||||
// SharingPolicies : Team policies governing sharing.
|
||||
SharingPolicies *team_policies.TeamSharingPolicies `json:"sharing_policies"`
|
||||
}
|
||||
|
||||
// NewFullTeam returns a new FullTeam instance
|
||||
func NewFullTeam(Id string, Name string, SharingPolicies *team_policies.TeamSharingPolicies) *FullTeam {
|
||||
s := new(FullTeam)
|
||||
s.Id = Id
|
||||
s.Name = Name
|
||||
s.SharingPolicies = SharingPolicies
|
||||
return s
|
||||
}
|
||||
|
||||
// GetAccountArg : has no documentation (yet)
|
||||
type GetAccountArg struct {
|
||||
// AccountId : A user's account identifier.
|
||||
AccountId string `json:"account_id"`
|
||||
}
|
||||
|
||||
// NewGetAccountArg returns a new GetAccountArg instance
|
||||
func NewGetAccountArg(AccountId string) *GetAccountArg {
|
||||
s := new(GetAccountArg)
|
||||
s.AccountId = AccountId
|
||||
return s
|
||||
}
|
||||
|
||||
// GetAccountBatchArg : has no documentation (yet)
|
||||
type GetAccountBatchArg struct {
|
||||
// AccountIds : List of user account identifiers. Should not contain any
|
||||
// duplicate account IDs.
|
||||
AccountIds []string `json:"account_ids"`
|
||||
}
|
||||
|
||||
// NewGetAccountBatchArg returns a new GetAccountBatchArg instance
|
||||
func NewGetAccountBatchArg(AccountIds []string) *GetAccountBatchArg {
|
||||
s := new(GetAccountBatchArg)
|
||||
s.AccountIds = AccountIds
|
||||
return s
|
||||
}
|
||||
|
||||
// GetAccountBatchError : has no documentation (yet)
|
||||
type GetAccountBatchError struct {
|
||||
dropbox.Tagged
|
||||
// NoAccount : The value is an account ID specified in
|
||||
// `GetAccountBatchArg.account_ids` that does not exist.
|
||||
NoAccount string `json:"no_account,omitempty"`
|
||||
}
|
||||
|
||||
// Valid tag values for GetAccountBatchError
|
||||
const (
|
||||
GetAccountBatchErrorNoAccount = "no_account"
|
||||
GetAccountBatchErrorOther = "other"
|
||||
)
|
||||
|
||||
// UnmarshalJSON deserializes into a GetAccountBatchError instance
|
||||
func (u *GetAccountBatchError) UnmarshalJSON(body []byte) error {
|
||||
type wrap struct {
|
||||
dropbox.Tagged
|
||||
}
|
||||
var w wrap
|
||||
var err error
|
||||
if err = json.Unmarshal(body, &w); err != nil {
|
||||
return err
|
||||
}
|
||||
u.Tag = w.Tag
|
||||
switch u.Tag {
|
||||
case "no_account":
|
||||
err = json.Unmarshal(body, &u.NoAccount)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetAccountError : has no documentation (yet)
|
||||
type GetAccountError struct {
|
||||
dropbox.Tagged
|
||||
}
|
||||
|
||||
// Valid tag values for GetAccountError
|
||||
const (
|
||||
GetAccountErrorNoAccount = "no_account"
|
||||
GetAccountErrorOther = "other"
|
||||
)
|
||||
|
||||
// IndividualSpaceAllocation : has no documentation (yet)
|
||||
type IndividualSpaceAllocation struct {
|
||||
// Allocated : The total space allocated to the user's account (bytes).
|
||||
Allocated uint64 `json:"allocated"`
|
||||
}
|
||||
|
||||
// NewIndividualSpaceAllocation returns a new IndividualSpaceAllocation instance
|
||||
func NewIndividualSpaceAllocation(Allocated uint64) *IndividualSpaceAllocation {
|
||||
s := new(IndividualSpaceAllocation)
|
||||
s.Allocated = Allocated
|
||||
return s
|
||||
}
|
||||
|
||||
// Name : Representations for a person's name to assist with
|
||||
// internationalization.
|
||||
type Name struct {
|
||||
// GivenName : Also known as a first name.
|
||||
GivenName string `json:"given_name"`
|
||||
// Surname : Also known as a last name or family name.
|
||||
Surname string `json:"surname"`
|
||||
// FamiliarName : Locale-dependent name. In the US, a person's familiar name
|
||||
// is their `given_name`, but elsewhere, it could be any combination of a
|
||||
// person's `given_name` and `surname`.
|
||||
FamiliarName string `json:"familiar_name"`
|
||||
// DisplayName : A name that can be used directly to represent the name of a
|
||||
// user's Dropbox account.
|
||||
DisplayName string `json:"display_name"`
|
||||
// AbbreviatedName : An abbreviated form of the person's name. Their
|
||||
// initials in most locales.
|
||||
AbbreviatedName string `json:"abbreviated_name"`
|
||||
}
|
||||
|
||||
// NewName returns a new Name instance
|
||||
func NewName(GivenName string, Surname string, FamiliarName string, DisplayName string, AbbreviatedName string) *Name {
|
||||
s := new(Name)
|
||||
s.GivenName = GivenName
|
||||
s.Surname = Surname
|
||||
s.FamiliarName = FamiliarName
|
||||
s.DisplayName = DisplayName
|
||||
s.AbbreviatedName = AbbreviatedName
|
||||
return s
|
||||
}
|
||||
|
||||
// SpaceAllocation : Space is allocated differently based on the type of
|
||||
// account.
|
||||
type SpaceAllocation struct {
|
||||
dropbox.Tagged
|
||||
// Individual : The user's space allocation applies only to their individual
|
||||
// account.
|
||||
Individual *IndividualSpaceAllocation `json:"individual,omitempty"`
|
||||
// Team : The user shares space with other members of their team.
|
||||
Team *TeamSpaceAllocation `json:"team,omitempty"`
|
||||
}
|
||||
|
||||
// Valid tag values for SpaceAllocation
|
||||
const (
|
||||
SpaceAllocationIndividual = "individual"
|
||||
SpaceAllocationTeam = "team"
|
||||
SpaceAllocationOther = "other"
|
||||
)
|
||||
|
||||
// UnmarshalJSON deserializes into a SpaceAllocation instance
|
||||
func (u *SpaceAllocation) UnmarshalJSON(body []byte) error {
|
||||
type wrap struct {
|
||||
dropbox.Tagged
|
||||
// Individual : The user's space allocation applies only to their
|
||||
// individual account.
|
||||
Individual json.RawMessage `json:"individual,omitempty"`
|
||||
// Team : The user shares space with other members of their team.
|
||||
Team json.RawMessage `json:"team,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 "individual":
|
||||
err = json.Unmarshal(body, &u.Individual)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
case "team":
|
||||
err = json.Unmarshal(body, &u.Team)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// SpaceUsage : Information about a user's space usage and quota.
|
||||
type SpaceUsage struct {
|
||||
// Used : The user's total space usage (bytes).
|
||||
Used uint64 `json:"used"`
|
||||
// Allocation : The user's space allocation.
|
||||
Allocation *SpaceAllocation `json:"allocation"`
|
||||
}
|
||||
|
||||
// NewSpaceUsage returns a new SpaceUsage instance
|
||||
func NewSpaceUsage(Used uint64, Allocation *SpaceAllocation) *SpaceUsage {
|
||||
s := new(SpaceUsage)
|
||||
s.Used = Used
|
||||
s.Allocation = Allocation
|
||||
return s
|
||||
}
|
||||
|
||||
// TeamSpaceAllocation : has no documentation (yet)
|
||||
type TeamSpaceAllocation struct {
|
||||
// Used : The total space currently used by the user's team (bytes).
|
||||
Used uint64 `json:"used"`
|
||||
// Allocated : The total space allocated to the user's team (bytes).
|
||||
Allocated uint64 `json:"allocated"`
|
||||
}
|
||||
|
||||
// NewTeamSpaceAllocation returns a new TeamSpaceAllocation instance
|
||||
func NewTeamSpaceAllocation(Used uint64, Allocated uint64) *TeamSpaceAllocation {
|
||||
s := new(TeamSpaceAllocation)
|
||||
s.Used = Used
|
||||
s.Allocated = Allocated
|
||||
return s
|
||||
}
|
37
vendor/github.com/ncw/dropbox-sdk-go-unofficial/dropbox/users_common/types.go
generated
vendored
37
vendor/github.com/ncw/dropbox-sdk-go-unofficial/dropbox/users_common/types.go
generated
vendored
@ -1,37 +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 users_common : This namespace contains common data types used within
|
||||
// the users namespace
|
||||
package users_common
|
||||
|
||||
import "github.com/ncw/dropbox-sdk-go-unofficial/dropbox"
|
||||
|
||||
// AccountType : What type of account this user has.
|
||||
type AccountType struct {
|
||||
dropbox.Tagged
|
||||
}
|
||||
|
||||
// Valid tag values for AccountType
|
||||
const (
|
||||
AccountTypeBasic = "basic"
|
||||
AccountTypePro = "pro"
|
||||
AccountTypeBusiness = "business"
|
||||
)
|
237
vendor/github.com/ncw/dropbox-sdk-go-unofficial/generator/README.md
generated
vendored
237
vendor/github.com/ncw/dropbox-sdk-go-unofficial/generator/README.md
generated
vendored
@ -1,237 +0,0 @@
|
||||
# Dropbox Go SDK Generator
|
||||
|
||||
This directory contains the [Stone](https://github.com/dropbox/stone) code generators
|
||||
used to programmatically generate the [Dropbox Go SDK](https://github.com/dropbox/dropbox-sdk-go).
|
||||
|
||||
## Requirements
|
||||
|
||||
* While not a hard requirement, this repo currently assumes `python3` in the path.
|
||||
* Assumes you have already installed [Stone](https://github.com/dropbox/stone)
|
||||
* Requires [goimports](https://godoc.org/golang.org/x/tools/cmd/goimports) to fix up imports in the auto-generated code
|
||||
|
||||
## Basic Setup
|
||||
|
||||
. Clone this repo
|
||||
. Run `git submodule init` followed by `git submodule update`
|
||||
. Run `./generate-sdk.sh` to generate code under `../dropbox`
|
||||
|
||||
## Generated Code
|
||||
|
||||
### Basic Types
|
||||
|
||||
Here is how Stone [basic types](https://github.com/dropbox/stone/blob/master/doc/lang_ref.rst#basic-types) map to Go types:
|
||||
|
||||
Stone Type | Go Type
|
||||
---------- | -------
|
||||
Int32/Int64/UInt32/UInt64 | int32/int64/uint32/uint64
|
||||
Float32/Float64 | float32/float64
|
||||
Boolean | bool
|
||||
String | string
|
||||
Timestamp | time.Time
|
||||
Void | struct{}
|
||||
|
||||
### Structs
|
||||
|
||||
Stone [structs](https://github.com/dropbox/stone/blob/master/doc/lang_ref.rst#struct) are represented as Go [structs](https://gobyexample.com/structs) in a relatively straight-forward manner. Each struct member is exported and also gets assigned the correct json tag. The latter is used for serializing requests and deserializing responses. Non-primitive types are represented as pointers to the corresponding type.
|
||||
|
||||
```
|
||||
struct Account
|
||||
"The amount of detail revealed about an account depends on the user
|
||||
being queried and the user making the query."
|
||||
|
||||
account_id AccountId
|
||||
"The user's unique Dropbox ID."
|
||||
name Name
|
||||
"Details of a user's name."
|
||||
```
|
||||
|
||||
```go
|
||||
// The amount of detail revealed about an account depends on the user being
|
||||
// queried and the user making the query.
|
||||
type Account struct {
|
||||
// The user's unique Dropbox ID.
|
||||
AccountId string `json:"account_id"`
|
||||
// Details of a user's name.
|
||||
Name *Name `json:"name"`
|
||||
}
|
||||
```
|
||||
|
||||
#### Inheritance
|
||||
|
||||
Stone supports [struct inheritance](https://github.com/dropbox/stone/blob/master/doc/lang_ref.rst#inheritance). In Go, we support this via [embedding](https://golang.org/doc/effective_go.html#embedding)
|
||||
|
||||
```
|
||||
struct BasicAccount extends Account
|
||||
"Basic information about any account."
|
||||
|
||||
is_teammate Boolean
|
||||
"Whether this user is a teammate of the current user. If this account
|
||||
is the current user's account, then this will be :val:`true`."
|
||||
```
|
||||
|
||||
```go
|
||||
// Basic information about any account.
|
||||
type BasicAccount struct {
|
||||
Account
|
||||
// Whether this user is a teammate of the current user. If this account is
|
||||
// the current user's account, then this will be `True`.
|
||||
IsTeammate bool `json:"is_teammate"`
|
||||
```
|
||||
|
||||
### Unions
|
||||
|
||||
Stone https://github.com/dropbox/stone/blob/master/doc/lang_ref.rst#union[unions] are bit more complex as Go doesn't have native support for union types (tagged or otherwise). We declare a union as a Go struct with all the possible fields as pointer types, and then use the tag value to populate the correct field during deserialization. This necessitates the use of an intermediate wrapper struct for the deserialization to work correctly, see below for a concrete example.
|
||||
|
||||
```
|
||||
union SpaceAllocation
|
||||
"Space is allocated differently based on the type of account."
|
||||
|
||||
individual IndividualSpaceAllocation
|
||||
"The user's space allocation applies only to their individual account."
|
||||
team TeamSpaceAllocation
|
||||
"The user shares space with other members of their team."
|
||||
```
|
||||
|
||||
```go
|
||||
// Space is allocated differently based on the type of account.
|
||||
type SpaceAllocation struct {
|
||||
dropbox.Tagged
|
||||
// The user's space allocation applies only to their individual account.
|
||||
Individual *IndividualSpaceAllocation `json:"individual,omitempty"`
|
||||
// The user shares space with other members of their team.
|
||||
Team *TeamSpaceAllocation `json:"team,omitempty"`
|
||||
}
|
||||
|
||||
// Valid tag values for `SpaceAllocation`
|
||||
const (
|
||||
SpaceAllocation_Individual = "individual"
|
||||
SpaceAllocation_Team = "team"
|
||||
SpaceAllocation_Other = "other"
|
||||
)
|
||||
|
||||
func (u *SpaceAllocation) UnmarshalJSON(body []byte) error {
|
||||
type wrap struct {
|
||||
dropbox.Tagged
|
||||
// The user's space allocation applies only to their individual account.
|
||||
Individual json.RawMessage `json:"individual,omitempty"`
|
||||
// The user shares space with other members of their team.
|
||||
Team json.RawMessage `json:"team,omitempty"`
|
||||
}
|
||||
var w wrap
|
||||
if err := json.Unmarshal(body, &w); err != nil {
|
||||
return err
|
||||
}
|
||||
u.Tag = w.Tag
|
||||
switch u.Tag {
|
||||
case "individual":
|
||||
if err := json.Unmarshal(body, &u.Individual); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
case "team":
|
||||
if err := json.Unmarshal(body, &u.Team); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
}
|
||||
return nil
|
||||
}
|
||||
```
|
||||
|
||||
### Struct with Enumerated Subtypes
|
||||
|
||||
Per the https://github.com/dropbox/stone/blob/master/doc/lang_ref.rst#struct-polymorphism[spec], structs with enumerated subtypes are a mechanism of inheritance:
|
||||
|
||||
> If a struct enumerates its subtypes, an instance of any subtype will satisfy the type constraint. This is useful when wanting to discriminate amongst types that are part of the same hierarchy while simultaneously being able to avoid discriminating when accessing common fields.
|
||||
|
||||
To represent structs with enumerated subtypes in Go, we use a combination of Go interface types and unions as implemented above. Considering the following:
|
||||
|
||||
```
|
||||
struct Metadata
|
||||
union
|
||||
file FileMetadata
|
||||
folder FolderMetadata
|
||||
deleted DeletedMetadata # Used by list_folder* and search
|
||||
|
||||
name String
|
||||
path_lower String?
|
||||
path_display String?
|
||||
parent_shared_folder_id common.SharedFolderId?
|
||||
|
||||
struct FileMetadata extends Metadata
|
||||
id Id
|
||||
client_modified common.DropboxTimestamp
|
||||
...
|
||||
```
|
||||
|
||||
In this case, `FileMetadata`, `FolderMetadata` etc are subtypes of `Metadata`. Specifically, any subtype can be used where a parent type is expected. Thus, if `list_folder` returns a list of `Metadata`s, we should be able to parse and "upcast" to one of the enumerated subtypes.
|
||||
|
||||
First, we define structs to represent the base and enumerated types as we did for inherited structs above:
|
||||
|
||||
```go
|
||||
type Metadata struct {
|
||||
Name string `json:"name"`
|
||||
PathLower string `json:"path_lower,omitempty"`
|
||||
PathDisplay string `json:"path_display,omitempty"`
|
||||
ParentSharedFolderId string `json:"parent_shared_folder_id,omitempty"`
|
||||
}
|
||||
|
||||
type FileMetadata struct {
|
||||
Metadata
|
||||
Id string `json:"id"`
|
||||
ClientModified time.Time `json:"client_modified"`
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
Next, we define an interface type with a dummy method and ensure that both the base and the subtypes implement the interface:
|
||||
|
||||
```go
|
||||
type IsMetadata interface {
|
||||
IsMetadata()
|
||||
}
|
||||
|
||||
func (u *Metadata) IsMetadata() {} // Subtypes get this for free due to embedding
|
||||
```
|
||||
|
||||
At this point, types or methods that accept/return a struct with enumerated subtypes can use the interface type instead. For instance:
|
||||
|
||||
```go
|
||||
func GetMetadata(arg *GetMetadataArg) (res IsMetadata, err error) {...}
|
||||
|
||||
type ListFolderResult struct {
|
||||
// The files and (direct) subfolders in the folder.
|
||||
Entries []IsMetadata `json:"entries"`
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
Finally, to actually deserialize a bag of bytes into the appropriate type or subtype, we use a trick similar to how we handle unions above.
|
||||
|
||||
```go
|
||||
type metadataUnion struct {
|
||||
dropbox.Tagged
|
||||
File *FileMetadata `json:"file,omitempty"`
|
||||
Folder *FolderMetadata `json:"folder,omitempty"`
|
||||
Deleted *DeletedMetadata `json:"deleted,omitempty"`
|
||||
}
|
||||
|
||||
func (u *metadataUnion) UnmarshalJSON(body []byte) error {...}
|
||||
|
||||
func (dbx *apiImpl) GetMetadata(arg *GetMetadataArg) (res IsMetadata, err error) {
|
||||
...
|
||||
var tmp metadataUnion
|
||||
err = json.Unmarshal(body, &tmp)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
switch tmp.Tag {
|
||||
case "file":
|
||||
res = tmp.File
|
||||
case "folder":
|
||||
res = tmp.Folder
|
||||
case "deleted":
|
||||
res = tmp.Deleted
|
||||
}
|
||||
}
|
||||
```
|
25
vendor/github.com/ncw/dropbox-sdk-go-unofficial/generator/generate-sdk.sh
generated
vendored
25
vendor/github.com/ncw/dropbox-sdk-go-unofficial/generator/generate-sdk.sh
generated
vendored
@ -1,25 +0,0 @@
|
||||
#! /usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
if [[ $# -ne 0 ]]; then
|
||||
echo "$0: Not expecting any command-line arguments, got $#." 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
loc=$(realpath -e $0)
|
||||
base_dir=$(dirname "$loc")
|
||||
spec_dir="$base_dir/dropbox-api-spec"
|
||||
gen_dir=$(dirname ${base_dir})/dropbox
|
||||
|
||||
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.0.0-beta"
|
||||
pushd ${spec_dir}
|
||||
spec_version=$(git rev-parse --short HEAD)
|
||||
popd
|
||||
|
||||
sed -i -e "s/UNKNOWN SDK VERSION/${sdk_version}/" \
|
||||
-e "s/UNKNOWN SPEC VERSION/${spec_version}/" ${gen_dir}/sdk.go
|
||||
goimports -l -w ${gen_dir}
|
207
vendor/github.com/ncw/dropbox-sdk-go-unofficial/generator/go_client.stoneg.py
generated
vendored
207
vendor/github.com/ncw/dropbox-sdk-go-unofficial/generator/go_client.stoneg.py
generated
vendored
@ -1,207 +0,0 @@
|
||||
import os
|
||||
|
||||
from stone.generator import CodeGenerator
|
||||
from stone.data_type import (
|
||||
is_void_type,
|
||||
is_struct_type
|
||||
)
|
||||
|
||||
from go_helpers import (
|
||||
HEADER,
|
||||
fmt_type,
|
||||
fmt_var,
|
||||
generate_doc,
|
||||
)
|
||||
|
||||
|
||||
class GoClientGenerator(CodeGenerator):
|
||||
def generate(self, api):
|
||||
for namespace in api.namespaces.values():
|
||||
if len(namespace.routes) > 0:
|
||||
self._generate_client(namespace)
|
||||
|
||||
def _generate_client(self, namespace):
|
||||
file_name = os.path.join(self.target_folder_path, namespace.name,
|
||||
'client.go')
|
||||
with self.output_to_relative_path(file_name):
|
||||
self.emit_raw(HEADER)
|
||||
self.emit()
|
||||
self.emit('package %s' % namespace.name)
|
||||
self.emit()
|
||||
|
||||
self.emit('// Client interface describes all routes in this namespace')
|
||||
with self.block('type Client interface'):
|
||||
for route in namespace.routes:
|
||||
generate_doc(self, route)
|
||||
self.emit(self._generate_route_signature(namespace, route))
|
||||
self.emit()
|
||||
|
||||
self.emit('type apiImpl dropbox.Context')
|
||||
for route in namespace.routes:
|
||||
self._generate_route(namespace, route)
|
||||
self.emit('// New returns a Client implementation for this namespace')
|
||||
with self.block('func New(c dropbox.Config) *apiImpl'):
|
||||
self.emit('ctx := apiImpl(dropbox.NewContext(c))')
|
||||
self.emit('return &ctx')
|
||||
|
||||
def _generate_route_signature(self, namespace, route):
|
||||
req = fmt_type(route.arg_data_type, namespace)
|
||||
res = fmt_type(route.result_data_type, namespace, use_interface=True)
|
||||
fn = fmt_var(route.name)
|
||||
style = route.attrs.get('style', 'rpc')
|
||||
|
||||
arg = '' if is_void_type(route.arg_data_type) else 'arg {req}'
|
||||
ret = '(err error)' if is_void_type(route.result_data_type) else \
|
||||
'(res {res}, err error)'
|
||||
signature = '{fn}(' + arg + ') ' + ret
|
||||
if style == 'download':
|
||||
signature = '{fn}(' + arg + \
|
||||
') (res {res}, content io.ReadCloser, err error)'
|
||||
elif style == 'upload':
|
||||
signature = '{fn}(' + arg + ', content io.Reader) ' + ret
|
||||
if is_void_type(route.arg_data_type):
|
||||
signature = '{fn}(content io.Reader) ' + ret
|
||||
return signature.format(fn=fn, req=req, res=res)
|
||||
|
||||
|
||||
def _generate_route(self, namespace, route):
|
||||
out = self.emit
|
||||
fn = fmt_var(route.name)
|
||||
err = fmt_type(route.error_data_type, namespace)
|
||||
out('//%sAPIError is an error-wrapper for the %s route' %
|
||||
(fn, route.name))
|
||||
with self.block('type {fn}APIError struct'.format(fn=fn)):
|
||||
out('dropbox.APIError')
|
||||
out('EndpointError {err} `json:"error"`'.format(err=err))
|
||||
out()
|
||||
|
||||
signature = 'func (dbx *apiImpl) ' + self._generate_route_signature(
|
||||
namespace, route)
|
||||
with self.block(signature):
|
||||
out('cli := dbx.Client')
|
||||
out()
|
||||
|
||||
self._generate_request(namespace, route)
|
||||
self._generate_post()
|
||||
self._generate_response(route)
|
||||
ok_check = 'if resp.StatusCode == http.StatusOK'
|
||||
if fn == "Download":
|
||||
ok_check += ' || resp.StatusCode == http.StatusPartialContent'
|
||||
with self.block(ok_check):
|
||||
self._generate_result(route)
|
||||
self._generate_error_handling(route)
|
||||
|
||||
out()
|
||||
|
||||
def _generate_request(self, namespace, route):
|
||||
out = self.emit
|
||||
auth = route.attrs.get('auth', '')
|
||||
host = route.attrs.get('host', 'api')
|
||||
style = route.attrs.get('style', 'rpc')
|
||||
|
||||
body = 'nil'
|
||||
if not is_void_type(route.arg_data_type):
|
||||
with self.block('if dbx.Config.Verbose'):
|
||||
out('log.Printf("arg: %v", arg)')
|
||||
out('b, err := json.Marshal(arg)')
|
||||
with self.block('if err != nil'):
|
||||
out('return')
|
||||
out()
|
||||
if host != 'content':
|
||||
body = 'bytes.NewReader(b)'
|
||||
if style == 'upload':
|
||||
body = 'content'
|
||||
|
||||
headers = {}
|
||||
if not is_void_type(route.arg_data_type):
|
||||
if host == 'content':
|
||||
headers["Dropbox-API-Arg"] = "string(b)"
|
||||
else:
|
||||
headers["Content-Type"] = '"application/json"'
|
||||
if style == 'upload':
|
||||
headers["Content-Type"] = '"application/octet-stream"'
|
||||
|
||||
out('headers := map[string]string{')
|
||||
for k, v in sorted(headers.items()):
|
||||
out('\t"{}": {},'.format(k, v))
|
||||
out('}')
|
||||
if fmt_var(route.name) == "Download":
|
||||
out('for k, v := range arg.ExtraHeaders { headers[k] = v }')
|
||||
if auth != 'noauth' and auth != 'team':
|
||||
with self.block('if dbx.Config.AsMemberID != ""'):
|
||||
out('headers["Dropbox-API-Select-User"] = dbx.Config.AsMemberID')
|
||||
out()
|
||||
|
||||
authed = 'false' if auth == 'noauth' else 'true'
|
||||
out('req, err := (*dropbox.Context)(dbx).NewRequest("{}", "{}", {}, "{}", "{}", headers, {})'.format(
|
||||
host, style, authed, namespace.name, route.name, body))
|
||||
with self.block('if err != nil'):
|
||||
out('return')
|
||||
with self.block('if dbx.Config.Verbose'):
|
||||
out('log.Printf("req: %v", req)')
|
||||
out()
|
||||
|
||||
def _generate_post(self):
|
||||
out = self.emit
|
||||
|
||||
out('resp, err := cli.Do(req)')
|
||||
with self.block('if dbx.Config.Verbose'):
|
||||
out('log.Printf("resp: %v", resp)')
|
||||
|
||||
with self.block('if err != nil'):
|
||||
out('return')
|
||||
out()
|
||||
|
||||
def _generate_response(self, route):
|
||||
out = self.emit
|
||||
style = route.attrs.get('style', 'rpc')
|
||||
if style == 'download':
|
||||
out('body := []byte(resp.Header.Get("Dropbox-API-Result"))')
|
||||
out('content = resp.Body')
|
||||
else:
|
||||
out('defer resp.Body.Close()')
|
||||
with self.block('body, err := ioutil.ReadAll(resp.Body);'
|
||||
'if err != nil'):
|
||||
out('return')
|
||||
out()
|
||||
with self.block('if dbx.Config.Verbose'):
|
||||
out('log.Printf("body: %s", body)')
|
||||
|
||||
def _generate_error_handling(self, route):
|
||||
out = self.emit
|
||||
with self.block('if resp.StatusCode == http.StatusConflict'):
|
||||
out('var apiError %sAPIError' % fmt_var(route.name))
|
||||
with self.block('err = json.Unmarshal(body, &apiError);'
|
||||
'if err != nil'):
|
||||
out('return')
|
||||
out('err = apiError')
|
||||
out('return')
|
||||
out('var apiError dropbox.APIError')
|
||||
with self.block('if resp.StatusCode == http.StatusBadRequest'):
|
||||
out('apiError.ErrorSummary = string(body)')
|
||||
out('err = apiError')
|
||||
out('return')
|
||||
with self.block('err = json.Unmarshal(body, &apiError);'
|
||||
'if err != nil'):
|
||||
out('return')
|
||||
out('err = apiError')
|
||||
out('return')
|
||||
|
||||
def _generate_result(self, route):
|
||||
out = self.emit
|
||||
if is_struct_type(route.result_data_type) and \
|
||||
route.result_data_type.has_enumerated_subtypes():
|
||||
out('var tmp %sUnion' % fmt_var(route.result_data_type.name, export=False))
|
||||
with self.block('err = json.Unmarshal(body, &tmp);'
|
||||
'if err != nil'):
|
||||
out('return')
|
||||
with self.block('switch tmp.Tag'):
|
||||
for t in route.result_data_type.get_enumerated_subtypes():
|
||||
with self.block('case "%s":' % t.name, delim=(None, None)):
|
||||
self.emit('res = tmp.%s' % fmt_var(t.name))
|
||||
elif not is_void_type(route.result_data_type):
|
||||
with self.block('err = json.Unmarshal(body, &res);'
|
||||
'if err != nil'):
|
||||
out('return')
|
||||
out()
|
||||
out('return')
|
134
vendor/github.com/ncw/dropbox-sdk-go-unofficial/generator/go_helpers.py
generated
vendored
134
vendor/github.com/ncw/dropbox-sdk-go-unofficial/generator/go_helpers.py
generated
vendored
@ -1,134 +0,0 @@
|
||||
from stone.api import ApiNamespace
|
||||
from stone.data_type import (
|
||||
Boolean,
|
||||
Float32,
|
||||
Float64,
|
||||
Int32,
|
||||
Int64,
|
||||
String,
|
||||
Timestamp,
|
||||
UInt32,
|
||||
UInt64,
|
||||
unwrap_nullable,
|
||||
is_composite_type,
|
||||
is_list_type,
|
||||
is_struct_type,
|
||||
Void,
|
||||
)
|
||||
from stone.target import helpers
|
||||
|
||||
HEADER = """\
|
||||
// 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.
|
||||
"""
|
||||
|
||||
_reserved_keywords = {
|
||||
'break', 'default', 'func', 'interface', 'select',
|
||||
'case', 'defer', 'go', 'map', 'struct',
|
||||
'chan', 'else', 'goto', 'package', 'switch',
|
||||
'const', 'fallthrough', 'if', 'range', 'type',
|
||||
'continue', 'for', 'import', 'return', 'var',
|
||||
}
|
||||
|
||||
_type_table = {
|
||||
UInt64: 'uint64',
|
||||
Int64: 'int64',
|
||||
UInt32: 'uint32',
|
||||
Int32: 'int32',
|
||||
Float64: 'float64',
|
||||
Float32: 'float32',
|
||||
Boolean: 'bool',
|
||||
String: 'string',
|
||||
Timestamp: 'time.Time',
|
||||
Void: 'struct{}',
|
||||
}
|
||||
|
||||
|
||||
def _rename_if_reserved(s):
|
||||
if s in _reserved_keywords:
|
||||
return s + '_'
|
||||
else:
|
||||
return s
|
||||
|
||||
|
||||
def fmt_type(data_type, namespace=None, use_interface=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)
|
||||
type_name = data_type.name
|
||||
if use_interface and _needs_base_type(data_type):
|
||||
type_name = 'Is' + type_name
|
||||
if is_composite_type(data_type) and namespace is not None and \
|
||||
namespace.name != data_type.namespace.name:
|
||||
type_name = data_type.namespace.name + '.' + type_name
|
||||
if use_interface and _needs_base_type(data_type):
|
||||
return _type_table.get(data_type.__class__, type_name)
|
||||
else:
|
||||
return _type_table.get(data_type.__class__, '*' + type_name)
|
||||
|
||||
|
||||
def fmt_var(name, export=True, check_reserved=False):
|
||||
s = helpers.fmt_pascal(name) if export else helpers.fmt_camel(name)
|
||||
return _rename_if_reserved(s) if check_reserved else s
|
||||
|
||||
|
||||
def _doc_handler(tag, val):
|
||||
if tag == 'type':
|
||||
return '`{}`'.format(val)
|
||||
elif tag == 'route':
|
||||
return '`{}`'.format(helpers.fmt_camel(val))
|
||||
elif tag == 'link':
|
||||
anchor, link = val.rsplit(' ', 1)
|
||||
return '`{}` <{}>'.format(anchor, link)
|
||||
elif tag == 'val':
|
||||
if val == 'null':
|
||||
return 'nil'
|
||||
else:
|
||||
return val
|
||||
elif tag == 'field':
|
||||
return '`{}`'.format(val)
|
||||
else:
|
||||
raise RuntimeError('Unknown doc ref tag %r' % tag)
|
||||
|
||||
|
||||
def generate_doc(code_generator, t):
|
||||
doc = t.doc
|
||||
if doc is None:
|
||||
doc = 'has no documentation (yet)'
|
||||
doc = code_generator.process_doc(doc, _doc_handler)
|
||||
d = '%s : %s' % (fmt_var(t.name), doc)
|
||||
if isinstance(t, ApiNamespace):
|
||||
d = 'Package %s : %s' % (t.name, doc)
|
||||
code_generator.emit_wrapped_text(d, prefix='// ')
|
||||
|
||||
|
||||
def _needs_base_type(data_type):
|
||||
if is_struct_type(data_type) and data_type.has_enumerated_subtypes():
|
||||
return True
|
||||
if is_list_type(data_type):
|
||||
return _needs_base_type(data_type.data_type)
|
||||
return False
|
||||
|
||||
|
||||
def needs_base_type(struct):
|
||||
for field in struct.fields:
|
||||
if _needs_base_type(field.data_type):
|
||||
return True
|
||||
return False
|
75
vendor/github.com/ncw/dropbox-sdk-go-unofficial/generator/go_rsrc/files/metadata.go
generated
vendored
75
vendor/github.com/ncw/dropbox-sdk-go-unofficial/generator/go_rsrc/files/metadata.go
generated
vendored
@ -1,75 +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 []metadataUnion `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 {
|
||||
switch e.Tag {
|
||||
case "file":
|
||||
r.Entries[i] = e.File
|
||||
case "folder":
|
||||
r.Entries[i] = e.Folder
|
||||
case "deleted":
|
||||
r.Entries[i] = e.Deleted
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type searchMatch struct {
|
||||
MatchType *SearchMatchType `json:"match_type"`
|
||||
Metadata metadataUnion `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
|
||||
e := m.Metadata
|
||||
switch e.Tag {
|
||||
case "file":
|
||||
s.Metadata = e.File
|
||||
case "folder":
|
||||
s.Metadata = e.Folder
|
||||
case "deleted":
|
||||
s.Metadata = e.Deleted
|
||||
}
|
||||
return nil
|
||||
}
|
170
vendor/github.com/ncw/dropbox-sdk-go-unofficial/generator/go_rsrc/sdk.go
generated
vendored
170
vendor/github.com/ncw/dropbox-sdk-go-unofficial/generator/go_rsrc/sdk.go
generated
vendored
@ -1,170 +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 dropbox
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"golang.org/x/oauth2"
|
||||
)
|
||||
|
||||
const (
|
||||
apiVersion = 2
|
||||
defaultDomain = ".dropboxapi.com"
|
||||
hostAPI = "api"
|
||||
hostContent = "content"
|
||||
hostNotify = "notify"
|
||||
sdkVersion = "UNKNOWN SDK VERSION"
|
||||
specVersion = "UNKNOWN SPEC VERSION"
|
||||
)
|
||||
|
||||
// Version returns the current SDK version and API Spec version
|
||||
func Version() (string, string) {
|
||||
return sdkVersion, specVersion
|
||||
}
|
||||
|
||||
// Config contains parameters for configuring the SDK.
|
||||
type Config struct {
|
||||
// OAuth2 access token
|
||||
Token string
|
||||
// Enable verbose logging in SDK
|
||||
Verbose bool
|
||||
// Used with APIs that support operations as another user
|
||||
AsMemberID string
|
||||
// No need to set -- for testing only
|
||||
Domain string
|
||||
// No need to set -- for testing only
|
||||
Client *http.Client
|
||||
// No need to set -- for testing only
|
||||
HeaderGenerator func(hostType string, style string, namespace string, route string) map[string]string
|
||||
// No need to set -- for testing only
|
||||
URLGenerator func(hostType string, style string, namespace string, route string) string
|
||||
}
|
||||
|
||||
// Context is the base client context used to implement per-namespace clients.
|
||||
type Context struct {
|
||||
Config Config
|
||||
Client *http.Client
|
||||
HeaderGenerator func(hostType string, style string, namespace string, route string) map[string]string
|
||||
URLGenerator func(hostType string, style string, namespace string, route string) string
|
||||
}
|
||||
|
||||
// NewRequest returns an appropriate Request object for the given namespace/route.
|
||||
func (c *Context) NewRequest(
|
||||
hostType string,
|
||||
style string,
|
||||
authed bool,
|
||||
namespace string,
|
||||
route string,
|
||||
headers map[string]string,
|
||||
body io.Reader,
|
||||
) (*http.Request, error) {
|
||||
url := c.URLGenerator(hostType, style, namespace, route)
|
||||
req, err := http.NewRequest("POST", url, body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for k, v := range headers {
|
||||
req.Header.Add(k, v)
|
||||
}
|
||||
for k, v := range c.HeaderGenerator(hostType, style, namespace, route) {
|
||||
req.Header.Add(k, v)
|
||||
}
|
||||
if req.Header.Get("Host") != "" {
|
||||
req.Host = req.Header.Get("Host")
|
||||
}
|
||||
if !authed {
|
||||
req.Header.Del("Authorization")
|
||||
}
|
||||
return req, nil
|
||||
}
|
||||
|
||||
// NewContext returns a new Context with the given Config.
|
||||
func NewContext(c Config) Context {
|
||||
domain := c.Domain
|
||||
if domain == "" {
|
||||
domain = defaultDomain
|
||||
}
|
||||
|
||||
client := c.Client
|
||||
if client == nil {
|
||||
var conf = &oauth2.Config{Endpoint: OAuthEndpoint(domain)}
|
||||
tok := &oauth2.Token{AccessToken: c.Token}
|
||||
client = conf.Client(oauth2.NoContext, tok)
|
||||
}
|
||||
|
||||
headerGenerator := c.HeaderGenerator
|
||||
if headerGenerator == nil {
|
||||
headerGenerator = func(hostType string, style string, namespace string, route string) map[string]string {
|
||||
return map[string]string{}
|
||||
}
|
||||
}
|
||||
|
||||
urlGenerator := c.URLGenerator
|
||||
if urlGenerator == nil {
|
||||
hostMap := map[string]string{
|
||||
hostAPI: hostAPI + domain,
|
||||
hostContent: hostContent + domain,
|
||||
hostNotify: hostNotify + domain,
|
||||
}
|
||||
urlGenerator = func(hostType string, style string, namespace string, route string) string {
|
||||
fqHost := hostMap[hostType]
|
||||
return fmt.Sprintf("https://%s/%d/%s/%s", fqHost, apiVersion, namespace, route)
|
||||
}
|
||||
}
|
||||
|
||||
return Context{c, client, headerGenerator, urlGenerator}
|
||||
}
|
||||
|
||||
// OAuthEndpoint constructs an `oauth2.Endpoint` for the given domain
|
||||
func OAuthEndpoint(domain string) oauth2.Endpoint {
|
||||
if domain == "" {
|
||||
domain = defaultDomain
|
||||
}
|
||||
authURL := fmt.Sprintf("https://meta%s/1/oauth2/authorize", domain)
|
||||
tokenURL := fmt.Sprintf("https://api%s/1/oauth2/token", domain)
|
||||
if domain == defaultDomain {
|
||||
authURL = "https://www.dropbox.com/1/oauth2/authorize"
|
||||
}
|
||||
return oauth2.Endpoint{AuthURL: authURL, TokenURL: tokenURL}
|
||||
}
|
||||
|
||||
// Tagged is used for tagged unions.
|
||||
type Tagged struct {
|
||||
Tag string `json:".tag"`
|
||||
}
|
||||
|
||||
// APIError is the base type for endpoint-specific errors.
|
||||
type APIError struct {
|
||||
ErrorSummary string `json:"error_summary"`
|
||||
}
|
||||
|
||||
func (e APIError) Error() string {
|
||||
return e.ErrorSummary
|
||||
}
|
||||
|
||||
func init() {
|
||||
// These are not registered in the oauth library by default
|
||||
oauth2.RegisterBrokenAuthHeaderProvider("https://api.dropboxapi.com")
|
||||
oauth2.RegisterBrokenAuthHeaderProvider("https://api-dbdev.dev.corp.dropbox.com")
|
||||
}
|
49
vendor/github.com/ncw/dropbox-sdk-go-unofficial/generator/go_rsrc/sharing/metadata.go
generated
vendored
49
vendor/github.com/ncw/dropbox-sdk-go-unofficial/generator/go_rsrc/sharing/metadata.go
generated
vendored
@ -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
|
||||
}
|
198
vendor/github.com/ncw/dropbox-sdk-go-unofficial/generator/go_types.stoneg.py
generated
vendored
198
vendor/github.com/ncw/dropbox-sdk-go-unofficial/generator/go_types.stoneg.py
generated
vendored
@ -1,198 +0,0 @@
|
||||
import os
|
||||
import shutil
|
||||
|
||||
from stone.generator import CodeGenerator
|
||||
from stone.data_type import (
|
||||
is_boolean_type,
|
||||
is_nullable_type,
|
||||
is_primitive_type,
|
||||
is_struct_type,
|
||||
is_union_type,
|
||||
is_void_type,
|
||||
)
|
||||
|
||||
from go_helpers import (
|
||||
HEADER,
|
||||
fmt_type,
|
||||
fmt_var,
|
||||
generate_doc,
|
||||
)
|
||||
|
||||
|
||||
class GoTypesGenerator(CodeGenerator):
|
||||
def generate(self, api):
|
||||
rsrc_folder = os.path.join(os.path.dirname(__file__), 'go_rsrc')
|
||||
shutil.copy(os.path.join(rsrc_folder, 'sdk.go'),
|
||||
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,
|
||||
'types.go')
|
||||
with self.output_to_relative_path(file_name):
|
||||
self.emit_raw(HEADER)
|
||||
self.emit()
|
||||
generate_doc(self, namespace)
|
||||
self.emit('package %s' % namespace.name)
|
||||
self.emit()
|
||||
|
||||
for data_type in namespace.linearize_data_types():
|
||||
self._generate_data_type(data_type)
|
||||
|
||||
def _generate_data_type(self, data_type):
|
||||
generate_doc(self, data_type)
|
||||
if is_struct_type(data_type):
|
||||
self._generate_struct(data_type)
|
||||
if data_type.has_enumerated_subtypes():
|
||||
self._generate_base_type(data_type)
|
||||
elif is_union_type(data_type):
|
||||
self._generate_union(data_type)
|
||||
else:
|
||||
self.logger.info("Unhandled data type", data_type)
|
||||
|
||||
def _generate_base_type(self, base):
|
||||
t = fmt_type(base).lstrip('*')
|
||||
self.emit('// Is{0} is the interface type for {0} and its subtypes'.format(t))
|
||||
with self.block('type Is%s interface' % t):
|
||||
self.emit('Is%s()' % t)
|
||||
self.emit()
|
||||
self.emit('// Is{0} implements the Is{0} interface'.format(t))
|
||||
self.emit("func (u *{0}) Is{0}() {{}}".format(t))
|
||||
self.emit()
|
||||
self._generate_union_helper(base)
|
||||
|
||||
self.emit("// Is{0}FromJSON converts JSON to a concrete Is{0} instance".format(t))
|
||||
with self.block("func Is{0}FromJSON(data []byte) (Is{0}, error)".format(t)):
|
||||
name = fmt_var(t, export=False) + 'Union'
|
||||
self.emit("var t {0}".format(name))
|
||||
with self.block("if err := json.Unmarshal(data, &t); err != nil"):
|
||||
self.emit("return nil, err")
|
||||
with self.block("switch t.Tag"):
|
||||
fields = base.get_enumerated_subtypes()
|
||||
for field in fields:
|
||||
with self.block('case "%s":' % field.name, delim=(None, None)):
|
||||
self.emit("return t.{0}, nil".format(fmt_var(field.name)))
|
||||
# FIX THIS
|
||||
self.emit("return nil, nil")
|
||||
|
||||
def _generate_struct(self, struct):
|
||||
with self.block('type %s struct' % struct.name):
|
||||
if struct.parent_type:
|
||||
self.emit(fmt_type(struct.parent_type, struct.namespace).lstrip('*'))
|
||||
for field in struct.fields:
|
||||
self._generate_field(field, namespace=struct.namespace)
|
||||
if struct.name in ('DownloadArg',):
|
||||
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)
|
||||
|
||||
def _generate_struct_builder(self, struct):
|
||||
fields = ["%s %s" % (fmt_var(field.name),
|
||||
fmt_type(field.data_type, struct.namespace,
|
||||
use_interface=True))
|
||||
for field in struct.all_required_fields]
|
||||
self.emit('// New{0} returns a new {0} instance'.format(struct.name))
|
||||
signature = "func New{0}({1}) *{0}".format(struct.name, ', '.join(fields))
|
||||
with self.block(signature):
|
||||
self.emit('s := new({0})'.format(struct.name))
|
||||
for field in struct.all_required_fields:
|
||||
field_name = fmt_var(field.name)
|
||||
self.emit("s.{0} = {0}".format(field_name))
|
||||
|
||||
for field in struct.all_optional_fields:
|
||||
if field.has_default:
|
||||
if is_primitive_type(field.data_type):
|
||||
default = field.default
|
||||
if is_boolean_type(field.data_type):
|
||||
default = str(default).lower()
|
||||
self.emit('s.{0} = {1}'.format(fmt_var(field.name), default))
|
||||
elif is_union_type(field.data_type):
|
||||
self.emit('s.%s = &%s{Tagged:dropbox.Tagged{"%s"}}' %
|
||||
(fmt_var(field.name),
|
||||
fmt_type(field.data_type, struct.namespace).lstrip('*'),
|
||||
field.default.tag_name))
|
||||
self.emit('return s')
|
||||
self.emit()
|
||||
|
||||
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)
|
||||
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))
|
||||
|
||||
def _generate_union(self, union):
|
||||
self._generate_union_helper(union)
|
||||
|
||||
def _generate_union_helper(self, u):
|
||||
name = u.name
|
||||
namespace = u.namespace
|
||||
fields = u.fields
|
||||
if is_struct_type(u) and u.has_enumerated_subtypes():
|
||||
name = fmt_var(name, export=False) + 'Union'
|
||||
fields = u.get_enumerated_subtypes()
|
||||
|
||||
with self.block('type %s struct' % name):
|
||||
self.emit('dropbox.Tagged')
|
||||
for field in fields:
|
||||
if is_void_type(field.data_type):
|
||||
continue
|
||||
self._generate_field(field, union_field=True,
|
||||
namespace=namespace)
|
||||
self.emit()
|
||||
self.emit('// Valid tag values for %s' % fmt_var(u.name))
|
||||
with self.block('const', delim=('(', ')')):
|
||||
for field in fields:
|
||||
self.emit('%s%s = "%s"' % (fmt_var(u.name), fmt_var(field.name), field.name))
|
||||
self.emit()
|
||||
|
||||
num_void_fields = sum([is_void_type(f.data_type) for f in fields])
|
||||
# Simple structure, no need in UnmarshalJSON
|
||||
if len(fields) == num_void_fields:
|
||||
return
|
||||
|
||||
self.emit('// UnmarshalJSON deserializes into a %s instance' % name)
|
||||
with self.block('func (u *%s) UnmarshalJSON(body []byte) error' % name):
|
||||
with self.block('type wrap struct'):
|
||||
self.emit('dropbox.Tagged')
|
||||
for field in fields:
|
||||
if is_void_type(field.data_type) or \
|
||||
is_primitive_type(field.data_type):
|
||||
continue
|
||||
self._generate_field(field, union_field=True,
|
||||
namespace=namespace, raw=True)
|
||||
self.emit('var w wrap')
|
||||
self.emit('var err error')
|
||||
with self.block('if err = json.Unmarshal(body, &w); err != nil'):
|
||||
self.emit('return err')
|
||||
self.emit('u.Tag = w.Tag')
|
||||
with self.block('switch u.Tag'):
|
||||
for field in fields:
|
||||
if is_void_type(field.data_type):
|
||||
continue
|
||||
field_name = fmt_var(field.name)
|
||||
with self.block('case "%s":' % field.name, delim=(None, None)):
|
||||
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():
|
||||
self.emit("u.{0}, err = Is{1}FromJSON(body)"
|
||||
.format(field_name, field.data_type.name))
|
||||
else:
|
||||
self.emit('err = json.Unmarshal(body, &u.{0})'
|
||||
.format(field_name))
|
||||
with self.block("if err != nil"):
|
||||
self.emit("return err")
|
||||
self.emit('return nil')
|
||||
self.emit()
|
Loading…
Reference in New Issue
Block a user