Documentation ¶
Overview ¶
Package dropbox implements the Dropbox core and datastore API.
Example ¶
Downloading a file
db := NewDropbox() db.SetAppInfo("application id", "application secret") db.SetAccessToken("your secret token for this application") db.DownloadToFile("file on Dropbox", "local destination", "revision of the file on Dropbox")
Output:
Index ¶
- Constants
- Variables
- func GenerateKey(length int) ([]byte, error)
- func NewAESCrypterReader(key []byte, input io.Reader, size int) (io.ReadCloser, int, error)
- func NewAESDecrypterReader(key []byte, input io.Reader, size int) (io.ReadCloser, error)
- type Account
- type AtomType
- type ChunkUploadResponse
- type CopyRef
- type Cursor
- type DBTime
- type Datastore
- func (ds *Datastore) AwaitDeltas() error
- func (ds *Datastore) Close()
- func (ds *Datastore) Commit() error
- func (ds *Datastore) Delete() error
- func (ds *Datastore) GetTable(tableID string) (*Table, error)
- func (ds *Datastore) LoadSnapshot() error
- func (ds *Datastore) Rollback() error
- func (ds *Datastore) SetMTime(t time.Time) error
- func (ds *Datastore) SetTitle(t string) error
- type DatastoreInfo
- type DatastoreManager
- func (dmgr *DatastoreManager) CreateDatastore(dsID string) (*Datastore, error)
- func (dmgr *DatastoreManager) DeleteDatastore(dsID string) error
- func (dmgr *DatastoreManager) ListDatastores() ([]DatastoreInfo, error)
- func (dmgr *DatastoreManager) OpenDatastore(dsID string) (*Datastore, error)
- func (dmgr *DatastoreManager) OpenDefaultDatastore() (*Datastore, error)
- type DeltaEntry
- type DeltaPage
- type DeltaPoll
- type Dropbox
- func (db *Dropbox) AccessToken() string
- func (db *Dropbox) Auth() error
- func (db *Dropbox) AuthCode(code string) error
- func (db *Dropbox) AuthCodeURL(state string) string
- func (db *Dropbox) ChunkedUpload(session *ChunkUploadResponse, input io.ReadCloser, chunksize int) (*ChunkUploadResponse, error)
- func (db *Dropbox) CommitChunkedUpload(uploadid, dst string, overwrite bool, parentRev string) (*Entry, error)
- func (db *Dropbox) Copy(src, dst string, isRef bool) (*Entry, error)
- func (db *Dropbox) CopyRef(src string) (*CopyRef, error)
- func (db *Dropbox) CreateFolder(path string) (*Entry, error)
- func (db *Dropbox) Delete(path string) (*Entry, error)
- func (db *Dropbox) Delta(cursor, pathPrefix string) (*DeltaPage, error)
- func (db *Dropbox) DisableAccessToken() error
- func (db *Dropbox) Download(src, rev string, offset int64) (io.ReadCloser, int64, http.Header, error)
- func (db *Dropbox) DownloadAES(key []byte, src, rev string, offset int) (io.ReadCloser, error)
- func (db *Dropbox) DownloadToFile(src, dst, rev string) error
- func (db *Dropbox) DownloadToFileAES(key []byte, src, dst, rev string) error
- func (db *Dropbox) DownloadToFileResume(src, dst, rev string) error
- func (db *Dropbox) FilesPut(input io.ReadCloser, size int64, dst string, overwrite bool, parentRev string) (*Entry, error)
- func (db *Dropbox) FilesPutAES(key []byte, input io.ReadCloser, size int64, dst string, overwrite bool, ...) (*Entry, error)
- func (db *Dropbox) GetAccountInfo() (*Account, error)
- func (db *Dropbox) LatestCursor(prefix string, mediaInfo bool) (*Cursor, error)
- func (db *Dropbox) LongPollDelta(cursor string, timeout int) (*DeltaPoll, error)
- func (db *Dropbox) Media(path string) (*Link, error)
- func (db *Dropbox) Metadata(src string, list bool, includeDeleted bool, hash, rev string, limit int) (*Entry, error)
- func (db *Dropbox) Move(src, dst string) (*Entry, error)
- func (db *Dropbox) NewDatastoreManager() *DatastoreManager
- func (db *Dropbox) Previews(src, rev string) (io.ReadCloser, int64, int64, http.Header, error)
- func (db *Dropbox) PreviewssToFile(src, dst, rev string) (int64, error)
- func (db *Dropbox) Restore(src string, rev string) (*Entry, error)
- func (db *Dropbox) Revisions(src string, revLimit int) ([]Entry, error)
- func (db *Dropbox) Search(path, query string, fileLimit int, includeDeleted bool) ([]Entry, error)
- func (db *Dropbox) SetAccessToken(accesstoken string)
- func (db *Dropbox) SetAppInfo(clientid, clientsecret string) error
- func (db *Dropbox) SetContext(ctx context.Context)
- func (db *Dropbox) SetRedirectURL(url string)
- func (db *Dropbox) SetToken(token *oauth2.Token)
- func (db *Dropbox) SharedFolders(sharedFolderID string) ([]SharedFolder, error)
- func (db *Dropbox) Shares(path string, shortURL bool) (*Link, error)
- func (db *Dropbox) Thumbnails(src, format, size string) (io.ReadCloser, int64, *Entry, http.Header, error)
- func (db *Dropbox) ThumbnailsToFile(src, dst, format, size string) (*Entry, error)
- func (db *Dropbox) Token() *oauth2.Token
- func (db *Dropbox) UploadByChunk(input io.ReadCloser, chunksize int, dst string, overwrite bool, ...) (*Entry, error)
- func (db *Dropbox) UploadFile(src, dst string, overwrite bool, parentRev string) (*Entry, error)
- func (db *Dropbox) UploadFileAES(key []byte, src, dst string, overwrite bool, parentRev string) (*Entry, error)
- type Entry
- type Error
- type Fields
- type Link
- type List
- func (l *List) Add(i interface{}) error
- func (l *List) AddAtPos(n int, i interface{}) error
- func (l *List) Get(n int) (interface{}, error)
- func (l *List) GetType(n int) (AtomType, error)
- func (l *List) IsEmpty() bool
- func (l *List) Move(from, to int) error
- func (l *List) Remove(n int) error
- func (l *List) Set(n int, i interface{}) error
- func (l *List) Size() int
- type Modifier
- type Record
- func (r *Record) DeleteField(field string) error
- func (r *Record) DeleteRecord()
- func (r *Record) FieldNames() []string
- func (r *Record) Get(field string) (interface{}, bool, error)
- func (r *Record) GetFieldType(field string) (AtomType, error)
- func (r *Record) GetID() string
- func (r *Record) GetOrCreateList(field string) (*List, error)
- func (r *Record) GetTable() *Table
- func (r *Record) HasField(field string) (bool, error)
- func (r *Record) IsDeleted() bool
- func (r *Record) Set(field string, value interface{}) error
- type SharedFolder
- type SharedFolderMember
- type Table
- func (t *Table) Get(recordID string) (*Record, error)
- func (t *Table) GetDatastore() *Datastore
- func (t *Table) GetID() string
- func (t *Table) GetOrInsert(recordID string) (*Record, error)
- func (t *Table) GetOrInsertWithFields(recordID string, fields Fields) (*Record, error)
- func (t *Table) Query(fields Fields) ([]*Record, error)
- type User
Examples ¶
Constants ¶
const ( // PollMinTimeout is the minimum timeout for longpoll. PollMinTimeout = 30 // PollMaxTimeout is the maximum timeout for longpoll. PollMaxTimeout = 480 // DefaultChunkSize is the maximum size of a file sendable using files_put. DefaultChunkSize = 4 * 1024 * 1024 // MaxPutFileSize is the maximum size of a file sendable using files_put. MaxPutFileSize = 150 * 1024 * 1024 // MetadataLimitMax is the maximum number of entries returned by metadata. MetadataLimitMax = 25000 // MetadataLimitDefault is the default number of entries returned by metadata. MetadataLimitDefault = 10000 // RevisionsLimitMax is the maximum number of revisions returned by revisions. RevisionsLimitMax = 1000 // RevisionsLimitDefault is the default number of revisions returned by revisions. RevisionsLimitDefault = 10 // SearchLimitMax is the maximum number of entries returned by search. SearchLimitMax = 1000 // SearchLimitDefault is the default number of entries returned by search. SearchLimitDefault = 1000 // DateFormat is the format to use when decoding a time. DateFormat = time.RFC1123Z )
Variables ¶
var ErrNotAuth = errors.New("authentication required")
ErrNotAuth is the error returned when the OAuth token is not provided
Functions ¶
func GenerateKey ¶
GenerateKey generates a key by reading length bytes from /dev/random
func NewAESCrypterReader ¶
NewAESCrypterReader creates and returns a new io.ReadCloser to encrypt the given io.Reader containing size bytes with the given AES key. The AES key should be either 16, 24, or 32 bytes to select AES-128, AES-192, or AES-256.
func NewAESDecrypterReader ¶
NewAESDecrypterReader creates and returns a new io.ReadCloser to decrypt the given io.Reader containing size bytes with the given AES key. The AES key should be either 16, 24, or 32 bytes to select AES-128, AES-192, or AES-256.
Types ¶
type Account ¶
type Account struct { ReferralLink string `json:"referral_link,omitempty"` // URL for referral. DisplayName string `json:"display_name,omitempty"` // User name. Email string `json:"email,omitempty"` // Email address. Not officially documented but included - sometimes, at least... UID int `json:"uid,omitempty"` // User account ID. Country string `json:"country,omitempty"` // Country ISO code. QuotaInfo struct { Shared int64 `json:"shared,omitempty"` // Quota for shared files. Quota int64 `json:"quota,omitempty"` // Quota in bytes. Normal int64 `json:"normal,omitempty"` // Quota for non-shared files. } `json:"quota_info"` }
Account represents information about the user account.
type AtomType ¶
type AtomType int
AtomType represents the type of the value.
const ( // TypeBoolean is the returned type when the value is a bool TypeBoolean AtomType = iota // TypeInteger is the returned type when the value is an int TypeInteger // TypeDouble is the returned type when the value is a float TypeDouble // TypeString is the returned type when the value is a string TypeString // TypeBytes is the returned type when the value is a []byte TypeBytes // TypeDate is the returned type when the value is a Date TypeDate // TypeList is the returned type when the value is a List TypeList )
type ChunkUploadResponse ¶
type ChunkUploadResponse struct { UploadID string `json:"upload_id"` // Unique ID of this upload. Offset int64 `json:"offset"` // Size in bytes of already sent data. Expires DBTime `json:"expires"` // Expiration time of this upload. }
ChunkUploadResponse represents the reply of chunked_upload.
type CopyRef ¶
type CopyRef struct { CopyRef string `json:"copy_ref"` // Reference to use on fileops/copy. Expires string `json:"expires"` // Expiration date. }
CopyRef represents the reply of CopyRef.
type Cursor ¶
type Cursor struct {
Cursor string `json:"cursor"`
}
Cursor represents the tag of a server state at a given moment.
type DBTime ¶
DBTime allow marshalling and unmarshalling of time.
func (DBTime) MarshalJSON ¶
MarshalJSON marshals a time according to the Dropbox format.
func (*DBTime) UnmarshalJSON ¶
UnmarshalJSON unmarshals a time according to the Dropbox format.
type Datastore ¶
type Datastore struct {
// contains filtered or unexported fields
}
Datastore represents a datastore.
func (*Datastore) AwaitDeltas ¶
AwaitDeltas awaits for deltas and applies them.
func (*Datastore) LoadSnapshot ¶
LoadSnapshot updates the state of the datastore from the server.
type DatastoreInfo ¶
type DatastoreInfo struct { ID string // contains filtered or unexported fields }
DatastoreInfo represents the information about a datastore.
type DatastoreManager ¶
type DatastoreManager struct {
// contains filtered or unexported fields
}
DatastoreManager represents all datastores linked to the current account.
func (*DatastoreManager) CreateDatastore ¶
func (dmgr *DatastoreManager) CreateDatastore(dsID string) (*Datastore, error)
CreateDatastore creates a global datastore with a unique ID, empty string for a random key.
func (*DatastoreManager) DeleteDatastore ¶
func (dmgr *DatastoreManager) DeleteDatastore(dsID string) error
DeleteDatastore deletes a datastore.
func (*DatastoreManager) ListDatastores ¶
func (dmgr *DatastoreManager) ListDatastores() ([]DatastoreInfo, error)
ListDatastores lists all datastores.
func (*DatastoreManager) OpenDatastore ¶
func (dmgr *DatastoreManager) OpenDatastore(dsID string) (*Datastore, error)
OpenDatastore opens or creates a datastore.
func (*DatastoreManager) OpenDefaultDatastore ¶
func (dmgr *DatastoreManager) OpenDefaultDatastore() (*Datastore, error)
OpenDefaultDatastore opens the default datastore.
type DeltaEntry ¶
type DeltaEntry struct { Path string // Path of this entry in lowercase. Entry *Entry // nil when this entry does not exists. }
DeltaEntry represents the list of changes for a given path.
type DeltaPage ¶
type DeltaPage struct { Reset bool // if true the local state must be cleared. HasMore bool // if true an other call to delta should be made. Cursor // Tag of the current state. Entries []DeltaEntry // List of changed entries. }
DeltaPage represents the reply of delta.
type DeltaPoll ¶
type DeltaPoll struct { Changes bool `json:"changes"` // true if the polled path has changed. Backoff int `json:"backoff"` // time in second before calling poll again. }
DeltaPoll represents the reply of longpoll_delta.
type Dropbox ¶
type Dropbox struct { RootDirectory string // dropbox or sandbox. Locale string // Locale sent to the API to translate/format messages. APIURL string // Normal API URL. APIContentURL string // URL for transferring files. APINotifyURL string // URL for realtime notification. // contains filtered or unexported fields }
Dropbox client.
func (*Dropbox) AccessToken ¶
AccessToken returns the OAuth access token.
func (*Dropbox) Auth ¶
Auth displays the URL to authorize this application to connect to your account.
func (*Dropbox) AuthCodeURL ¶
AuthCodeURL returns a URL to Dropbox's consent page that asks for permissions for the required scopes explicitly.
func (*Dropbox) ChunkedUpload ¶
func (db *Dropbox) ChunkedUpload(session *ChunkUploadResponse, input io.ReadCloser, chunksize int) (*ChunkUploadResponse, error)
ChunkedUpload sends a chunk with a maximum size of chunksize, if there is no session a new one is created.
func (*Dropbox) CommitChunkedUpload ¶
func (db *Dropbox) CommitChunkedUpload(uploadid, dst string, overwrite bool, parentRev string) (*Entry, error)
CommitChunkedUpload ends the chunked upload by giving a name to the UploadID.
func (*Dropbox) Copy ¶
Copy copies a file. If isRef is true src must be a reference from CopyRef instead of a path.
func (*Dropbox) CopyRef ¶
CopyRef gets a reference to a file. This reference can be used to copy this file to another user's Dropbox by passing it to the Copy method.
func (*Dropbox) CreateFolder ¶
CreateFolder creates a new directory.
func (*Dropbox) DisableAccessToken ¶
DisableAccessToken disables the OAuth access token.
func (*Dropbox) Download ¶
func (db *Dropbox) Download(src, rev string, offset int64) (io.ReadCloser, int64, http.Header, error)
Download requests the file located at src, the specific revision may be given. offset is used in case the download was interrupted. A io.ReadCloser and the file size is returned.
func (*Dropbox) DownloadAES ¶
DownloadAES downloads and decrypts the file located in the src path on Dropbox and returns a io.ReadCloser.
func (*Dropbox) DownloadToFile ¶
DownloadToFile downloads the file located in the src path on the Dropbox to the dst file on the local disk. If the destination file exists it will be truncated.
func (*Dropbox) DownloadToFileAES ¶
DownloadToFileAES downloads and decrypts the file located in the src path on Dropbox to the dst file on the local disk.
func (*Dropbox) DownloadToFileResume ¶
DownloadToFileResume resumes the download of the file located in the src path on the Dropbox to the dst file on the local disk.
func (*Dropbox) FilesPut ¶
func (db *Dropbox) FilesPut(input io.ReadCloser, size int64, dst string, overwrite bool, parentRev string) (*Entry, error)
FilesPut uploads size bytes from the input reader to the dst path on Dropbox.
func (*Dropbox) FilesPutAES ¶
func (db *Dropbox) FilesPutAES(key []byte, input io.ReadCloser, size int64, dst string, overwrite bool, parentRev string) (*Entry, error)
FilesPutAES uploads and encrypts size bytes from the input reader to the dst path on Dropbox.
func (*Dropbox) GetAccountInfo ¶
GetAccountInfo gets account information for the user currently authenticated.
func (*Dropbox) LatestCursor ¶
LatestCursor returns the latest cursor without fetching any data.
func (*Dropbox) LongPollDelta ¶
LongPollDelta waits for a notification to happen.
func (*Dropbox) Metadata ¶
func (db *Dropbox) Metadata(src string, list bool, includeDeleted bool, hash, rev string, limit int) (*Entry, error)
Metadata gets the metadata for a file or a directory. If list is true and src is a directory, immediate child will be sent in the Contents field. If include_deleted is true, entries deleted will be sent. hash is the hash of the contents of a directory, it is used to avoid sending data when directory did not change. rev is the specific revision to get the metadata from. limit is the maximum number of entries requested.
func (*Dropbox) NewDatastoreManager ¶
func (db *Dropbox) NewDatastoreManager() *DatastoreManager
NewDatastoreManager returns a new DatastoreManager linked to the current account.
func (*Dropbox) Previews ¶
Previews gets a preview for a file with one of the following extensions: .doc, .docx, .docm, .ppt, .pps, .ppsx, .ppsm, .pptx, .pptm, .xls, .xlsx, .xlsm, .rtf.
func (*Dropbox) PreviewssToFile ¶
PreviewssToFile downloads the preview file located in the src path on Dropbox to the dst file on the local disk.
func (*Dropbox) Search ¶
Search searches the entries matching all the words contained in query in the given path. The maximum number of entries and whether to consider deleted file may be given.
func (*Dropbox) SetAccessToken ¶
SetAccessToken sets access token to avoid calling Auth method.
func (*Dropbox) SetAppInfo ¶
SetAppInfo sets the clientid (app_key) and clientsecret (app_secret). You have to register an application on https://www.dropbox.com/developers/apps.
func (*Dropbox) SetContext ¶
SetContext allow to set a custom context.
func (*Dropbox) SetRedirectURL ¶
SetRedirectURL updates the configuration with the given redirection URL.
func (*Dropbox) SharedFolders ¶
func (db *Dropbox) SharedFolders(sharedFolderID string) ([]SharedFolder, error)
SharedFolders returns the list of allowed shared folders.
func (*Dropbox) Thumbnails ¶
func (db *Dropbox) Thumbnails(src, format, size string) (io.ReadCloser, int64, *Entry, http.Header, error)
Thumbnails gets a thumbnail for an image.
func (*Dropbox) ThumbnailsToFile ¶
ThumbnailsToFile downloads the file located in the src path on the Dropbox to the dst file on the local disk.
func (*Dropbox) UploadByChunk ¶
func (db *Dropbox) UploadByChunk(input io.ReadCloser, chunksize int, dst string, overwrite bool, parentRev string) (*Entry, error)
UploadByChunk uploads data from the input reader to the dst path on Dropbox by sending chunks of chunksize.
func (*Dropbox) UploadFile ¶
UploadFile uploads the file located in the src path on the local disk to the dst path on Dropbox.
type Entry ¶
type Entry struct { Bytes int64 `json:"bytes,omitempty"` // Size of the file in bytes. ClientMtime DBTime `json:"client_mtime,omitempty"` // Modification time set by the client when added. Contents []Entry `json:"contents,omitempty"` // List of children for a directory. Hash string `json:"hash,omitempty"` // Hash of this entry. Icon string `json:"icon,omitempty"` // Name of the icon displayed for this entry. IsDeleted bool `json:"is_deleted,omitempty"` // true if this entry was deleted. IsDir bool `json:"is_dir,omitempty"` // true if this entry is a directory. MimeType string `json:"mime_type,omitempty"` // MimeType of this entry. Modified DBTime `json:"modified,omitempty"` // Date of last modification. Path string `json:"path,omitempty"` // Absolute path of this entry. Revision string `json:"rev,omitempty"` // Unique ID for this file revision. Root string `json:"root,omitempty"` // dropbox or sandbox. Size string `json:"size,omitempty"` // Size of the file humanized/localized. ThumbExists bool `json:"thumb_exists,omitempty"` // true if a thumbnail is available for this entry. Modifier *Modifier `json:"modifier"` // last user to edit the file if in a shared folder }
Entry represents the metadata of a file or folder.
type Error ¶
Error - all errors generated by HTTP transactions are of this type. Other error may be passed on from library functions though.
type Link ¶
type Link struct { Expires DBTime `json:"expires"` // Expiration date of this link. URL string `json:"url"` // URL to share. }
Link for sharing a file.
type List ¶
type List struct {
// contains filtered or unexported fields
}
List represents a value of type list.
type Record ¶
type Record struct {
// contains filtered or unexported fields
}
Record represents an entry in a table.
func (*Record) DeleteField ¶
DeleteField deletes the given field from this record.
func (*Record) FieldNames ¶
FieldNames returns a list of fields names.
func (*Record) GetFieldType ¶
GetFieldType returns the type of the given field.
func (*Record) GetOrCreateList ¶
GetOrCreateList gets the current value of this field.
type SharedFolder ¶
type SharedFolder struct {}
SharedFolder reprensents a directory with a specific sharing policy.
type SharedFolderMember ¶
type SharedFolderMember struct {}
SharedFolderMember represents access right associated with a Dropbox user.
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table represents a list of records.
func (*Table) GetDatastore ¶
GetDatastore returns the datastore associated with this table.
func (*Table) GetOrInsert ¶
GetOrInsert gets the requested record.
func (*Table) GetOrInsertWithFields ¶
GetOrInsertWithFields gets the requested table.