box

package module
v0.0.0-...-a824dfa Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2014 License: BSD-3-Clause Imports: 13 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

go-box

go-box provides a client for Box's 2.0 API.

It is still a work in progress.

The supported features include

* Oauth2 authorization
* Following folder operations:

    * Get
    * Create
    * Delete
    * Rename
    * Move
    * Copy
    * Share
    * Unshare

* Following file operations:

    * Get
    * Delete
    * Rename
    * Move
    * Copy
    * Upload
    * Download

TODO

  • Tests
  • Example code
  • Rest of the box api

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SUCCESS    = &BoxError{200, "Success"}
	CREATED    = &BoxError{201, "Created"}
	ACCEPTED   = &BoxError{202, "Accepted"}
	NO_CONTENT = &BoxError{204, "No Content"}
)
View Source
var (
	REDIRECT     = &BoxError{302, "Redirect"}
	NOT_MODIFIED = &BoxError{304, "Not Modified"}
)
View Source
var (
	UNAUTHORIZED        = &BoxError{401, "Unauthorized"}        // Authorization failed
	FORBIDDEN           = &BoxError{403, "Forbidden"}           // Not enough permission for the operation
	NOT_FOUND           = &BoxError{404, "Not found"}           // Not Found
	NOT_ALLOWED         = &BoxError{405, "Not allowed"}         // Method not allowed
	CONFLICT            = &BoxError{409, "Conflict"}            // Same name item already exist
	PRECONDITION_FAILED = &BoxError{412, "Precondition failed"} // Precondition (If match) failed
	TOO_MANY_REQUESTS   = &BoxError{429, "Too many requests"}   // Too many requests
)
View Source
var (
	SERVER_ERROR = &BoxError{500, "Internal server error"} // Internal server error
	UNAVAILABLE  = &BoxError{503, "Unavailable"}           // Unavailable
)

Functions

This section is empty.

Types

type Box

type Box struct {
	APIURL       string
	APIUPLOADURL string
	// contains filtered or unexported fields
}

Box Client

func NewBox

func NewBox() *Box

NewBox gets the new Box object with appropriate APIURL.

func (*Box) AccessToken

func (box *Box) AccessToken() string

AccessToken returns the OAuth access token.

func (*Box) Auth

func (box *Box) Auth() error

Auth displays the URL to authorize this application to connect to your account.

func (*Box) SetAccessToken

func (box *Box) SetAccessToken(accesstoken string)

SetAccessToken sets access token to avoid calling Auth method.

func (*Box) SetAppInfo

func (box *Box) SetAppInfo(clientid, clientsecret string) error

SetAppInfo adds oauth2 app info

type BoxError

type BoxError struct {
	StatusCode int
	Message    string
}

func (*BoxError) Error

func (e *BoxError) Error() string

type BoxLock

type BoxLock struct {
	Id        string   `json:"id,omitempty"`
	CreatedBy string   `json:"created_by,omitempty"`
	CreatedAt *BoxTime `json:"created_at,omitempty"`
	ExpiresAt *BoxTime `json:"expires_at,omitempty"`
	Download  bool     `json:"is_download_prevented,omitempty"`
}

type BoxTime

type BoxTime time.Time

func (BoxTime) MarshalJSON

func (bt BoxTime) MarshalJSON() ([]byte, error)

MarshalJSON marshals a time according to the Dropbox format.

func (*BoxTime) UnmarshalJSON

func (bt *BoxTime) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals a time according to the Dropbox format.

type Collection

type Collection struct {
	Count  int      `json:"total_count,omitempty"`
	Entry  []Entity `json:"entries,omitempty"`
	Limit  int      `json:"limit,omitempty"`
	Offset int      `json:"offset,omitempty"`
}

type Entity

type Entity struct {
	SequenceId string `json:"sequence_id,omitempty"` // A unique ID for use with the /events endpoint.
	Name       string `json:"name,omitempty"`        // The name of the entity.
	Id         string `json:"id,omitempty"`          // The id of the entity.
	ETag       string `json:"etag,omitempty"`        // A unique string identifying the version of this entity.
	Type       string `json:"type,omitempty"`        // Type of entity
}

Represents both mini folder and mini file.

func (*Entity) IsFile

func (e *Entity) IsFile() bool

IsFile checks if the given entity is a file.

func (*Entity) IsFolder

func (e *Entity) IsFolder() bool

IsFolder checks if the given entity is a folder

type File

