Skip to content

Commit

Permalink
upd: types.go (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyabrin authored Nov 11, 2022
1 parent aef2f2f commit 2c68fbb
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 20 deletions.
3 changes: 2 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ linters:
- testpackage # makes you use a separate _test package
- tparallel # detects inappropriate usage of t.Parallel() method in your Go test codes
- unconvert # removes unnecessary type conversions
- unparam # reports unused function parameters
# TODO: disabled, raises error for `(*Client).post` - `body` always receives `nil`
# - unparam # reports unused function parameters
- usestdlibvars # detects the possibility to use variables/constants from the Go standard library
- wastedassign # finds wasted assignment statements
- whitespace # detects leading and trailing whitespace
Expand Down
13 changes: 10 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@ const API_URL = "https://cloud-api.yandex.net/v1/disk/"
type HTTPHeaders map[string]string
type QueryParams map[string]string

type Metadata map[string]map[string]string

type service struct{ client *Client }

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

type Client struct {
accessToken string
HTTPClient *http.Client
Expand Down Expand Up @@ -111,7 +118,7 @@ func (c *Client) get(ctx context.Context, resource string, params *QueryParams)
return c.do(ctx, http.MethodGet, resource, nil, nil, params)
}

func (c *Client) post(ctx context.Context, resource string, params *QueryParams) (*http.Response, error) {
func (c *Client) post(ctx context.Context, resource string, body io.Reader, params *QueryParams) (*http.Response, error) {
return c.do(ctx, http.MethodPost, resource, nil, nil, params)
}

Expand Down
2 changes: 1 addition & 1 deletion public.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (s *PublicService) DownloadURL(ctx context.Context, public_key string, para
func (s *PublicService) Save(ctx context.Context, public_key string, params *QueryParams) (*Link, *ErrorResponse) {
var link *Link

resp, err := s.client.post(ctx, s.client.apiURL+"public/resources/save-to-disk?public_key="+public_key, params)
resp, err := s.client.post(ctx, s.client.apiURL+"public/resources/save-to-disk?public_key="+public_key, nil, params)
if haveError(err) || !InArray(resp.StatusCode, []int{
http.StatusOK,
http.StatusCreated,
Expand Down
6 changes: 3 additions & 3 deletions resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (s *ResourceService) CreateDir(ctx context.Context, path string, params *Qu
func (s *ResourceService) Copy(ctx context.Context, from, to string, params *QueryParams) (*Link, *ErrorResponse) {
var link *Link

resp, err := s.client.post(ctx, s.client.apiURL+"resources/copy?from="+from+"&path="+to, params)
resp, err := s.client.post(ctx, s.client.apiURL+"resources/copy?from="+from+"&path="+to, nil, params)
if haveError(err) || !InArray(resp.StatusCode, []int{
http.StatusOK,
http.StatusCreated,
Expand Down Expand Up @@ -164,7 +164,7 @@ func (s *ResourceService) ListLastUploaded(ctx context.Context, params *QueryPar
func (s *ResourceService) Move(ctx context.Context, from, to string, params *QueryParams) (*Link, *ErrorResponse) {
var link *Link

resp, err := s.client.post(ctx, s.client.apiURL+"resources/move?from="+from+"&path="+to, params)
resp, err := s.client.post(ctx, s.client.apiURL+"resources/move?from="+from+"&path="+to, nil, params)
if haveError(err) || !InArray(resp.StatusCode, []int{
http.StatusCreated,
http.StatusAccepted,
Expand Down Expand Up @@ -279,7 +279,7 @@ func (s *ResourceService) UploadFromURL(ctx context.Context, path, url string, p

ext := filepath.Ext(url) // TODO: fix for files without extension (e.g. www.example.com/filename)
reqURL := fmt.Sprintf("resources/upload?path=%s%s&url=%s", path, ext, url)
resp, err := s.client.post(ctx, s.client.apiURL+reqURL, params)
resp, err := s.client.post(ctx, s.client.apiURL+reqURL, nil, params)
if haveError(err) || resp.StatusCode != http.StatusOK {
return nil, handleResponseCode(resp.StatusCode)
}
Expand Down
27 changes: 15 additions & 12 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package disk

// Disk Данные о свободном и занятом пространстве на Диске
type Disk struct {
UnlimitedAutouploadEnabled bool `json:"unlimited_autoupload_enabled,omitempty"`
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"`
}

Expand All @@ -19,11 +20,15 @@ type SystemFolders struct {
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"`
}
Expand All @@ -36,6 +41,10 @@ type User struct {
UID string `json:"uid,omitempty"`
}

// Metadata is a type for a CustomProperties filed
// TODO: rename to CustomProperty ?
type Metadata map[string]map[string]string

// Resource ...
type Resource struct {
AntivirusStatus string `json:"antivirus_status,omitempty"`
Expand All @@ -58,8 +67,8 @@ type Resource struct {
PublicKey string `json:"public_key,omitempty"`
Sha256 string `json:"sha256,omitempty"`
Name string `json:"name"`
Created string `json:"created"`
Modified string `json:"modified"`
Created string `json:"created"` // TODO: time format
Modified string `json:"modified"` // TODO: time format
CommentIDs *CommentIds `json:"comment_ids,omitempty"`
}

Expand Down Expand Up @@ -89,7 +98,9 @@ type ResourceList struct {

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

// CommentIds ...
Expand Down Expand Up @@ -146,13 +157,5 @@ type Operation struct {
Status string `json:"status"`
}

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

// TrashResource ...
type TrashResource Resource

0 comments on commit 2c68fbb

Please sign in to comment.