src

package
v0.0.0-...-1b1593a Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2017 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const RootAddr = "https://cloud-api.yandex.com" //also https://cloud-api.yandex.net and https://cloud-api.yandex.ru

RootAddr is the base URL for Yandex Disk API.

Variables

This section is empty.

Functions

func CheckAPIError

func CheckAPIError(resp *http.Response) (err error)

CheckAPIError is a convenient function to turn erroneous API response into go error. It closes the Body on error.

func CheckClose

func CheckClose(c io.Closer, err *error)

CheckClose is a utility function used to check the return from Close in a defer statement.

Types

type Client

type Client struct {
	HTTPClient *http.Client
	// contains filtered or unexported fields
}

Client struct

func NewClient

func NewClient(token string, client ...*http.Client) *Client

NewClient creates new client

func (*Client) Delete

func (c *Client) Delete(remotePath string, permanently bool) error

Delete will remove specified file/folder from Yandex Disk

func (*Client) Download

func (c *Client) Download(remotePath string, headers map[string]string) (io.ReadCloser, error)

Download will get specified data from Yandex.Disk supplying the extra headers

func (*Client) DownloadRequest

func (c *Client) DownloadRequest(remotePath string) (ur *DownloadResponse, err error)

DownloadRequest will make an download request and return a URL to download data to.

func (*Client) EmptyTrash

func (c *Client) EmptyTrash() error

EmptyTrash will permanently delete all trashed files/folders from Yandex Disk

func (*Client) Mkdir

func (c *Client) Mkdir(remotePath string) (int, string, error)

Mkdir will make specified folder on Yandex Disk

func (*Client) NewDiskInfoRequest

func (c *Client) NewDiskInfoRequest() *DiskInfoRequest

NewDiskInfoRequest create new DiskInfo Request

func (*Client) NewFlatFileListRequest

func (c *Client) NewFlatFileListRequest(options ...FlatFileListRequestOptions) *FlatFileListRequest

NewFlatFileListRequest create new FlatFileList Request

func (*Client) NewLastUploadedResourceListRequest

func (c *Client) NewLastUploadedResourceListRequest(options ...LastUploadedResourceListRequestOptions) *LastUploadedResourceListRequest

NewLastUploadedResourceListRequest create new LastUploadedResourceList Request

func (*Client) NewResourceInfoRequest

func (c *Client) NewResourceInfoRequest(path string, options ...ResourceInfoRequestOptions) *ResourceInfoRequest

NewResourceInfoRequest create new ResourceInfo Request

func (*Client) NewTrashResourceInfoRequest

func (c *Client) NewTrashResourceInfoRequest(path string, options ...ResourceInfoRequestOptions) *TrashResourceInfoRequest

NewTrashResourceInfoRequest create new TrashResourceInfo Request

func (*Client) ParseAPIError

func (c *Client) ParseAPIError(jsonErr string) (string, error)

ParseAPIError Parse json error response from API

func (*Client) PerformDelete

func (c *Client) PerformDelete(url string) error

PerformDelete does the actual delete via DELETE request.

func (*Client) PerformDownload

func (c *Client) PerformDownload(url string, headers map[string]string) (out io.ReadCloser, err error)

PerformDownload does the actual download via unscoped GET request.

func (*Client) PerformMkdir

func (c *Client) PerformMkdir(url string) (int, string, error)

PerformMkdir does the actual mkdir via PUT request.

func (*Client) PerformUpload

func (c *Client) PerformUpload(url string, data io.Reader, contentType string) (err error)

PerformUpload does the actual upload via unscoped PUT request.

func (*Client) SetCustomProperty

func (c *Client) SetCustomProperty(remotePath string, property string, value string) error

SetCustomProperty will set specified data from Yandex Disk

func (*Client) SetCustomPropertyRequest

func (c *Client) SetCustomPropertyRequest(remotePath string, body io.Reader) (err error)

SetCustomPropertyRequest will make an CustomProperty request and return a URL to CustomProperty data to.

func (*Client) Upload

