github.com/stripe/stripe-go/v76@v76.25.0/terminal/location/client.go (about) 1 // 2 // 3 // File generated from our OpenAPI spec 4 // 5 // 6 7 // Package location provides the /terminal/locations APIs 8 package location 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 /terminal/locations APIs. 18 type Client struct { 19 B stripe.Backend 20 Key string 21 } 22 23 // New creates a new terminal location. 24 func New(params *stripe.TerminalLocationParams) (*stripe.TerminalLocation, error) { 25 return getC().New(params) 26 } 27 28 // New creates a new terminal location. 29 func (c Client) New(params *stripe.TerminalLocationParams) (*stripe.TerminalLocation, error) { 30 location := &stripe.TerminalLocation{} 31 err := c.B.Call( 32 http.MethodPost, 33 "/v1/terminal/locations", 34 c.Key, 35 params, 36 location, 37 ) 38 return location, err 39 } 40 41 // Get returns the details of a terminal location. 42 func Get(id string, params *stripe.TerminalLocationParams) (*stripe.TerminalLocation, error) { 43 return getC().Get(id, params) 44 } 45 46 // Get returns the details of a terminal location. 47 func (c Client) Get(id string, params *stripe.TerminalLocationParams) (*stripe.TerminalLocation, error) { 48 path := stripe.FormatURLPath("/v1/terminal/locations/%s", id) 49 location := &stripe.TerminalLocation{} 50 err := c.B.Call(http.MethodGet, path, c.Key, params, location) 51 return location, err 52 } 53 54 // Update updates a terminal location's properties. 55 func Update(id string, params *stripe.TerminalLocationParams) (*stripe.TerminalLocation, error) { 56 return getC().Update(id, params) 57 } 58 59 // Update updates a terminal location's properties. 60 func (c Client) Update(id string, params *stripe.TerminalLocationParams) (*stripe.TerminalLocation, error) { 61 path := stripe.FormatURLPath("/v1/terminal/locations/%s", id) 62 location := &stripe.TerminalLocation{} 63 err := c.B.Call(http.MethodPost, path, c.Key, params, location) 64 return location, err 65 } 66 67 // Del removes a terminal location. 68 func Del(id string, params *stripe.TerminalLocationParams) (*stripe.TerminalLocation, error) { 69 return getC().Del(id, params) 70 } 71 72 // Del removes a terminal location. 73 func (c Client) Del(id string, params *stripe.TerminalLocationParams) (*stripe.TerminalLocation, error) { 74 path := stripe.FormatURLPath("/v1/terminal/locations/%s", id) 75 location := &stripe.TerminalLocation{} 76 err := c.B.Call(http.MethodDelete, path, c.Key, params, location) 77 return location, err 78 } 79 80 // List returns a list of terminal locations. 81 func List(params *stripe.TerminalLocationListParams) *Iter { 82 return getC().List(params) 83 } 84 85 // List returns a list of terminal locations. 86 func (c Client) List(listParams *stripe.TerminalLocationListParams) *Iter { 87 return &Iter{ 88 Iter: stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) { 89 list := &stripe.TerminalLocationList{} 90 err := c.B.CallRaw(http.MethodGet, "/v1/terminal/locations", c.Key, b, p, list) 91 92 ret := make([]interface{}, len(list.Data)) 93 for i, v := range list.Data { 94 ret[i] = v 95 } 96 97 return ret, list, err 98 }), 99 } 100 } 101 102 // Iter is an iterator for terminal locations. 103 type Iter struct { 104 *stripe.Iter 105 } 106 107 // TerminalLocation returns the terminal location which the iterator is currently pointing to. 108 func (i *Iter) TerminalLocation() *stripe.TerminalLocation { 109 return i.Current().(*stripe.TerminalLocation) 110 } 111 112 // TerminalLocationList returns the current list object which the iterator is 113 // currently using. List objects will change as new API calls are made to 114 // continue pagination. 115 func (i *Iter) TerminalLocationList() *stripe.TerminalLocationList { 116 return i.List().(*stripe.TerminalLocationList) 117 } 118 119 func getC() Client { 120 return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key} 121 }