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

     1  package files_sdk
     2  
     3  import (
     4  	"encoding/json"
     5  	"io"
     6  
     7  	lib "github.com/Files-com/files-sdk-go/v3/lib"
     8  )
     9  
    10  type Style struct {
    11  	Id        int64     `json:"id,omitempty" path:"id,omitempty" url:"id,omitempty"`
    12  	Path      string    `json:"path,omitempty" path:"path,omitempty" url:"path,omitempty"`
    13  	Logo      Image     `json:"logo,omitempty" path:"logo,omitempty" url:"logo,omitempty"`
    14  	Thumbnail Image     `json:"thumbnail,omitempty" path:"thumbnail,omitempty" url:"thumbnail,omitempty"`
    15  	File      io.Reader `json:"file,omitempty" path:"file,omitempty" url:"file,omitempty"`
    16  }
    17  
    18  func (s Style) Identifier() interface{} {
    19  	return s.Id
    20  }
    21  
    22  type StyleCollection []Style
    23  
    24  type StyleFindParams struct {
    25  	Path string `url:"-,omitempty" required:"false" json:"-,omitempty" path:"path"`
    26  }
    27  
    28  type StyleUpdateParams struct {
    29  	Path string    `url:"-,omitempty" required:"false" json:"-,omitempty" path:"path"`
    30  	File io.Writer `url:"file,omitempty" required:"true" json:"file,omitempty" path:"file"`
    31  }
    32  
    33  type StyleDeleteParams struct {
    34  	Path string `url:"-,omitempty" required:"false" json:"-,omitempty" path:"path"`
    35  }
    36  
    37  func (s *Style) UnmarshalJSON(data []byte) error {
    38  	type style Style
    39  	var v style
    40  	if err := json.Unmarshal(data, &v); err != nil {
    41  		return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, map[string]interface{}{})
    42  	}
    43  
    44  	*s = Style(v)
    45  	return nil
    46  }
    47  
    48  func (s *StyleCollection) UnmarshalJSON(data []byte) error {
    49  	type styles StyleCollection
    50  	var v styles
    51  	if err := json.Unmarshal(data, &v); err != nil {
    52  		return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, []map[string]interface{}{})
    53  	}
    54  
    55  	*s = StyleCollection(v)
    56  	return nil
    57  }
    58  
    59  func (s *StyleCollection) ToSlice() *[]interface{} {
    60  	ret := make([]interface{}, len(*s))
    61  	for i, v := range *s {
    62  		ret[i] = v
    63  	}
    64  
    65  	return &ret
    66  }