Archived
1
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

View File

@ -157,6 +157,12 @@ 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.
@ -173,6 +179,8 @@ type Entry struct {
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
}