dropbox

package module
v0.0.0-...-044ec7f Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2023 License: MIT Imports: 10 Imported by: 4

README

dropbox

Build Status | codecov | Go Report Card | GoDoc

A simple dropbox v2 client.

Support for

User

  • Get account information

Files

  • Upload / Download files
  • Create / Delete files

Folders

  • List files
  • Create folders
  • Delete folders
If i miss something or you have something interesting, please be part of this project. Let me know! My contact is at the end.

Dependecy Management

Dep

Project dependencies are managed using Dep. Read more about Dep.

  • Install dependencies: dep ensure
  • Update dependencies: dep ensure -update
Go
go get github.com/joaosoft/dropbox

Usage

This examples are available in the project at dropbox/examples

import "github.com/joaosoft/dropbox"

dropbox := dropbox.NewDropbox()

//get user information
log.Info("get user information")
if user, err := dropbox.User().Get(); err != nil {
    log.Error(err.Error())
} else {
    fmt.Printf("\n\nUSER: %+v \n\n", user)
}

// upload a file
log.Info("upload a file")
if response, err := dropbox.File().Upload("/teste.txt", []byte("teste")); err != nil {
    log.Error(err.Error())
} else {
    fmt.Printf("\n\nUPLOADED: %+v \n\n", response)
}

// download the uploaded file
log.Info("download the uploaded file")
if response, err := dropbox.File().Download("/teste.txt"); err != nil {
    log.Error(err.Error())
} else {
    fmt.Printf("\n\nDOWNLOADED: %s \n\n", string(response))
}

// create folder
log.Info("listing folder")
if response, err := dropbox.Folder().Create("/bananas"); err != nil {
    log.Error(err.Error())
} else {
    fmt.Printf("\n\nCREATED FOLDER: %+v \n\n", response)
}

// listing folder
log.Info("listing folder")
if response, err := dropbox.Folder().List("/"); err != nil {
    log.Error(err.Error())
} else {
    fmt.Printf("\n\nLIST FOLDER: %+v \n\n", response)
}

// deleting the uploaded file
log.Info("deleting the uploaded file")
if response, err := dropbox.File().Delete("/teste.txt"); err != nil {
    log.Error(err.Error())
} else {
    fmt.Printf("\n\nDELETED FILE: %+v \n\n", response)
}

// deleting the created folder
log.Info("deleting the created folder")
if response, err := dropbox.Folder().DeleteFolder("/bananas"); err != nil {
    log.Error(err.Error())
} else {
    fmt.Printf("\n\nDELETED FOLDER: %+v \n\n", response)
}

Known issues

Follow me at

Facebook: https://www.facebook.com/joaosoft

LinkedIn: https://www.linkedin.com/in/jo%C3%A3o-ribeiro-b2775438/

If you have something to add, please let me know joaosoft@gmail.com

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Exists

func Exists(file string) bool

func GetEnv

func GetEnv() string

func ReadFile

func ReadFile(fileName string, obj interface{}) ([]byte, error)

func ReadFileLines

func ReadFileLines(fileName string) ([]string, error)

func WriteFile

func WriteFile(fileName string, obj interface{}) error

Types

type AppConfig

type AppConfig struct {
	Dropbox *DropboxConfig `json:"dropbox"`
}

AppConfig ...

func NewConfig

func NewConfig() (*AppConfig, manager.IConfig, error)

NewConfig ...

type Dropbox

type Dropbox struct {
	// contains filtered or unexported fields
}

func NewDropbox

func NewDropbox(options ...DropboxOption) (*Dropbox, error)

NewDropbox ...

func (*Dropbox) File

func (d *Dropbox) File() *File

File ...

func (*Dropbox) Folder

func (d *Dropbox) Folder() *Folder

Folder ...

func (*Dropbox) Reconfigure

func (dropbox *Dropbox) Reconfigure(options ...DropboxOption)

Reconfigure ...

func (*Dropbox) User

func (d *Dropbox) User() *User

Api ...

type DropboxConfig

type DropboxConfig struct {
	Log struct {
		Level string `json:"level"`
	} `json:"log"`
	Authorization struct {
		Access string `json:"access"`
		Token  string `json:"token"`
	} `json:"authorization"`
	Hosts struct {
		Api     string `json:"api"`
		Content string `json:"content"`
	} `json:"hosts"`
}

DropboxConfig ...

type DropboxOption

type DropboxOption func(dropbox *Dropbox)

DropboxOption ...

func WithConfiguration

func WithConfiguration(config *DropboxConfig) DropboxOption

WithConfiguration ...

func WithLogLevel

func WithLogLevel(level logger.Level) DropboxOption

WithLogLevel ...

func WithLogger

func WithLogger(logger logger.ILogger) DropboxOption

WithLogger ...

func WithManager

func WithManager(mgr *manager.Manager) DropboxOption

WithManager ...

type File

type File struct {
	// contains filtered or unexported fields
}

func (*File) Delete

func (f *File) Delete(path string) (*deleteFileResponse, error)

func (*File) Download

func (f *File) Download(path string) ([]byte, error)

func (*File) Upload

func (f *File) Upload(path string, file []byte) (*uploadFileResponse, error)

type Folder

type Folder struct {
	// contains filtered or unexported fields
}

func (*Folder) Create

func (f *Folder) Create(path string) (*createFolderResponse, error)

func (*Folder) DeleteFolder

func (f *Folder) DeleteFolder(path string) (*deleteFileResponse, error)

func (*Folder) List

func (f *Folder) List(path string) (*listFolderResponse, error)

type User

type User struct {
	// contains filtered or unexported fields
}

func (*User) Get

func (u *User) Get() (*getUserResponse, error)

Get ...

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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