github.com/stripe/stripe-go/v76@v76.25.0/filelink/client.go (about) 1 // 2 // 3 // File generated from our OpenAPI spec 4 // 5 // 6 7 // Package filelink provides the /file_links APIs 8 package filelink 9 10 import ( 11 "net/http" 12 13 stripe "github.com/stripe/stripe-go/v76" 14 "github.com/stripe/stripe-go/v76/form" 15 ) 16 17 // Client is used to invoke /file_links APIs. 18 type Client struct { 19 B stripe.Backend 20 Key string 21 } 22 23 // New creates a new file link. 24 func New(params *stripe.FileLinkParams) (*stripe.FileLink, error) { 25 return getC().New(params) 26 } 27 28 // New creates a new file link. 29 func (c Client) New(params *stripe.FileLinkParams) (*stripe.FileLink, error) { 30 filelink := &stripe.FileLink{} 31 err := c.B.Call(http.MethodPost, "/v1/file_links", c.Key, params, filelink) 32 return filelink, err 33 } 34 35 // Get returns the details of a file link. 36 func Get(id string, params *stripe.FileLinkParams) (*stripe.FileLink, error) { 37 return getC().Get(id, params) 38 } 39 40 // Get returns the details of a file link. 41 func (c Client) Get(id string, params *stripe.FileLinkParams) (*stripe.FileLink, error) { 42 path := stripe.FormatURLPath("/v1/file_links/%s", id) 43 filelink := &stripe.FileLink{} 44 err := c.B.Call(http.MethodGet, path, c.Key, params, filelink) 45 return filelink, err 46 } 47 48 // Update updates a file link's properties. 49 func Update(id string, params *stripe.FileLinkParams) (*stripe.FileLink, error) { 50 return getC().Update(id, params) 51 } 52 53 // Update updates a file link's properties. 54 func (c Client) Update(id string, params *stripe.FileLinkParams) (*stripe.FileLink, error) { 55 path := stripe.FormatURLPath("/v1/file_links/%s", id) 56 filelink := &stripe.FileLink{} 57 err := c.B.Call(http.MethodPost, path, c.Key, params, filelink) 58 return filelink, err 59 } 60 61 // List returns a list of file links. 62 func List(params *stripe.FileLinkListParams) *Iter { 63 return getC().List(params) 64 } 65 66 // List returns a list of file links. 67 func (c Client) List(listParams *stripe.FileLinkListParams) *Iter { 68 return &Iter{ 69 Iter: stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) { 70 list := &stripe.FileLinkList{} 71 err := c.B.CallRaw(http.MethodGet, "/v1/file_links", c.Key, b, p, list) 72 73 ret := make([]interface{}, len(list.Data)) 74 for i, v := range list.Data { 75 ret[i] = v 76 } 77 78 return ret, list, err 79 }), 80 } 81 } 82 83 // Iter is an iterator for file links. 84 type Iter struct { 85 *stripe.Iter 86 } 87 88 // FileLink returns the file link which the iterator is currently pointing to. 89 func (i *Iter) FileLink() *stripe.FileLink { 90 return i.Current().(*stripe.FileLink) 91 } 92 93 // FileLinkList returns the current list object which the iterator is 94 // currently using. List objects will change as new API calls are made to 95 // continue pagination. 96 func (i *Iter) FileLinkList() *stripe.FileLinkList { 97 return i.List().(*stripe.FileLinkList) 98 } 99 100 func getC() Client { 101 return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key} 102 }