stacktic
/
dropbox
Archived
1
0
Fork 0

Merge pull request #15 from sirwart/master

Allow easier use of the library in servers
This commit is contained in:
Arnaud Ysmal 2015-04-25 10:52:07 +02:00
commit 6250fdfc3b
1 changed files with 64 additions and 17 deletions

View File

@ -157,22 +157,30 @@ func (dbt DBTime) MarshalJSON() ([]byte, error) {
return json.Marshal(time.Time(dbt).Format(DateFormat))
}
// Represents the user who made a change on a particular file
type Modifier struct {
Uid int64 `json:"uid"`
DisplayName string `json:"display_name"`
}
// Entry represents the metadata of a file or folder.
type Entry struct {
Bytes int `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.
Bytes int `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
ParentSharedFolderId string `json:"parent_shared_folder_id,omitempty"`
}
// Link for sharing a file.
@ -181,6 +189,27 @@ type Link struct {
URL string `json:"url"` // URL to share.
}
type User struct {
Uid int64 `json:"uid"`
DisplayName string `json:"display_name"`
}
type SharedFolderMember struct {
User User `json:"user"`
Active bool `json:"active"`
AccessType string `json:"access_type"`
}
type SharedFolder struct {
SharedFolderId string `json:"shared_folder_id"`
SharedFolderName string `json:"shared_folder_name"`
Path string `json:"path"`
AccessType string `json:"access_type"`
SharedLinkPolicy string `json:"shared_link_policy"`
Owner User `json:"owner"`
Membership []SharedFolderMember `json:"membership"`
}
// Dropbox client.
type Dropbox struct {
RootDirectory string // dropbox or sandbox.
@ -235,6 +264,10 @@ func (db *Dropbox) AccessToken() string {
return db.token.AccessToken
}
func (db *Dropbox) SetRedirectUrl(url string) {
db.config.RedirectURL = url
}
func (db *Dropbox) client() *http.Client {
return db.config.Client(db.ctx, db.token)
}
@ -242,15 +275,20 @@ func (db *Dropbox) client() *http.Client {
// Auth displays the URL to authorize this application to connect to your account.
func (db *Dropbox) Auth() error {
var code string
var t *oauth2.Token
var err error
fmt.Printf("Please visit:\n%s\nEnter the code: ",
db.config.AuthCodeURL(""))
fmt.Scanln(&code)
if t, err = db.config.Exchange(oauth2.NoContext, code); err != nil {
return db.AuthCode(code)
}
// Authorizes the given code
func (db *Dropbox) AuthCode(code string) error {
t, err := db.config.Exchange(oauth2.NoContext, code)
if err != nil {
return err
}
db.token = t
db.token.TokenType = "Bearer"
return nil
@ -881,3 +919,12 @@ func (db *Dropbox) LatestCursor(prefix string, mediaInfo bool) (*Cursor, error)
err := db.doRequest("POST", "delta/latest_cursor", params, &cur)
return &cur, err
}
func (db *Dropbox) SharedFolder(sharedFolderId string) (pSharedFolder *SharedFolder, err error) {
var sharedFolder SharedFolder
err = db.doRequest("GET", "/shared_folders/" + sharedFolderId, nil, &sharedFolder)
if err == nil {
pSharedFolder = &sharedFolder
}
return
}