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

     1  //
     2  //
     3  // File generated from our OpenAPI spec
     4  //
     5  //
     6  
     7  // Package review provides the /reviews APIs
     8  package review
     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 /reviews APIs.
    18  type Client struct {
    19  	B   stripe.Backend
    20  	Key string
    21  }
    22  
    23  // Get returns the details of a review.
    24  func Get(id string, params *stripe.ReviewParams) (*stripe.Review, error) {
    25  	return getC().Get(id, params)
    26  }
    27  
    28  // Get returns the details of a review.
    29  func (c Client) Get(id string, params *stripe.ReviewParams) (*stripe.Review, error) {
    30  	path := stripe.FormatURLPath("/v1/reviews/%s", id)
    31  	review := &stripe.Review{}
    32  	err := c.B.Call(http.MethodGet, path, c.Key, params, review)
    33  	return review, err
    34  }
    35  
    36  // Approve is the method for the `POST /v1/reviews/{review}/approve` API.
    37  func Approve(id string, params *stripe.ReviewApproveParams) (*stripe.Review, error) {
    38  	return getC().Approve(id, params)
    39  }
    40  
    41  // Approve is the method for the `POST /v1/reviews/{review}/approve` API.
    42  func (c Client) Approve(id string, params *stripe.ReviewApproveParams) (*stripe.Review, error) {
    43  	path := stripe.FormatURLPath("/v1/reviews/%s/approve", id)
    44  	review := &stripe.Review{}
    45  	err := c.B.Call(http.MethodPost, path, c.Key, params, review)
    46  	return review, err
    47  }
    48  
    49  // List returns a list of reviews.
    50  func List(params *stripe.ReviewListParams) *Iter {
    51  	return getC().List(params)
    52  }
    53  
    54  // List returns a list of reviews.
    55  func (c Client) List(listParams *stripe.ReviewListParams) *Iter {
    56  	return &Iter{
    57  		Iter: stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) {
    58  			list := &stripe.ReviewList{}
    59  			err := c.B.CallRaw(http.MethodGet, "/v1/reviews", c.Key, b, p, list)
    60  
    61  			ret := make([]interface{}, len(list.Data))
    62  			for i, v := range list.Data {
    63  				ret[i] = v
    64  			}
    65  
    66  			return ret, list, err
    67  		}),
    68  	}
    69  }
    70  
    71  // Iter is an iterator for reviews.
    72  type Iter struct {
    73  	*stripe.Iter
    74  }
    75  
    76  // Review returns the review which the iterator is currently pointing to.
    77  func (i *Iter) Review() *stripe.Review {
    78  	return i.Current().(*stripe.Review)
    79  }
    80  
    81  // ReviewList returns the current list object which the iterator is
    82  // currently using. List objects will change as new API calls are made to
    83  // continue pagination.
    84  func (i *Iter) ReviewList() *stripe.ReviewList {
    85  	return i.List().(*stripe.ReviewList)
    86  }
    87  
    88  func getC() Client {
    89  	return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key}
    90  }