func (c *Client) Upload(data io.Reader, remotePath string, overwrite bool, contentType string) error

Upload will put specified data to Yandex.Disk.

func (*Client) UploadRequest

func (c *Client) UploadRequest(remotePath string, overwrite bool) (ur *UploadResponse, err error)

UploadRequest will make an upload request and return a URL to upload data to.

type CustomPropertyResponse

type CustomPropertyResponse struct {
	CustomProperties map[string]interface{} `json:"custom_properties"`
}

CustomPropertyResponse struct we send and is returned by the API for CustomProperty request.

type DiskClientError

type DiskClientError struct {
	Description string `json:"Description"`
	Code        string `json:"Error"`
}

DiskClientError struct

func (DiskClientError) Error

func (e DiskClientError) Error() string

type DiskInfoRequest

type DiskInfoRequest struct {
	HTTPRequest *HTTPRequest
	// contains filtered or unexported fields
}

DiskInfoRequest type

func (*DiskInfoRequest) Exec

func (req *DiskInfoRequest) Exec() (*DiskInfoResponse, error)

Exec run DiskInfo Request

type DiskInfoResponse

type DiskInfoResponse struct {
	TrashSize     uint64            `json:"TrashSize"`
	TotalSpace    uint64            `json:"TotalSpace"`
	UsedSpace     uint64            `json:"UsedSpace"`
	SystemFolders map[string]string `json:"SystemFolders"`
}

DiskInfoResponse struct is returned by the API for DiskInfo request.

type DownloadResponse

type DownloadResponse struct {
	HRef      string `json:"href"`
	Method    string `json:"method"`
	Templated bool   `json:"templated"`
}

DownloadResponse struct is returned by the API for Download request.

func ParseDownloadResponse

func ParseDownloadResponse(data io.Reader) (*DownloadResponse, error)

ParseDownloadResponse tries to read and parse DownloadResponse struct.

type ErrorHandler

type ErrorHandler func(*http.Response) error

ErrorHandler type

type ErrorResponse

type ErrorResponse struct {
	ErrorName   string `json:"error"`
	Description string `json:"description"`
	Message     string `json:"message"`

	StatusCode int `json:""`
}

ErrorResponse represents erroneous API response. Implements go's built in `error`.

func ProccessErrorResponse

func ProccessErrorResponse(data io.Reader) (*ErrorResponse, error)

ProccessErrorResponse tries to represent data passed as an ErrorResponse object.

func ProccessErrorString

func ProccessErrorString(data string) (*ErrorResponse, error)

ProccessErrorString tries to represent data passed as an ErrorResponse object.

func (*ErrorResponse) Error

func (e *ErrorResponse) Error() string

type FilesResourceListResponse

type FilesResourceListResponse struct {
	Items  []ResourceInfoResponse `json:"items"`
	Limit  *uint64                `json:"limit"`
	Offset *uint64                `json:"offset"`
}

FilesResourceListResponse struct is returned by the API for requests.

type FlatFileListRequest

type FlatFileListRequest struct {
	HTTPRequest *HTTPRequest
	// contains filtered or unexported fields
}

FlatFileListRequest struct client for FlatFileList Request

func (*FlatFileListRequest) Exec

Exec run FlatFileList Request

func (*FlatFileListRequest) Request

func (req *FlatFileListRequest) Request() *HTTPRequest

Request get request

type FlatFileListRequestOptions

type FlatFileListRequestOptions struct {
	MediaType   []MediaType
	Limit       *uint32
	Offset      *uint32
	Fields      []string
	PreviewSize *PreviewSize
	PreviewCrop *bool
}

FlatFileListRequestOptions struct - options for request

type HTTPRequest

type HTTPRequest struct {
	Method     string
	Path       string
	Parameters map[string]interface{}
	Headers    map[string][]string
}

HTTPRequest struct

type LastUploadedResourceListRequest

type LastUploadedResourceListRequest struct {
	HTTPRequest *HTTPRequest
	// contains filtered or unexported fields
}

LastUploadedResourceListRequest struct

