1- package client
1+ package neero
22
33import (
44 "bytes"
55 "context"
66 "encoding/json"
77 "fmt"
88 "io"
9- "io/ioutil"
109 "net/http"
11- "strconv"
1210)
1311
1412type service struct {
1513 client * Client
1614}
1715
18- // Client is the campay API client.
16+ // Client is the neero API client.
1917// Do not instantiate this client with Client{}. Use the New method instead.
2018type Client struct {
21- httpClient * http.Client
22- common service
23- baseURL string
24- delay int
25-
26- Status * statusService
19+ common service
20+ httpClient * http.Client
21+ baseURL string
22+ secretKey string
23+ PaymentMethod * paymentMethodService
24+ Balance * balanceService
25+ TransactionIntent * transactionIntentService
2726}
2827
29- // New creates and returns a new campay .Client from a slice of campay .ClientOption.
28+ // New creates and returns a new neero .Client from a slice of neero .ClientOption.
3029func New (options ... Option ) * Client {
3130 config := defaultClientConfig ()
3231
@@ -36,19 +35,21 @@ func New(options ...Option) *Client {
3635
3736 client := & Client {
3837 httpClient : config .httpClient ,
39- delay : config .delay ,
38+ secretKey : config .secretKey ,
4039 baseURL : config .baseURL ,
4140 }
4241
4342 client .common .client = client
44- client .Status = (* statusService )(& client .common )
43+ client .PaymentMethod = (* paymentMethodService )(& client .common )
44+ client .Balance = (* balanceService )(& client .common )
45+ client .TransactionIntent = (* transactionIntentService )(& client .common )
4546 return client
4647}
4748
4849// newRequest creates an API request. A relative URL can be provided in uri,
4950// in which case it is resolved relative to the BaseURL of the Client.
5051// URI's should always be specified without a preceding slash.
51- func (client * Client ) newRequest (ctx context.Context , method , uri string , body interface {} ) (* http.Request , error ) {
52+ func (client * Client ) newRequest (ctx context.Context , method , uri string , body any ) (* http.Request , error ) {
5253 var buf io.ReadWriter
5354 if body != nil {
5455 buf = & bytes.Buffer {}
@@ -68,9 +69,7 @@ func (client *Client) newRequest(ctx context.Context, method, uri string, body i
6869 req .Header .Set ("Content-Type" , "application/json" )
6970 req .Header .Set ("Accept" , "application/json" )
7071
71- if client .delay > 0 {
72- client .addURLParams (req , map [string ]string {"sleep" : strconv .Itoa (client .delay )})
73- }
72+ req .SetBasicAuth (client .secretKey , "" )
7473
7574 return req , nil
7675}
@@ -103,7 +102,7 @@ func (client *Client) do(req *http.Request) (*Response, error) {
103102 return resp , err
104103 }
105104
106- _ , err = io .Copy (ioutil .Discard , httpResponse .Body )
105+ _ , err = io .Copy (io .Discard , httpResponse .Body )
107106 if err != nil {
108107 return resp , err
109108 }
@@ -120,7 +119,7 @@ func (client *Client) newResponse(httpResponse *http.Response) (*Response, error
120119 resp := new (Response )
121120 resp .HTTPResponse = httpResponse
122121
123- buf , err := ioutil .ReadAll (resp .HTTPResponse .Body )
122+ buf , err := io .ReadAll (resp .HTTPResponse .Body )
124123 if err != nil {
125124 return nil , err
126125 }
0 commit comments