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

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