Documentation
¶
Index ¶
- Constants
- Variables
- type AppAuth
- type Auth
- type Client
- type ContextInfo
- type Credentials
- type DownloadOptions
- type FileCollection
- type FileEntry
- type FileVersion
- type Files
- func (module *Files) Download(ctx context.Context, entry *FileEntry) (*request.Content, error)
- func (module *Files) FindByID(ctx context.Context, fileID string) (*FileEntry, error)
- func (module *Files) FindByName(ctx context.Context, name string, parent *PathEntry) (*FileEntry, error)
- func (module *Files) Upload(ctx context.Context, options *UploadOptions) (*FileCollection, error)
- type FolderCollection
- type FolderEntry
- type Folders
- func (module *Folders) Create(ctx context.Context, entry *FolderEntry) (*FolderEntry, error)
- func (module *Folders) Delete(ctx context.Context, entry *FolderEntry) error
- func (module *Folders) FindByID(ctx context.Context, folderID string) (*FolderEntry, error)
- func (module *Folders) FindByName(ctx context.Context, name string) (*FolderEntry, error)
- type PathCollection
- type PathEntry
- type Permissions
- type RequestError
- type SharedLink
- type SharedLinkOptions
- type SharedLinks
- type Token
- type UploadOptions
- type UserEntry
Constants ¶
const TokenContextKey key = iota
TokenContextKey is the key for the token stored in a context.Context
Variables ¶
var ( BadRequest = RequestError{Type: "error", ID: "bad_request", StatusCode: 400, Message: "Bad Request"} ItemNameInvalid = RequestError{Type: "error", ID: "item_name_invalid", StatusCode: 400, Message: "Item name invalid"} TermsOfServiceRequired = RequestError{Type: "error", ID: "terms_of_service_required", StatusCode: 400, Message: "User must accept custom terms of service before action can be taken"} FolderNotEmpty = RequestError{Type: "error", ID: "folder_not_empty", StatusCode: 400, Message: "Cannot delete – folder not empty"} InvalidGrant = RequestError{Type: "error", ID: "invalid_grant", StatusCode: 420, Message: "Please check the 'iss' claim. The client id specified is invalid."} InvalidPrivateKey = RequestError{Type: "error", ID: "invalid_private_key", StatusCode: 400, Message: "Invalid Private Key in request"} InvalidRequestParameters = RequestError{Type: "error", ID: "invalid_request_parameters", StatusCode: 400, Message: "Invalid input parameters in request"} UserAlreadyCollaborator = RequestError{Type: "error", ID: "user_already_collaborator", StatusCode: 400, Message: "User is already a collaborator"} CannotMakeCollaboratedSubfolderPrivate = RequestError{Type: "error", ID: "cannot_make_collaborated_subfolder_private", StatusCode: 400, Message: "Cannot move a collaborated subfolder to a private folder unless the new owner is explicitly specified"} ItemNameTooLong = RequestError{Type: "error", ID: "item_name_too_long", StatusCode: 400, Message: "Item name too long"} CollaborationsNotAvailableOnRootFolder = RequestError{Type: "error", ID: "collaborations_not_available_on_root_folder", StatusCode: 400, Message: "Root folder cannot be collaborated"} SyncItemMoveFailure = RequestError{Type: "error", ID: "sync_item_move_failure", StatusCode: 400, Message: "Cannot move a synced item"} RequestedPageOutOfRange = RequestError{Type: "error", ID: "requested_page_out_of_range", StatusCode: 400, Message: "Requested representation page out of range"} CyclicalFolderStructure = RequestError{Type: "error", ID: "cyclical_folder_structure", StatusCode: 400, Message: "Folder move creates cyclical folder structure"} BadDigest = RequestError{Type: "error", ID: "bad_digest", StatusCode: 400, Message: "The specified Content-MD5 did not match what we received"} InvalidCollaborationItem = RequestError{Type: "error", ID: "invalid_collaboration_item", StatusCode: 400, Message: "Item type must be specified and set to ‘folder’"} TaskAssigneeNotAllowed = RequestError{Type: "error", ID: "task_assignee_not_allowed", StatusCode: 400, Message: "Assigner does not have sufficient privileges to assign task to assignee"} InvalidStatus = RequestError{Type: "error", ID: "invalid_status", StatusCode: 400, Message: "You can change the status only if the collaboration is pending"} Forbidden = RequestError{Type: "error", ID: "forbidden", StatusCode: 403, Message: "Forbidden"} StorageLimitExceeded = RequestError{Type: "error", ID: "storage_limit_exceeded", StatusCode: 403, Message: "Account storage limit reached"} CorsOriginNotWhitelisted = RequestError{Type: "error", ID: "cors_origin_not_whitelisted", StatusCode: 403, Message: "You’re attempting to make a request from a domain that is not whitelisted in your app’s cors configuration"} AccessDeniedInsufficientPermissions = RequestError{Type: "error", ID: "access_denied_insufficient_permissions", StatusCode: 403, Message: "Access denied – insufficient permission"} AccessDeniedItemLocked = RequestError{Type: "error", ID: "access_denied_item_locked", StatusCode: 403, Message: "Access Denied, item locked"} FileSizeLimitExceeded = RequestError{Type: "error", ID: "file_size_limit_exceeded", StatusCode: 403, Message: "File size exceeds the folder owner’s file size limit"} AccessFromLocationBlocked = RequestError{Type: "error", ID: "access_from_location_blocked", StatusCode: 403, Message: "You’re attempting to log in to Box from a location that has not been approved by your admin. Please talk to your admin to resolve this issue."} NotFound = RequestError{Type: "error", ID: "not_found", StatusCode: 404, Message: "When the item is not found, or if the user does not have access to the item."} PreviewCannotBeGenerated = RequestError{Type: "error", ID: "preview_cannot_be_generated", StatusCode: 404, Message: "Preview cannot be generated"} Trashed = RequestError{Type: "error", ID: "trashed", StatusCode: 404, Message: "Item is trashed"} NotTrashed = RequestError{Type: "error", ID: "not_trashed", StatusCode: 404, Message: "Item is not trashed"} MethodNotAllowed = RequestError{Type: "error", ID: "method_not_allowed", StatusCode: 405, Message: "Method Not Allowed"} ItemNameInUse = RequestError{Type: "error", ID: "item_name_in_use", StatusCode: 409, Message: "Item with the same name already exists"} Conflict = RequestError{Type: "error", ID: "conflict", StatusCode: 409, Message: "A resource with this value already exists"} UserLoginAlreadyUsed = RequestError{Type: "error", ID: "user_login_already_used", StatusCode: 409, Message: "User with the specified login already exists"} RecentSimilarComment = RequestError{Type: "error", ID: "recent_similar_comment", StatusCode: 409, Message: "A similar comment has been made recently"} OperationBlockedTemporary = RequestError{Type: "error", ID: "operation_blocked_temporary", StatusCode: 409, Message: "The operation is blocked by another ongoing operation."} NameTemporarilyReserved = RequestError{Type: "error", ID: "name_temporarily_reserved", StatusCode: 409, Message: "Two duplicate requests have been submitted at the same time. Box acknowledges the first and reserves the name, but a second duplicate request arrives before the first request has completed."} SyncStatePreconditionFailed = RequestError{Type: "error", ID: "sync_state_precondition_failed", StatusCode: 412, Message: "The resource has been modified. Please retrieve the resource again and retry"} PreconditionFailed = RequestError{Type: "error", ID: "precondition_failed", StatusCode: 412, Message: "The resource has been modified. Please retrieve the resource again and retry"} RateLimitExceeded = RequestError{Type: "error", ID: "rate_limit_exceeded", StatusCode: 429, Message: "Request rate limit exceeded, please try again later. There are two limits. The first is a limit of 10 API calls per second per user. The second limit is 4 uploads per second per user."} InternalServerError = RequestError{Type: "error", ID: "internal_server_error", StatusCode: 500, Message: "Internal Server Error"} )
var VERSION = "0.2.1" + commit
VERSION is the version of this application
Functions ¶
This section is empty.
Types ¶
type AppAuth ¶
type AppAuth struct { PublicKeyID string `json:"publickeyId"` PrivateKey string `json:"privateKey"` Passphrase string `json:"passphrase"` }
AppAuth is used to authenticate an application
type Auth ¶
Auth module
func (*Auth) Authenticate ¶
func (module *Auth) Authenticate(ctx context.Context, creds Credentials) (err error)
Authenticate authenticates with the given credentials Currently only AppAuth is supported
func (*Auth) IsAuthenticated ¶
IsAuthenticated tells if the client is authenticated
type Client ¶
type Client struct { Api *url.URL `json:"api"` Proxy *url.URL `json:"proxy"` Auth *Auth `json:"-"` Files *Files `json:"-"` Folders *Folders `json:"-"` Logger *logger.Logger `json:"-"` }
Client is the Box Client
func (*Client) IsAuthenticated ¶
IsAuthenticated tells if the client is authenticated
type ContextInfo ¶
type ContextInfo struct { // TODO: Find the best representation of this thing // https://developer.box.com/reference is not clear if it is errors or conflicts Errors []byte `json:"errors"` }
ContextInfo gives some contextual information about the current error
type Credentials ¶
type Credentials struct { ClientID string `json:"clientId"` ClientSecret string `json:"clientSecret"` AppAuth AppAuth `json:"appAuth"` EnterpriseID string `json:"enterpriseId,omitempty"` }
Credentials represents the Authentication information
func (*Credentials) MarshalJSON ¶
func (creds *Credentials) MarshalJSON() ([]byte, error)
MarshalJSON marshals into JSON
func (*Credentials) UnmarshalJSON ¶
func (creds *Credentials) UnmarshalJSON(payload []byte) (err error)
UnmarshalJSON unmarshals JSON into this
type DownloadOptions ¶
type DownloadOptions struct { Parent *PathEntry Filename string ContentType string Content []byte Payload interface{} }
DownloadOptions contains the options for downloading data
type FileCollection ¶
FileCollection represents a collection of FileEntry
type FileEntry ¶
type FileEntry struct { Type string `json:"type"` ID string `json:"id"` Name string `json:"name"` Description string `json:"description"` ETag string `json:"etag"` SequenceID string `json:"sequence_id"` Size int64 `json:"size"` ItemStatus string `json:"item_status"` Checksum string `json:"sha1"` FileVersion FileVersion `json:"file_version"` Parent PathEntry `json:"parent"` Paths PathCollection `json:"path_collection"` CreatedAt time.Time `json:"-"` ModifiedAt time.Time `json:"-"` TrashedAt time.Time `json:"-"` PurgedAt time.Time `json:"-"` ContentCreatedAt time.Time `json:"-"` ContentModifiedAt time.Time `json:"-"` CreatedBy UserEntry `json:"created_by"` ModifiedBy UserEntry `json:"modified_by"` OwnedBy UserEntry `json:"owned_by"` }
FileEntry represents a File Entry
func (FileEntry) MarshalJSON ¶
MarshalJSON marshals this into JSON
func (*FileEntry) UnmarshalJSON ¶
UnmarshalJSON decodes JSON
type FileVersion ¶
type FileVersion struct { Type string `json:"type"` ID string `json:"id"` Checksum string `json:"sha1"` }
FileVersion represents the version of a FileEntry
type Files ¶
type Files struct { *Client // contains filtered or unexported fields }
Files module
func (*Files) FindByName ¶
func (module *Files) FindByName(ctx context.Context, name string, parent *PathEntry) (*FileEntry, error)
FindByName retrieves a file by its name For now, exact match and 1 level (no recursion)
func (*Files) Upload ¶
func (module *Files) Upload(ctx context.Context, options *UploadOptions) (*FileCollection, error)
Upload uploads data to Box.com
type FolderCollection ¶
type FolderCollection struct { Count int `json:"total_count"` Folders []FolderEntry `json:"entries"` }
FolderCollection represents a collection of FolderEntry
type FolderEntry ¶
type FolderEntry struct { Type string `json:"type"` ID string `json:"id"` Name string `json:"name"` Description string `json:"description"` ETag string `json:"etag"` SequenceID string `json:"sequence_id"` Size int64 `json:"size"` ItemStatus string `json:"item_status"` Checksum string `json:"sha1"` FileVersion FileVersion `json:"file_version"` Parent *PathEntry `json:"parent"` Paths PathCollection `json:"path_collection"` ItemCollection PathCollection `json:"item_collection"` Tags []string `json:"tags"` SyncState string `json:"sync_state"` CreatedAt time.Time `json:"-"` ModifiedAt time.Time `json:"-"` TrashedAt time.Time `json:"-"` PurgedAt time.Time `json:"-"` ContentCreatedAt time.Time `json:"-"` ContentModifiedAt time.Time `json:"-"` CreatedBy UserEntry `json:"created_by"` ModifiedBy UserEntry `json:"modified_by"` OwnedBy UserEntry `json:"owned_by"` AllowedInviteeRoles []string `json:"allowed_invitee_roles"` HasCollaborations bool `json:"has_collaborations"` CanNonOwnersInvite bool `json:"can_non_owners_invite"` IsExternallyOwned bool `json:"is_externally_owned"` IsCollaborationRestrictedToEnterprise bool `json:"is_collaboration_restricted_to_enterprise"` }
FolderEntry represents a File Entry
func (*FolderEntry) AsPathEntry ¶
func (folder *FolderEntry) AsPathEntry() *PathEntry
AsPathEntry gets a PathEntry from the current FolderEntry
func (FolderEntry) MarshalJSON ¶
func (folder FolderEntry) MarshalJSON() ([]byte, error)
MarshalJSON marshals this into JSON
func (*FolderEntry) UnmarshalJSON ¶
func (folder *FolderEntry) UnmarshalJSON(payload []byte) (err error)
UnmarshalJSON decodes JSON
type Folders ¶
type Folders struct { *Client // contains filtered or unexported fields }
Folders module
func (*Folders) Create ¶
func (module *Folders) Create(ctx context.Context, entry *FolderEntry) (*FolderEntry, error)
Create creates a new folder entry.Name is mandatory, if entry.Parent.ID is not set the root folder is chosen
func (*Folders) Delete ¶
func (module *Folders) Delete(ctx context.Context, entry *FolderEntry) error
Delete deletes a folder recursively
func (*Folders) FindByName ¶
FindByName retrieves a folder by its name For now, exact match and 1 level (no recursion)
type PathCollection ¶
type PathCollection struct { Count int `json:"total_count"` Offset int `json:"offset,omitempty"` Limit int `json:"limit,omitempty"` Paths []PathEntry `json:"entries"` }
PathCollection represents a collection of PathEntry
type PathEntry ¶
type PathEntry struct { Type string `json:"type"` ID string `json:"id"` Name string `json:"name"` ETag string `json:"etag"` SequenceID string `json:"sequence_id"` Checksum string `json:"sha1,omitempty"` }
PathEntry represents a Path Entry
type Permissions ¶
type Permissions struct { CanDownload bool `json:"can_download,omitempty"` CanPreview bool `json:"can_preview,omitempty"` }
Permissions exresses what is allowed on objects
type RequestError ¶
type RequestError struct { Type string `json:"type"` ID string `json:"code"` StatusCode int `json:"status"` Message string `json:"message"` RequestID string `json:"request_id"` ContextInfo *ContextInfo `json:"context_info"` LocationURL *url.URL `json:"-"` HelpURL *url.URL `json:"-"` }
RequestError represents errors as returned by the BOX.com API
func (RequestError) Error ¶
func (e RequestError) Error() string
Error gives a string representation of this error Implements interface Error
func (RequestError) Is ¶
func (e RequestError) Is(target error) bool
Is tells if this error matches the target.
func (RequestError) MarshalJSON ¶
func (e RequestError) MarshalJSON() ([]byte, error)
MarshalJSON marshals this into JSON
func (*RequestError) UnmarshalJSON ¶
func (e *RequestError) UnmarshalJSON(payload []byte) (err error)
UnmarshalJSON decodes JSON
type SharedLink ¶
type SharedLink struct {}
SharedLink represents a shared link
func (SharedLink) MarshalJSON ¶
func (link SharedLink) MarshalJSON() ([]byte, error)
MarshalJSON marshals this into JSON
func (*SharedLink) UnmarshalJSON ¶
func (link *SharedLink) UnmarshalJSON(payload []byte) (err error)
UnmarshalJSON decodes JSON
type SharedLinkOptions ¶
type SharedLinkOptions struct {}
SharedLinkOptions contains the shared link options
func (SharedLinkOptions) MarshalJSON ¶
func (slo SharedLinkOptions) MarshalJSON() ([]byte, error)
MarshalJSON marshals this into JSON
type SharedLinks ¶
type SharedLinks struct { // contains filtered or unexported fields }
SharedLinks module
func (*SharedLinks) Create ¶
func (module *SharedLinks) Create(ctx context.Context, entry *FileEntry, options *SharedLinkOptions) (*SharedLink, error)
Create creates a shared link for a given File entry
type Token ¶
type Token struct { TokenType string `json:"token_type"` AccessToken string `json:"access_token"` ExpiresOn time.Time `json:"expires_on"` RestrictedTo []string `json:"restricted_to"` }
Token is the token used to send requests to Box.com
func TokenFromContext ¶
TokenFromContext retrieves a token from the given context If no token was stored in the context, nil is returned
func (*Token) ToContext ¶
ToContext stores this token to the given context If the token is not set, the context is untouched
func (*Token) UnmarshalJSON ¶
UnmarshalJSON decodes JSON
type UploadOptions ¶
type UploadOptions struct { Parent *PathEntry Filename string Content *request.Content Payload interface{} }
UploadOptions contains the options for uploading data