dropbox

package module
v0.0.0-...-42dd2be Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 7, 2017 License: MIT Imports: 10 Imported by: 10

README

GoDoc Build Status

Dropbox

Simple Dropbox v2 client for Go.

For a higher level client take a look at go-dropy.

About

Modelled more or less 1:1 with the API for consistency and parity with the official documentation. More sugar should be implemented on top.

Testing

To manually run tests use the test account access token:

$ export DROPBOX_ACCESS_TOKEN=oENFkq_oIVAAAAAAAAAAC8gE3wIUFMEraPBL-D71Aq2C4zuh1l4oDn5FiWSdVVlL
$ go test -v

License

MIT

Documentation

Overview

Package dropbox implements a simple v2 client.

Example

Example using the Client, which provides both User and File clients.

d := dropbox.New(dropbox.NewConfig("<token>"))

file, _ := os.Open("Readme.md")

d.Files.Upload(&dropbox.UploadInput{
	Path:   "Readme.md",
	Reader: file,
	Mute:   true,
})
Output:

Example (Files)

Example using the Files client directly.

files := dropbox.NewFiles(dropbox.NewConfig("<token>"))

out, _ := files.Download(&dropbox.DownloadInput{
	Path: "Readme.md",
})

io.Copy(os.Stdout, out.Body)
Output:

Example (Users)

Example using the Users client directly.

users := dropbox.NewUsers(dropbox.NewConfig("<token>"))
out, _ := users.GetCurrentAccount()
fmt.Printf("%v\n", out)
Output:

Index

Examples

Constants

View Source
const (
	SearchModeFilename           SearchMode = "filename"
	SearchModeFilenameAndContent            = "filename_and_content"
	SearchModeDeletedFilename               = "deleted_filename"
)

Supported search modes.

View Source
const (
	SearchMatchFilename SearchMatchType = "filename"
	SearchMatchContent                  = "content"
	SearchMatchBoth                     = "both"
)

Supported search match types.

View Source
const (
	// GetThumbnailSizeW32H32 specifies a size of 32 by 32 px
	GetThumbnailSizeW32H32 ThumbnailSize = "w32h32"
	// GetThumbnailSizeW64H64 specifies a size of 64 by 64 px
	GetThumbnailSizeW64H64 = "w64h64"
	// GetThumbnailSizeW128H128 specifies a size of 128 by 128 px
	GetThumbnailSizeW128H128 = "w128h128"
	// GetThumbnailSizeW640H480 specifies a size of 640 by 480 px
	GetThumbnailSizeW640H480 = "w640h480"
	// GetThumbnailSizeW1024H768 specifies a size of 1024 by 768 px
	GetThumbnailSizeW1024H768 = "w1024h768"
)
View Source
const (
	Public           VisibilityType = "public"
	TeamOnly                        = "team_only"
	Password                        = "password"
	TeamAndPassword                 = "team_and_password"
	SharedFolderOnly                = "shared_folder_only"
)

Visibility types supported.

View Source
const (
	Owner           AccessType = "owner"
	Editor                     = "editor"
	Viewer                     = "viewer"
	ViewerNoComment            = "viewer_no_comment"
)

Access types supported.

Variables

This section is empty.

Functions

func ContentHash

func ContentHash(r io.Reader) (string, error)

ContentHash returns the Dropbox content_hash for a io.Reader. See https://www.dropbox.com/developers/reference/content-hash

func FileContentHash

func FileContentHash(filename string) (string, error)

FileContentHash returns the Dropbox content_hash for a local file. See https://www.dropbox.com/developers/reference/content-hash

Types

type ACLUpdatePolicy

type ACLUpdatePolicy string

ACLUpdatePolicy determines who can add and remove members from this shared folder.

const (
	ACLUpdatePolicyOwner   ACLUpdatePolicy = "owner"
	ACLUpdatePolicyEditors                 = "editors"
)

ACLUpdatePolicy types supported.

type AccessType

type AccessType string

AccessType determines the level of access to a shared folder.

type Client

type Client struct {
	*Config
	Users   *Users
	Files   *Files
	Sharing *Sharing
}

Client implements a Dropbox client. You may use the Files and Users clients directly if preferred, however Client exposes them both.

func New

func New(config *Config) *Client

New client.

type Config

type Config struct {
	HTTPClient  *http.Client
	AccessToken string
}

Config for the Dropbox clients.

func NewConfig

func NewConfig(accessToken string) *Config

NewConfig with the given access token.

type CopyInput

type CopyInput struct {
	FromPath string `json:"from_path"`
	ToPath   string `json:"to_path"`
}

CopyInput request input.

