github.com/Files-com/files-sdk-go/v2@v2.1.2/behavior/client.go (about) 1 package behavior 2 3 import ( 4 files_sdk "github.com/Files-com/files-sdk-go/v2" 5 lib "github.com/Files-com/files-sdk-go/v2/lib" 6 listquery "github.com/Files-com/files-sdk-go/v2/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) Behavior() files_sdk.Behavior { 23 return i.Current().(files_sdk.Behavior) 24 } 25 26 func (i *Iter) LoadResource(identifier interface{}, opts ...files_sdk.RequestResponseOption) (interface{}, error) { 27 params := files_sdk.BehaviorFindParams{} 28 if id, ok := identifier.(int64); ok { 29 params.Id = id 30 } 31 return i.Client.Find(params, opts...) 32 } 33 34 func (c *Client) List(params files_sdk.BehaviorListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 35 i := &Iter{Iter: &files_sdk.Iter{}, Client: c} 36 path, err := lib.BuildPath("/behaviors", params) 37 if err != nil { 38 return i, err 39 } 40 i.ListParams = ¶ms 41 list := files_sdk.BehaviorCollection{} 42 i.Query = listquery.Build(c.Config, path, &list, opts...) 43 return i, nil 44 } 45 46 func List(params files_sdk.BehaviorListParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 47 return (&Client{}).List(params, opts...) 48 } 49 50 func (c *Client) Find(params files_sdk.BehaviorFindParams, opts ...files_sdk.RequestResponseOption) (behavior files_sdk.Behavior, err error) { 51 err = files_sdk.Resource(c.Config, lib.Resource{Method: "GET", Path: "/behaviors/{id}", Params: params, Entity: &behavior}, opts...) 52 return 53 } 54 55 func Find(params files_sdk.BehaviorFindParams, opts ...files_sdk.RequestResponseOption) (behavior files_sdk.Behavior, err error) { 56 return (&Client{}).Find(params, opts...) 57 } 58 59 func (c *Client) ListFor(params files_sdk.BehaviorListForParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 60 i := &Iter{Iter: &files_sdk.Iter{}, Client: c} 61 path, err := lib.BuildPath("/behaviors/folders/{path}", params) 62 if err != nil { 63 return i, err 64 } 65 i.ListParams = ¶ms 66 list := files_sdk.BehaviorCollection{} 67 i.Query = listquery.Build(c.Config, path, &list, opts...) 68 return i, nil 69 } 70 71 func ListFor(params files_sdk.BehaviorListForParams, opts ...files_sdk.RequestResponseOption) (*Iter, error) { 72 return (&Client{}).ListFor(params, opts...) 73 } 74 75 func (c *Client) Create(params files_sdk.BehaviorCreateParams, opts ...files_sdk.RequestResponseOption) (behavior files_sdk.Behavior, err error) { 76 err = files_sdk.Resource(c.Config, lib.Resource{Method: "POST", Path: "/behaviors", Params: params, Entity: &behavior}, opts...) 77 return 78 } 79 80 func Create(params files_sdk.BehaviorCreateParams, opts ...files_sdk.RequestResponseOption) (behavior files_sdk.Behavior, err error) { 81 return (&Client{}).Create(params, opts...) 82 } 83 84 func (c *Client) WebhookTest(params files_sdk.BehaviorWebhookTestParams, opts ...files_sdk.RequestResponseOption) (err error) { 85 err = files_sdk.Resource(c.Config, lib.Resource{Method: "POST", Path: "/behaviors/webhook/test", Params: params, Entity: nil}, opts...) 86 return 87 } 88 89 func WebhookTest(params files_sdk.BehaviorWebhookTestParams, opts ...files_sdk.RequestResponseOption) (err error) { 90 return (&Client{}).WebhookTest(params, opts...) 91 } 92 93 func (c *Client) Update(params files_sdk.BehaviorUpdateParams, opts ...files_sdk.RequestResponseOption) (behavior files_sdk.Behavior, err error) { 94 err = files_sdk.Resource(c.Config, lib.Resource{Method: "PATCH", Path: "/behaviors/{id}", Params: params, Entity: &behavior}, opts...) 95 return 96 } 97 98 func Update(params files_sdk.BehaviorUpdateParams, opts ...files_sdk.RequestResponseOption) (behavior files_sdk.Behavior, err error) { 99 return (&Client{}).Update(params, opts...) 100 } 101 102 func (c *Client) UpdateWithMap(params map[string]interface{}, opts ...files_sdk.RequestResponseOption) (behavior files_sdk.Behavior, err error) { 103 err = files_sdk.Resource(c.Config, lib.Resource{Method: "PATCH", Path: "/behaviors/{id}", Params: params, Entity: &behavior}, opts...) 104 return 105 } 106 107 func UpdateWithMap(params map[string]interface{}, opts ...files_sdk.RequestResponseOption) (behavior files_sdk.Behavior, err error) { 108 return (&Client{}).UpdateWithMap(params, opts...) 109 } 110 111 func (c *Client) Delete(params files_sdk.BehaviorDeleteParams, opts ...files_sdk.RequestResponseOption) (err error) { 112 err = files_sdk.Resource(c.Config, lib.Resource{Method: "DELETE", Path: "/behaviors/{id}", Params: params, Entity: nil}, opts...) 113 return 114 } 115 116 func Delete(params files_sdk.BehaviorDeleteParams, opts ...files_sdk.RequestResponseOption) (err error) { 117 return (&Client{}).Delete(params, opts...) 118 }