func (*LastUploadedResourceListRequest) Exec

Exec run LastUploadedResourceList Request

func (*LastUploadedResourceListRequest) Request

Request return request

type LastUploadedResourceListRequestOptions

type LastUploadedResourceListRequestOptions struct {
	MediaType   []MediaType
	Limit       *uint32
	Fields      []string
	PreviewSize *PreviewSize
	PreviewCrop *bool
}

LastUploadedResourceListRequestOptions struct

type LastUploadedResourceListResponse

type LastUploadedResourceListResponse struct {
	Items []ResourceInfoResponse `json:"items"`
	Limit *uint64                `json:"limit"`
}

LastUploadedResourceListResponse struct

type MediaType

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

MediaType struct - media types

func (*MediaType) Audio

func (m *MediaType) Audio() *MediaType

Audio - media type

func (*MediaType) Backup

func (m *MediaType) Backup() *MediaType

Backup - media type

func (*MediaType) Book

func (m *MediaType) Book() *MediaType

Book - media type

func (*MediaType) Compressed

func (m *MediaType) Compressed() *MediaType

Compressed - media type

func (*MediaType) Data

func (m *MediaType) Data() *MediaType

Data - media type

func (*MediaType) Development

func (m *MediaType) Development() *MediaType

Development - media type

func (*MediaType) Diskimage

func (m *MediaType) Diskimage() *MediaType

Diskimage - media type

func (*MediaType) Document

func (m *MediaType) Document() *MediaType

Document - media type

func (*MediaType) Encoded

func (m *MediaType) Encoded() *MediaType

Encoded - media type

func (*MediaType) Executable

func (m *MediaType) Executable() *MediaType

Executable - media type

func (*MediaType) Flash

func (m *MediaType) Flash() *MediaType

Flash - media type

func (*MediaType) Font

func (m *MediaType) Font() *MediaType

Font - media type

func (*MediaType) Image

func (m *MediaType) Image() *MediaType

Image - media type

func (*MediaType) Settings

func (m *MediaType) Settings() *MediaType

Settings - media type

func (*MediaType) Spreadsheet

func (m *MediaType) Spreadsheet() *MediaType

Spreadsheet - media type

func (*MediaType) String

func (m *MediaType) String() string

String - media type

func (*MediaType) Text

func (m *MediaType) Text() *MediaType

Text - media type

func (*MediaType) Unknown

func (m *MediaType) Unknown() *MediaType

Unknown - media type

func (*MediaType) Video

func (m *MediaType) Video() *MediaType

Video - media type

func (*MediaType) Web

func (m *MediaType) Web() *MediaType

Web - media type

type PreviewSize

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

PreviewSize struct

func (*PreviewSize) ExactHeight

func (s *PreviewSize) ExactHeight(height uint32) *PreviewSize

ExactHeight - set preview size

func (*PreviewSize) ExactSize

func (s *PreviewSize) ExactSize(width uint32, height uint32) *PreviewSize

ExactSize - set preview size

func (*PreviewSize) ExactWidth

func (s *PreviewSize) ExactWidth(width uint32) *PreviewSize

ExactWidth - set preview size

func (*PreviewSize) PredefinedSizeL

func (s *PreviewSize) PredefinedSizeL() *PreviewSize

PredefinedSizeL - set preview size

func (*PreviewSize) PredefinedSizeM

func (s *PreviewSize) PredefinedSizeM() *PreviewSize

PredefinedSizeM - set preview size

func (*PreviewSize) PredefinedSizeS

func (s *PreviewSize) PredefinedSizeS() *PreviewSize

PredefinedSizeS - set preview size

func (*PreviewSize) PredefinedSizeXL

func (s *PreviewSize) PredefinedSizeXL() *PreviewSize

PredefinedSizeXL - set preview size

func (*PreviewSize) PredefinedSizeXXL

func (s *PreviewSize) PredefinedSizeXXL() *PreviewSize

PredefinedSizeXXL - set preview size

func (*PreviewSize) PredefinedSizeXXXL

