onedrive

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2021 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {

	// Base URL for API requests. Defaults to the public OneDrive API. BaseURL should
	// always be specified with a trailing slash.
	BaseURL *url.URL

	// Services used for talking to different parts of the OneDrive API.
	Drives           *DrivesService
	DriveItems       *DriveItemsService
	DriveSearch      *DriveSearchService
	DriveAsyncJob    *DriveAsyncJobService
	DrivePermissions *PermissionService
	// contains filtered or unexported fields
}

A Client manages communication with the OneDrive API.

func NewClient

func NewClient(httpClient *http.Client) *Client

NewClient returns a new OneDrive API client. If a nil httpClient is provided, a new http.Client will be used. To use API methods which require authentication, provide an http.Client that will perform the authentication for you (such as that provided by the golang.org/x/oauth2 library).

func (*Client) Do

func (c *Client) Do(ctx context.Context, req *http.Request, isUsingPlainHttpClient bool, target interface{}) error

Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed to by target, or returned as an error if an API error has occurred.

func (*Client) NewFileUploadRequest

func (c *Client) NewFileUploadRequest(relativeURL string, contentType string, fileReader *bytes.Reader) (*http.Request, error)

NewFileUploadRequest creates an API request to upload files. A relative URL can be provided in relativeURL, in which case it is resolved relative to the BaseURL of the Client. Relative URLs should always be specified WITHOUT a preceding slash.

func (*Client) NewLargeFileUploadRequest added in v1.1.3

func (c *Client) NewLargeFileUploadRequest(URL string, fileSize, contentLength, startIndex, endIndex int, data *bytes.Buffer) (*http.Request, error)

func (*Client) NewRequest

func (c *Client) NewRequest(method, relativeURL string, body interface{}) (*http.Request, error)

NewRequest creates an API request. A relative URL can be provided in relativeURL, in which case it is resolved relative to the BaseURL of the Client. Relative URLs should always be specified WITHOUT a preceding slash.

func (*Client) NewRequestToOneDrive

func (c *Client) NewRequestToOneDrive(method, absoluteUrl string, body interface{}) (*http.Request, error)

NewRequest creates an API request to OneDrive API directly with an absolute URL.

type CopyItemRequest

type CopyItemRequest struct {
	Name         string          `json:"name"`
	ParentFolder ParentReference `json:"parentReference"`
}

CopyItemRequest represents the information needed of copying an item in OneDrive.

type CopyItemResponse

type CopyItemResponse struct {
	Location string `json:"location"`
}

CopyItemResponse represents the JSON object returned by the OneDrive API after copying an item.

type CreateShareLinkRequest

type CreateShareLinkRequest struct {
	Type  string `json:"type"`  // The type of sharing link to create. Either view, edit, or embed.
	Scope string `json:"scope"` // Optional. The scope of link to create. Either anonymous or organization.
}

CreateShareLinkRequest is the request for creating a share link.

type CreateUploadSessionItem added in v1.1.3

type CreateUploadSessionItem struct {
	ConflictBehavior string `json:"@microsoft.graph.conflictBehavior"`
}

type CreateUploadSessionRequest added in v1.1.3

type CreateUploadSessionRequest struct {
	Item CreateUploadSessionItem `json:"item"`
}

type CreateUploadSessionResponse added in v1.1.3

type CreateUploadSessionResponse struct {
	UploadUrl          string `json:"uploadUrl"`
	ExpirationDateTime string `json:"expirationDateTime"`
}

type Drive

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

Drive represents a OneDrive drive.

type DriveAsyncJobService

type DriveAsyncJobService service

DriveAsyncJobService handles communication with the drive items searching related methods of the OneDrive API.

OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/concepts/long-running-actions?view=odsp-graph-online

type DriveItem

type DriveItem struct {
	Name        string           `json:"name"`
	Id          string           `json:"id"`
	DownloadURL string           `json:"@microsoft.graph.downloadUrl"`
	Description string           `json:"description"`
	WebURL      string           `json:"webUrl"`
	Audio       *OneDriveAudio   `json:"audio"`
	Video       *OneDriveVideo   `json:"video"`
	Image       *OneDriveImage   `json:"image"`
	Photo       *OneDrivePhoto   `json:"photo"`
	File        *DriveItemFile   `json:"file"`
	Folder      *DriveItemFolder `json:"folder"`
}

DriveItem represents a OneDrive drive item. Ref https://docs.microsoft.com/en-us/graph/api/resources/driveitem?view=graph-rest-1.0

type DriveItemFile

type DriveItemFile struct {
	MIMEType string `json:"mimeType"`
}

DriveItemFile represents a OneDrive drive item file info.

type DriveItemFolder