type CopyOutput

type CopyOutput struct {
	Metadata
}

CopyOutput request output.

type CreateFolderInput

type CreateFolderInput struct {
	Path string `json:"path"`
}

CreateFolderInput request input.

type CreateFolderOutput

type CreateFolderOutput struct {
	Name      string `json:"name"`
	PathLower string `json:"path_lower"`
	ID        string `json:"id"`
}

CreateFolderOutput request output.

type CreateSharedLinkInput

type CreateSharedLinkInput struct {
	Path string `json:"path"`
}

CreateSharedLinkInput request input.

type CreateSharedLinkOutput

type CreateSharedLinkOutput struct {
	URL             string `json:"url"`
	Path            string `json:"path"`
	VisibilityModel struct {
		Tag VisibilityType `json:".tag"`
	} `json:"visibility"`
	Expires time.Time `json:"expires,omitempty"`
}

CreateSharedLinkOutput request output.

type DeleteInput

type DeleteInput struct {
	Path string `json:"path"`
}

DeleteInput request input.

type DeleteOutput

type DeleteOutput struct {
	Metadata
}

DeleteOutput request output.

type Dimensions

type Dimensions struct {
	Width  uint64 `json:"width"`
	Height uint64 `json:"height"`
}

Dimensions specifies the dimensions of a photo or video.

type DownloadInput

type DownloadInput struct {
	Path string `json:"path"`
}

DownloadInput request input.

type DownloadOutput

type DownloadOutput struct {
	Body   io.ReadCloser
	Length int64
}

DownloadOutput request output.

type Error

type Error struct {
	Status     string
	StatusCode int
	Summary    string `json:"error_summary"`
}

Error response.

func (*Error) Error

func (e *Error) Error() string

Error string.

type FileSharingInfo

type FileSharingInfo struct {
	ReadOnly             bool   `json:"read_only"`
	ParentSharedFolderID string `json:"parent_shared_folder_id"`
	ModifiedBy           string `json:"modified_by,omitempty"`
}

FileSharingInfo for a file which is contained in a shared folder.

type Files

type Files struct {
	*Client
}

Files client for files and folders.

func NewFiles

func NewFiles(config *Config) *Files

NewFiles client.

func (*Files) Copy

func (c *Files) Copy(in *CopyInput) (out *CopyOutput, err error)

Copy a file or folder to a different location.

func (*Files) CreateFolder

func (c *Files) CreateFolder(in *CreateFolderInput) (out *CreateFolderOutput, err error)

CreateFolder creates a folder.

func (*Files) Delete

func (c *Files) Delete(in *DeleteInput) (out *DeleteOutput, err error)

Delete a file or folder and its contents.

func (*Files) Download

func (c *Files) Download(in *DownloadInput) (out *DownloadOutput, err error)

Download a file.

func (*Files) GetMetadata

func (c *Files) GetMetadata(in *GetMetadataInput) (out *GetMetadataOutput, err error)

GetMetadata returns the metadata for a file or folder.

func (*Files) GetPreview

func (c *Files) GetPreview(in *GetPreviewInput) (out *GetPreviewOutput, err error)

GetPreview a preview for a file. Currently previews are only generated for the files with the following extensions: .doc, .docx, .docm, .ppt, .pps, .ppsx, .ppsm, .pptx, .pptm, .xls, .xlsx, .xlsm, .rtf

func (*Files) GetThumbnail

func (c *Files) GetThumbnail(in *GetThumbnailInput) (out *GetThumbnailOutput, err error)

GetThumbnail a thumbnail for a file. Currently thumbnails are only generated for the files with the following extensions: png, jpeg, png, tiff, tif, gif and bmp.

func (*Files) ListFolder

func (c *Files) ListFolder(in *ListFolderInput) (out *ListFolderOutput, err error)

ListFolder returns the metadata for a file or folder.

func (*Files) ListFolderContinue

func (c *Files) ListFolderContinue(in *ListFolderContinueInput) (out *ListFolderOutput, err error)

ListFolderContinue pagenates using the cursor from ListFolder.

func (*Files) ListRevisions

func (c *Files) ListRevisions(in *ListRevisionsInput) (out *ListRevisionsOutput, err error)

ListRevisions gets the revisions of the specified file.

func (*Files) Move

func (c *Files) Move(in *MoveInput) (out *MoveOutput, err error)

Move a file or folder to a different location.

func (*Files) PermanentlyDelete

func (c *Files) PermanentlyDelete(in *PermanentlyDeleteInput) (err error)

PermanentlyDelete a file or folder and its contents.

func (*Files) Restore

