From f8dacf2572f847b8ca8a11b46bdf2d91b5fc10b5 Mon Sep 17 00:00:00 2001 From: Yejia Chen Date: Wed, 6 Oct 2021 13:31:38 -0400 Subject: [PATCH] Make some clients codegen-able --- invoice/client.go | 44 +++++++++++++++++++---------------- promotioncode/client.go | 24 ++++++++++--------- radar/valuelistitem/client.go | 25 +++++++++++--------- reversal/client.go | 24 ++++++++++--------- 4 files changed, 64 insertions(+), 53 deletions(-) diff --git a/invoice/client.go b/invoice/client.go index e2452d2608..41c069d2ec 100644 --- a/invoice/client.go +++ b/invoice/client.go @@ -161,17 +161,19 @@ func List(params *stripe.InvoiceListParams) *Iter { // List returns a list of invoices. func (c Client) List(listParams *stripe.InvoiceListParams) *Iter { - return &Iter{stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) { - list := &stripe.InvoiceList{} - err := c.B.CallRaw(http.MethodGet, "/v1/invoices", c.Key, b, p, list) + return &Iter{ + Iter: stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) { + list := &stripe.InvoiceList{} + err := c.B.CallRaw(http.MethodGet, "/v1/invoices", c.Key, b, p, list) - ret := make([]interface{}, len(list.Data)) - for i, v := range list.Data { - ret[i] = v - } + ret := make([]interface{}, len(list.Data)) + for i, v := range list.Data { + ret[i] = v + } - return ret, list, err - })} + return ret, list, err + }), + } } // Iter is an iterator for invoices. @@ -202,17 +204,19 @@ func (c Client) ListLines(listParams *stripe.InvoiceLineListParams) *LineIter { "/v1/invoices/%s/lines", stripe.StringValue(listParams.ID), ) - return &LineIter{stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) { - list := &stripe.InvoiceLineList{} - err := c.B.CallRaw(http.MethodGet, path, c.Key, b, p, list) - - ret := make([]interface{}, len(list.Data)) - for i, v := range list.Data { - ret[i] = v - } - - return ret, list, err - })} + return &LineIter{ + Iter: stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) { + list := &stripe.InvoiceLineList{} + err := c.B.CallRaw(http.MethodGet, path, c.Key, b, p, list) + + ret := make([]interface{}, len(list.Data)) + for i, v := range list.Data { + ret[i] = v + } + + return ret, list, err + }), + } } // LineIter is an iterator for invoice line items. diff --git a/promotioncode/client.go b/promotioncode/client.go index af7e4ad95c..53419777c3 100644 --- a/promotioncode/client.go +++ b/promotioncode/client.go @@ -71,17 +71,19 @@ func List(params *stripe.PromotionCodeListParams) *Iter { // List returns a list of promotion codes. func (c Client) List(listParams *stripe.PromotionCodeListParams) *Iter { - return &Iter{stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) { - list := &stripe.PromotionCodeList{} - err := c.B.CallRaw(http.MethodGet, "/v1/promotion_codes", c.Key, b, p, list) - - ret := make([]interface{}, len(list.Data)) - for i, v := range list.Data { - ret[i] = v - } - - return ret, list, err - })} + return &Iter{ + Iter: stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) { + list := &stripe.PromotionCodeList{} + err := c.B.CallRaw(http.MethodGet, "/v1/promotion_codes", c.Key, b, p, list) + + ret := make([]interface{}, len(list.Data)) + for i, v := range list.Data { + ret[i] = v + } + + return ret, list, err + }), + } } // Iter is an iterator for promotion codes. diff --git a/radar/valuelistitem/client.go b/radar/valuelistitem/client.go index 9621e41c61..9f921b67ff 100644 --- a/radar/valuelistitem/client.go +++ b/radar/valuelistitem/client.go @@ -5,6 +5,7 @@ // // Package valuelistitem provides the /radar/value_list_items APIs +// For more details, see: https://stripe.com/docs/api/radar/list_items?lang=go package valuelistitem import ( @@ -71,17 +72,19 @@ func List(params *stripe.RadarValueListItemListParams) *Iter { // List returns a list of radar value list items. func (c Client) List(listParams *stripe.RadarValueListItemListParams) *Iter { - return &Iter{stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) { - list := &stripe.RadarValueListItemList{} - err := c.B.CallRaw(http.MethodGet, "/v1/radar/value_list_items", c.Key, b, p, list) - - ret := make([]interface{}, len(list.Data)) - for i, v := range list.Data { - ret[i] = v - } - - return ret, list, err - })} + return &Iter{ + Iter: stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) { + list := &stripe.RadarValueListItemList{} + err := c.B.CallRaw(http.MethodGet, "/v1/radar/value_list_items", c.Key, b, p, list) + + ret := make([]interface{}, len(list.Data)) + for i, v := range list.Data { + ret[i] = v + } + + return ret, list, err + }), + } } // Iter is an iterator for radar value list items. diff --git a/reversal/client.go b/reversal/client.go index 4c288842e7..2d6f1bb142 100644 --- a/reversal/client.go +++ b/reversal/client.go @@ -87,17 +87,19 @@ func (c Client) List(listParams *stripe.ReversalListParams) *Iter { "/v1/transfers/%s/reversals", stripe.StringValue(listParams.Transfer), ) - return &Iter{stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) { - list := &stripe.ReversalList{} - err := c.B.CallRaw(http.MethodGet, path, c.Key, b, p, list) - - ret := make([]interface{}, len(list.Data)) - for i, v := range list.Data { - ret[i] = v - } - - return ret, list, err - })} + return &Iter{ + Iter: stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) { + list := &stripe.ReversalList{} + err := c.B.CallRaw(http.MethodGet, path, c.Key, b, p, list) + + ret := make([]interface{}, len(list.Data)) + for i, v := range list.Data { + ret[i] = v + } + + return ret, list, err + }), + } } // Iter is an iterator for reversals.