onedriveclient

package module
Version: v0.0.0-...-fabdace Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2016 License: MIT Imports: 10 Imported by: 0

README

OneDrive Client

This is a basic client for uploading and downloading files to/from Microsoft OneDrive. You will need to perform OAuth authentication yourself - see MSDN documentation.

Files and folders in OneDrive are referenced by node id. If you want to reference them by path you will have to use the ResolvePath method. Then you can stat the node (NodeInfo) or list its children (NodeFiles).

Methods Upload and Download perform streming uploads and downloads to desired nodes.

Documentation

Index

Constants

View Source
const (
	AddressTypeId   = 0
	AddressTypePath = 1
)
View Source
const (
	ErrorCodeItemNotFound      = "itemNotFound"
	ErrorCodeNameAlreadyExists = "nameAlreadyExists"
)
View Source
const (
	NameConflictBehaviorRename  = "rename"
	NameConflictBehaviorReplace = "replace"
	NameConflictBehaviorFail    = "fail"
)
View Source
const (
	AsyncOperationStatusNotStarted    = "notStarted"
	AsyncOperationStatusInProgress    = "inProgress"
	AsyncOperationStatusCompleted     = "completed"
	AsyncOperationStatusUpdating      = "updating"
	AsyncOperationStatusFailed        = "failed"
	AsyncOperationStatusDeletePending = "deletePending"
	AsyncOperationStatusDeleteFailed  = "deleteFailed"
	AsyncOperationStatusWaiting       = "waiting"
)
View Source
const (
	DefaultMaxFragmentSize = 60 * 1024 * 1024
)
View Source
const (
	InvalidGrantError = "invalid_grant"
)

Variables

View Source
var AddressRoot = Address{
	Address: "/drive/items/root",
	Type:    AddressTypeId,
}

Functions

func HandleError

func HandleError(err error) error

func NormalizePath

func NormalizePath(pth string) string

Types

type Address

type Address struct {
	Address string
	Type    int
}

func AddressId

func AddressId(id string) Address

func AddressPath

func AddressPath(pth string) Address

func (Address) String

func (a Address) String() string

func (Address) Subpath

func (a Address) Subpath(path string) Address

type AsyncOperationStatus

type AsyncOperationStatus struct {
	Operation          string  `json:"operation"`
	PercentageComplete float64 `json:"percentageComplete"`
	Status             string  `json:"status"`
}

type ChunkedUploadSessionDescriptor

type ChunkedUploadSessionDescriptor struct {
	NameConflictBehavior string `json:"@name.conflictBehavior"`
	Name                 string `json:"name"`
}

type CreateSessionBody

type CreateSessionBody struct {
	Item ChunkedUploadSessionDescriptor `json:"item"`
}

type Deleted

type Deleted struct {
	State string `json:"state"`
}

type DeltaCollectionPage

type DeltaCollectionPage struct {
	Value    []*Item `json:"value"`
	NextLink string  `json:"@odata.nextLink"`
	Token    string  `json:"@delta.token"`
}

type Drive

type Drive struct {
	Id        string      `json:"id"`
	DriveType string      `json:"driveType"`
	Owner     IdentitySet `json:"owner"`
	Quota     Quota       `json:"quota"`
}

type File

type File struct {
	Hashes   Hashes `json:"hashes"`
	MimeType string `json:"mimeType"`
}

type FileSystemInfo

type FileSystemInfo struct {
	CreatedDateTime      time.Time `json:"createdDateTime"`
	LastModifiedDateTime time.Time `json:"lastModifiedDateTime"`
}

type Folder

type Folder struct {
	ChildCount int `json:"childCount"`
}

type Hashes

type Hashes struct {
	Crc32Hash string `json:"crc32Hash"`
	Sha1Hash  string `json:"sha1Hash"`
}

type Identity

type Identity struct {
	DisplayName string `json:"displayName"`
	Id          string `json:"id"`
}

type IdentitySet

type IdentitySet struct {
	Application Identity `json:"application"`
	User        Identity `json:"user"`
}

type Item

type Item struct {
	CreatedBy            *IdentitySet    `json:"createdBy,omitempty"`
	CreatedDateTime      time.Time       `json:"createdDateTime,omitempty"`
	CTag                 string          `json:"cTag,omitempty"`
	Description          string          `json:"description,omitempty"`
	ETag                 string          `json:"eTag,omitempty"`
	Id                   string          `json:"id,omitempty"`
	LastModifiedBy       *IdentitySet    `json:"lastModifiedBy,omitempty"`
	LastModifiedDateTime time.Time       `json:"lastModifiedDateTime,omitempty"`
	Name                 string          `json:"name,omitempty"`
	ParentReference      *ItemReference  `json:"parentReference,omitempty"`
	Size                 int64           `json:"size,omitempty"`
	WebURL               string          `json:"webUrl,omitempty"`
	Deleted              *Deleted        `json:"deleted,omitempty"`
	File                 *File           `json:"file,omitempty"`
	FileSystemInfo       *FileSystemInfo `json:"fileSystemInfo,omitempty"`
	Folder               *Folder         `json:"folder,omitempty"`
}

type ItemCollectionPage