func (c *Files) Restore(in *RestoreInput) (out *RestoreOutput, err error)

Restore a file to a specific revision.

func (*Files) Search

func (c *Files) Search(in *SearchInput) (out *SearchOutput, err error)

Search for files and folders.

func (*Files) Upload

func (c *Files) Upload(in *UploadInput) (out *UploadOutput, err error)

Upload a file smaller than 150MB.

type FolderAction

type FolderAction struct {
	ChangeOptions string
}

FolderAction defines actions that may be taken on shared folders.

type FolderPolicy

type FolderPolicy struct {
	ACLUpdatePolicy struct {
		Tag ACLUpdatePolicy `json:".tag"`
	} `json:"acl_update_policy"`
	SharedLinkPolicy struct {
		Tag SharedLinkPolicy `json:".tag"`
	} `json:"shared_link_policy"`
	MemberPolicy struct {
		Tag MemberPolicy `json:".tag"`
	} `json:"member_policy"`
	ResolvedMemberPolicy struct {
		Tag MemberPolicy `json:".tag"`
	} `json:"resolved_member_policy"`
}

FolderPolicy enumerates the policies governing this shared folder.

type GPSCoordinates

type GPSCoordinates struct {
	Latitude  float64 `json:"latitude"`
	Longitude float64 `json:"longitude"`
}

GPSCoordinates specifies the GPS coordinate of a photo or video.

type GetAccountInput

type GetAccountInput struct {
	AccountID string `json:"account_id"`
}

GetAccountInput request input.

type GetAccountOutput

type GetAccountOutput struct {
	AccountID string `json:"account_id"`
	Name      struct {
		GivenName    string `json:"given_name"`
		Surname      string `json:"surname"`
		FamiliarName string `json:"familiar_name"`
		DisplayName  string `json:"display_name"`
	} `json:"name"`
}

GetAccountOutput request output.

type GetCurrentAccountOutput

type GetCurrentAccountOutput struct {
	AccountID string `json:"account_id"`
	Name      struct {
		GivenName    string `json:"given_name"`
		Surname      string `json:"surname"`
		FamiliarName string `json:"familiar_name"`
		DisplayName  string `json:"display_name"`
	} `json:"name"`
	Email        string `json:"email"`
	Locale       string `json:"locale"`
	ReferralLink string `json:"referral_link"`
	IsPaired     bool   `json:"is_paired"`
	AccountType  struct {
		Tag string `json:".tag"`
	} `json:"account_type"`
	Country string `json:"country"`
}

GetCurrentAccountOutput request output.

type GetMetadataInput

type GetMetadataInput struct {
	Path             string `json:"path"`
	IncludeMediaInfo bool   `json:"include_media_info"`
}

GetMetadataInput request input.

type GetMetadataOutput

type GetMetadataOutput struct {
	Metadata
}

GetMetadataOutput request output.

type GetPreviewInput

type GetPreviewInput struct {
	Path string `json:"path"`
}

GetPreviewInput request input.

type GetPreviewOutput

type GetPreviewOutput struct {
	Body   io.ReadCloser
	Length int64
}

GetPreviewOutput request output.

type GetSpaceUsageOutput

type GetSpaceUsageOutput struct {
	Used       uint64 `json:"used"`
	Allocation struct {
		Used      uint64 `json:"used"`
		Allocated uint64 `json:"allocated"`
	} `json:"allocation"`
}

GetSpaceUsageOutput request output.

type GetThumbnailInput

type GetThumbnailInput struct {
	Path   string          `json:"path"`
	Format ThumbnailFormat `json:"format"`
	Size   ThumbnailSize   `json:"size"`
}

GetThumbnailInput request input.

type GetThumbnailOutput

type GetThumbnailOutput struct {
	Body   io.ReadCloser
	Length int64
}

GetThumbnailOutput request output.

type ListFolderContinueInput

type ListFolderContinueInput struct {
	Cursor string `json:"cursor"`
}

ListFolderContinueInput request input.

type ListFolderInput

type ListFolderInput struct {
	Path             string `json:"path"`
	Recursive        bool   `json:"recursive"`
	IncludeMediaInfo bool   `json:"include_media_info"`
	IncludeDeleted   bool   `json:"include_deleted"`
}

ListFolderInput request input.

type ListFolderOutput

type ListFolderOutput struct {
	Cursor  string `json:"cursor"`
	HasMore bool   `json:"has_more"`
	Entries []*Metadata
}

ListFolderOutput request output.

type ListRevisionsInput

type ListRevisionsInput struct {
	Path  string `json:"path"`
	Limit uint64 `json:"limit,omitempty"`
}