type DriveItemFolder struct {
	ChildCount int32 `json:"childCount"`
}

DriveItemFolder represents a OneDrive drive item folder info.

type DriveItemsService

type DriveItemsService service

DriveItemsService handles communication with the drive items related methods of the OneDrive API.

OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/resources/driveitem?view=odsp-graph-online

func (*DriveItemsService) Copy

func (s *DriveItemsService) Copy(ctx context.Context, sourceDriveId string, itemId string,
	destinationDriveId string, destinationFolderId string, newItemName string) (*CopyItemResponse, error)

Copy a drive item to a new parent item or with a new name in a drive of the authenticated user.

If sourceDriveId or destinationDriveId is empty, it means the selected drive will be the default drive of the authenticated user.

OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_copy?view=odsp-graph-online

func (*DriveItemsService) CreateNewFolder

func (s *DriveItemsService) CreateNewFolder(ctx context.Context, driveId string, parentFolderName string, folderName string) (*DriveItem, error)

Create a new folder in a drive of the authenticated user. If there is already a folder in the same OneDrive directory with the same name, OneDrive will choose a new name for the folder while creating it.

If driveId is empty, it means the selected drive will be the default drive of the authenticated user.

If parentFolderName is empty, it means the new folder will be created at the root of the default drive.

OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_post_children?view=odsp-graph-online

func (*DriveItemsService) Delete

func (s *DriveItemsService) Delete(ctx context.Context, driveId string, itemId string) (*DriveItem, error)

Delete a drive item in a drive of the authenticated user. The deleted item will be moved to the Recycle Bin instead of getting permanently deleted.

If driveId is empty, it means the selected drive will be the default drive of the authenticated user.

OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_delete?view=odsp-graph-online

func (*DriveItemsService) Get

func (s *DriveItemsService) Get(ctx context.Context, itemId string) (*DriveItem, error)

Get an item in the default drive of the authenticated user.

OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_get?view=odsp-graph-online

func (*DriveItemsService) GetSpecial

func (s *DriveItemsService) GetSpecial(ctx context.Context, folderName DriveSpecialFolder) (*DriveItem, error)

Get an item from special folder in the default drive of the authenticated user.

OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/drive_get_specialfolder?view=odsp-graph-online

func (*DriveItemsService) List

List the items of a folder in the default drive of the authenticated user.

OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/resources/driveitem?view=odsp-graph-online

func (*DriveItemsService) ListSpecial

List the items of a special folder in the default drive of the authenticated user.

OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/drive_get_specialfolder?view=odsp-graph-online#get-children-of-a-special-folder

func (*DriveItemsService) Move

func (s *DriveItemsService) Move(ctx context.Context, driveId string, itemId string, destinationParentFolderId string) (*MoveItemResponse, error)

Move a drive item to a new parent folder in a drive of the authenticated user.

When moving an item to the root of a drive, for example, we cannot use "root" as the destinationParentFolderId. Instead, we need to provide the actual ID of the root.

If driveId is empty, it means the selected drive will be the default drive of the authenticated user.

OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_move?view=odsp-graph-online

func (*DriveItemsService) Rename

func (s *DriveItemsService) Rename(ctx context.Context, driveId string, itemId string, newItemName string) (*RenameItemResponse, error)

Rename a drive item in a drive of the authenticated user.

If driveId is empty, it means the selected drive will be the default drive of the authenticated user.

OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_update?view=odsp-graph-online

func (*DriveItemsService) UploadLargeFile added in v1.1.3

func (s *DriveItemsService) UploadLargeFile(ctx context.Context, driveId string, destinationParentFolderId string, localFilePath string) (*MoveItemResponse, error)

func (*DriveItemsService) UploadNewFile

func (s *DriveItemsService) UploadNewFile(ctx context.Context, driveId string, destinationParentFolderId string, localFilePath string) (*DriveItem, error)

UploadNewFile is to upload a file to a drive of the authenticated user.

By default, this API will upload and then rename an item if there is an existing item with the same name on OneDrive.

If driveId is empty, it means the selected drive will be the default drive of the authenticated user.

OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_put_content?view=odsp-graph-online#http-request-to-upload-a-new-file

func (*DriveItemsService) UploadToReplaceFile

func (s *DriveItemsService) UploadToReplaceFile(ctx context.Context, driveId string, localFilePath string, itemId string) (*DriveItem, error)

UploadToReplaceFile is to upload a file to replace an existing file in a drive of the authenticated user.

If driveId is empty, it means the selected drive will be the default drive of the authenticated user.

OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_put_content?view=odsp-graph-online#http-request-to-replace-an-existing-item

type DriveQuota

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

DriveQuota represents the usage quota of a drive.