type File struct {
	Id                string        `json:"id,omitempty"`                  // Box’s unique string identifying this file.
	SequenceId        string        `json:"sequence_id,omitempty"`         // A unique ID for use with the /events endpoint.
	ETag              string        `json:"etag,omitempty"`                // A unique string identifying the version of this file.
	Sha1              string        `json:"sha1,omitempty"`                // The sha1 hash of this file.
	Name              string        `json:"name,omitempty"`                // The name of this file.
	Description       string        `json:"description,omitempty"`         // The description of this file.
	Size              int           `json:"size,omitempty"`                // Size of this file in bytes.
	PathCollection    *Collection   `json:"path_collection,omitempty"`     // The path of folders to this item, starting at the root.
	CreatedAt         *BoxTime      `json:"created_at,omitempty"`          // When this file was created on Box’s servers.
	ModifiedAt        *BoxTime      `json:"modified_at,omitempty"`         // When this file was last updated on the Box servers.
	ThrashedAt        *BoxTime      `json:"thrashed_at,omitempty"`         // When this file was last moved to the trash.
	PurgedAt          *BoxTime      `json:"purged_at,omitempty"`           // When this file will be permanently deleted.
	ContentCreatedAt  *BoxTime      `json:"content_created_at,omitempty"`  // When the content of this file was created.
	ContentModifiedAt *BoxTime      `json:"content_modified_at,omitempty"` // When the content of this file was last modified.
	CreatedBy         *Entity       `json:"created_by,omitempty"`          // The user who first created file.
	ModifiedBy        *Entity       `json:"modified_by,omitempty"`         // The user who last updated this file.
	OwnedBy           *Entity       `json:"owned_by,omitempty"`            // The user who owns this file.
	SharedLink        *SharedObject `json:"shared_link,omitempty"`         // The shared link object for this file.
	Parent            *Entity       `json:"parent,omitempty"`              // The folder containing this file.
	ItemStatus        string        `json:"item_status,omitempty"`         // Whether this item is deleted or not.
	VersionNumber     string        `json:"version_number,omitempty"`      // The version of the file.
	CommentCount      int           `json:"comment_count,omitempty"`       // The number of comments on a file.
	Permissions       *Permission   `json:"permissions,omitempty"`         // The permissions that the current user has on this file.
	Tags              []string      `json:"tags,omitempty"`                // All tags applied to this file.
	Lock              *BoxLock      `json:"lock,omitempty"`                // The lock held on the file.
	Extension         string        `json:"extension,omitempty"`           // Indicates the suffix, when available, on the file.
}

func (*File) Copy

func (f *File) Copy(box *Box, parent *Folder) (*File, error)

Copy copies the current file under the given parent. Note that only Id is required apriori for both file and parent folder. The copied file is returned after copy is successful.

func (*File) Delete

func (f *File) Delete(box *Box) error

Delete deletes the file. Note that only Id is required apriori.

func (*File) Download

func (f *File) Download(box *Box, writer io.Writer) error

Download downloads the file. Note that only file id is required apriori.

func (*File) DownloadFile

func (f *File) DownloadFile(box *Box, path string) error

Download downloads the file at the given file path. File will be overwritten if it already exists. Note that only file id is required apriori.

func (*File) Get

func (f *File) Get(box *Box) error

Get populates the fields of the file struct. Node that only Id is required apriori.

func (*File) Move

func (f *File) Move(box *Box, parent *Folder) error

Move moves the current file under the given parent. Note that only Id is required apriori for both file and parent folder. The file is populated with all the information after the call.

func (*File) Rename

func (f *File) Rename(box *Box, name string) error

Rename renames the file with the new name. Note that only Id is required apriori. The file object is populated with all the information after the call.

func (*File) Upload

func (f *File) Upload(box *Box, reader io.Reader, parent *Folder) error

Upload uploads the file (given by the reader) at the given file path. The file name on the box server is taken from the Name attribute of file object. After upload, it then fills the information of the recently uploaded file in the file object. Note that Id attribute is required for the parent folder.

func (*File) UploadFile

func (f *File) UploadFile(box *Box, path string, parent *Folder) error

UploadFile directly uploads the file on the box server. The name is taken from the Name attribute of the file object (if it is empty, file name is chosen). Note than only parent id is required apriori for the parent folder.

type Folder