ListRevisionsInput request input.

type ListRevisionsOutput

type ListRevisionsOutput struct {
	IsDeleted bool
	Entries   []*Metadata
}

ListRevisionsOutput request output.

type ListShareLinksInput

type ListShareLinksInput struct {
	Path string `json:"path"`
}

ListShareLinksInput request input.

type ListShareLinksOutput

type ListShareLinksOutput struct {
	Links []SharedLinkOutput `json:"links"`
}

ListShareLinksOutput request output.

type ListSharedFolderContinueInput

type ListSharedFolderContinueInput struct {
	Cursor string `json:"cursor"`
}

ListSharedFolderContinueInput request input.

type ListSharedFolderInput

type ListSharedFolderInput struct {
	Limit   uint64         `json:"limit"`
	Actions []FolderAction `json:"actions,omitempty"`
}

ListSharedFolderInput request input.

type ListSharedFolderOutput

type ListSharedFolderOutput struct {
	Entries []SharedFolderMetadata `json:"entries"`
	Cursor  string                 `json:"cursor"`
}

ListSharedFolderOutput lists metadata about shared folders with a cursor to retrieve the next page.

type MediaInfo

type MediaInfo struct {
	Pending  bool           `json:"pending"`
	Metadata *MediaMetadata `json:"metadata,omitempty"`
}

MediaInfo provides additional information for a photo or video file.

type MediaMetadata

type MediaMetadata struct {
	Photo *PhotoMetadata `json:"photo,omitempty"`
	Video *VideoMetadata `json:"video,omitempty"`
}

MediaMetadata provides metadata for a photo or video.

type MemberPolicy

type MemberPolicy string

MemberPolicy determines who can be a member of this shared folder, as set on the folder itself.

const (
	MemberPolicyTeam   MemberPolicy = "team"
	MemberPolicyAnyone              = "anyone"
)

MemberPolicy types supported.

type Metadata

type Metadata struct {
	Tag            string           `json:".tag"`
	Name           string           `json:"name"`
	PathLower      string           `json:"path_lower"`
	PathDisplay    string           `json:"path_display"`
	ClientModified time.Time        `json:"client_modified"`
	ServerModified time.Time        `json:"server_modified"`
	Rev            string           `json:"rev"`
	Size           uint64           `json:"size"`
	ID             string           `json:"id"`
	MediaInfo      *MediaInfo       `json:"media_info,omitempty"`
	SharingInfo    *FileSharingInfo `json:"sharing_info,omitempty"`
	ContentHash    string           `json:"content_hash,omitempty"`
}

Metadata for a file or folder.

type MoveInput

type MoveInput struct {
	FromPath string `json:"from_path"`
	ToPath   string `json:"to_path"`
}

MoveInput request input.

type MoveOutput

type MoveOutput struct {
	Metadata
}

MoveOutput request output.

type PermanentlyDeleteInput

type PermanentlyDeleteInput struct {
	Path string `json:"path"`
}

PermanentlyDeleteInput request input.

type PhotoMetadata

type PhotoMetadata struct {
	Dimensions *Dimensions     `json:"dimensions,omitempty"`
	Location   *GPSCoordinates `json:"location,omitempty"`
	TimeTaken  time.Time       `json:"time_taken,omitempty"`
}

PhotoMetadata specifies metadata for a photo.

type RestoreInput

type RestoreInput struct {
	Path string `json:"path"`
	Rev  string `json:"rev"`
}

RestoreInput request input.

type RestoreOutput

type RestoreOutput struct {
	Metadata
}

RestoreOutput request output.

type SearchInput

type SearchInput struct {
	Path       string     `json:"path"`
	Query      string     `json:"query"`
	Start      uint64     `json:"start,omitempty"`
	MaxResults uint64     `json:"max_results,omitempty"`
	Mode       SearchMode `json:"mode"`
}

SearchInput request input.

type SearchMatch

type SearchMatch struct {
	MatchType struct {
		Tag SearchMatchType `json:".tag"`
	} `json:"match_type"`
	Metadata *Metadata `json:"metadata"`
}

SearchMatch represents a matched file or folder.

type SearchMatchType

type SearchMatchType string

SearchMatchType represents the type of match made.

type SearchMode

type SearchMode string

SearchMode determines how a search is performed.

type SearchOutput

type SearchOutput struct {
	Matches []*SearchMatch `json:"matches"`
	More    bool           `json:"more"`
	Start   uint64         `json:"start"`
}

SearchOutput request output.

type SharedFolderMetadata