type DriveSearchService

type DriveSearchService service

DriveSearchService handles communication with the drive items searching related methods of the OneDrive API.

OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_search?view=odsp-graph-online

func (*DriveSearchService) Search

Search the items in the default drive of the authenticated user.

OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_search?view=odsp-graph-online#request

func (*DriveSearchService) SearchAll

Search the items in the default drive of the authenticated user as well as items shared with the user.

OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_search?view=odsp-graph-online#searching-for-items-a-user-can-access

func (*DriveSearchService) SearchWithParent

func (s *DriveSearchService) SearchWithParent(ctx context.Context, parent string, query string) (*OneDriveDriveSearchResponse, error)

type DriveSpecialFolder

type DriveSpecialFolder int

DriveSpecialFolder indicates the pre-defined special folder in OneDrive

OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/drive_get_specialfolder?view=odsp-graph-online#special-folder-names

const (
	Documents DriveSpecialFolder = iota
	Photos
	CameraRoll
	AppRoot
	Music
)

type DrivesService

type DrivesService service

DrivesService handles communication with the drives related methods of the OneDrive API.

OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/resources/drive?view=odsp-graph-online

func (*DrivesService) Get

func (s *DrivesService) Get(ctx context.Context, driveId string) (*Drive, error)

Get a specified drive of the authenticated user.

If driveId is empty, it means the selected drive will be the default drive of the authenticated user.

OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/drive_get?view=odsp-graph-online

func (*DrivesService) List

List all the drives of the authenticated user.

OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/drive_list?view=odsp-graph-online

type Error

type Error struct {
	Code             string      `json:"code"`
	Message          string      `json:"message"`
	LocalizedMessage string      `json:"localizedMessage"`
	InnerError       *InnerError `json:"innerError"`
}

Error represents the error in the response returned by OneDrive drive API.

type ErrorResponse

type ErrorResponse struct {
	Error *Error `json:"error"`
}

ErrorResponse represents the error response returned by OneDrive drive API.

type Facet

type Facet struct {
}

Facet represents one of the facets for a folder or file.

type InnerError

type InnerError struct {
	Date            string `json:"date"`
	RequestId       string `json:"request-id"`
	ClientRequestId string `json:"client-request-id"`
}

InnerError represents the error details in the error returned by OneDrive drive API.

type ListPermissionsResponse

type ListPermissionsResponse struct {
	Value []Permission `json:"value"`
}

ListPermissionsResponse is the response of list permissions of a drive item

type MoveItemRequest

type MoveItemRequest struct {
	ParentFolder ParentReference `json:"parentReference"`
}

MoveItemRequest represents the information needed of moving an item in OneDrive.

type MoveItemResponse

type MoveItemResponse struct {
	Id           string          `json:"id"`
	Name         string          `json:"name"`
	ParentFolder ParentReference `json:"parentReference"`
}

MoveItemResponse represents the JSON object returned by the OneDrive API after moving an item.

type NewFolderCreationRequest

type NewFolderCreationRequest struct {
	FolderName       string `json:"name"`
	FolderFacet      Facet  `json:"folder"`
	ConflictBehavior string `json:"@microsoft.graph.conflictBehavior"`
}

NewFolderCreationRequest represents the information needed of a new OneDrive folder to be created.

type OneDriveAsyncJobMonitorResponse

type OneDriveAsyncJobMonitorResponse struct {
	ErrorCode           string  `json:"errorCode"`
	ResourceId          string  `json:"resourceId"`
	Operation           string  `json:"operation"`
	Status              string  `json:"status"`
	StatusDescription   string  `json:"statusDescription"`
	PercentageCompleted float64 `json:"percentageCompleted"`
}

OneDriveAsyncJobMonitorResponse represents the JSON object returned by the OneDrive Async Job Monitoring API.

type OneDriveAudio

type OneDriveAudio struct {
	Title       string `json:"title"`
	Album       string `json:"album"`
	AlbumArtist string `json:"albumArtist"`
	Duration    int    `json:"duration"`
}

OneDriveAudio represents the audio metadata of a OneDrive drive item which is an audio.

type OneDriveDriveItemsResponse

type OneDriveDriveItemsResponse struct {
	ODataContext string       `json:"@odata.context"`
	Count        int          `json:"@odata.count"`
	DriveItems   []*DriveItem `json:"value"`
}

OneDriveDriveItemsResponse represents the JSON object returned by the OneDrive API.

type OneDriveDriveSearchResponse

type OneDriveDriveSearchResponse struct {
	ODataContext string       `json:"@odata.context"`
	DriveItems   []*DriveItem `json:"value"`
}

OneDriveDriveSearchResponse represents the JSON object returned by the OneDrive API.