type ItemCollectionPage struct {
	Value    []*Item `json:"value"`
	NextLink string  `json:"@odata.nextLink"`
}

type ItemCopyBody

type ItemCopyBody struct {
	Name            string         `json:"name,omitempty"`
	ParentReference *ItemReference `json:"parentReference,omitempty"`
}

type ItemCreateBody

type ItemCreateBody struct {
	Name   string `json:"name,omitempty"`
	Folder Folder `json:"folder,omitempty"`
}

type ItemReference

type ItemReference struct {
	DriveId string `json:"driveId,omitempty"`
	Id      string `json:"id,omitempty"`
	Path    string `json:"path,omitempty"`
}

type ItemUpdateBody

type ItemUpdateBody struct {
	Name            string         `json:"name,omitempty"`
	ParentReference *ItemReference `json:"parentReference,omitempty"`
}

type OneDrive

type OneDrive struct {
	ApiClient       *httpclient.HTTPClient
	Auth            *OneDriveAuth
	MaxFragmentSize int64
}

func NewOneDrive

func NewOneDrive(auth *OneDriveAuth) (c *OneDrive)

func (*OneDrive) Drive

func (c *OneDrive) Drive() (drive *Drive, err error)

func (*OneDrive) HandleError

func (c *OneDrive) HandleError(err error) error

func (*OneDrive) ItemsChildren

func (c *OneDrive) ItemsChildren(address Address, link string) (res *ItemCollectionPage, err error)

func (*OneDrive) ItemsContent

func (c *OneDrive) ItemsContent(address Address, span *ioutils.FileSpan) (reader io.ReadCloser, size int64, err error)

func (*OneDrive) ItemsCopy

func (c *OneDrive) ItemsCopy(address Address, body *ItemCopyBody) (monitorUrl string, err error)

func (*OneDrive) ItemsCopyAwait

func (c *OneDrive) ItemsCopyAwait(monitorUrl string) (item *Item, err error)

func (*OneDrive) ItemsCopyStatus

func (c *OneDrive) ItemsCopyStatus(monitorUrl string) (status *AsyncOperationStatus, item *Item, err error)

func (*OneDrive) ItemsCreate

func (c *OneDrive) ItemsCreate(address Address, body *ItemCreateBody) (item *Item, err error)

func (*OneDrive) ItemsDelete

func (c *OneDrive) ItemsDelete(address Address) (err error)

func (*OneDrive) ItemsDelta

func (c *OneDrive) ItemsDelta(address Address, link string, token string) (res *DeltaCollectionPage, err error)

func (*OneDrive) ItemsGet

func (c *OneDrive) ItemsGet(address Address) (item *Item, err error)

func (*OneDrive) ItemsUpdate

func (c *OneDrive) ItemsUpdate(address Address, itemUpdate *ItemUpdateBody) (item *Item, err error)

func (*OneDrive) ItemsUpload

func (c *OneDrive) ItemsUpload(address Address, name string, nameConflictBehavior string, content io.Reader, size int64) (item *Item, err error)

func (*OneDrive) ItemsUploadCreateSession

func (c *OneDrive) ItemsUploadCreateSession(address Address, body *CreateSessionBody) (uploadSession *UploadSession, err error)

func (*OneDrive) ItemsUploadSessionAppend

func (c *OneDrive) ItemsUploadSessionAppend(uploadSession *UploadSession, content io.Reader, start int64, end int64, size int64) (err error)

func (*OneDrive) ItemsUploadSessionFinish

func (c *OneDrive) ItemsUploadSessionFinish(uploadSession *UploadSession, content io.Reader, start int64, end int64, size int64) (item *Item, err error)

func (*OneDrive) Request

func (c *OneDrive) Request(request *httpclient.RequestData) (res *http.Response, err error)

type OneDriveAuth

type OneDriveAuth struct {
	ClientId     string
	ClientSecret string
	RedirectUri  string
	AccessToken  string
	RefreshToken string
	ExpiresAt    time.Time
}

func (*OneDriveAuth) ValidToken

func (a *OneDriveAuth) ValidToken() (token string, err error)

type OneDriveError

type OneDriveError struct {
	Err             OneDriveErrorDetails `json:"error"`
	HttpClientError *httpclient.InvalidStatusError
}

func IsOneDriveError

func IsOneDriveError(err error) (oneDriveErr *OneDriveError, ok bool)

func (*OneDriveError) Error

func (e *OneDriveError) Error() string

type OneDriveErrorDetails

type OneDriveErrorDetails struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

type Quota

type Quota struct {
	Deleted   int64  `json:"deleted"`
	Remaining int64  `json:"remaining"`
	State     string `json:"state"`
	Total     int64  `json:"total"`
	Used      int64  `json:"used"`
}

type RefreshResp

type RefreshResp struct {
	ExpiresIn    int64  `json:"expires_in"`
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
}

type RefreshRespError

type RefreshRespError struct {
	Error            string `json:"error"`
	ErrorDescription string `json:"error_description"`
}

type UploadSession

type UploadSession struct {
	UploadUrl          string    `json:"uploadUrl"`
	ExpirationDateTime time.Time `json:"expirationDateTime"`
	NextExpectedRanges []string  `json:"nextExpectedRanges"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL