@@ -9,15 +9,18 @@ import (
99)
1010
1111func NewClient (clientID , secret string , environment environmentURL ) client {
12- return client {clientID , secret , environment }
12+ return client {clientID , secret , environment , & http. Client {} }
1313}
1414
1515type client struct {
1616 clientID string
1717 secret string
1818 environment environmentURL
19+ httpClient * http.Client
1920}
2021
22+ var userAgent = "plaid-go"
23+
2124type environmentURL string
2225
2326var Tartan environmentURL = "https://tartan.plaid.com"
@@ -133,6 +136,7 @@ type deleteResponse struct {
133136 Message string `json:"message"`
134137}
135138
139+ // getAndUnmarshal is not a method because no client authentication is required
136140func getAndUnmarshal (environment environmentURL , endpoint string , structure interface {}) error {
137141 res , err := http .Get (string (environment ) + endpoint )
138142 if err != nil {
@@ -160,10 +164,16 @@ func getAndUnmarshal(environment environmentURL, endpoint string, structure inte
160164 return plaidErr
161165}
162166
163- func postAndUnmarshal ( environment environmentURL , endpoint string ,
167+ func ( c client ) postAndUnmarshal ( endpoint string ,
164168 body io.Reader ) (* postResponse , * mfaResponse , error ) {
165169 // Read response body
166- res , err := http .Post (string (environment )+ endpoint , "application/json" , body )
170+ req , err := http .NewRequest ("POST" , string (c .environment )+ endpoint , body )
171+ if err != nil {
172+ return nil , nil , err
173+ }
174+ req .Header .Add ("Content-Type" , "application/json" )
175+ req .Header .Add ("User-Agent" , "plaid-go" )
176+ res , err := c .httpClient .Do (req )
167177 if err != nil {
168178 return nil , nil , err
169179 }
@@ -176,16 +186,16 @@ func postAndUnmarshal(environment environmentURL, endpoint string,
176186 return unmarshalPostMFA (res , raw )
177187}
178188
179- func patchAndUnmarshal ( environment environmentURL , endpoint string ,
189+ func ( c client ) patchAndUnmarshal ( endpoint string ,
180190 body io.Reader ) (* postResponse , * mfaResponse , error ) {
181191
182- httpClient := & http.Client {}
183- req , err := http .NewRequest ("PATCH" , string (environment )+ endpoint , body )
192+ req , err := http .NewRequest ("PATCH" , string (c .environment )+ endpoint , body )
184193 if err != nil {
185194 return nil , nil , err
186195 }
187196 req .Header .Add ("Content-Type" , "application/json" )
188- res , err := httpClient .Do (req )
197+ req .Header .Add ("User-Agent" , "plaid-go" )
198+ res , err := c .httpClient .Do (req )
189199 if err != nil {
190200 return nil , nil , err
191201 }
@@ -198,16 +208,16 @@ func patchAndUnmarshal(environment environmentURL, endpoint string,
198208 return unmarshalPostMFA (res , raw )
199209}
200210
201- func deleteAndUnmarshal ( environment environmentURL , endpoint string ,
211+ func ( c client ) deleteAndUnmarshal ( endpoint string ,
202212 body io.Reader ) (* deleteResponse , error ) {
203213
204- httpClient := & http.Client {}
205- req , err := http .NewRequest ("DELETE" , string (environment )+ endpoint , body )
214+ req , err := http .NewRequest ("DELETE" , string (c .environment )+ endpoint , body )
206215 if err != nil {
207216 return nil , err
208217 }
209218 req .Header .Add ("Content-Type" , "application/json" )
210- res , err := httpClient .Do (req )
219+ req .Header .Add ("User-Agent" , "plaid-go" )
220+ res , err := c .httpClient .Do (req )
211221 if err != nil {
212222 return nil , err
213223 }
0 commit comments