type OneDriveDrivesResponse

type OneDriveDrivesResponse struct {
	ODataContext string   `json:"@odata.context"`
	Drives       []*Drive `json:"value"`
}

OneDriveDrivesResponse represents the JSON object containing drive list returned by the OneDrive API.

type OneDriveFileSystemInfo added in v1.1.3

type OneDriveFileSystemInfo struct {
	CreatedDateTime      int64 `json:"createdDateTime"`
	LastAccessedDateTime int64 `json:"lastAccessedDateTime"`
	LastModifiedDateTime int64 `json:"lastModifiedDateTime"`
}

type OneDriveImage

type OneDriveImage struct {
	Height float64 `json:"height"`
	Width  float64 `json:"width"`
}

OneDriveAudio represents the image metadata of a OneDrive drive item which is an image.

type OneDrivePhoto

type OneDrivePhoto struct {
	CameraMake  string `json:"cameraMake"`
	CameraModel string `json:"cameraModel"`
}

OneDrivePhoto represents the photo metadata of a OneDrive drive item which is a photo. Ref https://docs.microsoft.com/en-us/graph/api/resources/photo?view=graph-rest-1.0

type OneDriveVideo

type OneDriveVideo struct {
	Duration int     `json:"duration"`
	Height   float64 `json:"height"`
	Width    float64 `json:"width"`
}

OneDriveVideo represents the video metadata of a OneDrive drive item. Ref: https://docs.microsoft.com/en-us/graph/api/resources/video?view=graph-rest-1.0

type Owner

type Owner struct {
	User User `json:"user"`
}

Owner represents the owner of a OneDrive drive.

type ParentReference

type ParentReference struct {
	Id      string `json:"id"`
	Path    string `json:"path"`
	DriveId string `json:"driveId"`
}

ParentReference represents the information of a folder in OneDrive.

type Permission

type Permission struct {
	ID        string      `json:"id"`
	GrantedTo interface{} `json:"grantedTo"`
	Link      SharingLink `json:"link"`
	Roles     []string    `json:"roles"`
}

Permission is the permission of a drive item.

type PermissionService

type PermissionService service

PermissionService handles permission settings of a drive item

OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/resources/permission?view=odsp-graph-online

func (s *PermissionService) CreateShareLink(ctx context.Context, itemId string, permissionType ShareLinkType, permissionScope ShareLinkScope) (*Permission, error)

CreateShareLink will create a new sharing link if the specified link type doesn't already exist for the calling application. If a sharing link of the specified type already exists for the app, the existing sharing link will be returned.

OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_createlink?view=odsp-graph-online

func (*PermissionService) List

func (s *PermissionService) List(ctx context.Context, itemId string) ([]Permission, error)

List lists the effective sharing permissions of on a DriveItem.

OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_list_permissions?view=odsp-graph-online

type RenameItemRequest

type RenameItemRequest struct {
	Name string `json:"name"`
}

RenameItemRequest represents the information needed of renaming an item in OneDrive.

type RenameItemResponse

type RenameItemResponse struct {
	Id   string `json:"id"`
	Name string `json:"name"`
	File Facet  `json:"file"`
}

RenameItemResponse represents the JSON object returned by the OneDrive API after renaming an item.

type ShareLinkScope

type ShareLinkScope int

ShareLinkType the possible values for the scope property of SharingLink

OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/resources/sharinglink?view=odsp-graph-online#scope-options

const (
	Anonymous ShareLinkScope = iota
	Organization
)

type ShareLinkType

type ShareLinkType int

ShareLinkType the possible values for the type property of SharingLink

OneDrive API docs: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/resources/sharinglink?view=odsp-graph-online#type-options

const (
	View ShareLinkType = iota
	Edit
	Embed
)
type SharingLink struct {
	Type  string `json:"type"`  // The type of sharing link to create. Either view, edit, or embed.
	Scope string `json:"scope"` // Optional. The scope of link to create. Either anonymous or organization.
	URL   string `json:"webUrl"`
}

SharingLink resource groups link-related data items into a single structure. Ref: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/resources/sharinglink?view=odsp-graph-online

type UploadLargeFileResponse added in v1.1.3

type UploadLargeFileResponse struct {
	ExpirationDateTime string   `json:"expirationDateTime"`
	NextExpectedRanges []string `json:"nextExpectedRanges"`
}

type UploadLargeFileSuccessResponse added in v1.1.3

type UploadLargeFileSuccessResponse struct {
	Id   string `json:"id"`
	Name string `json:"name"`
	Size int    `json:"size"`
}

type User

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

User represents an user in Microsoft Live.

Jump to

Keyboard shortcuts

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