github.com/Files-com/files-sdk-go/v2@v2.1.2/behavior.go (about)

     1  package files_sdk
     2  
     3  import (
     4  	"encoding/json"
     5  	"io"
     6  
     7  	lib "github.com/Files-com/files-sdk-go/v2/lib"
     8  )
     9  
    10  type Behavior 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  	AttachmentUrl    string                 `json:"attachment_url,omitempty" path:"attachment_url,omitempty" url:"attachment_url,omitempty"`
    14  	Behavior         string                 `json:"behavior,omitempty" path:"behavior,omitempty" url:"behavior,omitempty"`
    15  	Name             string                 `json:"name,omitempty" path:"name,omitempty" url:"name,omitempty"`
    16  	Description      string                 `json:"description,omitempty" path:"description,omitempty" url:"description,omitempty"`
    17  	Value            map[string]interface{} `json:"value,omitempty" path:"value,omitempty" url:"value,omitempty"`
    18  	AttachmentFile   io.Reader              `json:"attachment_file,omitempty" path:"attachment_file,omitempty" url:"attachment_file,omitempty"`
    19  	AttachmentDelete *bool                  `json:"attachment_delete,omitempty" path:"attachment_delete,omitempty" url:"attachment_delete,omitempty"`
    20  }
    21  
    22  func (b Behavior) Identifier() interface{} {
    23  	return b.Id
    24  }
    25  
    26  type BehaviorCollection []Behavior
    27  
    28  type BehaviorListParams struct {
    29  	SortBy       map[string]interface{} `url:"sort_by,omitempty" required:"false" json:"sort_by,omitempty" path:"sort_by"`
    30  	Filter       Behavior               `url:"filter,omitempty" required:"false" json:"filter,omitempty" path:"filter"`
    31  	FilterPrefix map[string]interface{} `url:"filter_prefix,omitempty" required:"false" json:"filter_prefix,omitempty" path:"filter_prefix"`
    32  	ListParams
    33  }
    34  
    35  type BehaviorFindParams struct {
    36  	Id int64 `url:"-,omitempty" required:"false" json:"-,omitempty" path:"id"`
    37  }
    38  
    39  type BehaviorListForParams struct {
    40  	SortBy       map[string]interface{} `url:"sort_by,omitempty" required:"false" json:"sort_by,omitempty" path:"sort_by"`
    41  	Filter       Behavior               `url:"filter,omitempty" required:"false" json:"filter,omitempty" path:"filter"`
    42  	FilterPrefix map[string]interface{} `url:"filter_prefix,omitempty" required:"false" json:"filter_prefix,omitempty" path:"filter_prefix"`
    43  	Path         string                 `url:"-,omitempty" required:"false" json:"-,omitempty" path:"path"`
    44  	Recursive    string                 `url:"recursive,omitempty" required:"false" json:"recursive,omitempty" path:"recursive"`
    45  	Behavior     string                 `url:"behavior,omitempty" required:"false" json:"behavior,omitempty" path:"behavior"`
    46  	ListParams
    47  }
    48  
    49  type BehaviorCreateParams struct {
    50  	Value          string    `url:"value,omitempty" required:"false" json:"value,omitempty" path:"value"`
    51  	AttachmentFile io.Writer `url:"attachment_file,omitempty" required:"false" json:"attachment_file,omitempty" path:"attachment_file"`
    52  	Name           string    `url:"name,omitempty" required:"false" json:"name,omitempty" path:"name"`
    53  	Description    string    `url:"description,omitempty" required:"false" json:"description,omitempty" path:"description"`
    54  	Path           string    `url:"path,omitempty" required:"true" json:"path,omitempty" path:"path"`
    55  	Behavior       string    `url:"behavior,omitempty" required:"true" json:"behavior,omitempty" path:"behavior"`
    56  }
    57  
    58  type BehaviorWebhookTestParams struct {
    59  	Url      string                 `url:"url,omitempty" required:"true" json:"url,omitempty" path:"url"`
    60  	Method   string                 `url:"method,omitempty" required:"false" json:"method,omitempty" path:"method"`
    61  	Encoding string                 `url:"encoding,omitempty" required:"false" json:"encoding,omitempty" path:"encoding"`
    62  	Headers  map[string]interface{} `url:"headers,omitempty" required:"false" json:"headers,omitempty" path:"headers"`
    63  	Body     map[string]interface{} `url:"body,omitempty" required:"false" json:"body,omitempty" path:"body"`
    64  	Action   string                 `url:"action,omitempty" required:"false" json:"action,omitempty" path:"action"`
    65  }
    66  
    67  type BehaviorUpdateParams struct {
    68  	Id               int64     `url:"-,omitempty" required:"false" json:"-,omitempty" path:"id"`
    69  	Value            string    `url:"value,omitempty" required:"false" json:"value,omitempty" path:"value"`
    70  	AttachmentFile   io.Writer `url:"attachment_file,omitempty" required:"false" json:"attachment_file,omitempty" path:"attachment_file"`
    71  	Name             string    `url:"name,omitempty" required:"false" json:"name,omitempty" path:"name"`
    72  	Description      string    `url:"description,omitempty" required:"false" json:"description,omitempty" path:"description"`
    73  	Behavior         string    `url:"behavior,omitempty" required:"false" json:"behavior,omitempty" path:"behavior"`
    74  	Path             string    `url:"path,omitempty" required:"false" json:"path,omitempty" path:"path"`
    75  	AttachmentDelete *bool     `url:"attachment_delete,omitempty" required:"false" json:"attachment_delete,omitempty" path:"attachment_delete"`
    76  }
    77  
    78  type BehaviorDeleteParams struct {
    79  	Id int64 `url:"-,omitempty" required:"false" json:"-,omitempty" path:"id"`
    80  }
    81  
    82  func (b *Behavior) UnmarshalJSON(data []byte) error {
    83  	type behavior Behavior
    84  	var v behavior
    85  	if err := json.Unmarshal(data, &v); err != nil {
    86  		return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, map[string]interface{}{})
    87  	}
    88  
    89  	*b = Behavior(v)
    90  	return nil
    91  }
    92  
    93  func (b *BehaviorCollection) UnmarshalJSON(data []byte) error {
    94  	type behaviors BehaviorCollection
    95  	var v behaviors
    96  	if err := json.Unmarshal(data, &v); err != nil {
    97  		return lib.ErrorWithOriginalResponse{}.ProcessError(data, err, []map[string]interface{}{})
    98  	}
    99  
   100  	*b = BehaviorCollection(v)
   101  	return nil
   102  }
   103  
   104  func (b *BehaviorCollection) ToSlice() *[]interface{} {
   105  	ret := make([]interface{}, len(*b))
   106  	for i, v := range *b {
   107  		ret[i] = v
   108  	}
   109  
   110  	return &ret
   111  }