type SharedFolderMetadata struct {
	AccessType struct {
		Tag AccessType `json:".tag"`
	} `json:"access_type"`
	IsTeamFolder   bool         `json:"is_team_folder"`
	Policy         FolderPolicy `json:"policy"`
	Name           string       `json:"name"`
	SharedFolderID string       `json:"shared_folder_id"`
	TimeInvited    time.Time    `json:"time_invited"`
	OwnerTeam      struct {
		ID   string `json:"id"`
		Name string `json:"name"`
	} `json:"owner_team"`
	ParentSharedFolderID string   `json:"parent_shared_folder_id"`
	PathLower            string   `json:"path_lower"`
	Permissions          []string `json:"permissions"`
}

SharedFolderMetadata includes basic information about the shared folder.

type SharedLinkOutput

type SharedLinkOutput struct {
	URL             string `json:"url"`
	Path            string `json:"path"`
	VisibilityModel struct {
		Tag VisibilityType `json:".tag"`
	} `json:"visibility"`
	Expires time.Time `json:"expires,omitempty"`
}

SharedLinkOutput request output.

type SharedLinkPolicy

type SharedLinkPolicy string

SharedLinkPolicy governs who can view shared links.

const (
	SharedLinkPolicyAnyone  SharedLinkPolicy = "anyone"
	SharedLinkPolicyMembers                  = "members"
)

SharedLinkPolicy types supported.

type Sharing

type Sharing struct {
	*Client
}

Sharing client.

func NewSharing

func NewSharing(config *Config) *Sharing

NewSharing client.

func (c *Sharing) CreateSharedLink(in *CreateSharedLinkInput) (out *CreateSharedLinkOutput, err error)

CreateSharedLink returns a shared link.

func (*Sharing) ListSharedFolders

func (c *Sharing) ListSharedFolders(in *ListSharedFolderInput) (out *ListSharedFolderOutput, err error)

ListSharedFolders returns the list of all shared folders the current user has access to.

func (*Sharing) ListSharedFoldersContinue

func (c *Sharing) ListSharedFoldersContinue(in *ListSharedFolderContinueInput) (out *ListSharedFolderOutput, err error)

ListSharedFoldersContinue returns the list of all shared folders the current user has access to.

func (c *Sharing) ListSharedLinks(in *ListShareLinksInput) (out *ListShareLinksOutput, err error)

ListSharedLinks gets shared links of input.

type ThumbnailFormat

type ThumbnailFormat string

ThumbnailFormat determines the format of the thumbnail.

const (
	// GetThumbnailFormatJPEG specifies a JPG thumbnail
	GetThumbnailFormatJPEG ThumbnailFormat = "jpeg"
	// GetThumbnailFormatPNG specifies a PNG thumbnail
	GetThumbnailFormatPNG = "png"
)

type ThumbnailSize

type ThumbnailSize string

ThumbnailSize determines the size of the thumbnail.

type UploadInput

type UploadInput struct {
	Path           string    `json:"path"`
	Mode           WriteMode `json:"mode"`
	AutoRename     bool      `json:"autorename"`
	Mute           bool      `json:"mute"`
	ClientModified string    `json:"client_modified,omitempty"`
	Reader         io.Reader `json:"-"`
}

UploadInput request input.

type UploadOutput

type UploadOutput struct {
	Metadata
}

UploadOutput request output.

type Users

type Users struct {
	*Client
}

Users client for user accounts.

func NewUsers

func NewUsers(config *Config) *Users

NewUsers client.

func (*Users) GetAccount

func (c *Users) GetAccount(in *GetAccountInput) (out *GetAccountOutput, err error)

GetAccount returns information about a user's account.

func (*Users) GetCurrentAccount

func (c *Users) GetCurrentAccount() (out *GetCurrentAccountOutput, err error)

GetCurrentAccount returns information about the current user's account.

func (*Users) GetSpaceUsage

func (c *Users) GetSpaceUsage() (out *GetSpaceUsageOutput, err error)

GetSpaceUsage returns space usage information for the current user's account.

type VideoMetadata

type VideoMetadata struct {
	Dimensions *Dimensions     `json:"dimensions,omitempty"`
	Location   *GPSCoordinates `json:"location,omitempty"`
	TimeTaken  time.Time       `json:"time_taken,omitempty"`
	Duration   uint64          `json:"duration,omitempty"`
}

VideoMetadata specifies metadata for a video.

type VisibilityType

type VisibilityType string

VisibilityType determines who can access the link.

type WriteMode

type WriteMode string

WriteMode determines what to do if the file already exists.

const (
	WriteModeAdd       WriteMode = "add"
	WriteModeOverwrite           = "overwrite"
)

Supported write modes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL