github.com/stripe/stripe-go/v76@v76.25.0/usagerecordsummary/client.go (about)

     1  //
     2  //
     3  // File generated from our OpenAPI spec
     4  //
     5  //
     6  
     7  // Package usagerecordsummary provides the /subscription_items/{subscription_item}/usage_record_summaries APIs
     8  package usagerecordsummary
     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 /subscription_items/{subscription_item}/usage_record_summaries APIs.
    18  type Client struct {
    19  	B   stripe.Backend
    20  	Key string
    21  }
    22  
    23  // List returns a list of usage record summaries.
    24  func List(params *stripe.UsageRecordSummaryListParams) *Iter {
    25  	return getC().List(params)
    26  }
    27  
    28  // List returns a list of usage record summaries.
    29  func (c Client) List(listParams *stripe.UsageRecordSummaryListParams) *Iter {
    30  	path := stripe.FormatURLPath(
    31  		"/v1/subscription_items/%s/usage_record_summaries",
    32  		stripe.StringValue(listParams.SubscriptionItem),
    33  	)
    34  	return &Iter{
    35  		Iter: stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) {
    36  			list := &stripe.UsageRecordSummaryList{}
    37  			err := c.B.CallRaw(http.MethodGet, path, c.Key, b, p, list)
    38  
    39  			ret := make([]interface{}, len(list.Data))
    40  			for i, v := range list.Data {
    41  				ret[i] = v
    42  			}
    43  
    44  			return ret, list, err
    45  		}),
    46  	}
    47  }
    48  
    49  // Iter is an iterator for usage record summaries.
    50  type Iter struct {
    51  	*stripe.Iter
    52  }
    53  
    54  // UsageRecordSummary returns the usage record summary which the iterator is currently pointing to.
    55  func (i *Iter) UsageRecordSummary() *stripe.UsageRecordSummary {
    56  	return i.Current().(*stripe.UsageRecordSummary)
    57  }
    58  
    59  // UsageRecordSummaryList returns the current list object which the iterator is
    60  // currently using. List objects will change as new API calls are made to
    61  // continue pagination.
    62  func (i *Iter) UsageRecordSummaryList() *stripe.UsageRecordSummaryList {
    63  	return i.List().(*stripe.UsageRecordSummaryList)
    64  }
    65  
    66  func getC() Client {
    67  	return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key}
    68  }