func (s *PreviewSize) PredefinedSizeXXXL() *PreviewSize

PredefinedSizeXXXL - set preview size

func (*PreviewSize) String

func (s *PreviewSize) String() string

type ResourceInfoRequest

type ResourceInfoRequest struct {
	HTTPRequest *HTTPRequest
	// contains filtered or unexported fields
}

ResourceInfoRequest struct

func (*ResourceInfoRequest) Exec

Exec run ResourceInfo Request

func (*ResourceInfoRequest) Request

func (req *ResourceInfoRequest) Request() *HTTPRequest

Request of ResourceInfoRequest

type ResourceInfoRequestOptions

type ResourceInfoRequestOptions struct {
	SortMode    *SortMode
	Limit       *uint32
	Offset      *uint32
	Fields      []string
	PreviewSize *PreviewSize
	PreviewCrop *bool
}

ResourceInfoRequestOptions struct

type ResourceInfoResponse

type ResourceInfoResponse struct {
	PublicKey        string                 `json:"public_key"`
	Name             string                 `json:"name"`
	Created          string                 `json:"created"`
	CustomProperties map[string]interface{} `json:"custom_properties"`
	Preview          string                 `json:"preview"`
	PublicURL        string                 `json:"public_url"`
	OriginPath       string                 `json:"origin_path"`
	Modified         string                 `json:"modified"`
	Path             string                 `json:"path"`
	Md5              string                 `json:"md5"`
	ResourceType     string                 `json:"type"`
	MimeType         string                 `json:"mime_type"`
	Size             uint64                 `json:"size"`
	Embedded         *ResourceListResponse  `json:"_embedded"`
}

ResourceInfoResponse struct is returned by the API for metedata requests.

type ResourceListResponse

type ResourceListResponse struct {
	Sort      *SortMode              `json:"sort"`
	PublicKey string                 `json:"public_key"`
	Items     []ResourceInfoResponse `json:"items"`
	Path      string                 `json:"path"`
	Limit     *uint64                `json:"limit"`
	Offset    *uint64                `json:"offset"`
	Total     *uint64                `json:"total"`
}

ResourceListResponse struct

type SortMode

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

SortMode struct - sort mode

func (*SortMode) ByCreated

func (m *SortMode) ByCreated() *SortMode

ByCreated - sort mode

func (*SortMode) ByModified

func (m *SortMode) ByModified() *SortMode

ByModified - sort mode

func (*SortMode) ByName

func (m *SortMode) ByName() *SortMode

ByName - sort mode

func (*SortMode) ByPath

func (m *SortMode) ByPath() *SortMode

ByPath - sort mode

func (*SortMode) BySize

func (m *SortMode) BySize() *SortMode

BySize - sort mode

func (*SortMode) Default

func (m *SortMode) Default() *SortMode

Default - sort mode

func (*SortMode) Reverse

func (m *SortMode) Reverse() *SortMode

Reverse - sort mode

func (*SortMode) String

func (m *SortMode) String() string

func (*SortMode) UnmarshalJSON

func (m *SortMode) UnmarshalJSON(value []byte) error

UnmarshalJSON sort mode

type TrashResourceInfoRequest

type TrashResourceInfoRequest struct {
	HTTPRequest *HTTPRequest
	// contains filtered or unexported fields
}

TrashResourceInfoRequest struct

func (*TrashResourceInfoRequest) Exec

Exec run TrashResourceInfo Request

func (*TrashResourceInfoRequest) Request

func (req *TrashResourceInfoRequest) Request() *HTTPRequest

Request of TrashResourceInfoRequest struct

type UploadResponse

type UploadResponse struct {
	HRef      string `json:"href"`
	Method    string `json:"method"`
	Templated bool   `json:"templated"`
}

UploadResponse struct is returned by the API for upload request.

func ParseUploadResponse

func ParseUploadResponse(data io.Reader) (*UploadResponse, error)

ParseUploadResponse tries to read and parse UploadResponse struct.

Jump to

Keyboard shortcuts

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