github.com/Files-com/files-sdk-go/v3@v3.1.81/folder/client.go (about)

     1  package folder
     2  
     3  import (
     4  	files_sdk "github.com/Files-com/files-sdk-go/v3"
     5  	lib "github.com/Files-com/files-sdk-go/v3/lib"
     6  	listquery "github.com/Files-com/files-sdk-go/v3/listquery"
     7  )
     8  
     9  type Client struct {
    10  	files_sdk.Config
    11  }
    12  
    13  type Iter struct {
    14  	*files_sdk.Iter
    15  	*Client
    16  }
    17  
    18  func (i *Iter) Reload(opts ...files_sdk.RequestResponseOption) files_sdk.IterI {
    19  	return &Iter{Iter: i.Iter.Reload(opts...).(*files_sdk.Iter), Client: i.Client}
    20  }
    21  
    22  func (i *Iter) File() files_sdk.File {
    23  	return i.Current().(files_sdk.File)
    24  }
    25  
    26  func (i *Iter) Iterate(identifier interface{}, opts ...files_sdk.RequestResponseOption) (files_sdk.IterI, error) {
    27  	params := files_sdk.FolderListForParams{}
    28  	if path, ok := identifier.(string); ok {
    29  		params.Path = path
    30  	}
    31  	return i.Client.ListFor(params, opts...)
    32  }
    33  
    34  func (c *Client) ListFor(params files_sdk.FolderListForParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) {
    35  	i := &Iter{Iter: &files_sdk.Iter{}, Client: c}
    36  	path, err := lib.BuildPath("/folders/{path}", params)
    37  	if err != nil {
    38  		return i, err
    39  	}
    40  	i.ListParams = &params
    41  	list := files_sdk.FileCollection{}
    42  	i.Query = listquery.Build(c.Config, path, &list, opts...)
    43  	return i, nil
    44  }
    45  
    46  func ListFor(params files_sdk.FolderListForParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) {
    47  	return (&Client{}).ListFor(params, opts...)
    48  }
    49  
    50  func (c *Client) Create(params files_sdk.FolderCreateParams, opts ...files_sdk.RequestResponseOption) (file files_sdk.File, err error) {
    51  	err = files_sdk.Resource(c.Config, lib.Resource{Method: "POST", Path: "/folders/{path}", Params: params, Entity: &file}, opts...)
    52  	return
    53  }
    54  
    55  func Create(params files_sdk.FolderCreateParams, opts ...files_sdk.RequestResponseOption) (file files_sdk.File, err error) {
    56  	return (&Client{}).Create(params, opts...)
    57  }