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

     1  //
     2  //
     3  // File generated from our OpenAPI spec
     4  //
     5  //
     6  
     7  // Package testclock provides the /test_helpers/test_clocks APIs
     8  package testclock
     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 /test_helpers/test_clocks APIs.
    18  type Client struct {
    19  	B   stripe.Backend
    20  	Key string
    21  }
    22  
    23  // New creates a new test helpers test clock.
    24  func New(params *stripe.TestHelpersTestClockParams) (*stripe.TestHelpersTestClock, error) {
    25  	return getC().New(params)
    26  }
    27  
    28  // New creates a new test helpers test clock.
    29  func (c Client) New(params *stripe.TestHelpersTestClockParams) (*stripe.TestHelpersTestClock, error) {
    30  	testclock := &stripe.TestHelpersTestClock{}
    31  	err := c.B.Call(
    32  		http.MethodPost,
    33  		"/v1/test_helpers/test_clocks",
    34  		c.Key,
    35  		params,
    36  		testclock,
    37  	)
    38  	return testclock, err
    39  }
    40  
    41  // Get returns the details of a test helpers test clock.
    42  func Get(id string, params *stripe.TestHelpersTestClockParams) (*stripe.TestHelpersTestClock, error) {
    43  	return getC().Get(id, params)
    44  }
    45  
    46  // Get returns the details of a test helpers test clock.
    47  func (c Client) Get(id string, params *stripe.TestHelpersTestClockParams) (*stripe.TestHelpersTestClock, error) {
    48  	path := stripe.FormatURLPath("/v1/test_helpers/test_clocks/%s", id)
    49  	testclock := &stripe.TestHelpersTestClock{}
    50  	err := c.B.Call(http.MethodGet, path, c.Key, params, testclock)
    51  	return testclock, err
    52  }
    53  
    54  // Del removes a test helpers test clock.
    55  func Del(id string, params *stripe.TestHelpersTestClockParams) (*stripe.TestHelpersTestClock, error) {
    56  	return getC().Del(id, params)
    57  }
    58  
    59  // Del removes a test helpers test clock.
    60  func (c Client) Del(id string, params *stripe.TestHelpersTestClockParams) (*stripe.TestHelpersTestClock, error) {
    61  	path := stripe.FormatURLPath("/v1/test_helpers/test_clocks/%s", id)
    62  	testclock := &stripe.TestHelpersTestClock{}
    63  	err := c.B.Call(http.MethodDelete, path, c.Key, params, testclock)
    64  	return testclock, err
    65  }
    66  
    67  // Advance is the method for the `POST /v1/test_helpers/test_clocks/{test_clock}/advance` API.
    68  func Advance(id string, params *stripe.TestHelpersTestClockAdvanceParams) (*stripe.TestHelpersTestClock, error) {
    69  	return getC().Advance(id, params)
    70  }
    71  
    72  // Advance is the method for the `POST /v1/test_helpers/test_clocks/{test_clock}/advance` API.
    73  func (c Client) Advance(id string, params *stripe.TestHelpersTestClockAdvanceParams) (*stripe.TestHelpersTestClock, error) {
    74  	path := stripe.FormatURLPath("/v1/test_helpers/test_clocks/%s/advance", id)
    75  	testclock := &stripe.TestHelpersTestClock{}
    76  	err := c.B.Call(http.MethodPost, path, c.Key, params, testclock)
    77  	return testclock, err
    78  }
    79  
    80  // List returns a list of test helpers test clocks.
    81  func List(params *stripe.TestHelpersTestClockListParams) *Iter {
    82  	return getC().List(params)
    83  }
    84  
    85  // List returns a list of test helpers test clocks.
    86  func (c Client) List(listParams *stripe.TestHelpersTestClockListParams) *Iter {
    87  	return &Iter{
    88  		Iter: stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) {
    89  			list := &stripe.TestHelpersTestClockList{}
    90  			err := c.B.CallRaw(http.MethodGet, "/v1/test_helpers/test_clocks", 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 test helpers test clocks.
   103  type Iter struct {
   104  	*stripe.Iter
   105  }
   106  
   107  // TestHelpersTestClock returns the test helpers test clock which the iterator is currently pointing to.
   108  func (i *Iter) TestHelpersTestClock() *stripe.TestHelpersTestClock {
   109  	return i.Current().(*stripe.TestHelpersTestClock)
   110  }
   111  
   112  // TestHelpersTestClockList 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) TestHelpersTestClockList() *stripe.TestHelpersTestClockList {
   116  	return i.List().(*stripe.TestHelpersTestClockList)
   117  }
   118  
   119  func getC() Client {
   120  	return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key}
   121  }