disk

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2022 License: MIT Imports: 11 Imported by: 0

README

disk

Yandex.Disk API client | REST API

GitHub GitHub code size in bytes Coverage Status GitHub pull requests

Install

go get github.com/ilyabrin/disk

Using

package main

import (
  "context"
  "log"

  "github.com/ilyabrin/disk"
)

func main() {
  ctx := context.Background()

  client := disk.New("YOUR_ACCESS_TOKEN")

  disk, errorResponse := client.Disk.Info(ctx, nil)
  if errorResponse != nil {
    log.Fatal(errorResponse)
  }

  log.Println(disk)
}

Available methods

Full documentation available here

Disk
// Disk information
client.Disk.Info()
Resources
// Remove resource
client.Resources.Delete(ctx, "path_to_file", false, nil)

// Get meta information
client.Resources.Meta(ctx, "path_to_file", nil)

// Update meta information
newMeta := &disk.Metadata{
  "custom_properties": {
    "key": "value",
    "foo": "bar",
    "platform": "linux",
  },
}
client.Resources.UpdateMeta(ctx, "path_to_file", newMeta)

// Create directory
client.Resources.CreateDir(ctx, "path_to_file", nil)

// Copy resource
client.Resources.Copy(ctx, "path_to_file", "copy_here", nil)

// Get download link for resource
client.Resources.DownloadURL(ctx, "name_for_uploaded_file", nil)

// Get list of sorted files
client.Resources.GetSortedFiles(ctx, nil)

// List of last uploaded files
client.Resources.ListLastUploaded(ctx, nil)

// Move resource or rename it
client.Resources.Move(ctx, "path_to_file", "move_here", nil)

// List all public links
client.Resources.ListPublic(ctx, nil)

// Publish resource
client.Resources.Publish(ctx, "path_to_file", nil)

// Unpublish resource
client.Resources.Unpublish(ctx, "path_to_file", nil)

// Get link for ipload new file to Disk
client.Resources.GetUploadLink(ctx, "path_to_file")

// Upload new file to Disk
client.Resources.Upload(ctx, "local_file_path", "link_from_GetUploadLink", nil)

// Upload file from Internet
client.Resources.UploadFromURL(ctx, "filename_you_want", "url_to_file", nil)
Public
// Get metadata for public resource
client.Public.Meta(ctx, "full_url_to_file", nil)

// Get link for download public resource
client.Public.DownloadURL(ctx, "full_url_to_file", nil)

// Save public file to Disk
client.Public.Save(ctx, "full_url_to_file", nil)
Trash
// Delete file from trash
client.Trash.Delete(ctx, "path_to_file", nil)

// Restore file from trash
client.Trash.Restore(ctx, "path_to_file", nil)

// List all resources OR all about resource in Trash
client.Trash.List(ctx, "/", nil)
Operations
// Get operation status
client.Operations.Status(ctx, "operation_id_string", nil)

License

Licensed under the MIT License, Copyright © 2020-present Ilya Brin

Documentation

Index

Constants

View Source
const API_URL = "https://cloud-api.yandex.net/v1/disk/"

Variables

This section is empty.

Functions

func InArray

func InArray[T comparable](el T, a []T) bool

Types

type Client

type Client struct {
	HTTPClient *http.Client

	Disk      *DiskService
	Trash     *TrashService
	Public    *PublicService
	Resources *ResourceService
	Operation *OperationService
	// contains filtered or unexported fields
}

func New

func New(token string) *Client

func (*Client) ApiURL

func (c *Client) ApiURL() string

func (*Client) ReqURL

func (c *Client) ReqURL() string

type CommentIds

type CommentIds struct {
	PrivateResource string `json:"private_resource,omitempty"`
	PublicResource  string `json:"public_resource,omitempty"`
}

CommentIds ...

type Disk

type Disk struct {
	MaxFileSize                int            `json:"max_file_size,omitempty"`
	PaidMaxFileSize            int            `json:"paid_max_file_size,omitempty"`
	TotalSpace                 int            `json:"total_space,omitempty"`
	TrashSize                  int            `json:"trash_size,omitempty"`
	IsPaid                     bool           `json:"is_paid,omitempty"`
	UsedSpace                  int            `json:"used_space,omitempty"`
	SystemFolders              *SystemFolders `json:"system_folders,omitempty"`
	User                       *User          `json:"user,omitempty"`
	UnlimitedAutouploadEnabled bool           `json:"unlimited_autoupload_enabled,omitempty"`
	Revision                   int            `json:"revision,omitempty"`
}

Disk Данные о свободном и занятом пространстве на Диске

type DiskService

type DiskService service

func (*DiskService) Info

func (s *DiskService) Info(ctx context.Context, params *QueryParams) (*Disk, *ErrorResponse)