type Folder struct {
	Id                string        `json:"id,omitempty"`                  // The folder’s ID.
	SequenceId        string        `json:"sequence_id,omitempty"`         // A unique ID for use with the /events endpoint.
	ETag              string        `json:"etag,omitempty"`                // A unique string identifying the version of this folder.
	Name              string        `json:"name,omitempty"`                // The name of this folder.
	Description       string        `json:"description,omitempty"`         // The description of this folder.
	Size              int           `json:"size,omitempty"`                // Size of this file in bytes.
	PathCollection    *Collection   `json:"path_collection,omitempty"`     // The path of folders to this item, starting at the root.
	CreatedAt         *BoxTime      `json:"created_at,omitempty"`          // The time the folder was created.
	ModifiedAt        *BoxTime      `json:"modified_at,omitempty"`         // The time the folder or its contents were last modified.
	ThrashedAt        *BoxTime      `json:"thrashed_at,omitempty"`         // The time the folder or its contents were put in the trash.
	PurgedAt          *BoxTime      `json:"purged_at,omitempty"`           // The time the folder or its contents were purged from the trash.
	ContentCreatedAt  *BoxTime      `json:"content_created_at,omitempty"`  // The time the folder or its contents were originally created (according to the uploader).
	ContentModifiedAt *BoxTime      `json:"content_modified_at,omitempty"` // The time the folder or its contents were last modified (according to the uploader).
	CreatedBy         *Entity       `json:"created_by,omitempty"`          // The user who created this folder.
	ModifiedBy        *Entity       `json:"modified_by,omitempty"`         // The user who last modified this folder.
	OwnedBy           *Entity       `json:"owned_by,omitempty"`            // The user who owns this file.
	SharedLink        *SharedObject `json:"shared_link,omitempty"`         // The shared link for this folder. Null if not set..
	Parent            *Entity       `json:"parent,omitempty"`              // The folder that contains this one.
	ItemStatus        string        `json:"item_status,omitempty"`         // Whether this item is deleted or not.
	Permissions       *Permission   `json:"permissions,omitempty"`         // The permissions that the current user has on this file.
	Tags              []string      `json:"tags,omitempty"`                // All tags applied to this file.
	HasCollaborations bool          `json:"has_collaborations,omitempty"`  // Whether this folder has any collaborators.
	SyncStatus        string        `json:"sync_status,omitempty"`         // Whether this folder will be synced by the Box sync clients or not. Can be
	ItemCollection    *Collection   `json:"item_collection,omitempty"`     // A collection of mini file and folder objects contained in this folder.
	FolderUploadEmail *UploadEmail  `json:"folder_upload_email,omitempty"` // The upload email address for this folder. Null if not set.
}

func (*Folder) Copy

func (f *Folder) Copy(box *Box, parent *Folder) (*Folder, error)

Copy copies the current folder under the given parent. Note that only Id is required apriori for both parent and current folder. The copied folder is returned after copy is successful.

func (*Folder) Create

func (f *Folder) Create(box *Box, name string) (*Folder, error)

Create creates a sub folder under the given folder. It returns the created folder. Note that only Id of the parent folder is required apriori.

func (*Folder) Delete

func (f *Folder) Delete(box *Box) error

Delete deletes the folder. Note that only Id is required apriori.

func (*Folder) Get

func (f *Folder) Get(box *Box) error

Get populates the fields of the struct. Node that only Id is required apriori.

func (*Folder) Items

func (f *Folder) Items(box *Box) ([]Entity, error)

Items returns all items (folder or files) under the given folder. It calls Get if the folder is not already populated.

func (*Folder) Move

func (f *Folder) Move(box *Box, parent *Folder) error

Move moves the current folder under the given parent. Note that only Id is required apriori for both parent and current folder. The folder is populated with all the information after the call.

func (*Folder) Rename

func (f *Folder) Rename(box *Box, name string) error

Rename renames the folder with the new name. Note that only Id is required apriori. The folder is populated with all the information after the call.

func (*Folder) Share

func (f *Folder) Share(box *Box, download, preview bool) error

Share creates a share link. download and preview sets appropriate permissions on the shared link. It only supports open sharing. Note that only folder Id is required apriori. The folder is populated with all the information after the call. You can get the SharedObject by accessing appropriate field of the folder.

func (*Folder) Unshare

func (f *Folder) Unshare(box *Box) error

Unshare invalidates the shared link of the folder.

type Permission

type Permission struct {
	Download bool `json:"can_download,omitempty"`
	Preview  bool `json:"can_preview,omitempty"`
	Upload   bool `json:"can_upload,omitempty"`
	Comment  bool `json:"can_comment,omitempty"`
	Rename   bool `json:"can_rename,omitempty"`
	Delete   bool `json:"can_delete,omitempty"`
	Share    bool `json:"can_share,omitempty"`
	SetShare bool `json:"can_set_share_access,omitempty"`
}

type SharedObject

type SharedObject struct {
	Url           string      `json:"url,omitempty"`
	DownloadUrl   string      `json:"download_url,omitempty"`
	VanityUrl     string      `json:"vanity_url,omitempty"`
	HasPassword   bool        `json:"is_password_enabled,omitempty"`
	UnsharedAt    *BoxTime    `json:"unshared_at,omitempty"`
	DownloadCount int         `json:"download_count,omitempty"`
	PreviewCount  int         `json:"preview_count,omitempty"`
	Access        string      `json:"access,omitempty"`
	Permission    *Permission `json:"permissions,omitempty"`
}

type UploadEmail

type UploadEmail struct {
	Access string `json:"access,omitempty"`
	Email  string `json:"email,omitempty"`
}

Jump to

Keyboard shortcuts

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