@@ -11,16 +11,39 @@ import (
1111
1212// Client returns a configured Resty client with base URL and auth token
1313func Client () * resty.Client {
14- baseURL := config .Cfg .APIBaseUrl
15-
1614 client := resty .New ().
17- SetBaseURL (baseURL ).
15+ SetBaseURL (config . Cfg . APIBaseUrl ).
1816 SetHeader ("Content-Type" , "application/json" ).
1917 SetHeader ("Accept" , "application/json" )
2018
2119 return client
2220}
2321
22+ func SandboxClient () (* resty.Client , error ) {
23+ if config .Cfg .SandboxAPIBaseUrl == "" {
24+ return nil , fmt .Errorf ("sandbox_api_base_url is required for sandbox tools" )
25+ }
26+
27+ client := resty .New ().
28+ SetBaseURL (config .Cfg .SandboxAPIBaseUrl ).
29+ SetHeader ("Content-Type" , "application/json" ).
30+ SetHeader ("Accept" , "application/json" )
31+
32+ return client , nil
33+ }
34+
35+ func setAuth (req * resty.Request , authMethod string , authValue string ) error {
36+ switch authMethod {
37+ case "api-key" :
38+ req .SetHeader ("X-Api-Key" , authValue )
39+ case "bearer-token" :
40+ req .SetHeader ("X-Access-Token" , authValue )
41+ default :
42+ return fmt .Errorf ("unsupported auth method: %s" , authMethod )
43+ }
44+ return nil
45+ }
46+
2447// Get makes a GET request with authentication
2548func Get (path string , queryParams map [string ]string , authMethod string , authValue string ) (* resty.Response , error ) {
2649 req := Client ().R ()
@@ -180,3 +203,69 @@ func DeleteWithBody(path string, body interface{}, authMethod string, authValue
180203
181204 return resp , nil
182205}
206+
207+ // SandboxPost makes a POST request to the sandbox API with authentication.
208+ func SandboxPost (path string , body interface {}, authMethod string , authValue string ) (* resty.Response , error ) {
209+ client , err := SandboxClient ()
210+ if err != nil {
211+ return nil , err
212+ }
213+ req := client .R ().SetBody (body )
214+ if err := setAuth (req , authMethod , authValue ); err != nil {
215+ return nil , err
216+ }
217+
218+ resp , err := req .Post (path )
219+ if err != nil {
220+ return nil , fmt .Errorf ("sandbox POST request failed: %w" , err )
221+ }
222+ if resp .IsError () {
223+ return resp , fmt .Errorf ("sandbox API error (status %d)" , resp .StatusCode ())
224+ }
225+
226+ return resp , nil
227+ }
228+
229+ // SandboxPatch makes a PATCH request to the sandbox API with authentication.
230+ func SandboxPatch (path string , body interface {}, authMethod string , authValue string ) (* resty.Response , error ) {
231+ client , err := SandboxClient ()
232+ if err != nil {
233+ return nil , err
234+ }
235+ req := client .R ().SetBody (body )
236+ if err := setAuth (req , authMethod , authValue ); err != nil {
237+ return nil , err
238+ }
239+
240+ resp , err := req .Patch (path )
241+ if err != nil {
242+ return nil , fmt .Errorf ("sandbox PATCH request failed: %w" , err )
243+ }
244+ if resp .IsError () {
245+ return resp , fmt .Errorf ("sandbox API error (status %d)" , resp .StatusCode ())
246+ }
247+
248+ return resp , nil
249+ }
250+
251+ // SandboxDelete makes a DELETE request to the sandbox API with authentication.
252+ func SandboxDelete (path string , authMethod string , authValue string ) (* resty.Response , error ) {
253+ client , err := SandboxClient ()
254+ if err != nil {
255+ return nil , err
256+ }
257+ req := client .R ()
258+ if err := setAuth (req , authMethod , authValue ); err != nil {
259+ return nil , err
260+ }
261+
262+ resp , err := req .Delete (path )
263+ if err != nil {
264+ return nil , fmt .Errorf ("sandbox DELETE request failed: %w" , err )
265+ }
266+ if resp .IsError () {
267+ return resp , fmt .Errorf ("sandbox API error (status %d)" , resp .StatusCode ())
268+ }
269+
270+ return resp , nil
271+ }
0 commit comments