type ErrorResponse

type ErrorResponse struct {
	Message     string `json:"message"`
	Description string `json:"description"`
	StatusCode  int    `json:"status_code"`
	Error       error  `json:"error"` // TODO: []errors
}

ErrorResponse ...

type Exif

type Exif struct {
	DateTime  string  `json:"date_time,omitempty"`
	Longitude float64 `json:"gps_longitude,omitempty"`
	Latitude  float64 `json:"gps_latitude,omitempty"`
}

Exif ...

type FilesResourceList

type FilesResourceList struct {
	Items  []*Resource `json:"items"`
	Limit  int         `json:"limit,omitempty"`
	Offset int         `json:"offset,omitempty"`
}

FilesResourceList ...

type HTTPHeaders

type HTTPHeaders map[string]string

type LastUploadedResourceList

type LastUploadedResourceList struct {
	Items []*Resource `json:"items"`
	Limit int         `json:"limit,omitempty"`
}

LastUploadedResourceList ...

type Link struct {
	Href      string `json:"href"`
	Method    string `json:"method"`
	Templated bool   `json:"templated,omitempty"`
}

Link ...

type Metadata

type Metadata map[string]map[string]string

Metadata is a type for a CustomProperties filed TODO: rename to CustomProperty ?

type Operation

type Operation struct {
	Status string `json:"status"`
}

Operation ...

type OperationService

type OperationService service

func (*OperationService) Status

func (s *OperationService) Status(ctx context.Context, operationID string, params *QueryParams) (*Operation, *ErrorResponse)

type PublicResource

type PublicResource struct {
	Resource
	Owner      *UserPublicInformation `json:"owner,omitempty"`
	ViewsCount int                    `json:"views_count,omitempty"`
}

PublicResource ...

type PublicResourcesList

type PublicResourcesList struct {
	Items  []*Resource `json:"items"`
	Type   string      `json:"type"`
	Limit  int         `json:"limit"`
	Offset int         `json:"offset"`
}

PublicResourcesList ...

type PublicService

type PublicService service

func (*PublicService) DownloadURL

func (s *PublicService) DownloadURL(ctx context.Context, public_key string, params *QueryParams) (*Link, *ErrorResponse)

func (*PublicService) Meta

func (s *PublicService) Meta(ctx context.Context, public_key string, params *QueryParams) (*PublicResource, *ErrorResponse)

func (*PublicService) Save

func (s *PublicService) Save(ctx context.Context, public_key string, params *QueryParams) (*Link, *ErrorResponse)

type QueryParams

type QueryParams map[string]string

type Resource

type Resource struct {
	AntivirusStatus  string            `json:"antivirus_status,omitempty"`
	ResourceID       string            `json:"resource_id,omitempty"`
	Share            *ShareInfo        `json:"share,omitempty"`
	File             string            `json:"file,omitempty"`
	Size             int               `json:"size,omitempty"`
	PhotosliceTime   string            `json:"photoslice_time,omitempty"`
	Embedded         *ResourceList     `json:"_embedded,omitempty"`
	Exif             *Exif             `json:"exif,omitempty"`
	CustomProperties map[string]string `json:"custom_properties,omitempty"`
	MediaType        string            `json:"media_type,omitempty"`
	Preview          string            `json:"preview,omitempty"`
	Type             string            `json:"type"`
	MimeType         string            `json:"mime_type,omitempty"`
	Revision         int               `json:"revision,omitempty"`
	PublicURL        string            `json:"public_url,omitempty"`
	Path             string            `json:"path"`
	Md5              string            `json:"md5,omitempty"`
	PublicKey        string            `json:"public_key,omitempty"`
	Sha256           string            `json:"sha256,omitempty"`
	Name             string            `json:"name"`
	Created          string            `json:"created"`  // TODO: time format
	Modified         string            `json:"modified"` // TODO: time format
	CommentIDs       *CommentIds       `json:"comment_ids,omitempty"`
}

Resource ...

type ResourceList

type ResourceList struct {
	Sort   string      `json:"sort,omitempty"`
	Items  []*Resource `json:"items"`
	Limit  int         `json:"limit,omitempty"`
	Offset int         `json:"offset,omitempty"`
	Path   string      `json:"path"`
	Total  int         `json:"total,omitempty"`
}

ResourceList ... Список ресурсов, содержащихся в папке. Содержит объекты Resource и свойства списка.

type ResourceService

type ResourceService service

func (*ResourceService) Copy

func (s *ResourceService) Copy(ctx context.Context, from, to string, params *QueryParams) (*Link, *ErrorResponse)

func (*ResourceService) CreateDir

func (s *ResourceService) CreateDir(ctx context.Context, path string, params *QueryParams) (*Link, *ErrorResponse)

CreateDir creates a new dorectory with 'path'(string) name todo: can't create nested dirs like newDir/subDir/anotherDir

func (*ResourceService) Delete

func (s *ResourceService) Delete(ctx context.Context, path string, permanent bool, params *QueryParams) *ErrorResponse

func (*ResourceService) DownloadURL

func (s *ResourceService) DownloadURL(ctx context.Context, path string, params *QueryParams) (*Link, *ErrorResponse)

func (*ResourceService) GetSortedFiles

func (s *ResourceService) GetSortedFiles(ctx context.Context, params *QueryParams) (*FilesResourceList, *ErrorResponse)

TODO: rename to ListFiles

func (s *ResourceService) GetUploadLink(ctx context.Context, path string) (*Link, *ErrorResponse)

func (*ResourceService) ListLastUploaded

func (s *ResourceService) ListLastUploaded(ctx context.Context, params *QueryParams) (*LastUploadedResourceList, *ErrorResponse)

get | sortBy = [name = default, uploadDate]

func (*ResourceService) ListPublic

func (*ResourceService) Meta

func (s *ResourceService) Meta(ctx context.Context, path string, params *QueryParams) (*Resource, *ErrorResponse)

func (*ResourceService) Move

func (s *ResourceService) Move(ctx context.Context, from, to string, params *QueryParams) (*Link, *ErrorResponse)

func (*ResourceService) Publish

func (s *ResourceService) Publish(ctx context.Context, path string, params *QueryParams) (*Link, *ErrorResponse)

func (*ResourceService) Unpublish

func (s *ResourceService) Unpublish(ctx context.Context, path string, params *QueryParams) (*Link, *ErrorResponse)

func (*ResourceService) UpdateMeta

func (s *ResourceService) UpdateMeta(ctx context.Context, path string, custom_properties *Metadata) (*Resource, *ErrorResponse)

func (*ResourceService) Upload

func (s *ResourceService) Upload(ctx context.Context, file, url string, params *QueryParams) *ErrorResponse

func (*ResourceService) UploadFromURL

func (s *ResourceService) UploadFromURL(ctx context.Context, path, url string, params *QueryParams) (*Link, *ErrorResponse)
type ResourceUploadLink struct {
	OperationID string `json:"operation_id"`
	Href        string `json:"href"`
	Method      string `json:"method"`
	Templated   bool   `json:"templated,omitempty"`
}

ResourceUploadLink ...

type ShareInfo

type ShareInfo struct {
	IsRoot  bool   `json:"is_root,omitempty"`
	IsOwned bool   `json:"is_owned,omitempty"`
	Rights  string `json:"rights"`
}

ShareInfo ...

type SystemFolders

type SystemFolders struct {
	Odnoklassniki string `json:"odnoklassniki,omitempty"`
	Google        string `json:"google,omitempty"`
	Instagram     string `json:"instagram,omitempty"`
	Vkontakte     string `json:"vkontakte,omitempty"`
	Attach        string `json:"attach,omitempty"`
	Mailru        string `json:"mailru,omitempty"`
	Downloads     string `json:"downloads,omitempty"`
	Applications  string `json:"applications,omitempty"`
	Facebook      string `json:"facebook,omitempty"`
	Social        string `json:"social,omitempty"`
	Messenger     string `json:"messenger,omitempty"`
	Calendar      string `json:"calendar,omitempty"`
	Scans         string `json:"scans,omitempty"`
	Screenshots   string `json:"screenshots,omitempty"`
	Photostream   string `json:"photostream,omitempty"`
}

SystemFolders ...

type TrashResource

type TrashResource Resource

TrashResource ...

type TrashService

type TrashService service

func (*TrashService) Delete

func (s *TrashService) Delete(ctx context.Context, path string, params *QueryParams) (*Link, *ErrorResponse)

func (*TrashService) List

func (s *TrashService) List(ctx context.Context, path string, params *QueryParams) (*TrashResource, *ErrorResponse)

ListTrashResources -

func (*TrashService) Restore

func (s *TrashService) Restore(ctx context.Context, path string, params *QueryParams) (*Link, *Operation, *ErrorResponse)

RestoreFromTrash -

type User

type User struct {
	Country     string `json:"country,omitempty"`
	Login       string `json:"login,omitempty"`
	DisplayName string `json:"display_name,omitempty"`
	UID         string `json:"uid,omitempty"`
}

User ...

type UserPublicInformation

type UserPublicInformation struct {
	Login       string `json:"login,omitempty"`
	DisplayName string `json:"display_name,omitempty"`
	UID         string `json:"uid,omitempty"`
}

UserPublicInformation ...

Jump to

Keyboard shortcuts

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